From 52061b7b516db3f88707dfe86257b76e485ec7f1 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 1 Jul 2021 22:29:53 +0100 Subject: [PATCH] Reverted proxy changes --- .../main/java/com/willfp/eco/core/EcoPlugin.java | 13 ------------- .../java/com/willfp/eco/internal/Internals.java | 4 ---- .../java/com/willfp/eco/spigot/EcoInternals.java | 10 ---------- .../java/com/willfp/eco/spigot/EcoSpigotPlugin.java | 6 +++--- .../main/java/com/willfp/eco/spigot/ProxyUtils.java | 13 +++++++++++++ .../willfp/eco/spigot/display/PacketAutoRecipe.java | 3 ++- .../com/willfp/eco/spigot/display/PacketChat.java | 3 ++- .../spigot/display/PacketOpenWindowMerchant.java | 3 ++- 8 files changed, 22 insertions(+), 33 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/ProxyUtils.java diff --git a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java index 9c4f1027..be5d658c 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java +++ b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java @@ -13,7 +13,6 @@ import com.willfp.eco.core.factory.NamespacedKeyFactory; import com.willfp.eco.core.factory.RunnableFactory; import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.core.integrations.placeholder.PlaceholderManager; -import com.willfp.eco.core.proxy.AbstractProxy; import com.willfp.eco.core.scheduling.Scheduler; import com.willfp.eco.internal.Internals; import com.willfp.eco.internal.UpdateChecker; @@ -608,18 +607,6 @@ public abstract class EcoPlugin extends JavaPlugin { return "5.0.0"; } - /** - * Get the implementation of a specified proxy. - * - * @param proxyClass The proxy interface. - * @param The type of the proxy. - * @return The proxy implementation. - */ - public @NotNull - final T getProxy(@NotNull final Class proxyClass) { - return Internals.getInstance().getProxy(this, proxyClass); - } - /** * Get the plugin's logger. * diff --git a/eco-api/src/main/java/com/willfp/eco/internal/Internals.java b/eco-api/src/main/java/com/willfp/eco/internal/Internals.java index 181ff49d..b5b7bf5c 100644 --- a/eco-api/src/main/java/com/willfp/eco/internal/Internals.java +++ b/eco-api/src/main/java/com/willfp/eco/internal/Internals.java @@ -1,7 +1,6 @@ package com.willfp.eco.internal; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.proxy.AbstractProxy; import org.jetbrains.annotations.NotNull; public abstract class Internals { @@ -13,9 +12,6 @@ public abstract class Internals { public abstract EcoPlugin getPlugin(); - public @NotNull abstract T getProxy(@NotNull EcoPlugin plugin, - @NotNull Class proxyClass); - public static Internals getInstance() { return internals; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoInternals.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoInternals.java index dcefa629..3ee3a138 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoInternals.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoInternals.java @@ -1,9 +1,6 @@ package com.willfp.eco.spigot; -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.proxy.AbstractProxy; import com.willfp.eco.internal.Internals; -import com.willfp.eco.proxy.util.ProxyFactory; import org.jetbrains.annotations.NotNull; public class EcoInternals extends Internals { @@ -17,11 +14,4 @@ public class EcoInternals extends Internals { public EcoSpigotPlugin getPlugin() { return plugin; } - - @Override - @NotNull - public T getProxy(@NotNull final EcoPlugin plugin, - @NotNull final Class proxyClass) { - return new ProxyFactory<>(plugin, proxyClass).getProxy(); - } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java index d9a27576..f8f99241 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java @@ -72,13 +72,13 @@ public class EcoSpigotPlugin extends EcoPlugin { Internals.setInterfacing(new EcoInternals(this)); Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized")); - SkullProxy skullProxy = instance.getProxy(SkullProxy.class); + SkullProxy skullProxy = ProxyUtils.getProxy(SkullProxy.class); SkullUtils.initialize(skullProxy::setSkullTexture); - BlockBreakProxy blockBreakProxy = instance.getProxy(BlockBreakProxy.class); + BlockBreakProxy blockBreakProxy = ProxyUtils.getProxy(BlockBreakProxy.class); BlockUtils.initialize(blockBreakProxy::breakBlock); - TridentStackProxy tridentStackProxy = instance.getProxy(TridentStackProxy.class); + TridentStackProxy tridentStackProxy = ProxyUtils.getProxy(TridentStackProxy.class); TridentUtils.initialize(tridentStackProxy::getTridentStack); this.dataJson = new DataJson(this); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/ProxyUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/ProxyUtils.java new file mode 100644 index 00000000..b558dc30 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/ProxyUtils.java @@ -0,0 +1,13 @@ +package com.willfp.eco.spigot; + +import com.willfp.eco.core.proxy.AbstractProxy; +import com.willfp.eco.proxy.util.ProxyFactory; +import lombok.experimental.UtilityClass; +import org.jetbrains.annotations.NotNull; + +@UtilityClass +public class ProxyUtils { + public T getProxy(@NotNull final Class proxy) { + return new ProxyFactory<>(EcoSpigotPlugin.getInstance(), proxy).getProxy(); + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketAutoRecipe.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketAutoRecipe.java index d3206444..0a1fa87b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketAutoRecipe.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketAutoRecipe.java @@ -6,6 +6,7 @@ import com.comphenix.protocol.events.PacketContainer; import com.willfp.eco.core.AbstractPacketAdapter; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.proxy.proxies.AutoCraftProxy; +import com.willfp.eco.spigot.ProxyUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -33,7 +34,7 @@ public class PacketAutoRecipe extends AbstractPacketAdapter { } try { - this.getPlugin().getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle()); + ProxyUtils.getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle()); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketChat.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketChat.java index 78a8d2a8..6bf91ae5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketChat.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketChat.java @@ -7,6 +7,7 @@ import com.comphenix.protocol.wrappers.WrappedChatComponent; import com.willfp.eco.core.AbstractPacketAdapter; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.proxy.proxies.ChatComponentProxy; +import com.willfp.eco.spigot.ProxyUtils; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -33,7 +34,7 @@ public class PacketChat extends AbstractPacketAdapter { return; } - WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(this.getPlugin().getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle())); + WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(ProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle())); packet.getChatComponents().write(i, newComponent); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketOpenWindowMerchant.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketOpenWindowMerchant.java index 0f496550..da59c9bd 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketOpenWindowMerchant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/display/PacketOpenWindowMerchant.java @@ -7,6 +7,7 @@ import com.comphenix.protocol.events.PacketEvent; import com.willfp.eco.core.AbstractPacketAdapter; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.proxy.proxies.VillagerTradeProxy; +import com.willfp.eco.spigot.ProxyUtils; import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemFlag; @@ -47,7 +48,7 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter { } for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) { - MerchantRecipe newRecipe = this.getPlugin().getProxy(VillagerTradeProxy.class).displayTrade(recipe); + MerchantRecipe newRecipe = ProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe); recipes.add(newRecipe); }