Added EcoPlugin#getProxy
This commit is contained in:
@@ -142,6 +142,11 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
onSend(event.getPacket(), event.getPlayer(), event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final EcoPlugin getPlugin() {
|
||||
return (EcoPlugin) super.getPlugin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the packet adapter with ProtocolLib.
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package com.willfp.eco.core;
|
||||
|
||||
import com.willfp.eco.core.command.AbstractCommand;
|
||||
import com.willfp.eco.core.config.ConfigHandler;
|
||||
import com.willfp.eco.core.config.base.ConfigYml;
|
||||
import com.willfp.eco.core.config.base.LangYml;
|
||||
import com.willfp.eco.core.config.ConfigHandler;
|
||||
import com.willfp.eco.internal.config.updating.EcoConfigHandler;
|
||||
import com.willfp.eco.core.display.Display;
|
||||
import com.willfp.eco.core.display.DisplayModule;
|
||||
import com.willfp.eco.core.events.EventManager;
|
||||
@@ -14,9 +13,12 @@ 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;
|
||||
import com.willfp.eco.internal.arrows.ArrowDataListener;
|
||||
import com.willfp.eco.internal.config.updating.EcoConfigHandler;
|
||||
import com.willfp.eco.internal.events.EcoEventManager;
|
||||
import com.willfp.eco.internal.extensions.EcoExtensionLoader;
|
||||
import com.willfp.eco.internal.factory.EcoMetadataValueFactory;
|
||||
@@ -168,6 +170,12 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private boolean outdated = false;
|
||||
|
||||
/**
|
||||
* If the plugin supports extensions.
|
||||
*/
|
||||
@Getter
|
||||
private final boolean supportingExtensions;
|
||||
|
||||
/**
|
||||
* Create a new plugin without a specified color, proxy support, spigot, or bStats.
|
||||
*/
|
||||
@@ -197,7 +205,7 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without proxy support.
|
||||
* Create a new plugin without proxy or extension support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
@@ -210,7 +218,22 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
* Create a new plugin without proxy support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this(resourceId, bStatsId, "", color, supportingExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin without extension support.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
@@ -221,7 +244,24 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this("", resourceId, bStatsId, proxyPackage, color);
|
||||
this(resourceId, bStatsId, proxyPackage, color, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
*
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
*/
|
||||
protected EcoPlugin(final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this("", resourceId, bStatsId, proxyPackage, color, supportingExtensions);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,11 +281,34 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this(pluginName, resourceId, bStatsId, proxyPackage, color, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin.
|
||||
*
|
||||
* @param pluginName The name of the plugin.
|
||||
* @param resourceId The spigot resource ID for the plugin.
|
||||
* @param bStatsId The bStats resource ID for the plugin.
|
||||
* @param proxyPackage The package where proxy implementations are stored.
|
||||
* @param color The color of the plugin (used in messages, such as &a, &b)
|
||||
* @param supportingExtensions If the plugin supports extensions.
|
||||
* @deprecated pluginName is redundant.
|
||||
*/
|
||||
@Deprecated
|
||||
@SuppressWarnings("unused")
|
||||
protected EcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color,
|
||||
final boolean supportingExtensions) {
|
||||
this.pluginName = this.getName();
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
this.supportingExtensions = supportingExtensions;
|
||||
|
||||
this.scheduler = new EcoScheduler(this);
|
||||
this.eventManager = new EcoEventManager(this);
|
||||
@@ -327,6 +390,17 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
|
||||
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
|
||||
|
||||
if (this.isSupportingExtensions()) {
|
||||
this.getExtensionLoader().loadExtensions();
|
||||
|
||||
if (this.getExtensionLoader().getLoadedExtensions().isEmpty()) {
|
||||
this.getLogger().info("&cNo extensions found");
|
||||
} else {
|
||||
this.getLogger().info("Extensions Loaded:");
|
||||
this.getExtensionLoader().getLoadedExtensions().forEach(extension -> this.getLogger().info("- " + extension.getName() + " v" + extension.getVersion()));
|
||||
}
|
||||
}
|
||||
|
||||
this.enable();
|
||||
|
||||
this.getLogger().info("");
|
||||
@@ -513,6 +587,17 @@ public abstract class EcoPlugin extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 final <T extends AbstractProxy> T getProxy(@NotNull final Class<T> proxyClass) {
|
||||
return Internals.getInstance().getProxy(this, proxyClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin's logger.
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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 {
|
||||
@@ -12,6 +13,9 @@ public abstract class Internals {
|
||||
|
||||
public abstract EcoPlugin getPlugin();
|
||||
|
||||
public @NotNull abstract <T extends AbstractProxy> T getProxy(@NotNull EcoPlugin plugin,
|
||||
@NotNull Class<T> proxyClass);
|
||||
|
||||
public static Internals getInstance() {
|
||||
return internals;
|
||||
}
|
||||
|
||||
@@ -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