Added EcoPlugin#getProxy

This commit is contained in:
Auxilor
2021-06-27 14:58:57 +01:00
parent aab1f31ca0
commit d6bec5d88b
9 changed files with 120 additions and 39 deletions

View File

@@ -1,6 +1,9 @@
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 {
@@ -14,4 +17,11 @@ public class EcoInternals extends Internals {
public EcoSpigotPlugin getPlugin() {
return plugin;
}
@Override
@NotNull
public <T extends AbstractProxy> T getProxy(@NotNull final EcoPlugin plugin,
@NotNull final Class<T> proxyClass) {
return new ProxyFactory<>(plugin, proxyClass).getProxy();
}
}

View File

@@ -71,13 +71,13 @@ public class EcoSpigotPlugin extends EcoPlugin {
instance = this;
Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized"));
SkullProxy skullProxy = InternalProxyUtils.getProxy(SkullProxy.class);
SkullProxy skullProxy = instance.getProxy(SkullProxy.class);
SkullUtils.initialize(skullProxy::setSkullTexture);
BlockBreakProxy blockBreakProxy = InternalProxyUtils.getProxy(BlockBreakProxy.class);
BlockBreakProxy blockBreakProxy = instance.getProxy(BlockBreakProxy.class);
BlockUtils.initialize(blockBreakProxy::breakBlock);
TridentStackProxy tridentStackProxy = InternalProxyUtils.getProxy(TridentStackProxy.class);
TridentStackProxy tridentStackProxy = instance.getProxy(TridentStackProxy.class);
TridentUtils.initialize(tridentStackProxy::getTridentStack);
this.dataJson = new DataJson(this);

View File

@@ -1,20 +0,0 @@
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 InternalProxyUtils {
/**
* Get the implementation of a specified proxy.
*
* @param proxyClass The proxy interface.
* @param <T> The type of the proxy.
* @return The proxy implementation.
*/
public @NotNull <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
return new ProxyFactory<>(EcoSpigotPlugin.getInstance(), proxyClass).getProxy();
}
}

View File

@@ -3,10 +3,9 @@ package com.willfp.eco.spigot.display;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
import com.willfp.eco.spigot.InternalProxyUtils;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.AbstractPacketAdapter;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.proxy.proxies.AutoCraftProxy;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -34,7 +33,7 @@ public class PacketAutoRecipe extends AbstractPacketAdapter {
}
try {
InternalProxyUtils.getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle());
this.getPlugin().getProxy(AutoCraftProxy.class).modifyPacket(packet.getHandle());
} catch (NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
}

View File

@@ -4,10 +4,9 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
import com.willfp.eco.spigot.InternalProxyUtils;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.AbstractPacketAdapter;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.proxy.proxies.ChatComponentProxy;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@@ -34,7 +33,7 @@ public class PacketChat extends AbstractPacketAdapter {
return;
}
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(InternalProxyUtils.getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
WrappedChatComponent newComponent = WrappedChatComponent.fromHandle(this.getPlugin().getProxy(ChatComponentProxy.class).modifyComponent(component.getHandle()));
packet.getChatComponents().write(i, newComponent);
}
}

View File

@@ -7,7 +7,6 @@ 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.InternalProxyUtils;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
@@ -35,7 +34,7 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
@NotNull final PacketEvent event) {
List<MerchantRecipe> recipes = new ArrayList<>();
if (((EcoPlugin) this.getPlugin()).getConfigYml().getBool("villager-display-fix")) {
if (this.getPlugin().getConfigYml().getBool("villager-display-fix")) {
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
ItemStack result = recipe.getResult();
ItemMeta meta = result.getItemMeta();
@@ -48,7 +47,7 @@ public class PacketOpenWindowMerchant extends AbstractPacketAdapter {
}
for (MerchantRecipe recipe : packet.getMerchantRecipeLists().read(0)) {
MerchantRecipe newRecipe = InternalProxyUtils.getProxy(VillagerTradeProxy.class).displayTrade(recipe);
MerchantRecipe newRecipe = this.getPlugin().getProxy(VillagerTradeProxy.class).displayTrade(recipe);
recipes.add(newRecipe);
}