diff --git a/build.gradle b/build.gradle index e051917..8a7413c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ allprojects { group 'com.azuriom' - version '1.3.2' + version '1.3.3' } subprojects { diff --git a/bukkit/build.gradle b/bukkit/build.gradle index f63d800..0e0d5ce 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -11,7 +11,7 @@ dependencies { compileOnly 'io.netty:netty-all:4.1.25.Final' compileOnly 'fr.xephi:authme:5.6.0-beta2' compileOnly 'me.clip:placeholderapi:2.11.1' - compileOnly 'net.skinsrestorer:skinsrestorer-api:14.2.3' + compileOnly 'net.skinsrestorer:skinsrestorer-api:15.0.2' } // Folia is compiled with Java 17 diff --git a/bukkit/src/main/java/com/azuriom/azlink/bukkit/AzLinkBukkitPlugin.java b/bukkit/src/main/java/com/azuriom/azlink/bukkit/AzLinkBukkitPlugin.java index a042b87..98d0322 100644 --- a/bukkit/src/main/java/com/azuriom/azlink/bukkit/AzLinkBukkitPlugin.java +++ b/bukkit/src/main/java/com/azuriom/azlink/bukkit/AzLinkBukkitPlugin.java @@ -87,7 +87,13 @@ && getServer().getPluginManager().getPlugin("AuthMe") != null) { if (getConfig().getBoolean("skinrestorer-integration") && getServer().getPluginManager().getPlugin("SkinsRestorer") != null) { - getServer().getPluginManager().registerEvents(new SkinRestorerIntegration(this), this); + try { + Class.forName("net.skinsrestorer.api.SkinsRestorer"); + + getServer().getPluginManager().registerEvents(new SkinRestorerIntegration(this), this); + } catch (ClassNotFoundException e) { + getLogger().severe("SkinsRestorer integration requires SkinsRestorer v15.0.0 or higher"); + } } if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) { diff --git a/bukkit/src/main/java/com/azuriom/azlink/bukkit/injector/NettyLibraryLoader.java b/bukkit/src/main/java/com/azuriom/azlink/bukkit/injector/NettyLibraryLoader.java index 6c9e542..99fcc65 100644 --- a/bukkit/src/main/java/com/azuriom/azlink/bukkit/injector/NettyLibraryLoader.java +++ b/bukkit/src/main/java/com/azuriom/azlink/bukkit/injector/NettyLibraryLoader.java @@ -62,12 +62,11 @@ private void loadLibrary(String groupId, String artifactId, String version) thro } URL[] urls = {jar.toUri().toURL()}; - ClassLoader pluginClassLoader = plugin.getClass().getClassLoader(); - Field classLoaderField = pluginClassLoader.getClass().getDeclaredField("libraryLoader"); - ClassLoader libraryLoader = new URLClassLoader(urls, pluginClassLoader.getParent()); + ClassLoader classLoader = plugin.getClass().getClassLoader(); + Field classLoaderField = classLoader.getClass().getDeclaredField("libraryLoader"); classLoaderField.setAccessible(true); - classLoaderField.set(pluginClassLoader, libraryLoader); + classLoaderField.set(classLoader, new URLClassLoader(urls, classLoader.getParent())); } private String identifyNettyVersion() { diff --git a/bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/SkinRestorerIntegration.java b/bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/SkinRestorerIntegration.java index 12ed843..8823ccb 100644 --- a/bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/SkinRestorerIntegration.java +++ b/bukkit/src/main/java/com/azuriom/azlink/bukkit/integrations/SkinRestorerIntegration.java @@ -1,10 +1,11 @@ package com.azuriom.azlink.bukkit.integrations; import com.azuriom.azlink.bukkit.AzLinkBukkitPlugin; -import net.skinsrestorer.api.PlayerWrapper; -import net.skinsrestorer.api.SkinsRestorerAPI; -import net.skinsrestorer.api.exception.SkinRequestException; -import net.skinsrestorer.api.property.IProperty; +import net.skinsrestorer.api.SkinsRestorer; +import net.skinsrestorer.api.SkinsRestorerProvider; +import net.skinsrestorer.api.connections.model.MineSkinResponse; +import net.skinsrestorer.api.exception.DataRequestException; +import net.skinsrestorer.api.exception.MineSkinException; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -12,10 +13,12 @@ public class SkinRestorerIntegration implements Listener { + private final SkinsRestorer skinsRestorer; private final AzLinkBukkitPlugin plugin; public SkinRestorerIntegration(AzLinkBukkitPlugin plugin) { this.plugin = plugin; + this.skinsRestorer = SkinsRestorerProvider.get(); this.plugin.getLoggerAdapter().info("SkinRestorer integration enabled."); } @@ -32,10 +35,10 @@ public void onPlayerJoin(PlayerJoinEvent e) { try { String url = baseUrl + "/api/skin-api/skins/" + player.getName(); - IProperty skin = SkinsRestorerAPI.getApi().genSkinUrl(url, null); + MineSkinResponse skin = this.skinsRestorer.getMineSkinAPI().genSkin(url, null); - SkinsRestorerAPI.getApi().applySkin(new PlayerWrapper(player), skin); - } catch (SkinRequestException ex) { + this.skinsRestorer.getSkinApplier(Player.class).applySkin(player, skin.getProperty()); + } catch (DataRequestException | MineSkinException ex) { this.plugin.getLoggerAdapter().warn("Unable to apply skin for " + player.getName() + ": " + ex.getMessage()); } } diff --git a/common/src/main/java/com/azuriom/azlink/common/command/AzLinkCommand.java b/common/src/main/java/com/azuriom/azlink/common/command/AzLinkCommand.java index b0e37c1..5ce64c6 100644 --- a/common/src/main/java/com/azuriom/azlink/common/command/AzLinkCommand.java +++ b/common/src/main/java/com/azuriom/azlink/common/command/AzLinkCommand.java @@ -2,6 +2,7 @@ import com.azuriom.azlink.common.AzLinkPlugin; import com.azuriom.azlink.common.data.UserInfo; +import com.azuriom.azlink.common.users.MoneyAction; import java.io.IOException; import java.util.Arrays; @@ -14,7 +15,6 @@ public class AzLinkCommand { private static final List COMPLETIONS = Arrays.asList("status", "setup", "fetch", "money", "port"); - private static final List MONEY_ACTIONS = Arrays.asList("add", "remove", "set"); protected final AzLinkPlugin plugin; @@ -123,7 +123,8 @@ public List tabComplete(CommandSender sender, String[] args) { } if (args.length == 2 && args[0].equalsIgnoreCase("money")) { - return MONEY_ACTIONS.stream() + return Arrays.stream(MoneyAction.values()) + .map(Enum::toString) .filter(s -> startsWithIgnoreCase(s, args[1])) .collect(Collectors.toList()); } @@ -139,12 +140,13 @@ public List tabComplete(CommandSender sender, String[] args) { } public void editMoney(CommandSender sender, String[] args) throws NumberFormatException { - if (args.length < 4 || !MONEY_ACTIONS.contains(args[1].toLowerCase())) { + MoneyAction action; + + if (args.length < 4 || (action = MoneyAction.fromString(args[1])) == null) { sender.sendMessage("&cUsage: /azlink money "); return; } - String action = args[1].toLowerCase(); double amount = Double.parseDouble(args[3]); Optional user = this.plugin.getUserManager().getUserByName(args[2]); diff --git a/common/src/main/java/com/azuriom/azlink/common/http/client/HttpClient.java b/common/src/main/java/com/azuriom/azlink/common/http/client/HttpClient.java index a9ad2ee..784ad24 100644 --- a/common/src/main/java/com/azuriom/azlink/common/http/client/HttpClient.java +++ b/common/src/main/java/com/azuriom/azlink/common/http/client/HttpClient.java @@ -22,7 +22,7 @@ public class HttpClient { private static final int CONNECT_TIMEOUT = 5000; // 5 seconds - private static final int REQUEST_TIMEOUT = 1000; // 1 second + private static final int READ_TIMEOUT = 5000; // 5 seconds private final AzLinkPlugin plugin; @@ -133,7 +133,7 @@ private HttpURLConnection prepareConnection(RequestMethod method, String endpoin conn.setUseCaches(false); conn.setInstanceFollowRedirects(true); conn.setConnectTimeout(CONNECT_TIMEOUT); - conn.setReadTimeout(REQUEST_TIMEOUT); + conn.setReadTimeout(READ_TIMEOUT); conn.setRequestMethod(method.name()); conn.addRequestProperty("Azuriom-Link-Token", token); conn.addRequestProperty("Content-Type", "application/json; charset=utf-8"); diff --git a/common/src/main/java/com/azuriom/azlink/common/tasks/FetcherTask.java b/common/src/main/java/com/azuriom/azlink/common/tasks/FetcherTask.java index eb51da5..26956d0 100644 --- a/common/src/main/java/com/azuriom/azlink/common/tasks/FetcherTask.java +++ b/common/src/main/java/com/azuriom/azlink/common/tasks/FetcherTask.java @@ -8,6 +8,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; @@ -83,7 +84,7 @@ private void dispatchCommands(Map> commands) { Map players = this.plugin.getPlatform() .getOnlinePlayers() - .collect(Collectors.toMap(cs -> cs.getName().toLowerCase(), p -> p, (p1, p2) -> { + .collect(Collectors.toMap(cs -> cs.getName().toLowerCase(Locale.ROOT), p -> p, (p1, p2) -> { String player1 = p1.getName() + " (" + p1.getUuid() + ')'; String player2 = p2.getName() + " (" + p2.getUuid() + ')'; this.plugin.getLogger().warn("Duplicate players names: " + player1 + " / " + player2); @@ -92,7 +93,7 @@ private void dispatchCommands(Map> commands) { for (Map.Entry> entry : commands.entrySet()) { String playerName = entry.getKey(); - CommandSender player = players.get(playerName.toLowerCase()); + CommandSender player = players.get(playerName.toLowerCase(Locale.ROOT)); if (player != null) { playerName = player.getName(); diff --git a/common/src/main/java/com/azuriom/azlink/common/users/MoneyAction.java b/common/src/main/java/com/azuriom/azlink/common/users/MoneyAction.java new file mode 100644 index 0000000..8bb7038 --- /dev/null +++ b/common/src/main/java/com/azuriom/azlink/common/users/MoneyAction.java @@ -0,0 +1,20 @@ +package com.azuriom.azlink.common.users; + +import java.util.Locale; + +public enum MoneyAction { + ADD, REMOVE, SET; + + @Override + public String toString() { + return name().toLowerCase(Locale.ROOT); + } + + public static MoneyAction fromString(String action) { + try { + return MoneyAction.valueOf(action.toUpperCase(Locale.ROOT)); + } catch (IllegalArgumentException e) { + return null; + } + } +} \ No newline at end of file diff --git a/common/src/main/java/com/azuriom/azlink/common/users/UserManager.java b/common/src/main/java/com/azuriom/azlink/common/users/UserManager.java index 6fe544a..ac0fa81 100644 --- a/common/src/main/java/com/azuriom/azlink/common/users/UserManager.java +++ b/common/src/main/java/com/azuriom/azlink/common/users/UserManager.java @@ -25,11 +25,19 @@ public void addUser(UserInfo user) { this.usersByName.put(user.getName(), user); } - public CompletableFuture editMoney(UserInfo user, String action, double amount) { - return this.plugin.getHttpClient().editMoney(user, action, amount) + public CompletableFuture editMoney(UserInfo user, MoneyAction action, double amount) { + return this.plugin.getHttpClient().editMoney(user, action.toString(), amount) .thenApply(result -> { user.setMoney(result.getNewBalance()); return user; }); } + + /** + * @deprecated Use {@link #editMoney(UserInfo, MoneyAction, double)} instead. + */ + @Deprecated + public CompletableFuture editMoney(UserInfo user, String action, double amount) { + return editMoney(user, MoneyAction.valueOf(action.toUpperCase()), amount); + } }