Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bdbbb7e40a | ||
|
|
f2503e989c | ||
|
|
11c54a0055 | ||
|
|
7cc24199fb | ||
|
|
068b2cca0c | ||
|
|
f67f01278e | ||
|
|
8be8e1dab2 | ||
|
|
6d3651aca1 | ||
|
|
3dd2c58595 | ||
|
|
255aa1dd54 | ||
|
|
f2c5b085e8 | ||
|
|
b8a5fe0031 | ||
|
|
5603890663 | ||
|
|
1a86cc4dbd | ||
|
|
734add6dbc | ||
|
|
5641c0def3 | ||
|
|
b74ab5349a | ||
|
|
b0971e5124 | ||
|
|
02d8c8c6b6 | ||
|
|
d9bd5257e3 | ||
|
|
c1a214f34e | ||
|
|
64d1fbb9b1 | ||
|
|
a5433fbb3f | ||
|
|
2a2aed52e0 | ||
|
|
b16266e22a | ||
|
|
2c886dc33b | ||
|
|
db9c60cf35 | ||
|
|
a34b36daec | ||
|
|
41a35e99fd | ||
|
|
8e12dad247 | ||
|
|
72afa1e5cc | ||
|
|
9904553325 | ||
|
|
ad069ab32f | ||
|
|
b83a3dd548 | ||
|
|
7f41eab5e4 | ||
|
|
0d1c2364da | ||
|
|
5bca33a9f5 | ||
|
|
1196fe8004 | ||
|
|
98ae416fa7 |
@@ -20,7 +20,7 @@ dependencies {
|
||||
compileOnly 'fr.neatmonster:nocheatplus:3.16.1-SNAPSHOT'
|
||||
compileOnly 'com.github.jiangdashao:matrix-api-repo:317d4635fd'
|
||||
compileOnly 'org.jetbrains:annotations:19.0.0'
|
||||
compileOnly fileTree(dir: '/lib', include: ['*.jar'])
|
||||
compileOnly fileTree(dir: 'lib', include: ['*.jar'])
|
||||
|
||||
// Lombok
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
@@ -98,5 +98,5 @@ build.dependsOn publishToMavenLocal
|
||||
|
||||
group = 'com.willfp'
|
||||
archivesBaseName = project.name
|
||||
version = '1.0.1'
|
||||
version = '3.0.1'
|
||||
java.sourceCompatibility = JavaVersion.VERSION_1_8
|
||||
69
src/main/java/com/willfp/eco/spigot/EcoSpigotMain.java
Normal file
69
src/main/java/com/willfp/eco/spigot/EcoSpigotMain.java
Normal 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<>();
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.willfp.eco.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
@@ -85,6 +87,24 @@ public class NumberUtils {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number from roman numeral.
|
||||
*
|
||||
* @param numeral The numeral to convert.
|
||||
* @return The number, converted from a roman numeral.
|
||||
*/
|
||||
public static int fromNumeral(@NotNull final String numeral) {
|
||||
if (numeral.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
for (Map.Entry<Integer, String> entry : NUMERALS.entrySet()) {
|
||||
if (numeral.startsWith(entry.getValue())) {
|
||||
return entry.getKey() + fromNumeral(numeral.substring(entry.getValue().length()));
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate random integer in range.
|
||||
*
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,16 @@ import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@UtilityClass
|
||||
public class VectorUtils {
|
||||
/**
|
||||
* Cached circles to prevent many sqrt calls.
|
||||
*/
|
||||
private static final Map<Integer, Vector[]> CIRCLE_CACHE = new HashMap<>();
|
||||
|
||||
/**
|
||||
* If vector has all components as finite.
|
||||
*
|
||||
@@ -66,6 +73,11 @@ public class VectorUtils {
|
||||
* @return An array of {@link Vector}s.
|
||||
*/
|
||||
public Vector[] getCircle(final int radius) {
|
||||
Vector[] cached = CIRCLE_CACHE.get(radius);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
|
||||
ArrayList<Vector> circleVecs = new ArrayList<>();
|
||||
|
||||
double xoffset = -radius;
|
||||
@@ -85,7 +97,9 @@ public class VectorUtils {
|
||||
zoffset++;
|
||||
}
|
||||
|
||||
return circleVecs.toArray(new Vector[0]);
|
||||
Vector[] result = circleVecs.toArray(new Vector[0]);
|
||||
CIRCLE_CACHE.put(radius, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ public abstract class BaseConfig extends PluginDependent implements ValueGetter
|
||||
/**
|
||||
* The physical config file, as stored on disk.
|
||||
*/
|
||||
@Getter(AccessLevel.PROTECTED)
|
||||
private final File configFile;
|
||||
|
||||
/**
|
||||
@@ -47,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;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Function;
|
||||
|
||||
@UtilityClass
|
||||
public final class TelekinesisUtils {
|
||||
/**
|
||||
* The test service registered to bukkit.
|
||||
* Instance of registered telekinesis tests.
|
||||
*/
|
||||
private final TelekinesisTests tests;
|
||||
|
||||
@@ -38,10 +40,6 @@ public final class TelekinesisUtils {
|
||||
}
|
||||
|
||||
static {
|
||||
if (!Bukkit.getServicesManager().isProvidedFor(TelekinesisTests.class)) {
|
||||
Bukkit.getServicesManager().register(TelekinesisTests.class, new EcoTelekinesisTests(), AbstractEcoPlugin.getInstance(), ServicePriority.Normal);
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -39,6 +41,10 @@ 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.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;
|
||||
@@ -46,22 +52,19 @@ 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
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.
|
||||
*/
|
||||
@@ -86,6 +89,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final String proxyPackage;
|
||||
|
||||
/**
|
||||
* The color of the plugin, used in messages.
|
||||
*/
|
||||
@Getter
|
||||
private final String color;
|
||||
|
||||
/**
|
||||
* Loaded integrations.
|
||||
*/
|
||||
@Getter
|
||||
private final Set<String> loadedIntegrations = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Set of external plugin integrations.
|
||||
*/
|
||||
@@ -114,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.
|
||||
*/
|
||||
@@ -132,6 +159,12 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private final RunnableFactory runnableFactory;
|
||||
|
||||
/**
|
||||
* Recipe handler for crafting recipes.
|
||||
*/
|
||||
@Getter
|
||||
private final RecipeManager recipeManager;
|
||||
|
||||
/**
|
||||
* The loader for all plugin extensions.
|
||||
*
|
||||
@@ -159,15 +192,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
* @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)
|
||||
*/
|
||||
protected AbstractEcoPlugin(@NotNull final String pluginName,
|
||||
final int resourceId,
|
||||
final int bStatsId,
|
||||
@NotNull final String proxyPackage) {
|
||||
@NotNull final String proxyPackage,
|
||||
@NotNull final String color) {
|
||||
this.pluginName = pluginName;
|
||||
this.resourceId = resourceId;
|
||||
this.bStatsId = bStatsId;
|
||||
this.proxyPackage = proxyPackage;
|
||||
this.color = color;
|
||||
|
||||
this.log = new EcoLogger(this);
|
||||
this.scheduler = new EcoScheduler(this);
|
||||
@@ -177,6 +213,10 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.runnableFactory = new RunnableFactory(this);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,18 +226,15 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
public final void onEnable() {
|
||||
super.onLoad();
|
||||
|
||||
this.getLog().info("==========================================");
|
||||
this.getLog().info("");
|
||||
this.getLog().info("Loading &a" + this.pluginName);
|
||||
this.getLog().info("Made by &aAuxilor&f - willfp.com");
|
||||
this.getLog().info("");
|
||||
this.getLog().info("==========================================");
|
||||
this.getLog().info("Loading " + this.color + this.pluginName);
|
||||
|
||||
this.getEventManager().registerListener(new ArrowDataListener(this));
|
||||
this.getEventManager().registerListener(new NaturalExpGainListeners());
|
||||
this.getEventManager().registerListener(new ArmorListener());
|
||||
this.getEventManager().registerListener(new DispenserArmorListener());
|
||||
this.getEventManager().registerListener(new EntityDeathByEntityListeners(this));
|
||||
this.getEventManager().registerListener(new RecipeListener(this));
|
||||
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
|
||||
@@ -219,17 +256,13 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
Set<String> enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet());
|
||||
|
||||
this.getDefaultIntegrations().forEach((integrationLoader -> {
|
||||
StringBuilder infoBuilder = new StringBuilder();
|
||||
infoBuilder.append(integrationLoader.getPluginName()).append(": ");
|
||||
if (enabledPlugins.contains(integrationLoader.getPluginName())) {
|
||||
this.loadedIntegrations.add(integrationLoader.getPluginName());
|
||||
integrationLoader.load();
|
||||
infoBuilder.append("&aENABLED");
|
||||
} else {
|
||||
infoBuilder.append("&9DISABLED");
|
||||
}
|
||||
this.getLog().info(infoBuilder.toString());
|
||||
}));
|
||||
this.getLog().info("");
|
||||
|
||||
this.getLog().info("Loaded integrations: " + String.join(", ", this.getLoadedIntegrations()));
|
||||
|
||||
Prerequisite.update();
|
||||
|
||||
@@ -242,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));
|
||||
@@ -256,6 +286,8 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
this.updatableClasses.forEach(clazz -> this.getConfigHandler().registerUpdatableClass(clazz));
|
||||
|
||||
this.enable();
|
||||
|
||||
this.getLog().info("");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -278,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();
|
||||
}
|
||||
@@ -312,14 +350,18 @@ public abstract class AbstractEcoPlugin extends JavaPlugin {
|
||||
|
||||
this.reload();
|
||||
|
||||
this.getLog().info("Loaded &a" + this.pluginName);
|
||||
this.getLog().info("Loaded " + this.color + this.pluginName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
new FastCollatedDropQueue.CollatedRunnable(this);
|
||||
|
||||
@@ -343,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;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -60,8 +61,10 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* The code that should be executed once the packet has been received.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
*/
|
||||
public void onReceive(@NotNull final PacketContainer packet) {
|
||||
public void onReceive(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
// Empty rather than abstract as implementations don't need both
|
||||
}
|
||||
|
||||
@@ -69,8 +72,10 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
* THe code that should be executed once the packet has been sent.
|
||||
*
|
||||
* @param packet The packet.
|
||||
* @param player The player.
|
||||
*/
|
||||
public void onSend(@NotNull final PacketContainer packet) {
|
||||
public void onSend(@NotNull final PacketContainer packet,
|
||||
@NotNull final Player player) {
|
||||
// Empty rather than abstract as implementations don't need both
|
||||
}
|
||||
|
||||
@@ -89,7 +94,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
onReceive(event.getPacket());
|
||||
onReceive(event.getPacket(), event.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -107,7 +112,7 @@ public abstract class AbstractPacketAdapter extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
onSend(event.getPacket());
|
||||
onSend(event.getPacket(), event.getPlayer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
257
src/main/java/com/willfp/eco/util/recipe/EcoShapedRecipe.java
Normal file
257
src/main/java/com/willfp/eco/util/recipe/EcoShapedRecipe.java
Normal file
@@ -0,0 +1,257 @@
|
||||
package com.willfp.eco.util.recipe;
|
||||
|
||||
import com.willfp.eco.util.interfaces.Registerable;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
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 org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public final class EcoShapedRecipe extends PluginDependent implements Registerable {
|
||||
/**
|
||||
* Recipe parts.
|
||||
*/
|
||||
private final RecipePart[] parts;
|
||||
|
||||
/**
|
||||
* The key of the recipe.
|
||||
*/
|
||||
@Getter
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The recipe's output.
|
||||
*/
|
||||
@Getter
|
||||
private final ItemStack output;
|
||||
|
||||
private EcoShapedRecipe(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String key,
|
||||
@NotNull final RecipePart[] parts,
|
||||
@NotNull final ItemStack output) {
|
||||
super(plugin);
|
||||
|
||||
this.parts = parts;
|
||||
this.key = key;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get item material at a specific index.
|
||||
*
|
||||
* @param index The index to check.
|
||||
* @return The material.
|
||||
*/
|
||||
public Material getMaterialAtIndex(final int index) {
|
||||
return parts[index].getDisplayed().getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get "real" item at specific index.
|
||||
*
|
||||
* @param index The index to check.
|
||||
* @return The item.
|
||||
*/
|
||||
public ItemStack getDisplayedAtIndex(final int index) {
|
||||
return parts[index].getDisplayed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test matrix against recipe.
|
||||
*
|
||||
* @param matrix The matrix to check.
|
||||
* @return If the recipe matches.
|
||||
*/
|
||||
public boolean test(@NotNull final ItemStack[] matrix) {
|
||||
boolean matches = true;
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (!parts[i].matches(matrix[i])) {
|
||||
matches = false;
|
||||
}
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the recipe.
|
||||
*/
|
||||
@Override
|
||||
public void register() {
|
||||
this.getPlugin().getRecipeManager().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EcoShapedRecipe{"
|
||||
+ "parts=" + Arrays.toString(parts)
|
||||
+ ", key='" + key + '\''
|
||||
+ ", output=" + output
|
||||
+ '}';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new recipe builder.
|
||||
*
|
||||
* @param plugin The plugin that owns the recipe.
|
||||
* @param key The recipe key.
|
||||
* @return A new builder.
|
||||
*/
|
||||
public static Builder builder(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String key) {
|
||||
return new Builder(plugin, key);
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
/**
|
||||
* The recipe parts.
|
||||
*/
|
||||
private final RecipePart[] recipeParts = new RecipePart[9];
|
||||
|
||||
/**
|
||||
* The output of the recipe.
|
||||
*/
|
||||
private ItemStack output = null;
|
||||
|
||||
/**
|
||||
* The key of the recipe.
|
||||
*/
|
||||
private final String key;
|
||||
|
||||
/**
|
||||
* The plugin that created the recipe.
|
||||
*/
|
||||
private final AbstractEcoPlugin plugin;
|
||||
|
||||
/**
|
||||
* Create a new recipe builder.
|
||||
*
|
||||
* @param plugin The plugin that owns the recipe.
|
||||
* @param key The recipe key.
|
||||
*/
|
||||
private Builder(@NotNull final AbstractEcoPlugin plugin,
|
||||
@NotNull final String key) {
|
||||
this.key = key;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a recipe part.
|
||||
*
|
||||
* @param position The position of the recipe within a crafting matrix.
|
||||
* @param part The part of the recipe.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setRecipePart(@NotNull final RecipePosition position,
|
||||
@NotNull final RecipePart part) {
|
||||
this.recipeParts[position.getIndex()] = part;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a recipe part.
|
||||
*
|
||||
* @param position The position of the recipe within a crafting matrix.
|
||||
* @param part The part of the recipe.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setRecipePart(final int position,
|
||||
@NotNull final RecipePart part) {
|
||||
this.recipeParts[position] = part;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the output of the recipe.
|
||||
*
|
||||
* @param output The output.
|
||||
* @return The builder.
|
||||
*/
|
||||
public Builder setOutput(@NotNull final ItemStack output) {
|
||||
this.output = output;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the recipe.
|
||||
*
|
||||
* @return The built recipe.
|
||||
*/
|
||||
public EcoShapedRecipe build() {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (recipeParts[i] == null) {
|
||||
recipeParts[i] = new EmptyRecipePart();
|
||||
}
|
||||
}
|
||||
|
||||
return new EcoShapedRecipe(plugin, key.toLowerCase(), recipeParts, output);
|
||||
}
|
||||
}
|
||||
|
||||
public enum RecipePosition {
|
||||
/**
|
||||
* Top left of matrix.
|
||||
*/
|
||||
TOP_LEFT(0),
|
||||
|
||||
/**
|
||||
* Top middle of matrix.
|
||||
*/
|
||||
TOP_MIDDLE(1),
|
||||
|
||||
/**
|
||||
* Top right of matrix.
|
||||
*/
|
||||
TOP_RIGHT(2),
|
||||
|
||||
/**
|
||||
* Middle left of matrix.
|
||||
*/
|
||||
MIDDLE_LEFT(3),
|
||||
|
||||
/**
|
||||
* Middle of matrix.
|
||||
*/
|
||||
MIDDLE(4),
|
||||
|
||||
/**
|
||||
* Middle right of matrix.
|
||||
*/
|
||||
MIDDLE_RIGHT(5),
|
||||
|
||||
/**
|
||||
* Bottom left of matrix.
|
||||
*/
|
||||
BOTTOM_LEFT(6),
|
||||
|
||||
/**
|
||||
* Bottom middle of matrix.
|
||||
*/
|
||||
BOTTOM_MIDDLE(7),
|
||||
|
||||
/**
|
||||
* Bottom right of matrix.
|
||||
*/
|
||||
BOTTOM_RIGHT(8);
|
||||
|
||||
/**
|
||||
* The index within a crafting table matrix.
|
||||
*/
|
||||
@Getter
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Recipe position with crafting table index.
|
||||
*
|
||||
* @param index The index.
|
||||
*/
|
||||
RecipePosition(final int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
89
src/main/java/com/willfp/eco/util/recipe/RecipeListener.java
Normal file
89
src/main/java/com/willfp/eco/util/recipe/RecipeListener.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.willfp.eco.util.recipe;
|
||||
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class RecipeListener extends PluginDependent implements Listener {
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public RecipeListener(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void prepareCraftListener(@NotNull final PrepareItemCraftEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!recipe.getKey().getNamespace().equals(this.getPlugin().getPluginName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = this.getPlugin().getRecipeManager().getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called on item craft.
|
||||
*
|
||||
* @param event The event to listen for.
|
||||
*/
|
||||
@EventHandler
|
||||
public void craftListener(@NotNull final CraftItemEvent event) {
|
||||
if (!(event.getRecipe() instanceof ShapedRecipe)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ShapedRecipe recipe = (ShapedRecipe) event.getRecipe();
|
||||
|
||||
if (!recipe.getKey().getNamespace().equals(this.getPlugin().getPluginName().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack[] matrix = event.getInventory().getMatrix();
|
||||
EcoShapedRecipe matched = this.getPlugin().getRecipeManager().getMatch(matrix);
|
||||
|
||||
if (matched == null) {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (matched.test(matrix)) {
|
||||
event.getInventory().setResult(matched.getOutput());
|
||||
} else {
|
||||
event.getInventory().setResult(new ItemStack(Material.AIR));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
80
src/main/java/com/willfp/eco/util/recipe/RecipeManager.java
Normal file
80
src/main/java/com/willfp/eco/util/recipe/RecipeManager.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.willfp.eco.util.recipe;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.willfp.eco.util.internal.PluginDependent;
|
||||
import com.willfp.eco.util.plugin.AbstractEcoPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.RecipeChoice;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class RecipeManager extends PluginDependent {
|
||||
/**
|
||||
* Registry of all recipes.
|
||||
*/
|
||||
private final BiMap<String, EcoShapedRecipe> registry = HashBiMap.create();
|
||||
|
||||
/**
|
||||
* Pass an {@link AbstractEcoPlugin} in order to interface with it.
|
||||
*
|
||||
* @param plugin The plugin to manage.
|
||||
*/
|
||||
public RecipeManager(@NotNull final AbstractEcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
void register(@NotNull final EcoShapedRecipe recipe) {
|
||||
String key = recipe.getKey();
|
||||
registry.forcePut(key, recipe);
|
||||
|
||||
NamespacedKey baseKey = this.getPlugin().getNamespacedKeyFactory().create(key);
|
||||
Bukkit.getServer().removeRecipe(baseKey);
|
||||
|
||||
NamespacedKey displayedKey = this.getPlugin().getNamespacedKeyFactory().create(key + "_displayed");
|
||||
Bukkit.getServer().removeRecipe(displayedKey);
|
||||
|
||||
ShapedRecipe shapedRecipe = new ShapedRecipe(baseKey, recipe.getOutput());
|
||||
shapedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
shapedRecipe.setIngredient(character, recipe.getMaterialAtIndex(i));
|
||||
}
|
||||
|
||||
ShapedRecipe displayedRecipe = new ShapedRecipe(displayedKey, recipe.getOutput());
|
||||
displayedRecipe.shape("012", "345", "678");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
char character = String.valueOf(i).toCharArray()[0];
|
||||
displayedRecipe.setIngredient(character, new RecipeChoice.ExactChoice(recipe.getDisplayedAtIndex(i)));
|
||||
}
|
||||
|
||||
Bukkit.getServer().addRecipe(shapedRecipe);
|
||||
Bukkit.getServer().addRecipe(displayedRecipe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipe matching matrix.
|
||||
*
|
||||
* @param matrix The matrix to test.
|
||||
* @return The match, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public EcoShapedRecipe getMatch(@NotNull final ItemStack[] matrix) {
|
||||
return registry.values().stream().filter(recipe -> recipe.test(matrix)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shaped recipe by key.
|
||||
*
|
||||
* @param key The key.
|
||||
* @return The shaped recipe, or null if not found.
|
||||
*/
|
||||
@Nullable
|
||||
public EcoShapedRecipe getShapedRecipe(@NotNull final String key) {
|
||||
return registry.get(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.willfp.eco.util.recipe.lookup;
|
||||
|
||||
import com.willfp.eco.util.recipe.parts.EmptyRecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import com.willfp.eco.util.recipe.parts.SimpleRecipePart;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class EcoItemLookup implements ItemLookup {
|
||||
/**
|
||||
* Set of tests that return if the player is telekinetic.
|
||||
*/
|
||||
private final Map<String, Function<String, RecipePart>> tests = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void registerLookup(@NotNull final String key,
|
||||
@NotNull final Function<String, RecipePart> lookup) {
|
||||
tests.put(key, lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipePart lookup(@NotNull final String key) {
|
||||
Function<String, RecipePart> lookup = tests.get(key);
|
||||
|
||||
if (lookup == null) {
|
||||
Material material = Material.getMaterial(key.toUpperCase());
|
||||
if (material == null || material == Material.AIR) {
|
||||
return new EmptyRecipePart();
|
||||
}
|
||||
return new SimpleRecipePart(material);
|
||||
}
|
||||
|
||||
return lookup.apply(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.willfp.eco.util.recipe.lookup;
|
||||
|
||||
import com.willfp.eco.util.recipe.parts.RecipePart;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface ItemLookup {
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void registerLookup(@NotNull String key,
|
||||
@NotNull Function<String, RecipePart> lookup);
|
||||
|
||||
/**
|
||||
* Lookup recipe part from string.
|
||||
*
|
||||
* @param key The string to test.
|
||||
* @return The generated recipe part, or null if invalid.
|
||||
*/
|
||||
RecipePart lookup(@NotNull String key);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
public class ComplexRecipePart implements RecipePart {
|
||||
/**
|
||||
* The test for itemstacks to pass.
|
||||
*/
|
||||
@Getter
|
||||
private final Predicate<ItemStack> predicate;
|
||||
|
||||
/**
|
||||
* Displayed itemstack: what the user should see.
|
||||
*/
|
||||
private final ItemStack displayed;
|
||||
|
||||
/**
|
||||
* Create a new complex recipe part.
|
||||
* @param predicate The test.
|
||||
* @param displayed The example itemstack.
|
||||
*/
|
||||
public ComplexRecipePart(@NotNull final Predicate<ItemStack> predicate,
|
||||
@NotNull final ItemStack displayed) {
|
||||
this.predicate = predicate;
|
||||
this.displayed = displayed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return predicate.test(itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
return displayed;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class EmptyRecipePart implements RecipePart {
|
||||
/**
|
||||
* Create a new empty recipe part.
|
||||
*/
|
||||
public EmptyRecipePart() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item is empty.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is empty.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack == null || itemStack.getType() == Material.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface RecipePart {
|
||||
/**
|
||||
* If an ItemStack matches the recipe part.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item matches.
|
||||
*/
|
||||
boolean matches(@Nullable ItemStack itemStack);
|
||||
|
||||
/**
|
||||
* Get a displayed itemstack, for autocraft.
|
||||
*
|
||||
* @return The item, displayed.
|
||||
*/
|
||||
ItemStack getDisplayed();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.willfp.eco.util.recipe.parts;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SimpleRecipePart implements RecipePart {
|
||||
/**
|
||||
* The material.
|
||||
*/
|
||||
@Getter
|
||||
private final Material material;
|
||||
|
||||
/**
|
||||
* Create a new simple recipe part.
|
||||
*
|
||||
* @param material The material.
|
||||
*/
|
||||
public SimpleRecipePart(@NotNull final Material material) {
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the item matches the material.
|
||||
*
|
||||
* @param itemStack The item to test.
|
||||
* @return If the item is of the specified material.
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(@Nullable final ItemStack itemStack) {
|
||||
return itemStack != null && itemStack.getType() == material;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getDisplayed() {
|
||||
return new ItemStack(material);
|
||||
}
|
||||
}
|
||||
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
26
src/main/resources/plugin.yml
Normal file
26
src/main/resources/plugin.yml
Normal 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
|
||||
Reference in New Issue
Block a user