Finally fixed proxies
This commit is contained in:
@@ -41,7 +41,6 @@ import com.willfp.eco.util.integrations.placeholder.PlaceholderManager;
|
||||
import com.willfp.eco.util.integrations.placeholder.plugins.PlaceholderIntegrationPAPI;
|
||||
import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.proxy.ProxyFactoryFactory;
|
||||
import com.willfp.eco.util.recipe.RecipeListener;
|
||||
import com.willfp.eco.util.recipe.RecipeManager;
|
||||
import com.willfp.eco.util.recipe.lookup.EcoItemLookup;
|
||||
@@ -160,12 +159,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
/**
|
||||
* Get proxy factory factory to produce {@link com.willfp.eco.util.proxy.AbstractProxy} implementations.
|
||||
*/
|
||||
@Getter
|
||||
private final ProxyFactoryFactory proxyFactory;
|
||||
|
||||
/**
|
||||
* Recipe handler for crafting recipes.
|
||||
*/
|
||||
@@ -218,7 +211,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.namespacedKeyFactory = new NamespacedKeyFactory(this);
|
||||
this.metadataValueFactory = new MetadataValueFactory(this);
|
||||
this.runnableFactory = new RunnableFactory(this);
|
||||
this.proxyFactory = new ProxyFactoryFactory(this);
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
this.recipeManager = new RecipeManager(this);
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent {
|
||||
/**
|
||||
* The instance of the proxy.
|
||||
*/
|
||||
private final T instance;
|
||||
|
||||
/**
|
||||
* Create a new Proxy Factory for a specific type.
|
||||
*
|
||||
* @param plugin The plugin to create proxies for.
|
||||
* @param proxyClass The class of the proxy interface.
|
||||
*/
|
||||
public ProxyFactory(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final Class<T> proxyClass) {
|
||||
super(plugin);
|
||||
|
||||
try {
|
||||
String className = this.getPlugin().getProxyPackage() + "." + ProxyConstants.NMS_VERSION + "." + proxyClass.getSimpleName().replace("Proxy", "");
|
||||
final Class<?> class2 = Class.forName(className);
|
||||
Object instance = class2.getConstructor().newInstance();
|
||||
|
||||
if (proxyClass.isInstance(instance)) {
|
||||
this.instance = proxyClass.cast(instance);
|
||||
} else {
|
||||
throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the implementation of a proxy.
|
||||
*
|
||||
* @return The proxy implementation.
|
||||
*/
|
||||
public @NotNull T getProxy() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.willfp.eco.util.proxy;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ProxyFactoryFactory extends PluginDependent {
|
||||
/**
|
||||
* Cached proxy implementations in order to not perform expensive reflective class-finding.
|
||||
*/
|
||||
private final Map<Class<? extends AbstractProxy>, ProxyFactory<? extends AbstractProxy>> cache = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public ProxyFactoryFactory(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get proxy factory.
|
||||
*
|
||||
* @param proxyClass The proxy class.
|
||||
* @param <T> The class.
|
||||
* @return The factory.
|
||||
*/
|
||||
public <T extends AbstractProxy> ProxyFactory<T> getFactory(@NotNull final Class<T> proxyClass) {
|
||||
ProxyFactory<T> cached = (ProxyFactory<T>) cache.get(proxyClass);
|
||||
if (cached == null) {
|
||||
cache.put(proxyClass, new ProxyFactory<>(this.getPlugin(), proxyClass));
|
||||
} else {
|
||||
return cached;
|
||||
}
|
||||
return getFactory(proxyClass);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user