Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdbbb7e40a | ||
|
|
f2503e989c | ||
|
|
11c54a0055 | ||
|
|
7cc24199fb | ||
|
|
068b2cca0c | ||
|
|
f67f01278e | ||
|
|
8be8e1dab2 | ||
|
|
6d3651aca1 | ||
|
|
3dd2c58595 | ||
|
|
255aa1dd54 | ||
|
|
f2c5b085e8 |
@@ -98,5 +98,5 @@ build.dependsOn publishToMavenLocal
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = '2.0.0'
|
||||
version = '3.0.1'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
@@ -1,7 +1,69 @@
|
||||
package com.willfp.eco.spigot;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.integrations.IntegrationLoader;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class EcoSpigotMain extends JavaPlugin {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EcoSpigotMain extends AbstractEcoPlugin {
|
||||
/**
|
||||
* Create a new instance of eco.
|
||||
*/
|
||||
public EcoSpigotMain() {
|
||||
super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReload() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postLoad() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IntegrationLoader> getIntegrationLoaders() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractCommand> getCommands() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPacketAdapter> getPacketAdapters() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Listener> getListeners() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Class<?>> getUpdatableClasses() {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.proxy.AbstractProxy;
|
||||
import com.willfp.eco.util.proxy.ProxyFactory;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@UtilityClass
|
||||
public class ProxyUtils {
|
||||
/**
|
||||
* 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<>(AbstractEcoPlugin.getInstance(), proxyClass).getProxy();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.util.command;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
@@ -112,12 +111,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
|
||||
}
|
||||
|
||||
if (playersOnly && !(sender instanceof Player)) {
|
||||
sender.sendMessage(Configs.LANG.getMessage("not-player"));
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getMessage("not-player"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!sender.hasPermission(permission) && sender instanceof Player) {
|
||||
sender.sendMessage(Configs.LANG.getNoPermission());
|
||||
sender.sendMessage(this.getPlugin().getLangYml().getNoPermission());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,10 +48,12 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
||||
*
|
||||
* @param configName The name of the config
|
||||
* @param removeUnused Whether keys not present in the default config should be removed on update.
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected BaseConfig(@NotNull final String configName,
|
||||
final boolean removeUnused) {
|
||||
super(AbstractEcoPlugin.getInstance());
|
||||
final boolean removeUnused,
|
||||
@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
this.name = configName + ".yml";
|
||||
this.removeUnused = removeUnused;
|
||||
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.willfp.eco.util.config;
|
||||
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import com.willfp.eco.util.config.configs.Config;
|
||||
import com.willfp.eco.util.config.configs.Lang;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public final class Configs {
|
||||
/**
|
||||
* The {@link BaseConfig} implementation for lang.yml.
|
||||
*/
|
||||
public static final Lang LANG = new Lang();
|
||||
|
||||
/**
|
||||
* The {@link BaseConfig} implementation for config.yml.
|
||||
*/
|
||||
public static final Config CONFIG = new Config();
|
||||
|
||||
/**
|
||||
* Update lang.yml and config.yml.
|
||||
*
|
||||
* @see BaseConfig
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public void update() {
|
||||
LANG.update();
|
||||
CONFIG.update();
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
package com.willfp.eco.util.config.configs;
|
||||
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class Config extends BaseConfig {
|
||||
/**
|
||||
* Config.yml.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public Config() {
|
||||
super("config", true);
|
||||
public Config(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super("config", true, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,17 @@ package com.willfp.eco.util.config.configs;
|
||||
|
||||
import com.willfp.eco.util.StringUtils;
|
||||
import com.willfp.eco.util.config.BaseConfig;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class Lang extends BaseConfig {
|
||||
/**
|
||||
* lang.yml.
|
||||
* Lang.yml.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public Lang() {
|
||||
super("lang", false);
|
||||
public Lang(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super("lang", false, plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.willfp.eco.util.drops.internal;
|
||||
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@@ -13,15 +11,5 @@ public final class DropManager {
|
||||
* Standard by default, used if drops.collate key is not present in config.
|
||||
*/
|
||||
@Getter
|
||||
private DropQueueType type = DropQueueType.STANDARD;
|
||||
|
||||
/**
|
||||
* Update the type of drop queue that should be used.
|
||||
*
|
||||
* @see DropQueueType
|
||||
*/
|
||||
@ConfigUpdater
|
||||
public void update() {
|
||||
type = Configs.CONFIG.getBool("drops.collate") ? DropQueueType.COLLATED : DropQueueType.STANDARD;
|
||||
}
|
||||
private DropQueueType type = DropQueueType.COLLATED;
|
||||
}
|
||||
|
||||
@@ -14,24 +14,9 @@ import java.util.function.Function;
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
/**
|
||||
* Instance of registered telekinesis utils.
|
||||
* Instance of registered telekinesis tests.
|
||||
*/
|
||||
private final Object instance;
|
||||
|
||||
/**
|
||||
* The class of the utils.
|
||||
*/
|
||||
private final Class<?> clazz;
|
||||
|
||||
/**
|
||||
* The test service registered to bukkit.
|
||||
*/
|
||||
private final Method testMethod;
|
||||
|
||||
/**
|
||||
* The register service registered to bukkit.
|
||||
*/
|
||||
private final Method registerMethod;
|
||||
private final TelekinesisTests tests;
|
||||
|
||||
/**
|
||||
* Test the player for telekinesis.
|
||||
@@ -42,13 +27,7 @@ public final class TelekinesisUtils {
|
||||
* @return If the player is telekinetic.
|
||||
*/
|
||||
public boolean testPlayer(@NotNull final Player player) {
|
||||
try {
|
||||
return (boolean) testMethod.invoke(instance, player);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
return tests.testPlayer(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,35 +36,10 @@ public final class TelekinesisUtils {
|
||||
* @param test The test to register, where the boolean output is if the player is telekinetic.
|
||||
*/
|
||||
public void registerTest(@NotNull final Function<Player, Boolean> test) {
|
||||
try {
|
||||
registerMethod.invoke(instance, test);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
tests.registerTest(test);
|
||||
}
|
||||
|
||||
static {
|
||||
Method testMethod1;
|
||||
Method registerMethod1;
|
||||
if (Bukkit.getServicesManager().getKnownServices().stream().noneMatch(clazz -> clazz.getName().contains("TelekinesisTests"))) {
|
||||
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal);
|
||||
}
|
||||
|
||||
instance = Bukkit.getServicesManager().load(Bukkit.getServicesManager().getKnownServices().stream().filter(clazz -> clazz.getName().contains("TelekinesisTests")).findFirst().get());
|
||||
clazz = instance.getClass();
|
||||
|
||||
try {
|
||||
testMethod1 = clazz.getDeclaredMethod("testPlayer", Player.class);
|
||||
registerMethod1 = clazz.getDeclaredMethod("registerTest", Function.class);
|
||||
testMethod1.setAccessible(true);
|
||||
registerMethod1.setAccessible(true);
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
testMethod1 = null;
|
||||
registerMethod1 = null;
|
||||
}
|
||||
|
||||
testMethod = testMethod1;
|
||||
registerMethod = registerMethod1;
|
||||
tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,16 @@ public abstract class Extension {
|
||||
* The {@link AbstractEcoPlugin} that this extension is for.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
private final AbstractEcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new extension for a plugin.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
protected Extension(@NotNull final AbstractEcoPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Metadata containing version and name.
|
||||
|
||||
@@ -100,7 +100,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
|
||||
Object object = null;
|
||||
try {
|
||||
cls = cl.loadClass(mainClass);
|
||||
object = cls.getConstructor().newInstance();
|
||||
object = cls.getConstructor(AbstractEcoPlugin.class).newInstance(this.getPlugin());
|
||||
} catch (ReflectiveOperationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -11,11 +11,6 @@ import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class AnticheatManager {
|
||||
/**
|
||||
* The linked {@link AbstractEcoPlugin} to register anticheat listeners to.
|
||||
*/
|
||||
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
|
||||
|
||||
/**
|
||||
* A set of all registered anticheats.
|
||||
*/
|
||||
@@ -24,9 +19,11 @@ public class AnticheatManager {
|
||||
/**
|
||||
* Register a new anticheat.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
* @param anticheat The anticheat to register.
|
||||
*/
|
||||
public void register(@NotNull final AnticheatWrapper anticheat) {
|
||||
public void register(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final AnticheatWrapper anticheat) {
|
||||
if (anticheat instanceof Listener) {
|
||||
plugin.getEventManager().registerListener((Listener) anticheat);
|
||||
}
|
||||
@@ -49,8 +46,6 @@ public class AnticheatManager {
|
||||
* @param player The player to remove the exemption.
|
||||
*/
|
||||
public void unexemptPlayer(@NotNull final Player player) {
|
||||
plugin.getScheduler().runLater(() -> {
|
||||
anticheats.forEach(anticheat -> anticheat.unexempt(player));
|
||||
}, 1);
|
||||
anticheats.forEach(anticheat -> anticheat.unexempt(player));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,12 @@ import com.willfp.eco.util.bukkit.scheduling.EcoScheduler;
|
||||
import com.willfp.eco.util.bukkit.scheduling.RunnableFactory;
|
||||
import com.willfp.eco.util.bukkit.scheduling.Scheduler;
|
||||
import com.willfp.eco.util.command.AbstractCommand;
|
||||
import com.willfp.eco.util.config.Configs;
|
||||
import com.willfp.eco.util.config.configs.Config;
|
||||
import com.willfp.eco.util.config.configs.Lang;
|
||||
import com.willfp.eco.util.config.updating.ConfigHandler;
|
||||
import com.willfp.eco.util.drops.internal.DropManager;
|
||||
import com.willfp.eco.util.drops.internal.FastCollatedDropQueue;
|
||||
import com.willfp.eco.util.drops.telekinesis.EcoTelekinesisTests;
|
||||
import com.willfp.eco.util.drops.telekinesis.TelekinesisTests;
|
||||
import com.willfp.eco.util.events.armorequip.ArmorListener;
|
||||
import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
|
||||
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityListeners;
|
||||
@@ -41,6 +43,8 @@ import com.willfp.eco.util.optional.Prerequisite;
|
||||
import com.willfp.eco.util.protocollib.AbstractPacketAdapter;
|
||||
import com.willfp.eco.util.recipe.RecipeListener;
|
||||
import com.willfp.eco.util.recipe.RecipeManager;
|
||||
import com.willfp.eco.util.recipe.lookup.EcoItemLookup;
|
||||
import com.willfp.eco.util.recipe.lookup.ItemLookup;
|
||||
import com.willfp.eco.util.updater.UpdateChecker;
|
||||
import lombok.Getter;
|
||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||
@@ -48,6 +52,7 @@ import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -58,13 +63,8 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
/**
|
||||
* The instance of the plugin.
|
||||
*/
|
||||
@Getter
|
||||
private static AbstractEcoPlugin instance;
|
||||
|
||||
/**
|
||||
* The name of the plugin.
|
||||
*/
|
||||
@@ -129,6 +129,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final EventManager eventManager;
|
||||
|
||||
/**
|
||||
* Config.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final Config configYml;
|
||||
|
||||
/**
|
||||
* Lang.yml.
|
||||
*/
|
||||
@Getter
|
||||
private final Lang langYml;
|
||||
|
||||
/**
|
||||
* The internal factory to produce {@link org.bukkit.NamespacedKey}s.
|
||||
*/
|
||||
@@ -202,6 +214,9 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.extensionLoader = new EcoExtensionLoader(this);
|
||||
this.configHandler = new ConfigHandler(this);
|
||||
this.recipeManager = new RecipeManager(this);
|
||||
|
||||
this.langYml = new Lang(this);
|
||||
this.configYml = new Config(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,9 +275,6 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
updatableClasses.add(Configs.class);
|
||||
updatableClasses.add(DropManager.class);
|
||||
updatableClasses.addAll(this.getUpdatableClasses());
|
||||
|
||||
this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener));
|
||||
@@ -298,7 +310,13 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
public final void onLoad() {
|
||||
super.onLoad();
|
||||
|
||||
instance = this;
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) {
|
||||
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), this, ServicePriority.Normal);
|
||||
}
|
||||
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(ItemLookup.class)) {
|
||||
Bukkit.getServicesManager().register(ItemLookup.class, new EcoItemLookup(), this, ServicePriority.Normal);
|
||||
}
|
||||
|
||||
this.load();
|
||||
}
|
||||
@@ -339,6 +357,9 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
* Default code to be executed on plugin reload.
|
||||
*/
|
||||
public final void reload() {
|
||||
this.getConfigYml().update();
|
||||
this.getLangYml().update();
|
||||
|
||||
this.getConfigHandler().callUpdate();
|
||||
this.getConfigHandler().callUpdate(); // Call twice to fix issues
|
||||
this.getScheduler().cancelAll();
|
||||
@@ -364,10 +385,10 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
integrationLoaders.add(new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())));
|
||||
|
||||
// Anticheat
|
||||
integrationLoaders.add(new IntegrationLoader("AAC5", () -> AnticheatManager.register(new AnticheatAAC())));
|
||||
integrationLoaders.add(new IntegrationLoader("Matrix", () -> AnticheatManager.register(new AnticheatMatrix())));
|
||||
integrationLoaders.add(new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(new AnticheatNCP())));
|
||||
integrationLoaders.add(new IntegrationLoader("Spartan", () -> AnticheatManager.register(new AnticheatSpartan())));
|
||||
integrationLoaders.add(new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())));
|
||||
integrationLoaders.add(new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())));
|
||||
integrationLoaders.add(new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())));
|
||||
integrationLoaders.add(new IntegrationLoader("Spartan", () -> AnticheatManager.register(this, new AnticheatSpartan())));
|
||||
integrationLoaders.addAll(this.getIntegrationLoaders());
|
||||
return integrationLoaders;
|
||||
}
|
||||
|
||||
@@ -1,72 +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.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ProxyFactory<T extends AbstractProxy> extends PluginDependent {
|
||||
/**
|
||||
* Cached proxy implementations in order to not perform expensive reflective class-finding.
|
||||
*/
|
||||
private static final Map<Class<? extends AbstractProxy>, AbstractProxy> CACHE = new IdentityHashMap<>();
|
||||
|
||||
/**
|
||||
* The class of the proxy interface.
|
||||
*/
|
||||
private final Class<T> proxyClass;
|
||||
|
||||
/**
|
||||
* 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);
|
||||
this.proxyClass = proxyClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the implementation of a proxy.
|
||||
*
|
||||
* @return The proxy implementation.
|
||||
*/
|
||||
public @NotNull T getProxy() {
|
||||
try {
|
||||
T cachedProxy = attemptCache();
|
||||
if (cachedProxy != null) {
|
||||
return cachedProxy;
|
||||
}
|
||||
|
||||
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.isAssignableFrom(class2) && proxyClass.isInstance(instance)) {
|
||||
T proxy = proxyClass.cast(instance);
|
||||
CACHE.put(proxyClass, proxy);
|
||||
return proxy;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// If not returned, then throw error
|
||||
}
|
||||
|
||||
throw new UnsupportedVersionException("You're running an unsupported server version: " + ProxyConstants.NMS_VERSION);
|
||||
}
|
||||
|
||||
private T attemptCache() {
|
||||
Object proxy = CACHE.get(proxyClass);
|
||||
if (proxy == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (proxyClass.isInstance(proxy)) {
|
||||
return proxyClass.cast(proxy);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,29 @@
|
||||
package com.willfp.eco.util.recipe.lookup;
|
||||
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@UtilityClass
|
||||
public final class RecipePartUtils {
|
||||
/**
|
||||
* Item lookup instance.
|
||||
* Instance of registered lookups.
|
||||
*/
|
||||
private static final ItemLookup itemLookup;
|
||||
private final ItemLookup lookup;
|
||||
|
||||
/**
|
||||
* Register a new lookup.
|
||||
*
|
||||
* @param key The key of the lookup.
|
||||
* @param lookupFunction The lookup to register, where the output is the recipe part generated.
|
||||
*/
|
||||
public void registerLookup(@NotNull final String key,
|
||||
@NotNull final Function<String, RecipePart> lookupFunction) {
|
||||
lookup.registerLookup(key, lookupFunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lookup recipe part from string.
|
||||
@@ -24,25 +32,10 @@ public final class RecipePartUtils {
|
||||
* @return The generated recipe part, or null if invalid.
|
||||
*/
|
||||
public RecipePart lookup(@NotNull final String key) {
|
||||
return itemLookup.lookup(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new lookup.
|
||||
*
|
||||
* @param key The key of the lookup.
|
||||
* @param lookup The lookup to register, where the output is the recipe part generated.
|
||||
*/
|
||||
public void registerLookup(@NotNull final String key,
|
||||
@NotNull final Function<String, RecipePart> lookup) {
|
||||
itemLookup.registerLookup(key, lookup);
|
||||
return lookup.lookup(key);
|
||||
}
|
||||
|
||||
static {
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(ItemLookup.class)) {
|
||||
Bukkit.getServicesManager().register(ItemLookup.class, new EcoItemLookup(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal);
|
||||
}
|
||||
|
||||
itemLookup = Bukkit.getServicesManager().load(ItemLookup.class);
|
||||
lookup = Bukkit.getServicesManager().load(ItemLookup.class);
|
||||
}
|
||||
}
|
||||
|
||||
0
src/main/resources/config.yml
Normal file
0
src/main/resources/config.yml
Normal file
0
src/main/resources/lang.yml
Normal file
0
src/main/resources/lang.yml
Normal file
@@ -1,10 +1,15 @@
|
||||
name: eco
|
||||
version: 2.0.0
|
||||
version: 3.0.1
|
||||
main: com.willfp.eco.spigot.EcoSpigotMain
|
||||
api-version: 1.15
|
||||
authors: [Auxilor]
|
||||
website: willfp.com
|
||||
load: STARTUP
|
||||
loadbefore:
|
||||
- EcoEnchants
|
||||
- Talismans
|
||||
- ItemStats
|
||||
- EcoArmor
|
||||
- Illusioner
|
||||
depend:
|
||||
- ProtocolLib
|
||||
softdepend:
|
||||
|
||||
Reference in New Issue
Block a user