Skip to content

Commit

Permalink
feat(SkinHandler): SkinsRestorer custom skins hook
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeV220 committed Mar 17, 2023
1 parent 2dc6ab2 commit 5762022
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ allprojects {
compileOnly "org.bstats:bstats-velocity:3.0.1"
compileOnly "org.bstats:bstats-sponge:3.0.1"

compileOnly 'net.skinsrestorer:skinsrestorer-api:14.2.8'

compileOnly 'org.apache.logging.log4j:log4j-api:2.20.0'
compileOnly 'net.kyori:adventure-api:4.12.0'
compileOnly 'net.kyori:adventure-text-serializer-legacy:4.13.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.skinoverlay.handler.SkinHandler.SkinHandler_;
import com.georgev22.skinoverlay.handler.handlers.*;
import com.georgev22.skinoverlay.hook.hooks.SkinsRestorerHook;
import com.georgev22.skinoverlay.listeners.bukkit.DeveloperInformListener;
import com.georgev22.skinoverlay.listeners.bukkit.PlayerListeners;
import com.georgev22.skinoverlay.utilities.OptionsUtil;
Expand Down Expand Up @@ -77,6 +78,14 @@ public void onEnable() {
case UNKNOWN -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_());
default -> SkinOverlay.getInstance().setSkinHandler(new SkinHandler_Legacy());
}
switch (OptionsUtil.SKIN_HOOK.getStringValue()) {
case "SkinsRestorer" -> {
if (getServer().getPluginManager().isPluginEnabled("SkinsRestorer")) {
SkinOverlay.getInstance().setSkinHook(new SkinsRestorerHook());
}
}
default -> SkinOverlay.getInstance().setSkinHook(null);
}
SkinOverlay.getInstance().setCommandManager(new PaperCommandManager(this));
SkinOverlay.getInstance().onEnable();
SkinOverlay.getInstance().setupCommands();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.library.utilities.Utils;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.hook.hooks.SkinsRestorerHook;
import com.georgev22.skinoverlay.listeners.bungee.DeveloperInformListener;
import com.georgev22.skinoverlay.listeners.bungee.PlayerListeners;
import com.georgev22.skinoverlay.utilities.BungeeCordPluginMessageUtils;
Expand Down Expand Up @@ -104,6 +105,14 @@ protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
return gameProfile;
}
});
switch (OptionsUtil.SKIN_HOOK.getStringValue()) {
case "SkinsRestorer" -> {
if (getProxy().getPluginManager().getPlugin("SkinsRestorer") != null) {
SkinOverlay.getInstance().setSkinHook(new SkinsRestorerHook());
}
}
default -> SkinOverlay.getInstance().setSkinHook(null);
}
SkinOverlay.getInstance().setCommandManager(new BungeeCommandManager(this));
SkinOverlay.getInstance().onEnable();
SkinOverlay.getInstance().setupCommands();
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/com/georgev22/skinoverlay/SkinOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.georgev22.skinoverlay.commands.SkinOverlayCommand;
import com.georgev22.skinoverlay.config.FileManager;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.hook.SkinHook;
import com.georgev22.skinoverlay.utilities.MessagesUtil;
import com.georgev22.skinoverlay.utilities.OptionsUtil;
import com.georgev22.skinoverlay.utilities.Updater;
Expand Down Expand Up @@ -42,6 +43,10 @@ public class SkinOverlay {
@Setter
private SkinHandler skinHandler;

@Getter
@Setter
private SkinHook skinHook;

@Getter
private FileManager fileManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ public Property getXUIDSkin(final String xuid) throws IOException {
* @throws InterruptedException When a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted
*/
public Property getJavaSkin(final PlayerObject playerObject) throws IOException, ExecutionException, InterruptedException {
if (skinOverlay.getSkinHook() != null) {
return skinOverlay.getSkinHook().getProperty(playerObject);
}
final JsonElement json = JsonParser.parseString(new String(this.getProfileBytes(playerObject, null)));
final JsonArray properties = json.getAsJsonObject().get("properties").getAsJsonArray();
Property property = null;
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/com/georgev22/skinoverlay/hook/SkinHook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.georgev22.skinoverlay.hook;

import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.mojang.authlib.properties.Property;
import org.jetbrains.annotations.NotNull;

public interface SkinHook {

Property getProperty(@NotNull PlayerObject playerObject);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.georgev22.skinoverlay.hook.hooks;

import com.georgev22.skinoverlay.hook.SkinHook;
import com.georgev22.skinoverlay.utilities.player.PlayerObject;
import com.mojang.authlib.properties.Property;
import net.skinsrestorer.api.SkinsRestorerAPI;
import net.skinsrestorer.api.property.IProperty;
import org.jetbrains.annotations.NotNull;

public class SkinsRestorerHook implements SkinHook {


private final SkinsRestorerAPI skinsRestorerAPI;

public SkinsRestorerHook() {
skinsRestorerAPI = SkinsRestorerAPI.getApi();
}

@Override
public Property getProperty(@NotNull PlayerObject playerObject) {
IProperty iProperty = skinsRestorerAPI.getSkinData(skinsRestorerAPI.getSkinName(playerObject.playerName()));
if (iProperty == null) {
throw new RuntimeException();
}
return new Property(iProperty.getName(), iProperty.getValue(), iProperty.getSignature());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public enum OptionsUtil {

OVERLAY_HAT("overlays.%s.hat", false, Optional.empty()),
DEFAULT_SKIN_UUID("default skin uuid", "8667ba71-b85a-4004-af54-457a9734eed7", Optional.empty()),
SKIN_HOOK("skin hook", "SkinsRestorer", Optional.empty()),
;
private static final SkinOverlay mainPlugin = SkinOverlay.getInstance();
private final String pathName;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Options:
password: "yourpassword"
database: "skinoverlay"
collection: "skinoverlay_users"
#Skin hooks are only used to retrieve player skin properties for offline players or players who have changed their skin.
#Currently available Skin Hooks: None, SkinsRestorer and Custom.
#With the custom option, you need to have your own plugin that sets the SkinOverlay.getInstance().setSkinHook(SkinHook).
skin hook: None
overlays:
policeman:
hat: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.georgev22.library.scheduler.SchedulerManager;
import com.georgev22.library.utilities.Utils;
import com.georgev22.skinoverlay.handler.SkinHandler;
import com.georgev22.skinoverlay.hook.hooks.SkinsRestorerHook;
import com.georgev22.skinoverlay.listeners.velocity.DeveloperInformListener;
import com.georgev22.skinoverlay.listeners.velocity.PlayerListeners;
import com.georgev22.skinoverlay.utilities.OptionsUtil;
Expand Down Expand Up @@ -139,6 +140,14 @@ protected <T> GameProfile getGameProfile0(@NotNull PlayerObject playerObject) {
return gameProfile;
}
});
switch (OptionsUtil.SKIN_HOOK.getStringValue()) {
case "SkinsRestorer" -> {
if (getProxy().getPluginManager().getPlugin("skinsrestorer").isPresent()) {
SkinOverlay.getInstance().setSkinHook(new SkinsRestorerHook());
}
}
default -> SkinOverlay.getInstance().setSkinHook(null);
}
SkinOverlay.getInstance().setCommandManager(new VelocityCommandManager(getProxy(), this, dataFolder()));
SkinOverlay.getInstance().onEnable();
SkinOverlay.getInstance().setupCommands();
Expand Down

0 comments on commit 5762022

Please sign in to comment.