Added EcoPlugin#getProxy
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user