From 993b9a01cde7a464bd782f8dd3e5d3da7369459a Mon Sep 17 00:00:00 2001 From: BenceX100 Date: Wed, 20 Nov 2024 15:07:33 +0100 Subject: [PATCH] 1.10.1 --- pom.xml | 4 +- .../com/artillexstudios/axtrade/AxTrade.java | 6 +-- .../axtrade/api/AxTradeAPI.java | 9 +++++ .../api/events/AxTradeRequestEvent.java | 1 - .../currencyconverter/CurrencyConverter.java | 40 ------------------- .../axtrade/hooks/HookManager.java | 4 +- .../listeners/EntityInteractListener.java | 6 +-- .../artillexstudios/axtrade/trade/Trade.java | 6 ++- .../axtrade/trade/TradeGui.java | 24 +++++------ .../axtrade/trade/TradeTicker.java | 2 +- .../axtrade/utils/ShulkerUtils.java | 1 + 11 files changed, 35 insertions(+), 68 deletions(-) delete mode 100644 src/main/java/com/artillexstudios/axtrade/currencyconverter/CurrencyConverter.java diff --git a/pom.xml b/pom.xml index 13b5f53..ada781d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.artillexstudios AxTrade - 1.10.0 + 1.10.1 jar AxTrade @@ -116,7 +116,7 @@ com.artillexstudios.axapi axapi - 1.4.396 + 1.4.403 compile all diff --git a/src/main/java/com/artillexstudios/axtrade/AxTrade.java b/src/main/java/com/artillexstudios/axtrade/AxTrade.java index 08a007e..b26416a 100644 --- a/src/main/java/com/artillexstudios/axtrade/AxTrade.java +++ b/src/main/java/com/artillexstudios/axtrade/AxTrade.java @@ -12,7 +12,6 @@ import com.artillexstudios.axapi.utils.FeatureFlags; import com.artillexstudios.axapi.utils.MessageUtils; import com.artillexstudios.axapi.utils.StringUtils; import com.artillexstudios.axtrade.commands.Commands; -import com.artillexstudios.axtrade.currencyconverter.CurrencyConverter; import com.artillexstudios.axtrade.hooks.HookManager; import com.artillexstudios.axtrade.lang.LanguageManager; import com.artillexstudios.axtrade.listeners.EntityInteractListener; @@ -54,7 +53,6 @@ public final class AxTrade extends AxPlugin { CONFIG = new Config(new File(getDataFolder(), "config.yml"), getResource("config.yml"), GeneralSettings.builder().setUseDefaults(false).build(), LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setKeepAll(true).setVersioning(new BasicVersioning("version")).build()); GUIS = new Config(new File(getDataFolder(), "guis.yml"), getResource("guis.yml"), GeneralSettings.builder().setUseDefaults(false).build(), LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setKeepAll(true).setVersioning(new BasicVersioning("version")).build()); LANG = new Config(new File(getDataFolder(), "lang.yml"), getResource("lang.yml"), GeneralSettings.builder().setUseDefaults(false).build(), LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setKeepAll(true).setVersioning(new BasicVersioning("version")).build()); - new CurrencyConverter(new Config(new File(getDataFolder(), "currencies.yml"))); HOOKS = new Config(new File(getDataFolder(), "currencies.yml"), getResource("currencies.yml"), GeneralSettings.builder().setUseDefaults(false).build(), LoaderSettings.builder().setAutoUpdate(true).build(), DumperSettings.DEFAULT, UpdaterSettings.builder().setKeepAll(true).setVersioning(new BasicVersioning("version")).build()); TOGGLED = new Config(new File(getDataFolder(), "toggled.yml"), getResource("toggled.yml"), GeneralSettings.builder().setUseDefaults(false).build(), LoaderSettings.DEFAULT, DumperSettings.DEFAULT, UpdaterSettings.DEFAULT); @@ -69,10 +67,10 @@ public final class AxTrade extends AxPlugin { getServer().getPluginManager().registerEvents(new EntityInteractListener(), this); getServer().getPluginManager().registerEvents(new TradeListeners(), this); - new HookManager().setupHooks(); + HookManager.setupHooks(); NumberUtils.reload(); - new TradeTicker().start(); + TradeTicker.start(); Commands.registerCommand(); diff --git a/src/main/java/com/artillexstudios/axtrade/api/AxTradeAPI.java b/src/main/java/com/artillexstudios/axtrade/api/AxTradeAPI.java index b0c944a..7619c80 100644 --- a/src/main/java/com/artillexstudios/axtrade/api/AxTradeAPI.java +++ b/src/main/java/com/artillexstudios/axtrade/api/AxTradeAPI.java @@ -1,4 +1,13 @@ package com.artillexstudios.axtrade.api; +import com.artillexstudios.axtrade.hooks.HookManager; +import com.artillexstudios.axtrade.hooks.currency.CurrencyHook; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + public class AxTradeAPI { + + public static void registerCurrencyHook(@NotNull Plugin plugin, @NotNull CurrencyHook currencyHook) { + HookManager.registerCurrencyHook(plugin, currencyHook); + } } diff --git a/src/main/java/com/artillexstudios/axtrade/api/events/AxTradeRequestEvent.java b/src/main/java/com/artillexstudios/axtrade/api/events/AxTradeRequestEvent.java index 6a3acab..72841a1 100644 --- a/src/main/java/com/artillexstudios/axtrade/api/events/AxTradeRequestEvent.java +++ b/src/main/java/com/artillexstudios/axtrade/api/events/AxTradeRequestEvent.java @@ -44,5 +44,4 @@ public class AxTradeRequestEvent extends Event implements Cancellable { public Player getReceiver() { return receiver; } - } \ No newline at end of file diff --git a/src/main/java/com/artillexstudios/axtrade/currencyconverter/CurrencyConverter.java b/src/main/java/com/artillexstudios/axtrade/currencyconverter/CurrencyConverter.java deleted file mode 100644 index 45c3245..0000000 --- a/src/main/java/com/artillexstudios/axtrade/currencyconverter/CurrencyConverter.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.artillexstudios.axtrade.currencyconverter; - -import com.artillexstudios.axapi.config.Config; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class CurrencyConverter { - - public CurrencyConverter(Config config) { - if (config.getString("currencies.CoinsEngine.currency-name", null) == null) return; - - final List> coinsEngine = new ArrayList<>(); - - coinsEngine.add(Map.of( - "currency-name", config.getString("currencies.CoinsEngine.currency-name", "coins"), - "name", config.getString("currencies.CoinsEngine.name", "coins") - )); - - config.set("currencies.CoinsEngine.enabled", coinsEngine); - - config.getBackingDocument().remove("currencies.CoinsEngine.currency-name"); - config.getBackingDocument().remove("currencies.CoinsEngine.name"); - - final List> ultraEconomy = new ArrayList<>(); - - ultraEconomy.add(Map.of( - "currency-name", config.getString("currencies.UltraEconomy.currency-name", "coins"), - "name", config.getString("currencies.UltraEconomy.name", "coins") - )); - - config.set("currencies.UltraEconomy.enabled", ultraEconomy); - - config.getBackingDocument().remove("currencies.UltraEconomy.currency-name"); - config.getBackingDocument().remove("currencies.UltraEconomy.name"); - - config.save(); - } -} diff --git a/src/main/java/com/artillexstudios/axtrade/hooks/HookManager.java b/src/main/java/com/artillexstudios/axtrade/hooks/HookManager.java index 9e9adf6..305a96f 100644 --- a/src/main/java/com/artillexstudios/axtrade/hooks/HookManager.java +++ b/src/main/java/com/artillexstudios/axtrade/hooks/HookManager.java @@ -31,11 +31,11 @@ import static com.artillexstudios.axtrade.AxTrade.HOOKS; public class HookManager { private static final ArrayList currency = new ArrayList<>(); - public void setupHooks() { + public static void setupHooks() { updateHooks(); } - public void updateHooks() { + public static void updateHooks() { currency.removeIf(currencyHook -> !currencyHook.isPersistent()); if (HOOKS.getBoolean("currencies.Experience.register", true)) diff --git a/src/main/java/com/artillexstudios/axtrade/listeners/EntityInteractListener.java b/src/main/java/com/artillexstudios/axtrade/listeners/EntityInteractListener.java index ffd4630..93026fb 100644 --- a/src/main/java/com/artillexstudios/axtrade/listeners/EntityInteractListener.java +++ b/src/main/java/com/artillexstudios/axtrade/listeners/EntityInteractListener.java @@ -1,6 +1,6 @@ package com.artillexstudios.axtrade.listeners; -import com.artillexstudios.axtrade.commands.Commands; +import com.artillexstudios.axtrade.request.Requests; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -15,7 +15,7 @@ public class EntityInteractListener implements Listener { private static final HashMap cd = new HashMap<>(); @EventHandler (ignoreCancelled = true) - public void onClick(@NotNull PlayerInteractEntityEvent event) { + public void onInteract(@NotNull PlayerInteractEntityEvent event) { if (!CONFIG.getBoolean("shift-click-send-request", true)) return; final Player player = event.getPlayer(); if (!player.hasPermission("axtrade.trade")) return; @@ -28,7 +28,7 @@ public class EntityInteractListener implements Listener { cd.put(player, System.currentTimeMillis()); if (!sendTo.isOnline()) return; - new Commands().trade(player, sendTo); + Requests.addRequest(player, sendTo); } public static void onQuit(Player player) { diff --git a/src/main/java/com/artillexstudios/axtrade/trade/Trade.java b/src/main/java/com/artillexstudios/axtrade/trade/Trade.java index e366211..05812ac 100644 --- a/src/main/java/com/artillexstudios/axtrade/trade/Trade.java +++ b/src/main/java/com/artillexstudios/axtrade/trade/Trade.java @@ -20,7 +20,7 @@ import static com.artillexstudios.axtrade.AxTrade.MESSAGEUTILS; public class Trade { protected final TradePlayer player1; protected final TradePlayer player2; - protected boolean ended = false; + private boolean ended = false; protected long prepTime = System.currentTimeMillis(); public Trade(Player p1, Player p2) { @@ -163,4 +163,8 @@ public class Trade { public Player getOtherPlayer(Player player) { return player1.getPlayer().equals(player) ? player2.getPlayer() : player1.getPlayer(); } + + public boolean isEnded() { + return ended; + } } diff --git a/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java b/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java index cd76242..0773c65 100644 --- a/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java +++ b/src/main/java/com/artillexstudios/axtrade/trade/TradeGui.java @@ -2,7 +2,6 @@ package com.artillexstudios.axtrade.trade; import com.artillexstudios.axapi.gui.SignInput; import com.artillexstudios.axapi.nms.NMSHandlers; -import com.artillexstudios.axapi.scheduler.ScheduledTask; import com.artillexstudios.axapi.scheduler.Scheduler; import com.artillexstudios.axapi.utils.StringUtils; import com.artillexstudios.axtrade.utils.BlackListUtils; @@ -25,7 +24,6 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.function.Consumer; import static com.artillexstudios.axtrade.AxTrade.GUIS; import static com.artillexstudios.axtrade.AxTrade.LANG; @@ -76,16 +74,13 @@ public class TradeGui extends GuiFrame { final BaseGui shulkerGui = Gui.storage().rows(3).title(StringUtils.format(Utils.getFormattedItemName(event.getCurrentItem()))).disableAllInteractions().create(); shulkerGui.getInventory().setContents(ShulkerUtils.getShulkerContents(event.getCurrentItem())); - shulkerGui.setCloseGuiAction(shulkerEvent -> Scheduler.get().run(new Consumer<>() { - @Override - public void accept(ScheduledTask scheduledTask) { - if (trade.ended) return; - trade.prepTime = System.currentTimeMillis(); - gui.open(player.getPlayer()); - inSign = false; - trade.update(); - updateTitle(); - } + shulkerGui.setCloseGuiAction(e -> Scheduler.get().run(t -> { + if (trade.isEnded()) return; + trade.prepTime = System.currentTimeMillis(); + gui.open(player.getPlayer()); + inSign = false; + trade.update(); + updateTitle(); })); shulkerGui.open(player.getPlayer()); return; @@ -150,7 +145,7 @@ public class TradeGui extends GuiFrame { trade.abort(); }); - if (trade.ended) return; + if (trade.isEnded()) return; update(); gui.open(player.getPlayer()); @@ -200,7 +195,7 @@ public class TradeGui extends GuiFrame { lines.set(0, Component.empty()); var sign = new SignInput.Builder().setLines(lines).setHandler((player1, result) -> { - if (trade.ended) return; + if (trade.isEnded()) return; trade.prepTime = System.currentTimeMillis(); String am = PlainTextComponentSerializer.plainText().serialize(result[0]); TradePlayer.Result addResult = player.setCurrency(currencyStr, am); @@ -217,6 +212,7 @@ public class TradeGui extends GuiFrame { } } Scheduler.get().run(scheduledTask -> { + if (trade.isEnded()) return; gui.open(player.getPlayer()); inSign = false; trade.update(); diff --git a/src/main/java/com/artillexstudios/axtrade/trade/TradeTicker.java b/src/main/java/com/artillexstudios/axtrade/trade/TradeTicker.java index bc5bb4e..2a899af 100644 --- a/src/main/java/com/artillexstudios/axtrade/trade/TradeTicker.java +++ b/src/main/java/com/artillexstudios/axtrade/trade/TradeTicker.java @@ -12,7 +12,7 @@ import static com.artillexstudios.axtrade.AxTrade.MESSAGEUTILS; public class TradeTicker { - public void start() { + public static void start() { Scheduler.get().runTimer(scheduledTask -> { for (Trade trade : Trades.getTrades()) { if (!(trade.player1.hasConfirmed() && trade.player2.hasConfirmed())) continue; diff --git a/src/main/java/com/artillexstudios/axtrade/utils/ShulkerUtils.java b/src/main/java/com/artillexstudios/axtrade/utils/ShulkerUtils.java index 011eabd..f5609b2 100644 --- a/src/main/java/com/artillexstudios/axtrade/utils/ShulkerUtils.java +++ b/src/main/java/com/artillexstudios/axtrade/utils/ShulkerUtils.java @@ -13,6 +13,7 @@ public class ShulkerUtils { public static ItemStack[] getShulkerContents(@NotNull ItemStack item) { if (!(item.getItemMeta() instanceof BlockStateMeta meta)) return new ItemStack[0]; if (meta.getBlockState() instanceof ShulkerBox shulker) { + // axshulkers viewer compatibility if (ClassUtils.INSTANCE.classExists("com.artillexstudios.axshulkers.utils.ShulkerUtils") && com.artillexstudios.axshulkers.utils.ShulkerUtils.getShulkerUUID(item) != null) { return com.artillexstudios.axshulkers.AxShulkers.getDB().getShulker(com.artillexstudios.axshulkers.utils.ShulkerUtils.getShulkerUUID(item)); }