Compare commits

..

13 Commits
1.3.1 ... 3.0.1

Author SHA1 Message Date
Auxilor
bdbbb7e40a Added redundant config.yml and lang.yml 2021-01-18 09:50:24 +00:00
Auxilor
f2503e989c Made eco an AbstractEcoPlugin and updated to 3.0.1 2021-01-18 09:48:36 +00:00
Auxilor
11c54a0055 Finally fixed proxies 2021-01-17 15:52:40 +00:00
Auxilor
7cc24199fb Kept trying to fix proxy error. 2021-01-17 15:01:01 +00:00
Auxilor
068b2cca0c Removed getInstance method 2021-01-17 14:22:29 +00:00
Auxilor
f67f01278e Moved cached proxies into cached factories 2021-01-17 13:35:53 +00:00
Auxilor
8be8e1dab2 Fixed DropManager updatable 2021-01-17 12:45:08 +00:00
Auxilor
6d3651aca1 Fixed fields 2021-01-17 12:42:37 +00:00
Auxilor
3dd2c58595 Added loadbefore 2021-01-17 12:40:02 +00:00
Auxilor
255aa1dd54 Re-added RecipePartUtils 2021-01-17 11:51:48 +00:00
Auxilor
f2c5b085e8 Removed all getInstance calls 2021-01-17 11:37:58 +00:00
Auxilor
b8a5fe0031 Fixed EcoShapedRecipe 2021-01-17 10:48:55 +00:00
Auxilor
5603890663 Reworked eco to be a spigot plugin 2021-01-17 10:48:34 +00:00
27 changed files with 225 additions and 285 deletions

View File

@@ -98,5 +98,5 @@ build.dependsOn publishToMavenLocal
group = 'com.willfp' group = 'com.willfp'
archivesBaseName = project.name archivesBaseName = project.name
version = '1.3.1' version = '3.0.1'
java.sourceCompatibility = JavaVersion.VERSION_1_8 java.sourceCompatibility = JavaVersion.VERSION_1_8

View File

@@ -1,48 +0,0 @@
package com.willfp.eco.common.recipes.lookup;
import com.willfp.eco.common.recipes.parts.RecipePart;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
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.
*/
private static final ItemLookup itemLookup;
/**
* Lookup recipe part from string.
*
* @param key The string to test.
* @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);
}
static {
if (!Bukkit.getServicesManager().isProvidedFor(ItemLookup.class)) {
Bukkit.getServicesManager().register(ItemLookup.class, new EcoItemLookup(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal);
}
itemLookup = Bukkit.getServicesManager().load(ItemLookup.class);
}
}

View File

@@ -0,0 +1,69 @@
package com.willfp.eco.spigot;
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;
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<>();
}
}

View File

@@ -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();
}
}

View File

@@ -1,6 +1,5 @@
package com.willfp.eco.util.command; 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.internal.PluginDependent;
import com.willfp.eco.util.interfaces.Registerable; import com.willfp.eco.util.interfaces.Registerable;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
@@ -112,12 +111,12 @@ public abstract class AbstractCommand extends PluginDependent implements Command
} }
if (playersOnly && !(sender instanceof Player)) { if (playersOnly && !(sender instanceof Player)) {
sender.sendMessage(Configs.LANG.getMessage("not-player")); sender.sendMessage(this.getPlugin().getLangYml().getMessage("not-player"));
return true; return true;
} }
if (!sender.hasPermission(permission) && sender instanceof Player) { if (!sender.hasPermission(permission) && sender instanceof Player) {
sender.sendMessage(Configs.LANG.getNoPermission()); sender.sendMessage(this.getPlugin().getLangYml().getNoPermission());
return true; return true;
} }

View File

@@ -48,10 +48,12 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
* *
* @param configName The name of the config * @param configName The name of the config
* @param removeUnused Whether keys not present in the default config should be removed on update. * @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, protected BaseConfig(@NotNull final String configName,
final boolean removeUnused) { final boolean removeUnused,
super(AbstractEcoPlugin.getInstance()); @NotNull final AbstractEcoPlugin plugin) {
super(plugin);
this.name = configName + ".yml"; this.name = configName + ".yml";
this.removeUnused = removeUnused; this.removeUnused = removeUnused;

View File

@@ -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();
}
}

View File

@@ -1,13 +1,17 @@
package com.willfp.eco.util.config.configs; package com.willfp.eco.util.config.configs;
import com.willfp.eco.util.config.BaseConfig; import com.willfp.eco.util.config.BaseConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull;
public class Config extends BaseConfig { public class Config extends BaseConfig {
/** /**
* Config.yml. * Config.yml.
*
* @param plugin The plugin.
*/ */
public Config() { public Config(@NotNull final AbstractEcoPlugin plugin) {
super("config", true); super("config", true, plugin);
} }
} }

View File

@@ -2,14 +2,17 @@ package com.willfp.eco.util.config.configs;
import com.willfp.eco.util.StringUtils; import com.willfp.eco.util.StringUtils;
import com.willfp.eco.util.config.BaseConfig; import com.willfp.eco.util.config.BaseConfig;
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class Lang extends BaseConfig { public class Lang extends BaseConfig {
/** /**
* lang.yml. * Lang.yml.
*
* @param plugin The plugin.
*/ */
public Lang() { public Lang(@NotNull final AbstractEcoPlugin plugin) {
super("lang", false); super("lang", false, plugin);
} }
/** /**

View File

@@ -1,7 +1,5 @@
package com.willfp.eco.util.drops.internal; 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.Getter;
import lombok.experimental.UtilityClass; 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. * Standard by default, used if drops.collate key is not present in config.
*/ */
@Getter @Getter
private DropQueueType type = DropQueueType.STANDARD; private DropQueueType type = DropQueueType.COLLATED;
/**
* 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;
}
} }

View File

@@ -14,24 +14,9 @@ import java.util.function.Function;
@UtilityClass @UtilityClass
public final class TelekinesisUtils { public final class TelekinesisUtils {
/** /**
* Instance of registered telekinesis utils. * Instance of registered telekinesis tests.
*/ */
private final Object instance; private final TelekinesisTests tests;
/**
* 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;
/** /**
* Test the player for telekinesis. * Test the player for telekinesis.
@@ -42,13 +27,7 @@ public final class TelekinesisUtils {
* @return If the player is telekinetic. * @return If the player is telekinetic.
*/ */
public boolean testPlayer(@NotNull final Player player) { public boolean testPlayer(@NotNull final Player player) {
try { return tests.testPlayer(player);
return (boolean) testMethod.invoke(instance, player);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
return false;
} }
/** /**
@@ -57,35 +36,10 @@ public final class TelekinesisUtils {
* @param test The test to register, where the boolean output is if the player is telekinetic. * @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) { public void registerTest(@NotNull final Function<Player, Boolean> test) {
try { tests.registerTest(test);
registerMethod.invoke(instance, test);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} }
static { static {
Method testMethod1; tests = Bukkit.getServicesManager().load(TelekinesisTests.class);
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;
} }
} }

View File

@@ -12,7 +12,16 @@ public abstract class Extension {
* The {@link AbstractEcoPlugin} that this extension is for. * The {@link AbstractEcoPlugin} that this extension is for.
*/ */
@Getter(AccessLevel.PROTECTED) @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. * Metadata containing version and name.

View File

@@ -100,7 +100,7 @@ public class EcoExtensionLoader extends PluginDependent implements ExtensionLoad
Object object = null; Object object = null;
try { try {
cls = cl.loadClass(mainClass); cls = cl.loadClass(mainClass);
object = cls.getConstructor().newInstance(); object = cls.getConstructor(AbstractEcoPlugin.class).newInstance(this.getPlugin());
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@@ -11,11 +11,6 @@ import java.util.Set;
@UtilityClass @UtilityClass
public class AnticheatManager { public class AnticheatManager {
/**
* The linked {@link AbstractEcoPlugin} to register anticheat listeners to.
*/
private final AbstractEcoPlugin plugin = AbstractEcoPlugin.getInstance();
/** /**
* A set of all registered anticheats. * A set of all registered anticheats.
*/ */
@@ -24,9 +19,11 @@ public class AnticheatManager {
/** /**
* Register a new anticheat. * Register a new anticheat.
* *
* @param plugin The plugin.
* @param anticheat The anticheat to register. * @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) { if (anticheat instanceof Listener) {
plugin.getEventManager().registerListener((Listener) anticheat); plugin.getEventManager().registerListener((Listener) anticheat);
} }
@@ -49,8 +46,6 @@ public class AnticheatManager {
* @param player The player to remove the exemption. * @param player The player to remove the exemption.
*/ */
public void unexemptPlayer(@NotNull final Player player) { public void unexemptPlayer(@NotNull final Player player) {
plugin.getScheduler().runLater(() -> { anticheats.forEach(anticheat -> anticheat.unexempt(player));
anticheats.forEach(anticheat -> anticheat.unexempt(player));
}, 1);
} }
} }

View File

@@ -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.RunnableFactory;
import com.willfp.eco.util.bukkit.scheduling.Scheduler; import com.willfp.eco.util.bukkit.scheduling.Scheduler;
import com.willfp.eco.util.command.AbstractCommand; 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.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.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.ArmorListener;
import com.willfp.eco.util.events.armorequip.DispenserArmorListener; import com.willfp.eco.util.events.armorequip.DispenserArmorListener;
import com.willfp.eco.util.events.entitydeathbyentity.EntityDeathByEntityListeners; 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.protocollib.AbstractPacketAdapter;
import com.willfp.eco.util.recipe.RecipeListener; import com.willfp.eco.util.recipe.RecipeListener;
import com.willfp.eco.util.recipe.RecipeManager; 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 com.willfp.eco.util.updater.UpdateChecker;
import lombok.Getter; import lombok.Getter;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
@@ -48,6 +52,7 @@ import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -58,13 +63,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@SuppressWarnings("unchecked")
public abstract class AbstractEcoPlugin extends JavaPlugin { public abstract class AbstractEcoPlugin extends JavaPlugin {
/**
* The instance of the plugin.
*/
@Getter
private static AbstractEcoPlugin instance;
/** /**
* The name of the plugin. * The name of the plugin.
*/ */
@@ -129,6 +129,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
@Getter @Getter
private final EventManager eventManager; 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. * 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.extensionLoader = new EcoExtensionLoader(this);
this.configHandler = new ConfigHandler(this); this.configHandler = new ConfigHandler(this);
this.recipeManager = new RecipeManager(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()); updatableClasses.addAll(this.getUpdatableClasses());
this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener)); this.getListeners().forEach(listener -> this.getEventManager().registerListener(listener));
@@ -298,7 +310,13 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
public final void onLoad() { public final void onLoad() {
super.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(); this.load();
} }
@@ -339,6 +357,9 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
* Default code to be executed on plugin reload. * Default code to be executed on plugin reload.
*/ */
public final void reload() { public final void reload() {
this.getConfigYml().update();
this.getLangYml().update();
this.getConfigHandler().callUpdate(); this.getConfigHandler().callUpdate();
this.getConfigHandler().callUpdate(); // Call twice to fix issues this.getConfigHandler().callUpdate(); // Call twice to fix issues
this.getScheduler().cancelAll(); this.getScheduler().cancelAll();
@@ -364,10 +385,10 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
integrationLoaders.add(new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms()))); integrationLoaders.add(new IntegrationLoader("Kingdoms", () -> AntigriefManager.register(new AntigriefKingdoms())));
// Anticheat // Anticheat
integrationLoaders.add(new IntegrationLoader("AAC5", () -> AnticheatManager.register(new AnticheatAAC()))); integrationLoaders.add(new IntegrationLoader("AAC5", () -> AnticheatManager.register(this, new AnticheatAAC())));
integrationLoaders.add(new IntegrationLoader("Matrix", () -> AnticheatManager.register(new AnticheatMatrix()))); integrationLoaders.add(new IntegrationLoader("Matrix", () -> AnticheatManager.register(this, new AnticheatMatrix())));
integrationLoaders.add(new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(new AnticheatNCP()))); integrationLoaders.add(new IntegrationLoader("NoCheatPlus", () -> AnticheatManager.register(this, new AnticheatNCP())));
integrationLoaders.add(new IntegrationLoader("Spartan", () -> AnticheatManager.register(new AnticheatSpartan()))); integrationLoaders.add(new IntegrationLoader("Spartan", () -> AnticheatManager.register(this, new AnticheatSpartan())));
integrationLoaders.addAll(this.getIntegrationLoaders()); integrationLoaders.addAll(this.getIntegrationLoaders());
return integrationLoaders; return integrationLoaders;
} }

View File

@@ -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;
}
}

View File

@@ -1,10 +1,10 @@
package com.willfp.eco.util.recipe; package com.willfp.eco.util.recipe;
import com.willfp.eco.common.recipes.parts.EmptyRecipePart;
import com.willfp.eco.common.recipes.parts.RecipePart;
import com.willfp.eco.util.interfaces.Registerable; import com.willfp.eco.util.interfaces.Registerable;
import com.willfp.eco.util.internal.PluginDependent; import com.willfp.eco.util.internal.PluginDependent;
import com.willfp.eco.util.plugin.AbstractEcoPlugin; import com.willfp.eco.util.plugin.AbstractEcoPlugin;
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
import com.willfp.eco.util.recipe.parts.RecipePart;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@@ -1,8 +1,8 @@
package com.willfp.eco.common.recipes.lookup; package com.willfp.eco.util.recipe.lookup;
import com.willfp.eco.common.recipes.parts.EmptyRecipePart; import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
import com.willfp.eco.common.recipes.parts.RecipePart; import com.willfp.eco.util.recipe.parts.RecipePart;
import com.willfp.eco.common.recipes.parts.SimpleRecipePart; import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
import org.bukkit.Material; import org.bukkit.Material;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@@ -1,6 +1,6 @@
package com.willfp.eco.common.recipes.lookup; package com.willfp.eco.util.recipe.lookup;
import com.willfp.eco.common.recipes.parts.RecipePart; import com.willfp.eco.util.recipe.parts.RecipePart;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.function.Function; import java.util.function.Function;

View File

@@ -0,0 +1,41 @@
package com.willfp.eco.util.recipe.lookup;
import com.willfp.eco.util.recipe.parts.RecipePart;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.jetbrains.annotations.NotNull;
import java.util.function.Function;
@UtilityClass
public final class RecipePartUtils {
/**
* Instance of registered lookups.
*/
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.
*
* @param key The string to test.
* @return The generated recipe part, or null if invalid.
*/
public RecipePart lookup(@NotNull final String key) {
return lookup.lookup(key);
}
static {
lookup = Bukkit.getServicesManager().load(ItemLookup.class);
}
}

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.common.recipes.parts; package com.willfp.eco.util.recipe.parts;
import lombok.Getter; import lombok.Getter;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.common.recipes.parts; package com.willfp.eco.util.recipe.parts;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.common.recipes.parts; package com.willfp.eco.util.recipe.parts;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View File

@@ -1,4 +1,4 @@
package com.willfp.eco.common.recipes.parts; package com.willfp.eco.util.recipe.parts;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Material; import org.bukkit.Material;

View File

View File

View File

@@ -0,0 +1,26 @@
name: eco
version: 3.0.1
main: com.willfp.eco.spigot.EcoSpigotMain
api-version: 1.15
authors: [Auxilor]
website: willfp.com
loadbefore:
- EcoEnchants
- Talismans
- ItemStats
- EcoArmor
- Illusioner
depend:
- ProtocolLib
softdepend:
- WorldGuard
- GriefPrevention
- Towny
- FactionsUUID
- Lands
- Kingdoms
- NoCheatPlus
- AAC
- Matrix
- Spartan
- PlaceholderAPI