diff --git a/eco-api/src/main/java/com/willfp/eco/core/Eco.java b/eco-api/src/main/java/com/willfp/eco/core/Eco.java
index f6fd7cb6..6d7592a9 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/Eco.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/Eco.java
@@ -1,82 +1,584 @@
package com.willfp.eco.core;
+import com.willfp.eco.core.config.ConfigType;
+import com.willfp.eco.core.config.interfaces.Config;
+import com.willfp.eco.core.config.interfaces.LoadableConfig;
+import com.willfp.eco.core.config.updating.ConfigHandler;
+import com.willfp.eco.core.data.ExtendedPersistentDataContainer;
+import com.willfp.eco.core.data.PlayerProfile;
+import com.willfp.eco.core.data.ServerProfile;
+import com.willfp.eco.core.data.keys.PersistentDataKey;
+import com.willfp.eco.core.drops.DropQueue;
+import com.willfp.eco.core.entities.ai.EntityController;
+import com.willfp.eco.core.events.EventManager;
+import com.willfp.eco.core.extensions.ExtensionLoader;
+import com.willfp.eco.core.factory.MetadataValueFactory;
+import com.willfp.eco.core.factory.NamespacedKeyFactory;
+import com.willfp.eco.core.factory.RunnableFactory;
+import com.willfp.eco.core.fast.FastItemStack;
+import com.willfp.eco.core.gui.menu.Menu;
+import com.willfp.eco.core.gui.menu.MenuBuilder;
+import com.willfp.eco.core.gui.menu.MenuType;
+import com.willfp.eco.core.gui.slot.SlotBuilder;
+import com.willfp.eco.core.gui.slot.functional.SlotProvider;
+import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
+import com.willfp.eco.core.items.TestableItem;
+import com.willfp.eco.core.placeholder.AdditionalPlayer;
+import com.willfp.eco.core.placeholder.PlaceholderInjectable;
+import com.willfp.eco.core.proxy.Cleaner;
+import com.willfp.eco.core.proxy.ProxyFactory;
+import com.willfp.eco.core.scheduling.Scheduler;
+import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.apache.commons.lang.Validate;
+import org.bukkit.Location;
+import org.bukkit.NamespacedKey;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Mob;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.SkullMeta;
+import org.bukkit.persistence.PersistentDataContainer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.logging.Logger;
/**
- * Holds the instance of the eco handler for bridging between the frontend
+ * Holds the instance of eco for bridging between the frontend
* and backend.
+ *
+ * Do not use this in your plugins! It can and will contain
+ * breaking changes between minor versions and even patches, and you will create
+ * compatibility issues by. All parts of this have been abstracted
+ * into logically named API components that you can use.
*
- * @see Eco#getHandler()
- * @see Handler
+ * @see Eco#get()
*/
@ApiStatus.Internal
-public final class Eco {
+public interface Eco {
/**
- * Instance of eco handler.
- */
- @ApiStatus.Internal
- private static Handler handler;
-
- /**
- * Set the handler.
+ * Create a scheduler.
*
- * @param handler The handler.
+ * @param plugin The plugin.
+ * @return The scheduler.
*/
- @ApiStatus.Internal
- public static void setHandler(@NotNull final Handler handler) {
- Validate.isTrue(Eco.handler == null, "Already initialized!");
-
- Eco.handler = handler;
- }
+ @NotNull
+ Scheduler createScheduler(@NotNull EcoPlugin plugin);
/**
- * Get the instance of the eco handler; the bridge between the api frontend
- * and the implementation backend.
- *
- * Do not use the handler in your plugins! It can and will contain
- * breaking changes between minor versions and even patches, and you will create
- * compatibility issues by using the handler. All parts of the handler have been abstracted
- * into logically named API components that you can use.
- *
- * Prior to version 6.12.0, the handler was considered as an API component, but it has
- * since been moved into an internal component, and in 6.17.0, the first breaking change
- * was introduced to {@link com.willfp.eco.core.config.wrapper.ConfigFactory}. This means
- * that any usages of the handler can now cause problems in your plugins.
+ * Create an event manager.
*
+ * @param plugin The plugin.
+ * @return The event manager.
+ */
+ @NotNull
+ EventManager createEventManager(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a NamespacedKey factory.
+ *
+ * @param plugin The plugin.
+ * @return The factory.
+ */
+ @NotNull
+ NamespacedKeyFactory createNamespacedKeyFactory(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a MetadataValue factory.
+ *
+ * @param plugin The plugin.
+ * @return The factory.
+ */
+ @NotNull
+ MetadataValueFactory createMetadataValueFactory(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a Runnable factory.
+ *
+ * @param plugin The plugin.
+ * @return The factory.
+ */
+ @NotNull
+ RunnableFactory createRunnableFactory(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create an ExtensionLoader.
+ *
+ * @param plugin The plugin.
+ * @return The factory.
+ */
+ @NotNull
+ ExtensionLoader createExtensionLoader(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a config handler.
+ *
+ * @param plugin The plugin.
* @return The handler.
*/
+ @NotNull
+ ConfigHandler createConfigHandler(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a logger.
+ *
+ * @param plugin The plugin.
+ * @return The logger.
+ */
+ @NotNull
+ Logger createLogger(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a PAPI integration.
+ *
+ * @param plugin The plugin.
+ * @return The integration.
+ */
+ @NotNull
+ PlaceholderIntegration createPAPIIntegration(@NotNull EcoPlugin plugin);
+
+ /**
+ * Create a proxy factory.
+ *
+ * @param plugin The plugin.
+ * @return The factory.
+ */
+ @NotNull
+ ProxyFactory createProxyFactory(@NotNull EcoPlugin plugin);
+
+ /**
+ * Get eco Spigot plugin.
+ *
+ * @return The plugin.
+ */
+ @NotNull
+ EcoPlugin getEcoPlugin();
+
+ /**
+ * Updatable config.
+ *
+ * @param configName The name of the config
+ * @param plugin The plugin.
+ * @param subDirectoryPath The subdirectory path.
+ * @param source The class that owns the resource.
+ * @param removeUnused Whether keys not present in the default config should be removed on update.
+ * @param type The config type.
+ * @param updateBlacklist Substring of keys to not add/remove keys for.
+ * @param requiresChangesToSave If the config must be changed in order to save the config.
+ * @return The config implementation.
+ */
+ LoadableConfig createUpdatableConfig(@NotNull String configName,
+ @NotNull PluginLike plugin,
+ @NotNull String subDirectoryPath,
+ @NotNull Class> source,
+ boolean removeUnused,
+ @NotNull ConfigType type,
+ boolean requiresChangesToSave,
+ @NotNull String... updateBlacklist);
+
+ /**
+ * Loadable config.
+ *
+ * @param configName The name of the config
+ * @param plugin The plugin.
+ * @param subDirectoryPath The subdirectory path.
+ * @param source The class that owns the resource.
+ * @param type The config type.
+ * @param requiresChangesToSave If the config must be changed in order to save the config.
+ * @return The config implementation.
+ */
+ LoadableConfig createLoadableConfig(@NotNull String configName,
+ @NotNull PluginLike plugin,
+ @NotNull String subDirectoryPath,
+ @NotNull Class> source,
+ @NotNull ConfigType type,
+ boolean requiresChangesToSave);
+
+ /**
+ * Create config.
+ *
+ * @param config The handle.
+ * @return The config implementation.
+ */
+ Config wrapConfigurationSection(@NotNull ConfigurationSection config);
+
+ /**
+ * Create config.
+ *
+ * @param values The values.
+ * @param type The config type.
+ * @return The config implementation.
+ */
+ Config createConfig(@NotNull Map values,
+ @NotNull ConfigType type);
+
+ /**
+ * Create config.
+ *
+ * @param contents The file contents.
+ * @param type The type.
+ * @return The config implementation.
+ */
+ Config createConfig(@NotNull String contents,
+ @NotNull ConfigType type);
+
+ /**
+ * Create a Drop Queue.
+ *
+ * @return The player..
+ */
+ @NotNull
+ DropQueue createDropQueue(@NotNull Player player);
+
+ /**
+ * Create slot builder.
+ *
+ * @param provider The provider.
+ * @return The builder.
+ */
+ @NotNull
+ SlotBuilder createSlotBuilder(@NotNull SlotProvider provider);
+
+ /**
+ * Create menu builder.
+ *
+ * @param rows The amount of rows.
+ * @param type The type.
+ * @return The builder.
+ */
+ @NotNull
+ MenuBuilder createMenuBuilder(int rows,
+ @NotNull MenuType type);
+
+ /**
+ * Combine the state of two menus together.
+ *
+ * @param base The base menu.
+ * @param additional The additional state.
+ * @return The menu.
+ */
+ @NotNull
+ Menu blendMenuState(@NotNull Menu base,
+ @NotNull Menu additional);
+
+ /**
+ * Get cleaner.
+ *
+ * @return The cleaner.
+ */
+ @NotNull
+ Cleaner getCleaner();
+
+ /**
+ * Add new plugin.
+ *
+ * @param plugin The plugin.
+ */
+ void addNewPlugin(@NotNull EcoPlugin plugin);
+
+ /**
+ * Get plugin by name.
+ *
+ * @param name The name.
+ * @return The plugin.
+ */
+ @Nullable
+ EcoPlugin getPluginByName(@NotNull String name);
+
+ /**
+ * Get all loaded eco plugins.
+ *
+ * @return A list of plugin names in lowercase.
+ */
+ @NotNull
+ List getLoadedPlugins();
+
+ /**
+ * Create a FastItemStack.
+ *
+ * @param itemStack The base ItemStack.
+ * @return The FastItemStack.
+ */
+ @NotNull
+ FastItemStack createFastItemStack(@NotNull ItemStack itemStack);
+
+ /**
+ * Register bStats metrics.
+ *
+ * @param plugin The plugin.
+ */
+ void registerBStats(@NotNull EcoPlugin plugin);
+
+ /**
+ * Get Adventure audiences.
+ *
+ * @return The audiences.
+ */
+ @Nullable
+ BukkitAudiences getAdventure();
+
+ /**
+ * Register a persistent data key to be stored.
+ *
+ * @param key The key.
+ */
+ void registerPersistentKey(@NotNull PersistentDataKey> key);
+
+ /**
+ * Get all registered keys.
+ *
+ * @return The keys.
+ */
+ Set> getRegisteredPersistentDataKeys();
+
+ /**
+ * Get persistent data key from namespaced key.
+ *
+ * @param namespacedKey The key.
+ * @return The key, or null if not found.
+ */
+ @Nullable
+ PersistentDataKey> getPersistentDataKeyFrom(@NotNull NamespacedKey namespacedKey);
+
+ /**
+ * Load a player profile.
+ *
+ * @param uuid The UUID.
+ * @return The profile.
+ */
+ PlayerProfile loadPlayerProfile(@NotNull UUID uuid);
+
+ /**
+ * Load the server profile.
+ *
+ * @return The profile.
+ */
+ ServerProfile getServerProfile();
+
+ /**
+ * Unload a player profile from memory.
+ *
+ * This will not save the profile first.
+ *
+ * @param uuid The uuid.
+ */
+ void unloadPlayerProfile(@NotNull UUID uuid);
+
+ /**
+ * Save keys for a player.
+ *
+ * Can run async if using MySQL.
+ *
+ * @param uuid The uuid.
+ * @param keys The keys.
+ */
+ void savePersistentDataKeysFor(@NotNull UUID uuid,
+ @NotNull Set> keys);
+
+ /**
+ * Commit all changes to the file.
+ *
+ * Does nothing if using MySQL.
+ */
+ void saveAllProfiles();
+
+ /**
+ * Create dummy entity - never spawned, exists purely in code.
+ *
+ * @param location The location.
+ * @return The entity.
+ */
+ @NotNull
+ Entity createDummyEntity(@NotNull Location location);
+
+ /**
+ * Create a {@link NamespacedKey} quickly
+ *
+ * Bypasses the constructor, allowing for the creation of invalid keys,
+ * therefore this is considered unsafe and should only be called after
+ * the key has been confirmed to be valid.
+ *
+ * @param namespace The namespace.
+ * @param key The key.
+ * @return The key.
+ */
+ @NotNull
+ NamespacedKey createNamespacedKey(@NotNull String namespace,
+ @NotNull String key);
+
+ /**
+ * Return or get props for a plugin.
+ *
+ * @param existing The existing constructor props.
+ * @param plugin The plugin.
+ * @return The props.
+ */
+ @NotNull
+ PluginProps getProps(@Nullable PluginProps existing,
+ @NotNull Class extends EcoPlugin> plugin);
+
+ /**
+ * Format a string with MiniMessage.
+ *
+ * @param message The message.
+ * @return The formatted string.
+ */
+ @NotNull
+ String formatMiniMessage(@NotNull String message);
+
+ /**
+ * Create controlled entity from a mob.
+ *
+ * @param mob The mob.
+ * @param The mob type.
+ * @return The controlled entity.
+ */
+ @NotNull EntityController createEntityController(@NotNull T mob);
+
+ /**
+ * Adapt base PDC to extended PDC.
+ *
+ * @param container The container.
+ * @return The extended container.
+ */
+ @NotNull
+ ExtendedPersistentDataContainer adaptPdc(@NotNull PersistentDataContainer container);
+
+ /**
+ * Create new PDC.
+ *
+ * @return The container.
+ */
+ @NotNull
+ PersistentDataContainer newPdc();
+
+ /**
+ * Get item from SNBT.
+ *
+ * @param snbt The NBT string.
+ * @return The ItemStack, or null if invalid.
+ */
+ @Nullable
+ ItemStack fromSNBT(@NotNull String snbt);
+
+ /**
+ * Convert item to SNBT.
+ *
+ * @param itemStack The item.
+ * @return The NBT string.
+ */
+ @NotNull
+ String toSNBT(@NotNull ItemStack itemStack);
+
+ /**
+ * Make TestableItem from SNBT.
+ *
+ * @param snbt The NBT string.
+ * @return The TestableItem.
+ */
+ @NotNull
+ TestableItem testableItemFromSNBT(@NotNull String snbt);
+
+ /**
+ * Get the texture of a skull.
+ *
+ * @param meta The skull meta.
+ * @return The texture, or null if not found.
+ */
+ @Nullable
+ String getSkullTexture(@NotNull SkullMeta meta);
+
+ /**
+ * Set the texture of a skull.
+ *
+ * @param meta The skull meta.
+ * @param base64 The texture.
+ */
+ void setSkullTexture(@NotNull SkullMeta meta,
+ @NotNull String base64);
+
+ /**
+ * Get the current server TPS.
+ *
+ * @return The TPS.
+ */
+ double getTPS();
+
+ /**
+ * Evaluate an expression.
+ *
+ * @param expression The expression.
+ * @param player The player.
+ * @param injectable The injectable placeholders.
+ * @param additionalPlayers The additional players.
+ * @return The value of the expression, or zero if invalid.
+ */
+ double evaluate(@NotNull String expression,
+ @Nullable Player player,
+ @NotNull PlaceholderInjectable injectable,
+ @NotNull Collection additionalPlayers);
+
+ /**
+ * Get the menu a player currently has open.
+ *
+ * @param player The player.
+ * @return The menu, or null if no menu open.
+ */
+ @Nullable
+ Menu getOpenMenu(@NotNull Player player);
+
+ /**
+ * Get the instance of eco; the bridge between the api frontend
+ * and the implementation backend.
+ *
+ * @return The instance of eco.
+ */
@ApiStatus.Internal
- public static Handler getHandler() {
- return handler;
+ static Eco get() {
+ return Instance.get();
}
/**
- * Eco Handler components are internals, so if a class is marked as a handler component,
- * then it should be treated the same as if it was marked with {@link ApiStatus.Internal}.
- *
- * If a class is marked with {@link HandlerComponent}, Do not reference it in
- * your code! It can and will contain breaking changes between minor versions and
- * even patches, and you will create compatibility issues by using them.
- *
- * Handler components should also be marked with {@link ApiStatus.Internal} in order to
- * cause compiler / IDE warnings.
+ * Manages the internal frontend -> backend communication.
*/
- @Documented
- @Retention(RetentionPolicy.CLASS)
- @Target({ElementType.TYPE})
- public @interface HandlerComponent {
+ @ApiStatus.Internal
+ final class Instance {
+ /**
+ * Instance of eco.
+ */
+ @ApiStatus.Internal
+ private static Eco eco;
- }
+ /**
+ * Initialize eco.
+ *
+ * @param eco The instance of eco.
+ */
+ @ApiStatus.Internal
+ static void set(@NotNull final Eco eco) {
+ Validate.isTrue(Instance.eco == null, "Already initialized!");
- private Eco() {
- throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ Instance.eco = eco;
+ }
+
+ /**
+ * Get eco.
+ *
+ * @return eco.
+ */
+ static Eco get() {
+ return eco;
+ }
+
+ private Instance() {
+ throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
+ }
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
index 5cee421a..44160f43 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/EcoPlugin.java
@@ -260,28 +260,28 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
*/
protected EcoPlugin(@Nullable final PluginProps pluginProps) {
/*
- The handler must be initialized before any plugin's constructors
- are called, as the constructors call Eco#getHandler().
+ Eco must be initialized before any plugin's constructors
+ are called, as the constructors call Eco#get().
To fix this, EcoSpigotPlugin an abstract class and the 'actual'
- plugin class is EcoHandler - that way I can create the handler
+ plugin class is EcoImpl - that way I can initialize eco
before any plugins are loaded while still having a separation between
- the plugin class and the handler class (for code clarity).
+ the plugin class and the implementation class (for code clarity).
- I don't really like the fact that the handler class *is* the
+ I don't really like the fact that the implementation class *is* the
spigot plugin, but it is what it is.
There is probably a better way of doing it - maybe with
- some sort of HandlerCreator interface in order to still have
- a standalone handler class, but then there would be an interface
+ some sort of EcoCrater interface in order to still have
+ a standalone eco class, but then there would be an interface
left in the API that doesn't really help anything.
- The other alternative would be to use reflection to get a 'createHandler'
+ The other alternative would be to use reflection to get a 'createEco'
method that only exists in EcoSpigotPlugin - but that feels filthy,
and I'd rather only use reflection where necessary.
*/
- if (Eco.getHandler() == null && this instanceof Handler) {
+ if (Eco.get() == null && this instanceof Eco) {
/*
This code is only ever called by EcoSpigotPlugin (EcoHandler)
as it's the first plugin to load, and it is a handler.
@@ -290,12 +290,12 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
will have already been initialized.
*/
- Eco.setHandler((Handler) this);
+ Eco.Instance.set((Eco) this);
}
- assert Eco.getHandler() != null;
+ assert Eco.get() != null;
- PluginProps generatedProps = Eco.getHandler().getProps(pluginProps, this.getClass());
+ PluginProps generatedProps = Eco.get().getProps(pluginProps, this.getClass());
generatedProps.validate();
PluginProps props = this.mutateProps(generatedProps);
props.validate();
@@ -306,23 +306,23 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
this.color = props.getColor();
this.supportingExtensions = props.isSupportingExtensions();
- this.proxyFactory = this.proxyPackage.equalsIgnoreCase("") ? null : Eco.getHandler().createProxyFactory(this);
- this.logger = Eco.getHandler().createLogger(this);
+ this.proxyFactory = this.proxyPackage.equalsIgnoreCase("") ? null : Eco.get().createProxyFactory(this);
+ this.logger = Eco.get().createLogger(this);
this.getLogger().info("Initializing " + this.getColor() + this.getName());
- this.scheduler = Eco.getHandler().createScheduler(this);
- this.eventManager = Eco.getHandler().createEventManager(this);
- this.namespacedKeyFactory = Eco.getHandler().createNamespacedKeyFactory(this);
- this.metadataValueFactory = Eco.getHandler().createMetadataValueFactory(this);
- this.runnableFactory = Eco.getHandler().createRunnableFactory(this);
- this.extensionLoader = Eco.getHandler().createExtensionLoader(this);
- this.configHandler = Eco.getHandler().createConfigHandler(this);
+ this.scheduler = Eco.get().createScheduler(this);
+ this.eventManager = Eco.get().createEventManager(this);
+ this.namespacedKeyFactory = Eco.get().createNamespacedKeyFactory(this);
+ this.metadataValueFactory = Eco.get().createMetadataValueFactory(this);
+ this.runnableFactory = Eco.get().createRunnableFactory(this);
+ this.extensionLoader = Eco.get().createExtensionLoader(this);
+ this.configHandler = Eco.get().createConfigHandler(this);
this.langYml = this.createLangYml();
this.configYml = this.createConfigYml();
- Eco.getHandler().addNewPlugin(this);
+ Eco.get().addNewPlugin(this);
/*
The minimum eco version check was moved here because it's very common
@@ -331,7 +331,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
they have an outdated version of eco installed.
*/
- DefaultArtifactVersion runningVersion = new DefaultArtifactVersion(Eco.getHandler().getEcoPlugin().getDescription().getVersion());
+ DefaultArtifactVersion runningVersion = new DefaultArtifactVersion(Eco.get().getEcoPlugin().getDescription().getVersion());
DefaultArtifactVersion requiredVersion = new DefaultArtifactVersion(this.getMinimumEcoVersion());
if (!(runningVersion.compareTo(requiredVersion) > 0 || runningVersion.equals(requiredVersion))) {
this.getLogger().severe("You are running an outdated version of eco!");
@@ -352,7 +352,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
this.getLogger().info("");
this.getLogger().info("Loading " + this.getColor() + this.getName());
- if (this.getResourceId() != 0 && !Eco.getHandler().getEcoPlugin().getConfigYml().getBool("no-update-checker")) {
+ if (this.getResourceId() != 0 && !Eco.get().getEcoPlugin().getConfigYml().getBool("no-update-checker")) {
new UpdateChecker(this).getVersion(version -> {
DefaultArtifactVersion currentVersion = new DefaultArtifactVersion(this.getDescription().getVersion());
DefaultArtifactVersion mostRecentVersion = new DefaultArtifactVersion(version);
@@ -366,7 +366,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
}
if (this.getBStatsId() != 0) {
- Eco.getHandler().registerBStats(this);
+ Eco.get().registerBStats(this);
}
Set enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins())
@@ -376,7 +376,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
if (enabledPlugins.contains("PlaceholderAPI".toLowerCase())) {
this.loadedIntegrations.add("PlaceholderAPI");
- PlaceholderManager.addIntegration(Eco.getHandler().createPAPIIntegration(this));
+ PlaceholderManager.addIntegration(Eco.get().createPAPIIntegration(this));
}
this.loadIntegrationLoaders().forEach(integrationLoader -> {
@@ -435,7 +435,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
}
this.getLogger().info("Cleaning up...");
- Eco.getHandler().getCleaner().clean(this);
+ Eco.get().getCleaner().clean(this);
}
/**
@@ -748,7 +748,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
* @return The plugin.
*/
public static EcoPlugin getPlugin(@NotNull final String pluginName) {
- return Eco.getHandler().getPluginByName(pluginName);
+ return Eco.get().getPluginByName(pluginName);
}
/**
@@ -757,7 +757,7 @@ public abstract class EcoPlugin extends JavaPlugin implements PluginLike {
* @return The set of names.
*/
public static Set getPluginNames() {
- return new HashSet<>(Eco.getHandler().getLoadedPlugins());
+ return new HashSet<>(Eco.get().getLoadedPlugins());
}
/**
diff --git a/eco-api/src/main/java/com/willfp/eco/core/Handler.java b/eco-api/src/main/java/com/willfp/eco/core/Handler.java
deleted file mode 100644
index fed4df98..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/Handler.java
+++ /dev/null
@@ -1,366 +0,0 @@
-package com.willfp.eco.core;
-
-import com.willfp.eco.core.config.updating.ConfigHandler;
-import com.willfp.eco.core.config.wrapper.ConfigFactory;
-import com.willfp.eco.core.data.ExtendedPersistentDataContainer;
-import com.willfp.eco.core.data.ProfileHandler;
-import com.willfp.eco.core.data.keys.KeyRegistry;
-import com.willfp.eco.core.drops.DropQueueFactory;
-import com.willfp.eco.core.entities.ai.EntityController;
-import com.willfp.eco.core.events.EventManager;
-import com.willfp.eco.core.extensions.ExtensionLoader;
-import com.willfp.eco.core.factory.MetadataValueFactory;
-import com.willfp.eco.core.factory.NamespacedKeyFactory;
-import com.willfp.eco.core.factory.RunnableFactory;
-import com.willfp.eco.core.fast.FastItemStack;
-import com.willfp.eco.core.gui.GUIFactory;
-import com.willfp.eco.core.gui.menu.Menu;
-import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration;
-import com.willfp.eco.core.items.SNBTHandler;
-import com.willfp.eco.core.placeholder.AdditionalPlayer;
-import com.willfp.eco.core.placeholder.PlaceholderInjectable;
-import com.willfp.eco.core.proxy.Cleaner;
-import com.willfp.eco.core.proxy.ProxyFactory;
-import com.willfp.eco.core.scheduling.Scheduler;
-import net.kyori.adventure.platform.bukkit.BukkitAudiences;
-import org.bukkit.Location;
-import org.bukkit.NamespacedKey;
-import org.bukkit.entity.Entity;
-import org.bukkit.entity.Mob;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.SkullMeta;
-import org.bukkit.persistence.PersistentDataContainer;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.logging.Logger;
-
-/**
- * @see Eco#getHandler()
- */
-@ApiStatus.Internal
-public interface Handler {
- /**
- * Create a scheduler.
- *
- * @param plugin The plugin.
- * @return The scheduler.
- */
- @NotNull
- Scheduler createScheduler(@NotNull EcoPlugin plugin);
-
- /**
- * Create an event manager.
- *
- * @param plugin The plugin.
- * @return The event manager.
- */
- @NotNull
- EventManager createEventManager(@NotNull EcoPlugin plugin);
-
- /**
- * Create a NamespacedKey factory.
- *
- * @param plugin The plugin.
- * @return The factory.
- */
- @NotNull
- NamespacedKeyFactory createNamespacedKeyFactory(@NotNull EcoPlugin plugin);
-
- /**
- * Create a MetadataValue factory.
- *
- * @param plugin The plugin.
- * @return The factory.
- */
- @NotNull
- MetadataValueFactory createMetadataValueFactory(@NotNull EcoPlugin plugin);
-
- /**
- * Create a Runnable factory.
- *
- * @param plugin The plugin.
- * @return The factory.
- */
- @NotNull
- RunnableFactory createRunnableFactory(@NotNull EcoPlugin plugin);
-
- /**
- * Create an ExtensionLoader.
- *
- * @param plugin The plugin.
- * @return The factory.
- */
- @NotNull
- ExtensionLoader createExtensionLoader(@NotNull EcoPlugin plugin);
-
- /**
- * Create a config handler.
- *
- * @param plugin The plugin.
- * @return The handler.
- */
- @NotNull
- ConfigHandler createConfigHandler(@NotNull EcoPlugin plugin);
-
- /**
- * Create a logger.
- *
- * @param plugin The plugin.
- * @return The logger.
- */
- @NotNull
- Logger createLogger(@NotNull EcoPlugin plugin);
-
- /**
- * Create a PAPI integration.
- *
- * @param plugin The plugin.
- * @return The integration.
- */
- @NotNull
- PlaceholderIntegration createPAPIIntegration(@NotNull EcoPlugin plugin);
-
- /**
- * Create a proxy factory.
- *
- * @param plugin The plugin.
- * @return The factory.
- */
- @NotNull
- ProxyFactory createProxyFactory(@NotNull EcoPlugin plugin);
-
- /**
- * Get eco Spigot plugin.
- *
- * @return The plugin.
- */
- @NotNull
- EcoPlugin getEcoPlugin();
-
- /**
- * Get config factory.
- *
- * @return The factory.
- */
- @NotNull
- ConfigFactory getConfigFactory();
-
- /**
- * Get drop queue factory.
- *
- * @return The factory.
- */
- @NotNull
- DropQueueFactory getDropQueueFactory();
-
- /**
- * Get GUI factory.
- *
- * @return The factory.
- */
- @NotNull
- GUIFactory getGUIFactory();
-
- /**
- * Get cleaner.
- *
- * @return The cleaner.
- */
- @NotNull
- Cleaner getCleaner();
-
- /**
- * Add new plugin.
- *
- * @param plugin The plugin.
- */
- void addNewPlugin(@NotNull EcoPlugin plugin);
-
- /**
- * Get plugin by name.
- *
- * @param name The name.
- * @return The plugin.
- */
- @Nullable
- EcoPlugin getPluginByName(@NotNull String name);
-
- /**
- * Get all loaded eco plugins.
- *
- * @return A list of plugin names in lowercase.
- */
- @NotNull
- List getLoadedPlugins();
-
- /**
- * Create a FastItemStack.
- *
- * @param itemStack The base ItemStack.
- * @return The FastItemStack.
- */
- @NotNull
- FastItemStack createFastItemStack(@NotNull ItemStack itemStack);
-
- /**
- * Register bStats metrics.
- *
- * @param plugin The plugin.
- */
- void registerBStats(@NotNull EcoPlugin plugin);
-
- /**
- * Get Adventure audiences.
- *
- * @return The audiences.
- */
- @Nullable
- BukkitAudiences getAdventure();
-
- /**
- * Get the key registry.
- *
- * @return The registry.
- */
- @NotNull
- KeyRegistry getKeyRegistry();
-
- /**
- * Get the PlayerProfile handler.
- *
- * @return The handler.
- */
- @NotNull
- ProfileHandler getProfileHandler();
-
- /**
- * Create dummy entity - never spawned, exists purely in code.
- *
- * @param location The location.
- * @return The entity.
- */
- @NotNull
- Entity createDummyEntity(@NotNull Location location);
-
- /**
- * Create a {@link NamespacedKey} quickly
- *
- * Bypasses the constructor, allowing for the creation of invalid keys,
- * therefore this is considered unsafe and should only be called after
- * the key has been confirmed to be valid.
- *
- * @param namespace The namespace.
- * @param key The key.
- * @return The key.
- */
- @NotNull
- NamespacedKey createNamespacedKey(@NotNull String namespace,
- @NotNull String key);
-
- /**
- * Return or get props for a plugin.
- *
- * @param existing The existing constructor props.
- * @param plugin The plugin.
- * @return The props.
- */
- @NotNull
- PluginProps getProps(@Nullable PluginProps existing,
- @NotNull Class extends EcoPlugin> plugin);
-
- /**
- * Format a string with MiniMessage.
- *
- * @param message The message.
- * @return The formatted string.
- */
- @NotNull
- String formatMiniMessage(@NotNull String message);
-
- /**
- * Create controlled entity from a mob.
- *
- * @param mob The mob.
- * @param The mob type.
- * @return The controlled entity.
- */
- @NotNull EntityController createEntityController(@NotNull T mob);
-
- /**
- * Adapt base PDC to extended PDC.
- *
- * @param container The container.
- * @return The extended container.
- */
- @NotNull
- ExtendedPersistentDataContainer adaptPdc(@NotNull PersistentDataContainer container);
-
- /**
- * Create new PDC.
- *
- * @return The container.
- */
- @NotNull
- PersistentDataContainer newPdc();
-
- /**
- * Get SNBT handler.
- *
- * @return The SNBT handler.
- */
- @NotNull
- SNBTHandler getSNBTHandler();
-
- /**
- * Get the texture of a skull.
- *
- * @param meta The skull meta.
- * @return The texture, or null if not found.
- */
- @Nullable
- String getSkullTexture(@NotNull SkullMeta meta);
-
- /**
- * Set the texture of a skull.
- *
- * @param meta The skull meta.
- * @param base64 The texture.
- */
- void setSkullTexture(@NotNull SkullMeta meta,
- @NotNull String base64);
-
- /**
- * Get the current server TPS.
- *
- * @return The TPS.
- */
- double getTPS();
-
- /**
- * Evaluate an expression.
- *
- * @param expression The expression.
- * @param player The player.
- * @param injectable The injectable placeholders.
- * @param additionalPlayers The additional players.
- * @return The value of the expression, or zero if invalid.
- */
- double evaluate(@NotNull String expression,
- @Nullable Player player,
- @NotNull PlaceholderInjectable injectable,
- @NotNull Collection additionalPlayers);
-
- /**
- * Get the menu a player currently has open.
- *
- * @param player The player.
- * @return The menu, or null if no menu open.
- */
- @Nullable
- Menu getOpenMenu(@NotNull Player player);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java b/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java
index 1951f536..58d7774d 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/config/BaseConfig.java
@@ -40,7 +40,7 @@ public abstract class BaseConfig extends LoadableConfigWrapper {
final boolean removeUnused,
@NotNull final ConfigType type,
final boolean requiresChangeToSave) {
- super(Eco.getHandler().getConfigFactory().createUpdatableConfig(
+ super(Eco.get().createUpdatableConfig(
configName,
plugin,
"",
diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/ExtendableConfig.java b/eco-api/src/main/java/com/willfp/eco/core/config/ExtendableConfig.java
index 90449103..4571cc07 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/config/ExtendableConfig.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/config/ExtendableConfig.java
@@ -31,7 +31,7 @@ public abstract class ExtendableConfig extends LoadableConfigWrapper {
@NotNull final String subDirectoryPath,
@NotNull final ConfigType type,
@NotNull final String... updateBlacklist) {
- super(Eco.getHandler().getConfigFactory().createUpdatableConfig(
+ super(Eco.get().createUpdatableConfig(
configName,
plugin,
subDirectoryPath,
diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/StaticBaseConfig.java b/eco-api/src/main/java/com/willfp/eco/core/config/StaticBaseConfig.java
index d0b1917c..b820b974 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/config/StaticBaseConfig.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/config/StaticBaseConfig.java
@@ -21,7 +21,7 @@ public abstract class StaticBaseConfig extends LoadableConfigWrapper {
protected StaticBaseConfig(@NotNull final String configName,
@NotNull final PluginLike plugin,
@NotNull final ConfigType type) {
- super(Eco.getHandler().getConfigFactory().createLoadableConfig(
+ super(Eco.get().createLoadableConfig(
configName,
plugin,
"",
diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/TransientConfig.java b/eco-api/src/main/java/com/willfp/eco/core/config/TransientConfig.java
index f9a6074c..d4cbe03a 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/config/TransientConfig.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/config/TransientConfig.java
@@ -26,7 +26,7 @@ public class TransientConfig extends ConfigWrapper {
* @param config The ConfigurationSection handle.
*/
public TransientConfig(@NotNull final ConfigurationSection config) {
- super(Eco.getHandler().getConfigFactory().createConfig(config));
+ super(Eco.get().wrapConfigurationSection(config));
}
/**
@@ -42,7 +42,7 @@ public class TransientConfig extends ConfigWrapper {
* @param stream The InputStream.
*/
public TransientConfig(@Nullable final InputStream stream) {
- super(stream != null ? Eco.getHandler().getConfigFactory().createConfig(YamlConfiguration.loadConfiguration(
+ super(stream != null ? Eco.get().wrapConfigurationSection(YamlConfiguration.loadConfiguration(
new InputStreamReader(stream)
)) : new TransientConfig());
}
@@ -62,7 +62,7 @@ public class TransientConfig extends ConfigWrapper {
*/
public TransientConfig(@Nullable final File file,
@NotNull final ConfigType type) {
- super(file != null ? Eco.getHandler().getConfigFactory().createConfig(readFile(file), type)
+ super(file != null ? Eco.get().createConfig(readFile(file), type)
: new TransientConfig());
}
@@ -72,7 +72,7 @@ public class TransientConfig extends ConfigWrapper {
* @param values The values.
*/
public TransientConfig(@NotNull final Map values) {
- super(Eco.getHandler().getConfigFactory().createConfig(values, ConfigType.YAML));
+ super(Eco.get().createConfig(values, ConfigType.YAML));
}
/**
@@ -83,7 +83,7 @@ public class TransientConfig extends ConfigWrapper {
*/
public TransientConfig(@NotNull final Map values,
@NotNull final ConfigType type) {
- super(Eco.getHandler().getConfigFactory().createConfig(values, type));
+ super(Eco.get().createConfig(values, type));
}
/**
@@ -99,7 +99,7 @@ public class TransientConfig extends ConfigWrapper {
*/
public TransientConfig(@NotNull final String contents,
@NotNull final ConfigType type) {
- super(Eco.getHandler().getConfigFactory().createConfig(contents, type));
+ super(Eco.get().createConfig(contents, type));
}
/**
diff --git a/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java b/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java
deleted file mode 100644
index 7fc4a68a..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/config/wrapper/ConfigFactory.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.willfp.eco.core.config.wrapper;
-
-import com.willfp.eco.core.Eco;
-import com.willfp.eco.core.PluginLike;
-import com.willfp.eco.core.config.ConfigType;
-import com.willfp.eco.core.config.interfaces.Config;
-import com.willfp.eco.core.config.interfaces.LoadableConfig;
-import org.bukkit.configuration.ConfigurationSection;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Map;
-
-/**
- * Internal component to create backend config implementations.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface ConfigFactory {
- /**
- * Updatable config.
- *
- * @param configName The name of the config
- * @param plugin The plugin.
- * @param subDirectoryPath The subdirectory path.
- * @param source The class that owns the resource.
- * @param removeUnused Whether keys not present in the default config should be removed on update.
- * @param type The config type.
- * @param updateBlacklist Substring of keys to not add/remove keys for.
- * @param requiresChangesToSave If the config must be changed in order to save the config.
- * @return The config implementation.
- */
- LoadableConfig createUpdatableConfig(@NotNull String configName,
- @NotNull PluginLike plugin,
- @NotNull String subDirectoryPath,
- @NotNull Class> source,
- boolean removeUnused,
- @NotNull ConfigType type,
- boolean requiresChangesToSave,
- @NotNull String... updateBlacklist);
-
- /**
- * Loadable config.
- *
- * @param configName The name of the config
- * @param plugin The plugin.
- * @param subDirectoryPath The subdirectory path.
- * @param source The class that owns the resource.
- * @param type The config type.
- * @param requiresChangesToSave If the config must be changed in order to save the config.
- * @return The config implementation.
- */
- LoadableConfig createLoadableConfig(@NotNull String configName,
- @NotNull PluginLike plugin,
- @NotNull String subDirectoryPath,
- @NotNull Class> source,
- @NotNull ConfigType type,
- boolean requiresChangesToSave);
-
- /**
- * Create config.
- *
- * @param config The handle.
- * @return The config implementation.
- */
- Config createConfig(@NotNull ConfigurationSection config);
-
- /**
- * Create config.
- *
- * @param values The values.
- * @param type The config type.
- * @return The config implementation.
- */
- Config createConfig(@NotNull Map values,
- @NotNull ConfigType type);
-
- /**
- * Create config.
- *
- * @param contents The file contents.
- * @param type The type.
- * @return The config implementation.
- */
- Config createConfig(@NotNull String contents,
- @NotNull ConfigType type);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/ExtendedPersistentDataContainer.java b/eco-api/src/main/java/com/willfp/eco/core/data/ExtendedPersistentDataContainer.java
index e0fc8cc2..a13325a7 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/data/ExtendedPersistentDataContainer.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/data/ExtendedPersistentDataContainer.java
@@ -87,7 +87,7 @@ public interface ExtendedPersistentDataContainer {
* @return The extended container.
*/
static ExtendedPersistentDataContainer extend(@NotNull PersistentDataContainer base) {
- return Eco.getHandler().adaptPdc(base);
+ return Eco.get().adaptPdc(base);
}
/**
@@ -96,6 +96,6 @@ public interface ExtendedPersistentDataContainer {
* @return The extended container.
*/
static ExtendedPersistentDataContainer create() {
- return extend(Eco.getHandler().newPdc());
+ return extend(Eco.get().newPdc());
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfile.java b/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfile.java
index 465a2495..e63d2b86 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfile.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/data/PlayerProfile.java
@@ -31,6 +31,6 @@ public interface PlayerProfile extends Profile {
*/
@NotNull
static PlayerProfile load(@NotNull final UUID uuid) {
- return Eco.getHandler().getProfileHandler().load(uuid);
+ return Eco.get().loadPlayerProfile(uuid);
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/ProfileHandler.java b/eco-api/src/main/java/com/willfp/eco/core/data/ProfileHandler.java
deleted file mode 100644
index 63acb9a9..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/data/ProfileHandler.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package com.willfp.eco.core.data;
-
-import com.willfp.eco.core.Eco;
-import com.willfp.eco.core.data.keys.PersistentDataKey;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Set;
-import java.util.UUID;
-
-/**
- * API to handle profiles.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface ProfileHandler {
- /**
- * Load a player profile.
- *
- * @param uuid The UUID.
- * @return The profile.
- */
- PlayerProfile load(@NotNull UUID uuid);
-
- /**
- * Load the server profile.
- *
- * @return The profile.
- */
- ServerProfile loadServerProfile();
-
- /**
- * Unload a player profile from memory.
- *
- * This will not save the profile first.
- *
- * @param uuid The uuid.
- */
- void unloadPlayer(@NotNull UUID uuid);
-
- /**
- * Save a player profile.
- *
- * Can run async if using MySQL.
- *
- * @param uuid The uuid.
- * @deprecated Saving changes is faster and should be used. Saving a player manually is not recommended.
- */
- @Deprecated
- default void savePlayer(@NotNull UUID uuid) {
- this.saveKeysFor(uuid, PersistentDataKey.values());
- }
-
- /**
- * Save keys for a player.
- *
- * Can run async if using MySQL.
- *
- * @param uuid The uuid.
- * @param keys The keys.
- */
- void saveKeysFor(@NotNull UUID uuid,
- @NotNull Set> keys);
-
- /**
- * Save all player data.
- *
- * @param async If the saving should be done asynchronously.
- * @deprecated async is now handled automatically depending on implementation.
- */
- @Deprecated(forRemoval = true)
- default void saveAll(boolean async) {
- saveAll();
- }
-
- /**
- * Save all player data.
- *
- * Can run async if using MySQL.
- *
- * @deprecated Never used.
- */
- @Deprecated(since = "6.36.0", forRemoval = true)
- default void saveAll() {
- // Do nothing.
- }
-
- /**
- * Commit all changes to the file.
- *
- * Does nothing if using MySQL.
- */
- void save();
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/ServerProfile.java b/eco-api/src/main/java/com/willfp/eco/core/data/ServerProfile.java
index c976bdd3..6feae5be 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/data/ServerProfile.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/data/ServerProfile.java
@@ -16,6 +16,6 @@ public interface ServerProfile extends Profile {
*/
@NotNull
static ServerProfile load() {
- return Eco.getHandler().getProfileHandler().loadServerProfile();
+ return Eco.get().getServerProfile();
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java
deleted file mode 100644
index 36cc22be..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/KeyRegistry.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.willfp.eco.core.data.keys;
-
-import com.willfp.eco.core.Eco;
-import org.bukkit.NamespacedKey;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Set;
-
-/**
- * API to register persistent data keys.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface KeyRegistry {
- /**
- * Register a persistent data key to be stored.
- *
- * @param key The key.
- */
- void registerKey(@NotNull PersistentDataKey> key);
-
- /**
- * Get all registered keys.
- *
- * @return The keys.
- */
- Set> getRegisteredKeys();
-
- /**
- * Get persistent data key from namespaced key.
- *
- * @param namespacedKey The key.
- * @return The key, or null if not found.
- */
- @Nullable
- PersistentDataKey> getKeyFrom(@NotNull NamespacedKey namespacedKey);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java
index 54b0ffbe..2ccc0cb7 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/data/keys/PersistentDataKey.java
@@ -43,7 +43,7 @@ public final class PersistentDataKey {
this.defaultValue = defaultValue;
this.type = type;
- Eco.getHandler().getKeyRegistry().registerKey(this);
+ Eco.get().registerPersistentKey(this);
}
@Override
@@ -126,7 +126,7 @@ public final class PersistentDataKey {
* @return The keys.
*/
public static Set> values() {
- return Eco.getHandler().getKeyRegistry().getRegisteredKeys();
+ return Eco.get().getRegisteredPersistentDataKeys();
}
@Override
diff --git a/eco-api/src/main/java/com/willfp/eco/core/display/Display.java b/eco-api/src/main/java/com/willfp/eco/core/display/Display.java
index acbca244..ea2db2c0 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/display/Display.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/display/Display.java
@@ -1,11 +1,22 @@
package com.willfp.eco.core.display;
+import com.willfp.eco.core.fast.FastItemStack;
+import com.willfp.eco.util.NamespacedKeyUtils;
+import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.persistence.PersistentDataType;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
/**
* Utility class to manage client-side item display.
*/
@@ -16,9 +27,14 @@ public final class Display {
public static final String PREFIX = "§z";
/**
- * The display handler.
+ * All registered modules.
*/
- private static DisplayHandler handler = null;
+ private static final Map> REGISTERED_MODULES = new TreeMap<>();
+
+ /**
+ * The finalize key.
+ */
+ private static final NamespacedKey FINALIZE_KEY = NamespacedKeyUtils.createEcoKey("finalized");
/**
* Display on ItemStacks.
@@ -39,7 +55,49 @@ public final class Display {
*/
public static ItemStack display(@NotNull final ItemStack itemStack,
@Nullable final Player player) {
- return handler.display(itemStack, player);
+ Map pluginVarArgs = new HashMap<>();
+
+ for (List modules : REGISTERED_MODULES.values()) {
+ for (DisplayModule module : modules) {
+ pluginVarArgs.put(module.getPluginName(), module.generateVarArgs(itemStack));
+ }
+ }
+
+ Display.revert(itemStack);
+
+ if (!itemStack.hasItemMeta()) {
+ return itemStack;
+ }
+
+ ItemStack original = itemStack.clone();
+ Inventory inventory = player == null ? null : player.getOpenInventory().getTopInventory();
+ boolean inInventory = inventory != null && inventory.contains(original);
+ boolean inGui = inventory != null && inventory.getHolder() == null;
+
+ DisplayProperties properties = new DisplayProperties(
+ inInventory,
+ inGui,
+ original
+ );
+
+ for (List modules : REGISTERED_MODULES.values()) {
+ for (DisplayModule module : modules) {
+ Object[] varargs = pluginVarArgs.get(module.getPluginName());
+
+ if (varargs == null) {
+ continue;
+ }
+
+ module.display(itemStack, varargs);
+
+ if (player != null) {
+ module.display(itemStack, player, varargs);
+ module.display(itemStack, player, properties, varargs);
+ }
+ }
+ }
+
+ return itemStack;
}
/**
@@ -71,7 +129,25 @@ public final class Display {
* @return The ItemStack.
*/
public static ItemStack revert(@NotNull final ItemStack itemStack) {
- return handler.revert(itemStack);
+ if (Display.isFinalized(itemStack)) {
+ Display.unfinalize(itemStack);
+ }
+
+ FastItemStack fast = FastItemStack.wrap(itemStack);
+
+ List lore = fast.getLore();
+
+ if (!lore.isEmpty() && lore.removeIf(line -> line.startsWith(Display.PREFIX))) {
+ fast.setLore(lore);
+ }
+
+ for (List modules : REGISTERED_MODULES.values()) {
+ for (DisplayModule module : modules) {
+ module.revert(itemStack);
+ }
+ }
+
+ return itemStack;
}
/**
@@ -81,7 +157,15 @@ public final class Display {
* @return The ItemStack.
*/
public static ItemStack finalize(@NotNull final ItemStack itemStack) {
- return handler.finalize(itemStack);
+ if (itemStack.getType().getMaxStackSize() > 1) {
+ return itemStack;
+ }
+
+ FastItemStack.wrap(itemStack)
+ .getPersistentDataContainer()
+ .set(FINALIZE_KEY, PersistentDataType.INTEGER, 1);
+
+ return itemStack;
}
/**
@@ -91,7 +175,11 @@ public final class Display {
* @return The ItemStack.
*/
public static ItemStack unfinalize(@NotNull final ItemStack itemStack) {
- return handler.unfinalize(itemStack);
+ FastItemStack.wrap(itemStack)
+ .getPersistentDataContainer()
+ .remove(FINALIZE_KEY);
+
+ return itemStack;
}
/**
@@ -101,7 +189,9 @@ public final class Display {
* @return If finalized.
*/
public static boolean isFinalized(@NotNull final ItemStack itemStack) {
- return handler.isFinalized(itemStack);
+ return FastItemStack.wrap(itemStack)
+ .getPersistentDataContainer()
+ .has(FINALIZE_KEY, PersistentDataType.INTEGER);
}
/**
@@ -110,23 +200,15 @@ public final class Display {
* @param module The module.
*/
public static void registerDisplayModule(@NotNull final DisplayModule module) {
- handler.registerDisplayModule(module);
- }
+ List modules = REGISTERED_MODULES.getOrDefault(
+ module.getWeight(),
+ new ArrayList<>()
+ );
- /**
- * Set the display handler.
- *
- * Internal API component, you will cause bugs if you create your own handler.
- *
- * @param handler The handler.
- */
- @ApiStatus.Internal
- public static void setHandler(@NotNull final DisplayHandler handler) {
- if (Display.handler != null) {
- throw new IllegalStateException("Display already initialized!");
- }
+ modules.removeIf(it -> it.getPluginName().equalsIgnoreCase(module.getPluginName()));
+ modules.add(module);
- Display.handler = handler;
+ REGISTERED_MODULES.put(module.getWeight(), modules);
}
private Display() {
diff --git a/eco-api/src/main/java/com/willfp/eco/core/display/DisplayHandler.java b/eco-api/src/main/java/com/willfp/eco/core/display/DisplayHandler.java
deleted file mode 100644
index 60976fb3..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/display/DisplayHandler.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.willfp.eco.core.display;
-
-import com.willfp.eco.core.Eco;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Interface for display implementations.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface DisplayHandler {
- /**
- * Register display module.
- *
- * @param module The module.
- */
- void registerDisplayModule(@NotNull DisplayModule module);
-
- /**
- * Display on ItemStacks.
- *
- * @param itemStack The item.
- * @param player The player.
- * @return The ItemStack.
- */
- ItemStack display(@NotNull ItemStack itemStack,
- @Nullable Player player);
-
- /**
- * Revert on ItemStacks.
- *
- * @param itemStack The item.
- * @return The ItemStack.
- */
- ItemStack revert(@NotNull ItemStack itemStack);
-
- /**
- * Finalize an ItemStacks.
- *
- * @param itemStack The item.
- * @return The ItemStack.
- */
- ItemStack finalize(@NotNull ItemStack itemStack);
-
- /**
- * Unfinalize an ItemStacks.
- *
- * @param itemStack The item.
- * @return The ItemStack.
- */
- ItemStack unfinalize(@NotNull ItemStack itemStack);
-
- /**
- * If an item is finalized.
- *
- * @param itemStack The item.
- * @return If finalized.
- */
- boolean isFinalized(@NotNull ItemStack itemStack);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueue.java b/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueue.java
index 884174ef..3774b0d4 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueue.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueue.java
@@ -21,13 +21,25 @@ public class DropQueue {
/**
* The internally used {@link DropQueue}.
*/
- private final InternalDropQueue handle;
+ private final DropQueue delegate;
/**
+ * Create a new DropQueue.
+ *
* @param player The player.
*/
public DropQueue(@NotNull final Player player) {
- handle = Eco.getHandler().getDropQueueFactory().create(player);
+ this.delegate = Eco.get().createDropQueue(player);
+ }
+
+ /**
+ * Create a new DropQueue with no delegate.
+ *
+ * Call this constructor if you're creating custom DropQueue
+ * implementations.
+ */
+ protected DropQueue() {
+ this.delegate = null;
}
/**
@@ -37,7 +49,11 @@ public class DropQueue {
* @return The DropQueue.
*/
public DropQueue addItem(@NotNull final ItemStack item) {
- handle.addItem(item);
+ if (delegate == null) {
+ return this;
+ }
+
+ delegate.addItem(item);
return this;
}
@@ -48,7 +64,11 @@ public class DropQueue {
* @return The DropQueue.
*/
public DropQueue addItems(@NotNull final Collection itemStacks) {
- handle.addItems(itemStacks);
+ if (delegate == null) {
+ return this;
+ }
+
+ delegate.addItems(itemStacks);
return this;
}
@@ -59,7 +79,11 @@ public class DropQueue {
* @return The DropQueue.
*/
public DropQueue addXP(final int amount) {
- handle.addXP(amount);
+ if (delegate == null) {
+ return this;
+ }
+
+ delegate.addXP(amount);
return this;
}
@@ -70,7 +94,11 @@ public class DropQueue {
* @return The DropQueue.
*/
public DropQueue setLocation(@NotNull final Location location) {
- handle.setLocation(location);
+ if (delegate == null) {
+ return this;
+ }
+
+ delegate.setLocation(location);
return this;
}
@@ -80,7 +108,11 @@ public class DropQueue {
* @return The DropQueue.
*/
public DropQueue forceTelekinesis() {
- handle.forceTelekinesis();
+ if (delegate == null) {
+ return this;
+ }
+
+ delegate.forceTelekinesis();
return this;
}
@@ -88,6 +120,10 @@ public class DropQueue {
* Push the queue.
*/
public void push() {
- handle.push();
+ if (delegate == null) {
+ return;
+ }
+
+ delegate.push();
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueueFactory.java b/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueueFactory.java
deleted file mode 100644
index 4e19b70b..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/drops/DropQueueFactory.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.willfp.eco.core.drops;
-
-import com.willfp.eco.core.Eco;
-import org.bukkit.entity.Player;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Internal component to create backend DropQueue implementations.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface DropQueueFactory {
- /**
- * Create a DropQueue.
- *
- * @param player The player.
- * @return The Queue.
- */
- InternalDropQueue create(@NotNull Player player);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/drops/InternalDropQueue.java b/eco-api/src/main/java/com/willfp/eco/core/drops/InternalDropQueue.java
deleted file mode 100644
index 8b8d51b2..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/drops/InternalDropQueue.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package com.willfp.eco.core.drops;
-
-import com.willfp.eco.core.Eco;
-import org.bukkit.Location;
-import org.bukkit.inventory.ItemStack;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Collection;
-
-/**
- * Internal interface for backend DropQueue implementations.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface InternalDropQueue {
- /**
- * Add item to queue.
- *
- * @param item The item to add.
- * @return The DropQueue.
- */
- InternalDropQueue addItem(@NotNull ItemStack item);
-
- /**
- * Add multiple items to queue.
- *
- * @param itemStacks The items to add.
- * @return The DropQueue.
- */
- InternalDropQueue addItems(@NotNull Collection itemStacks);
-
- /**
- * Add xp to queue.
- *
- * @param amount The amount to add.
- * @return The DropQueue.
- */
- InternalDropQueue addXP(int amount);
-
- /**
- * Set location of the origin of the drops.
- *
- * @param location The location.
- * @return The DropQueue.
- */
- InternalDropQueue setLocation(@NotNull Location location);
-
- /**
- * Force the queue to act as if player is telekinetic.
- *
- * @return The DropQueue.
- */
- InternalDropQueue forceTelekinesis();
-
- /**
- * Push the queue.
- */
- void push();
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityController.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityController.java
index 2d083f0d..d8a0e315 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityController.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityController.java
@@ -101,6 +101,6 @@ public interface EntityController {
* @return The entity controller.
*/
static EntityController getFor(@NotNull final T entity) {
- return Eco.getHandler().createEntityController(entity);
+ return Eco.get().createEntityController(entity);
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/impl/EmptyTestableEntity.java b/eco-api/src/main/java/com/willfp/eco/core/entities/impl/EmptyTestableEntity.java
index 9a6de05a..08a6ccf7 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/entities/impl/EmptyTestableEntity.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/entities/impl/EmptyTestableEntity.java
@@ -28,6 +28,6 @@ public class EmptyTestableEntity implements TestableEntity {
public Entity spawn(@NotNull final Location location) {
Validate.notNull(location.getWorld());
- return Eco.getHandler().createDummyEntity(location);
+ return Eco.get().createDummyEntity(location);
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/fast/FastItemStack.java b/eco-api/src/main/java/com/willfp/eco/core/fast/FastItemStack.java
index a6843fdb..2b6c2c96 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/fast/FastItemStack.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/fast/FastItemStack.java
@@ -72,6 +72,7 @@ public interface FastItemStack extends PersistentDataHolder {
* @deprecated Poorly named method. Use getEnchantmentLevel instead.
*/
@Deprecated(since = "6.34.0", forRemoval = true)
+ @SuppressWarnings("DeprecatedIsStillUsed")
default int getLevelOnItem(@NotNull Enchantment enchantment,
boolean checkStored) {
return getEnchantmentLevel(enchantment, checkStored);
@@ -271,6 +272,6 @@ public interface FastItemStack extends PersistentDataHolder {
* @return The FastItemStack.
*/
static FastItemStack wrap(@Nullable final ItemStack itemStack) {
- return Eco.getHandler().createFastItemStack(Objects.requireNonNullElseGet(itemStack, () -> new ItemStack(Material.AIR)));
+ return Eco.get().createFastItemStack(Objects.requireNonNullElseGet(itemStack, () -> new ItemStack(Material.AIR)));
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/component/GUIComponent.java b/eco-api/src/main/java/com/willfp/eco/core/gui/GUIComponent.java
similarity index 98%
rename from eco-api/src/main/java/com/willfp/eco/core/gui/component/GUIComponent.java
rename to eco-api/src/main/java/com/willfp/eco/core/gui/GUIComponent.java
index f0c3fc97..89a26392 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/component/GUIComponent.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/GUIComponent.java
@@ -1,4 +1,4 @@
-package com.willfp.eco.core.gui.component;
+package com.willfp.eco.core.gui;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.Slot;
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/GUIFactory.java b/eco-api/src/main/java/com/willfp/eco/core/gui/GUIFactory.java
deleted file mode 100644
index bb858d30..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/GUIFactory.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.willfp.eco.core.gui;
-
-import com.willfp.eco.core.Eco;
-import com.willfp.eco.core.gui.menu.Menu;
-import com.willfp.eco.core.gui.menu.MenuBuilder;
-import com.willfp.eco.core.gui.menu.MenuType;
-import com.willfp.eco.core.gui.slot.SlotBuilder;
-import com.willfp.eco.core.gui.slot.functional.SlotProvider;
-import org.bukkit.inventory.ItemStack;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Internal component used by {@link com.willfp.eco.core.gui.menu.Menu#builder(int)}
- * and {@link com.willfp.eco.core.gui.slot.Slot#builder(ItemStack)}.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface GUIFactory {
- /**
- * Create slot builder.
- *
- * @param provider The provider.
- * @return The builder.
- */
- @NotNull
- SlotBuilder createSlotBuilder(@NotNull SlotProvider provider);
-
- /**
- * Create menu builder.
- *
- * @param rows The amount of rows.
- * @param type The type.
- * @return The builder.
- */
- @NotNull
- MenuBuilder createMenuBuilder(int rows,
- @NotNull MenuType type);
-
- /**
- * Combine the state of two menus together.
- *
- * @param base The base menu.
- * @param additional The additional state.
- * @return The menu.
- */
- @NotNull
- Menu blendMenuState(@NotNull Menu base,
- @NotNull Menu additional);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java b/eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
index a3b9833a..c6513cb5 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/menu/Menu.java
@@ -241,7 +241,7 @@ public interface Menu {
* @return The builder.
*/
static MenuBuilder builder(final int rows) {
- return Eco.getHandler().getGUIFactory().createMenuBuilder(
+ return Eco.get().createMenuBuilder(
rows,
MenuType.NORMAL
);
@@ -254,6 +254,6 @@ public interface Menu {
* @return The builder.
*/
static MenuBuilder builder(@NotNull final MenuType type) {
- return Eco.getHandler().getGUIFactory().createMenuBuilder(type.getDefaultRows(), type);
+ return Eco.get().createMenuBuilder(type.getDefaultRows(), type);
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/menu/MenuBuilder.java b/eco-api/src/main/java/com/willfp/eco/core/gui/menu/MenuBuilder.java
index 28c14faf..31cd87c9 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/menu/MenuBuilder.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/menu/MenuBuilder.java
@@ -1,6 +1,6 @@
package com.willfp.eco.core.gui.menu;
-import com.willfp.eco.core.gui.component.GUIComponent;
+import com.willfp.eco.core.gui.GUIComponent;
import com.willfp.eco.core.gui.page.Page;
import com.willfp.eco.core.gui.page.PageBuilder;
import com.willfp.eco.core.gui.slot.FillerMask;
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/page/Page.java b/eco-api/src/main/java/com/willfp/eco/core/gui/page/Page.java
index 472fbe80..93351aa0 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/page/Page.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/page/Page.java
@@ -1,7 +1,7 @@
package com.willfp.eco.core.gui.page;
import com.willfp.eco.core.Eco;
-import com.willfp.eco.core.gui.component.GUIComponent;
+import com.willfp.eco.core.gui.GUIComponent;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.menu.MenuBuilder;
import com.willfp.eco.core.gui.slot.Slot;
@@ -82,7 +82,7 @@ public final class Page implements GUIComponent {
}
if (delegate == null) {
- delegate = Eco.getHandler().getGUIFactory().blendMenuState(page, menu);
+ delegate = Eco.get().blendMenuState(page, menu);
}
return page.getSlot(row, column, player, delegate);
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageBuilder.java b/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageBuilder.java
index 7a6c5383..b7976a9e 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageBuilder.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageBuilder.java
@@ -1,6 +1,6 @@
package com.willfp.eco.core.gui.page;
-import com.willfp.eco.core.gui.component.GUIComponent;
+import com.willfp.eco.core.gui.GUIComponent;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.menu.MenuLayer;
import com.willfp.eco.core.gui.slot.FillerMask;
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageChanger.java b/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageChanger.java
index c2e7417f..da752528 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageChanger.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/page/PageChanger.java
@@ -1,6 +1,6 @@
package com.willfp.eco.core.gui.page;
-import com.willfp.eco.core.gui.component.GUIComponent;
+import com.willfp.eco.core.gui.GUIComponent;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.Slot;
import org.bukkit.entity.Player;
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/FillerMask.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/FillerMask.java
index 3e2f1aa0..8ed40dc3 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/FillerMask.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/FillerMask.java
@@ -1,6 +1,6 @@
package com.willfp.eco.core.gui.slot;
-import com.willfp.eco.core.gui.component.GUIComponent;
+import com.willfp.eco.core.gui.GUIComponent;
import com.willfp.eco.core.items.builder.ItemStackBuilder;
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
diff --git a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
index 5136a9b4..787653e3 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/gui/slot/Slot.java
@@ -1,7 +1,7 @@
package com.willfp.eco.core.gui.slot;
import com.willfp.eco.core.Eco;
-import com.willfp.eco.core.gui.component.GUIComponent;
+import com.willfp.eco.core.gui.GUIComponent;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.functional.SlotProvider;
import com.willfp.eco.core.items.TestableItem;
@@ -97,7 +97,7 @@ public interface Slot extends GUIComponent {
* @return The builder.
*/
static SlotBuilder builder() {
- return Eco.getHandler().getGUIFactory().createSlotBuilder((player, menu) -> new ItemStack(Material.AIR));
+ return Eco.get().createSlotBuilder((player, menu) -> new ItemStack(Material.AIR));
}
/**
@@ -107,7 +107,7 @@ public interface Slot extends GUIComponent {
* @return The builder.
*/
static SlotBuilder builder(@NotNull final ItemStack itemStack) {
- return Eco.getHandler().getGUIFactory().createSlotBuilder((player, menu) -> itemStack);
+ return Eco.get().createSlotBuilder((player, menu) -> itemStack);
}
/**
@@ -117,7 +117,7 @@ public interface Slot extends GUIComponent {
* @return The builder.
*/
static SlotBuilder builder(@NotNull final TestableItem item) {
- return Eco.getHandler().getGUIFactory().createSlotBuilder((player, menu) -> item.getItem());
+ return Eco.get().createSlotBuilder((player, menu) -> item.getItem());
}
/**
@@ -127,7 +127,7 @@ public interface Slot extends GUIComponent {
* @return The builder.
*/
static SlotBuilder builder(@NotNull final Function provider) {
- return Eco.getHandler().getGUIFactory().createSlotBuilder((player, menu) -> provider.apply(player));
+ return Eco.get().createSlotBuilder((player, menu) -> provider.apply(player));
}
/**
@@ -137,7 +137,7 @@ public interface Slot extends GUIComponent {
* @return The builder.
*/
static SlotBuilder builder(@NotNull final SlotProvider provider) {
- return Eco.getHandler().getGUIFactory().createSlotBuilder(provider);
+ return Eco.get().createSlotBuilder(provider);
}
/**
diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/anticheat/AnticheatManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/anticheat/AnticheatManager.java
index 7ce9a87d..5d3433a7 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/integrations/anticheat/AnticheatManager.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/anticheat/AnticheatManager.java
@@ -38,7 +38,7 @@ public final class AnticheatManager {
*/
public static void register(@NotNull final AnticheatIntegration anticheat) {
if (anticheat instanceof Listener) {
- Eco.getHandler().getEcoPlugin().getEventManager().registerListener((Listener) anticheat);
+ Eco.get().getEcoPlugin().getEventManager().registerListener((Listener) anticheat);
}
ANTICHEATS.removeIf(it -> it.getPluginName().equalsIgnoreCase(anticheat.getPluginName()));
ANTICHEATS.add(anticheat);
diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderEntry.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderEntry.java
index a7f7c850..7f4cbb60 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderEntry.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderEntry.java
@@ -158,13 +158,13 @@ public class PlaceholderEntry {
Placeholder toModernPlaceholder() {
if (this.requiresPlayer) {
return new PlayerPlaceholder(
- Objects.requireNonNullElse(plugin, Eco.getHandler().getEcoPlugin()),
+ Objects.requireNonNullElse(plugin, Eco.get().getEcoPlugin()),
identifier,
function
);
} else {
return new PlayerlessPlaceholder(
- Objects.requireNonNullElse(plugin, Eco.getHandler().getEcoPlugin()),
+ Objects.requireNonNullElse(plugin, Eco.get().getEcoPlugin()),
identifier,
() -> function.apply(null)
);
diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java
index a3dd6786..89def921 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/placeholder/PlaceholderManager.java
@@ -92,7 +92,7 @@ public final class PlaceholderManager {
throw new IllegalArgumentException("Static placeholders cannot be registered!");
}
- EcoPlugin plugin = placeholder.getPlugin() == null ? Eco.getHandler().getEcoPlugin() : placeholder.getPlugin();
+ EcoPlugin plugin = placeholder.getPlugin() == null ? Eco.get().getEcoPlugin() : placeholder.getPlugin();
Map pluginPlaceholders = REGISTERED_PLACEHOLDERS
.getOrDefault(plugin, new HashMap<>());
pluginPlaceholders.put(placeholder.getIdentifier(), placeholder);
@@ -136,11 +136,11 @@ public final class PlaceholderManager {
public static String getResult(@Nullable final Player player,
@NotNull final String identifier,
@Nullable final EcoPlugin plugin) {
- EcoPlugin owner = plugin == null ? Eco.getHandler().getEcoPlugin() : plugin;
+ EcoPlugin owner = plugin == null ? Eco.get().getEcoPlugin() : plugin;
Placeholder placeholder = REGISTERED_PLACEHOLDERS.getOrDefault(owner, new HashMap<>()).get(identifier.toLowerCase());
if (placeholder == null && plugin != null) {
- Placeholder alternate = REGISTERED_PLACEHOLDERS.getOrDefault(Eco.getHandler().getEcoPlugin(), new HashMap<>())
+ Placeholder alternate = REGISTERED_PLACEHOLDERS.getOrDefault(Eco.get().getEcoPlugin(), new HashMap<>())
.get(identifier.toLowerCase());
if (alternate != null) {
placeholder = alternate;
diff --git a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java
index 882f498e..f6d7fd2f 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/integrations/shop/ShopManager.java
@@ -30,22 +30,6 @@ public final class ShopManager {
REGISTERED.add(integration);
}
- /**
- * Register the events with eco.
- *
- * @param plugin Instance of eco.
- */
- @ApiStatus.Internal
- public static void registerEvents(@NotNull final EcoPlugin plugin) {
- for (ShopIntegration integration : REGISTERED) {
- Listener listener = integration.getSellEventAdapter();
-
- if (listener != null) {
- plugin.getEventManager().registerListener(listener);
- }
- }
- }
-
/**
* Register eco item provider for shop plugins.
*/
@@ -89,6 +73,15 @@ public final class ShopManager {
return 0.0;
}
+ /**
+ * Get all registered integrations.
+ *
+ * @return The integrations.
+ */
+ public static Set getRegisteredIntegrations() {
+ return new HashSet<>(REGISTERED);
+ }
+
private ShopManager() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java
index 6b493cff..252a2d27 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/items/CustomItem.java
@@ -53,7 +53,7 @@ public class CustomItem implements TestableItem {
immediately after due to registration order; so eco waits until the item should be
working in order to check.
*/
- Eco.getHandler().getEcoPlugin().getScheduler().runLater(() -> {
+ Eco.get().getEcoPlugin().getScheduler().runLater(() -> {
if (!matches(getItem())) {
Bukkit.getLogger().severe("Item with key " + key + " is invalid!");
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/Items.java b/eco-api/src/main/java/com/willfp/eco/core/items/Items.java
index 1ec324c5..d31fcd0c 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/items/Items.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/items/Items.java
@@ -192,7 +192,7 @@ public final class Items {
@NotNull
public static TestableItem lookup(@NotNull final String key) {
if (key.startsWith("{")) {
- return Eco.getHandler().getSNBTHandler().createTestable(key);
+ return Eco.get().testableItemFromSNBT(key);
}
return ITEMS_LOOKUP_HANDLER.parseKey(key);
@@ -538,7 +538,7 @@ public final class Items {
*/
@NotNull
public static String toSNBT(@NotNull final ItemStack itemStack) {
- return Eco.getHandler().getSNBTHandler().toSNBT(itemStack);
+ return Eco.get().toSNBT(itemStack);
}
/**
@@ -549,7 +549,7 @@ public final class Items {
*/
@Nullable
public static ItemStack fromSNBT(@NotNull final String snbt) {
- return Eco.getHandler().getSNBTHandler().fromSNBT(snbt);
+ return Eco.get().fromSNBT(snbt);
}
/**
diff --git a/eco-api/src/main/java/com/willfp/eco/core/items/SNBTHandler.java b/eco-api/src/main/java/com/willfp/eco/core/items/SNBTHandler.java
deleted file mode 100644
index 1a73ae34..00000000
--- a/eco-api/src/main/java/com/willfp/eco/core/items/SNBTHandler.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.willfp.eco.core.items;
-
-import com.willfp.eco.core.Eco;
-import org.bukkit.inventory.ItemStack;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * API to handle SNBT conversion.
- */
-@ApiStatus.Internal
-@Eco.HandlerComponent
-public interface SNBTHandler {
- /**
- * Get item from SNBT.
- *
- * @param snbt The NBT string.
- * @return The ItemStack, or null if invalid.
- */
- @Nullable
- ItemStack fromSNBT(@NotNull String snbt);
-
- /**
- * Convert item to SNBT.
- *
- * @param itemStack The item.
- * @return The NBT string.
- */
- @NotNull
- String toSNBT(@NotNull ItemStack itemStack);
-
- /**
- * Make TestableItem from SNBT.
- *
- * @param snbt The NBT string.
- * @return The TestableItem.
- */
- @NotNull
- TestableItem createTestable(@NotNull String snbt);
-}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/placeholder/InjectablePlaceholder.java b/eco-api/src/main/java/com/willfp/eco/core/placeholder/InjectablePlaceholder.java
index cfd51de8..ae916ecf 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/placeholder/InjectablePlaceholder.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/placeholder/InjectablePlaceholder.java
@@ -9,6 +9,6 @@ import com.willfp.eco.core.EcoPlugin;
public sealed interface InjectablePlaceholder extends Placeholder permits PlayerStaticPlaceholder, StaticPlaceholder {
@Override
default EcoPlugin getPlugin() {
- return Eco.getHandler().getEcoPlugin();
+ return Eco.get().getEcoPlugin();
}
}
diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java
index e7d7e74e..7cb6f723 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapedCraftingRecipe.java
@@ -96,7 +96,7 @@ public final class ShapedCraftingRecipe extends PluginDependent imple
shapedRecipe.setIngredient(character, parts.get(i).getItem().getType());
}
- if (Eco.getHandler().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
+ if (Eco.get().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
ShapedRecipe displayedRecipe = new ShapedRecipe(this.getDisplayedKey(), this.getOutput());
displayedRecipe.shape("012", "345", "678");
for (int i = 0; i < 9; i++) {
@@ -124,7 +124,7 @@ public final class ShapedCraftingRecipe extends PluginDependent imple
List lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
assert lore != null;
lore.add("");
- String add = Eco.getHandler().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
+ String add = Eco.get().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
add = add.replace("%amount%", String.valueOf(item.getAmount()));
lore.add(add);
meta.setLore(lore);
diff --git a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapelessCraftingRecipe.java b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapelessCraftingRecipe.java
index 17e7f6e6..35ed1ee0 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapelessCraftingRecipe.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/recipe/recipes/ShapelessCraftingRecipe.java
@@ -101,7 +101,7 @@ public final class ShapelessCraftingRecipe extends PluginDependent im
shapelessRecipe.addIngredient(part.getItem().getType());
}
- if (Eco.getHandler().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
+ if (Eco.get().getEcoPlugin().getConfigYml().getBool("displayed-recipes")) {
ShapelessRecipe displayedRecipe = new ShapelessRecipe(this.getDisplayedKey(), this.getOutput());
for (TestableItem part : parts) {
List items = new ArrayList<>();
@@ -122,7 +122,7 @@ public final class ShapelessCraftingRecipe extends PluginDependent im
List lore = meta.hasLore() ? meta.getLore() : new ArrayList<>();
assert lore != null;
lore.add("");
- String add = Eco.getHandler().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
+ String add = Eco.get().getEcoPlugin().getLangYml().getFormattedString("multiple-in-craft");
add = add.replace("%amount%", String.valueOf(item.getAmount()));
lore.add(add);
meta.setLore(lore);
diff --git a/eco-api/src/main/java/com/willfp/eco/core/web/Paste.java b/eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
index f76ceacc..3ecc5dd7 100644
--- a/eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
+++ b/eco-api/src/main/java/com/willfp/eco/core/web/Paste.java
@@ -59,7 +59,7 @@ public class Paste {
* @param callback The consumer to accept the response token.
*/
public void getHastebinToken(@NotNull final Consumer callback) {
- Eco.getHandler().getEcoPlugin().getScheduler().runAsync(() -> {
+ Eco.get().getEcoPlugin().getScheduler().runAsync(() -> {
try {
byte[] postData = URLEncoder.encode(contents, StandardCharsets.UTF_8).getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
diff --git a/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java b/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java
index b57a776f..28392748 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/MenuUtils.java
@@ -70,7 +70,7 @@ public final class MenuUtils {
*/
@Nullable
public static Menu getOpenMenu(@NotNull final Player player) {
- return Eco.getHandler().getOpenMenu(player);
+ return Eco.get().getOpenMenu(player);
}
private MenuUtils() {
diff --git a/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java b/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java
index 747d55cd..987469e0 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/NamespacedKeyUtils.java
@@ -32,7 +32,7 @@ public final class NamespacedKeyUtils {
@NotNull
public static NamespacedKey create(@NotNull final String namespace,
@NotNull final String key) {
- return Eco.getHandler().createNamespacedKey(
+ return Eco.get().createNamespacedKey(
namespace,
key
);
diff --git a/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java b/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java
index 235780a1..5f555c3c 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/NumberUtils.java
@@ -323,7 +323,7 @@ public final class NumberUtils {
@Nullable final Player player,
@NotNull final PlaceholderInjectable context,
@NotNull final Collection additionalPlayers) {
- return Eco.getHandler().evaluate(expression, player, context, additionalPlayers);
+ return Eco.get().evaluate(expression, player, context, additionalPlayers);
}
private NumberUtils() {
diff --git a/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java b/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java
index 91d8107c..f97db394 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/PlayerUtils.java
@@ -42,7 +42,7 @@ public final class PlayerUtils {
*/
@NotNull
public static Audience getAudience(@NotNull final Player player) {
- BukkitAudiences adventure = Eco.getHandler().getAdventure();
+ BukkitAudiences adventure = Eco.get().getAdventure();
if (Prerequisite.HAS_PAPER.isMet()) {
if (player instanceof Audience) {
@@ -67,7 +67,7 @@ public final class PlayerUtils {
*/
@NotNull
public static Audience getAudience(@NotNull final CommandSender sender) {
- BukkitAudiences adventure = Eco.getHandler().getAdventure();
+ BukkitAudiences adventure = Eco.get().getAdventure();
if (Prerequisite.HAS_PAPER.isMet()) {
if (sender instanceof Audience) {
diff --git a/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java b/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java
index 74659ab5..2f95d9f8 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/ServerUtils.java
@@ -1,29 +1,18 @@
package com.willfp.eco.util;
-import org.apache.commons.lang.Validate;
-import org.jetbrains.annotations.ApiStatus;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.function.Supplier;
+import com.willfp.eco.core.Eco;
/**
* Utilities / API methods for the server.
*/
public final class ServerUtils {
- /**
- * The TPS supplier.
- */
- private static Supplier tpsSupplier = null;
-
/**
* Get the current server TPS.
*
* @return The TPS.
*/
public static double getTps() {
- Validate.notNull(tpsSupplier, "Not initialized!");
-
- double tps = tpsSupplier.get();
+ double tps = Eco.get().getTPS();
if (tps > 20) {
return 20;
@@ -32,18 +21,6 @@ public final class ServerUtils {
}
}
- /**
- * Initialize the tps supplier function.
- *
- * @param function The function.
- */
- @ApiStatus.Internal
- public static void initialize(@NotNull final Supplier function) {
- Validate.isTrue(tpsSupplier == null, "Already initialized!");
-
- tpsSupplier = function;
- }
-
private ServerUtils() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
diff --git a/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java b/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java
index 5eeb2ee4..4867d1a4 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/SkullUtils.java
@@ -17,7 +17,7 @@ public final class SkullUtils {
*/
public static void setSkullTexture(@NotNull final SkullMeta meta,
@NotNull final String base64) {
- Eco.getHandler().setSkullTexture(meta, base64);
+ Eco.get().setSkullTexture(meta, base64);
}
/**
@@ -28,7 +28,7 @@ public final class SkullUtils {
*/
@Nullable
public static String getSkullTexture(@NotNull final SkullMeta meta) {
- return Eco.getHandler().getSkullTexture(meta);
+ return Eco.get().getSkullTexture(meta);
}
private SkullUtils() {
diff --git a/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java b/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java
index 319fcc9c..ae6be762 100644
--- a/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java
+++ b/eco-api/src/main/java/com/willfp/eco/util/StringUtils.java
@@ -339,7 +339,7 @@ public final class StringUtils {
}
private static String translateMiniMessage(@NotNull final String message) {
- return Eco.getHandler().formatMiniMessage(message);
+ return Eco.get().formatMiniMessage(message);
}
private static String translateHexColorCodes(@NotNull final String message) {
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt
deleted file mode 100644
index aeb16f4d..00000000
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/config/EcoConfigFactory.kt
+++ /dev/null
@@ -1,61 +0,0 @@
-package com.willfp.eco.internal.config
-
-import com.willfp.eco.core.PluginLike
-import com.willfp.eco.core.config.ConfigType
-import com.willfp.eco.core.config.interfaces.Config
-import com.willfp.eco.core.config.interfaces.LoadableConfig
-import com.willfp.eco.core.config.wrapper.ConfigFactory
-import org.bukkit.configuration.ConfigurationSection
-
-object EcoConfigFactory : ConfigFactory {
- override fun createConfig(bukkit: ConfigurationSection): Config {
- val config = createConfig(emptyMap(), ConfigType.YAML)
- for (key in bukkit.getKeys(true)) {
- config.set(key, bukkit.get(key))
- }
-
- return config
- }
-
- override fun createConfig(values: Map, type: ConfigType): Config =
- EcoConfigSection(type, values)
-
- override fun createConfig(contents: String, type: ConfigType): Config =
- EcoConfigSection(type, type.toMap(contents))
-
- override fun createLoadableConfig(
- configName: String,
- plugin: PluginLike,
- subDirectoryPath: String,
- source: Class<*>,
- type: ConfigType,
- requiresChangesToSave: Boolean
- ): LoadableConfig = EcoLoadableConfig(
- type,
- configName,
- plugin,
- subDirectoryPath,
- source,
- requiresChangesToSave
- )
-
- override fun createUpdatableConfig(
- configName: String,
- plugin: PluginLike,
- subDirectoryPath: String,
- source: Class<*>,
- removeUnused: Boolean,
- type: ConfigType,
- requiresChangesToSave: Boolean,
- vararg updateBlacklist: String
- ): LoadableConfig = EcoUpdatableConfig(
- type,
- configName,
- plugin,
- subDirectoryPath,
- source,
- removeUnused,
- requiresChangesToSave,
- *updateBlacklist
- )
-}
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt
deleted file mode 100644
index d7c8b94c..00000000
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt
+++ /dev/null
@@ -1,112 +0,0 @@
-package com.willfp.eco.internal.display
-
-import com.willfp.eco.core.EcoPlugin
-import com.willfp.eco.core.display.Display
-import com.willfp.eco.core.display.DisplayHandler
-import com.willfp.eco.core.display.DisplayModule
-import com.willfp.eco.core.display.DisplayProperties
-import com.willfp.eco.core.fast.fast
-import org.bukkit.NamespacedKey
-import org.bukkit.entity.Player
-import org.bukkit.inventory.ItemStack
-import org.bukkit.persistence.PersistentDataType
-
-class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler {
- private val registeredModules = sortedMapOf>()
- private val finalizeKey: NamespacedKey = plugin.createNamespacedKey("finalized")
-
- override fun registerDisplayModule(module: DisplayModule) {
- val modules = registeredModules[module.weight] ?: mutableListOf()
- modules.removeIf {
- it.pluginName.equals(module.pluginName, ignoreCase = true)
- }
- modules.add(module)
- registeredModules[module.weight] = modules
- }
-
- override fun display(itemStack: ItemStack, player: Player?): ItemStack {
- val pluginVarArgs = mutableMapOf>()
-
- for ((_, modules) in registeredModules) {
- for (module in modules) {
- pluginVarArgs[module.pluginName] = module.generateVarArgs(itemStack)
- }
- }
-
- Display.revert(itemStack)
-
- if (!itemStack.hasItemMeta()) {
- return itemStack
- }
-
- val original = itemStack.clone()
- val inventory = player?.openInventory?.topInventory
- val inInventory = inventory?.contains(original) ?: false
-
- val props = DisplayProperties(
- inInventory,
- inInventory && inventory?.holder == null,
- original
- )
-
- for ((_, modules) in registeredModules) {
- for (module in modules) {
- val varargs = pluginVarArgs[module.pluginName] ?: continue
-
- module.display(itemStack, *varargs)
-
- if (player != null) {
- module.display(itemStack, player as Player?, *varargs)
- module.display(itemStack, player as Player?, props, *varargs)
- }
- }
- }
-
- return itemStack
- }
-
- override fun revert(itemStack: ItemStack): ItemStack {
- if (Display.isFinalized(itemStack)) {
- Display.unfinalize(itemStack)
- }
-
- val fast = itemStack.fast()
- val lore = fast.lore
-
- if (lore.isNotEmpty() && lore.removeIf { line: String ->
- line.startsWith(
- Display.PREFIX
- )
- }) { // Only modify lore if needed.
- fast.lore = lore
- }
-
- for ((_, modules) in registeredModules) {
- for (module in modules) {
- module.revert(itemStack)
- }
- }
-
- return itemStack
- }
-
- override fun finalize(itemStack: ItemStack): ItemStack {
- if (itemStack.type.maxStackSize > 1) {
- return itemStack
- }
-
- itemStack.fast().persistentDataContainer.set(finalizeKey, PersistentDataType.INTEGER, 1)
-
- return itemStack
- }
-
- override fun unfinalize(itemStack: ItemStack): ItemStack {
- itemStack.fast().persistentDataContainer.remove(finalizeKey)
-
- return itemStack
- }
-
- override fun isFinalized(itemStack: ItemStack): Boolean {
- return itemStack.fast().persistentDataContainer.has(finalizeKey, PersistentDataType.INTEGER)
- }
-}
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/DropManager.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/DropManager.kt
deleted file mode 100644
index 3bea626f..00000000
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/DropManager.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.willfp.eco.internal.drops
-
-import com.willfp.eco.core.EcoPlugin
-
-object DropManager {
- var type = DropQueueType.COLLATED
-
- fun update(plugin: EcoPlugin) {
- type = if (plugin.configYml.getBool("use-fast-collated-drops")) DropQueueType.COLLATED else DropQueueType.STANDARD
- }
-}
\ No newline at end of file
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/DropQueueType.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/DropQueueType.kt
deleted file mode 100644
index 4c838df9..00000000
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/DropQueueType.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.willfp.eco.internal.drops
-
-enum class DropQueueType {
- STANDARD, COLLATED
-}
\ No newline at end of file
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/impl/EcoDropQueue.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt
similarity index 83%
rename from eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/impl/EcoDropQueue.kt
rename to eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt
index 841621c4..0f6e6d57 100644
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/impl/EcoDropQueue.kt
+++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueue.kt
@@ -1,6 +1,6 @@
-package com.willfp.eco.internal.drops.impl
+package com.willfp.eco.internal.drops
-import com.willfp.eco.core.drops.InternalDropQueue
+import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.core.events.DropQueuePushEvent
import com.willfp.eco.core.integrations.antigrief.AntigriefManager
import com.willfp.eco.util.TelekinesisUtils
@@ -13,33 +13,33 @@ import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.util.Vector
-open class EcoDropQueue(val player: Player) : InternalDropQueue {
+open class EcoDropQueue(val player: Player) : DropQueue() {
val items = mutableListOf()
var xp: Int = 0
var location: Location
var hasTelekinesis = false
- override fun addItem(item: ItemStack): InternalDropQueue {
+ override fun addItem(item: ItemStack): DropQueue {
items.add(item)
return this
}
- override fun addItems(itemStacks: Collection): InternalDropQueue {
+ override fun addItems(itemStacks: Collection): DropQueue {
items.addAll(itemStacks)
return this
}
- override fun addXP(amount: Int): InternalDropQueue {
+ override fun addXP(amount: Int): DropQueue {
xp += amount
return this
}
- override fun setLocation(location: Location): InternalDropQueue {
+ override fun setLocation(location: Location): DropQueue {
this.location = location
return this
}
- override fun forceTelekinesis(): InternalDropQueue {
+ override fun forceTelekinesis(): DropQueue {
hasTelekinesis = true
return this
}
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueueFactory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueueFactory.kt
deleted file mode 100644
index da9bd5a1..00000000
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoDropQueueFactory.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.willfp.eco.internal.drops
-
-import com.willfp.eco.core.drops.DropQueueFactory
-import com.willfp.eco.core.drops.InternalDropQueue
-import com.willfp.eco.internal.drops.impl.EcoDropQueue
-import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue
-import org.bukkit.entity.Player
-
-object EcoDropQueueFactory : DropQueueFactory {
- override fun create(player: Player): InternalDropQueue {
- return if (DropManager.type == DropQueueType.COLLATED) EcoFastCollatedDropQueue(player) else EcoDropQueue(
- player
- )
- }
-}
\ No newline at end of file
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/impl/EcoFastCollatedDropQueue.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoFastCollatedDropQueue.kt
similarity index 96%
rename from eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/impl/EcoFastCollatedDropQueue.kt
rename to eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoFastCollatedDropQueue.kt
index 246d0023..d436f0fe 100644
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/impl/EcoFastCollatedDropQueue.kt
+++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/drops/EcoFastCollatedDropQueue.kt
@@ -1,4 +1,4 @@
-package com.willfp.eco.internal.drops.impl
+package com.willfp.eco.internal.drops
import org.bukkit.Location
import org.bukkit.entity.Player
@@ -29,7 +29,6 @@ class EcoFastCollatedDropQueue(player: Player) : EcoDropQueue(player) {
var xp: Int,
var telekinetic: Boolean
) {
-
fun addDrops(toAdd: List): CollatedDrops {
drops.addAll(toAdd)
return this
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt
index 045f8bdb..723ce522 100644
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt
+++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/extensions/EcoExtensionLoader.kt
@@ -33,7 +33,7 @@ class EcoExtensionLoader(
runCatching { loadExtension(extensionJar) }.onFailure {
this.plugin.logger.warning(extensionJar.name + " caused an error!")
- if (Eco.getHandler().ecoPlugin.configYml.getBool("log-full-extension-errors")) {
+ if (Eco.get().ecoPlugin.configYml.getBool("log-full-extension-errors")) {
it.printStackTrace()
}
}
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/EcoGUIFactory.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/EcoGUIFactory.kt
deleted file mode 100644
index fdfca628..00000000
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/EcoGUIFactory.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.willfp.eco.internal.gui
-
-import com.willfp.eco.core.gui.GUIFactory
-import com.willfp.eco.core.gui.menu.Menu
-import com.willfp.eco.core.gui.menu.MenuBuilder
-import com.willfp.eco.core.gui.menu.MenuType
-import com.willfp.eco.core.gui.slot.functional.SlotProvider
-import com.willfp.eco.internal.gui.menu.EcoMenuBuilder
-import com.willfp.eco.internal.gui.page.MergedStateMenu
-import com.willfp.eco.internal.gui.slot.EcoSlotBuilder
-
-object EcoGUIFactory : GUIFactory {
- override fun createSlotBuilder(provider: SlotProvider) =
- EcoSlotBuilder(provider)
-
- override fun createMenuBuilder(rows: Int, type: MenuType): MenuBuilder =
- EcoMenuBuilder(rows, type.columns)
-
- override fun blendMenuState(base: Menu, additional: Menu): Menu =
- MergedStateMenu(base, additional)
-}
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/page/MergedStateMenu.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/MergedStateMenu.kt
similarity index 94%
rename from eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/page/MergedStateMenu.kt
rename to eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/MergedStateMenu.kt
index d90241ec..d6b1075d 100644
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/page/MergedStateMenu.kt
+++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/MergedStateMenu.kt
@@ -1,4 +1,4 @@
-package com.willfp.eco.internal.gui.page
+package com.willfp.eco.internal.gui
import com.willfp.eco.core.gui.menu.Menu
import org.bukkit.entity.Player
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt
index 5cc441b5..9772d79b 100644
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt
+++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenu.kt
@@ -1,6 +1,6 @@
package com.willfp.eco.internal.gui.menu
-import com.willfp.eco.core.gui.component.GUIComponent
+import com.willfp.eco.core.gui.GUIComponent
import com.willfp.eco.core.gui.menu.CloseHandler
import com.willfp.eco.core.gui.menu.Menu
import com.willfp.eco.core.gui.menu.MenuEvent
diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenuBuilder.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenuBuilder.kt
index 306052f1..0b4476cf 100644
--- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenuBuilder.kt
+++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/gui/menu/EcoMenuBuilder.kt
@@ -1,6 +1,6 @@
package com.willfp.eco.internal.gui.menu
-import com.willfp.eco.core.gui.component.GUIComponent
+import com.willfp.eco.core.gui.GUIComponent
import com.willfp.eco.core.gui.menu.CloseHandler
import com.willfp.eco.core.gui.menu.Menu
import com.willfp.eco.core.gui.menu.MenuBuilder
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt
similarity index 51%
rename from eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt
rename to eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt
index a3760a4b..68d1c337 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoHandler.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoImpl.kt
@@ -1,21 +1,26 @@
package com.willfp.eco.internal.spigot
+import com.willfp.eco.core.Eco
import com.willfp.eco.core.EcoPlugin
-import com.willfp.eco.core.Handler
+import com.willfp.eco.core.PluginLike
import com.willfp.eco.core.PluginProps
-import com.willfp.eco.core.data.ExtendedPersistentDataContainer
-import com.willfp.eco.core.entities.ai.EntityController
-import com.willfp.eco.core.fast.FastItemStack
+import com.willfp.eco.core.Prerequisite
+import com.willfp.eco.core.config.ConfigType
+import com.willfp.eco.core.config.interfaces.Config
+import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.gui.menu.Menu
-import com.willfp.eco.core.integrations.placeholder.PlaceholderIntegration
-import com.willfp.eco.core.items.SNBTHandler
+import com.willfp.eco.core.gui.menu.MenuType
+import com.willfp.eco.core.gui.slot.functional.SlotProvider
import com.willfp.eco.core.placeholder.AdditionalPlayer
import com.willfp.eco.core.placeholder.PlaceholderInjectable
import com.willfp.eco.internal.EcoCleaner
import com.willfp.eco.internal.EcoPropsParser
-import com.willfp.eco.internal.config.EcoConfigFactory
import com.willfp.eco.internal.config.EcoConfigHandler
-import com.willfp.eco.internal.drops.EcoDropQueueFactory
+import com.willfp.eco.internal.config.EcoConfigSection
+import com.willfp.eco.internal.config.EcoLoadableConfig
+import com.willfp.eco.internal.config.EcoUpdatableConfig
+import com.willfp.eco.internal.config.toMap
+import com.willfp.eco.internal.drops.EcoDropQueue
import com.willfp.eco.internal.events.EcoEventManager
import com.willfp.eco.internal.extensions.EcoExtensionLoader
import com.willfp.eco.internal.factory.EcoMetadataValueFactory
@@ -24,15 +29,17 @@ import com.willfp.eco.internal.factory.EcoRunnableFactory
import com.willfp.eco.internal.fast.FastInternalNamespacedKeyFactory
import com.willfp.eco.internal.fast.InternalNamespacedKeyFactory
import com.willfp.eco.internal.fast.SafeInternalNamespacedKeyFactory
-import com.willfp.eco.internal.gui.EcoGUIFactory
+import com.willfp.eco.internal.gui.MergedStateMenu
+import com.willfp.eco.internal.gui.menu.EcoMenuBuilder
import com.willfp.eco.internal.gui.menu.renderedInventory
+import com.willfp.eco.internal.gui.slot.EcoSlotBuilder
import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI
import com.willfp.eco.internal.logging.EcoLogger
import com.willfp.eco.internal.proxy.EcoProxyFactory
import com.willfp.eco.internal.scheduling.EcoScheduler
import com.willfp.eco.internal.spigot.data.DataYml
-import com.willfp.eco.internal.spigot.data.EcoKeyRegistry
import com.willfp.eco.internal.spigot.data.EcoProfileHandler
+import com.willfp.eco.internal.spigot.data.KeyRegistry
import com.willfp.eco.internal.spigot.data.storage.HandlerType
import com.willfp.eco.internal.spigot.integrations.bstats.MetricHandler
import com.willfp.eco.internal.spigot.items.EcoSNBTHandler
@@ -48,16 +55,17 @@ import com.willfp.eco.internal.spigot.proxy.TPSProxy
import net.kyori.adventure.platform.bukkit.BukkitAudiences
import org.bukkit.Location
import org.bukkit.NamespacedKey
+import org.bukkit.configuration.ConfigurationSection
import org.bukkit.entity.Entity
import org.bukkit.entity.Mob
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
import org.bukkit.inventory.meta.SkullMeta
import org.bukkit.persistence.PersistentDataContainer
-import java.util.logging.Logger
+import java.util.UUID
@Suppress("UNUSED")
-class EcoHandler : EcoSpigotPlugin(), Handler {
+class EcoImpl : EcoSpigotPlugin(), Eco {
private val loaded = mutableMapOf()
init {
@@ -68,11 +76,11 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
private val cleaner = EcoCleaner()
- private var adventure: BukkitAudiences? = null
+ private var adventure: BukkitAudiences? = if (!Prerequisite.HAS_PAPER.isMet) {
+ BukkitAudiences.create(this)
+ } else null
- private val keyRegistry = EcoKeyRegistry()
-
- private val playerProfileHandler = EcoProfileHandler(
+ override val profileHandler = EcoProfileHandler(
HandlerType.valueOf(this.configYml.getString("data-handler").uppercase()),
this
)
@@ -84,49 +92,112 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
if (this.configYml.getBool("use-safer-namespacedkey-creation"))
SafeInternalNamespacedKeyFactory() else FastInternalNamespacedKeyFactory()
- override fun createScheduler(plugin: EcoPlugin): EcoScheduler =
+ override fun createScheduler(plugin: EcoPlugin) =
EcoScheduler(plugin)
- override fun createEventManager(plugin: EcoPlugin): EcoEventManager =
+ override fun createEventManager(plugin: EcoPlugin) =
EcoEventManager(plugin)
- override fun createNamespacedKeyFactory(plugin: EcoPlugin): EcoNamespacedKeyFactory =
+ override fun createNamespacedKeyFactory(plugin: EcoPlugin) =
EcoNamespacedKeyFactory(plugin)
- override fun createMetadataValueFactory(plugin: EcoPlugin): EcoMetadataValueFactory =
+ override fun createMetadataValueFactory(plugin: EcoPlugin) =
EcoMetadataValueFactory(plugin)
- override fun createRunnableFactory(plugin: EcoPlugin): EcoRunnableFactory =
+ override fun createRunnableFactory(plugin: EcoPlugin) =
EcoRunnableFactory(plugin)
- override fun createExtensionLoader(plugin: EcoPlugin): EcoExtensionLoader =
+ override fun createExtensionLoader(plugin: EcoPlugin) =
EcoExtensionLoader(plugin)
- override fun createConfigHandler(plugin: EcoPlugin): EcoConfigHandler =
+ override fun createConfigHandler(plugin: EcoPlugin) =
EcoConfigHandler(plugin)
- override fun createLogger(plugin: EcoPlugin): Logger =
+ override fun createLogger(plugin: EcoPlugin) =
EcoLogger(plugin)
- override fun createPAPIIntegration(plugin: EcoPlugin): PlaceholderIntegration =
+ override fun createPAPIIntegration(plugin: EcoPlugin) =
PlaceholderIntegrationPAPI(plugin)
override fun getEcoPlugin(): EcoPlugin =
this
- override fun getConfigFactory(): EcoConfigFactory =
- EcoConfigFactory
+ override fun createConfig(contents: String, type: ConfigType) =
+ EcoConfigSection(type, type.toMap(contents))
- override fun getDropQueueFactory(): EcoDropQueueFactory =
- EcoDropQueueFactory
+ override fun createConfig(values: Map, type: ConfigType) =
+ EcoConfigSection(type, values)
- override fun getGUIFactory(): EcoGUIFactory =
- EcoGUIFactory
+ override fun createLoadableConfig(
+ configName: String,
+ plugin: PluginLike,
+ subDirectoryPath: String,
+ source: Class<*>,
+ type: ConfigType,
+ requiresChangesToSave: Boolean
+ ) = EcoLoadableConfig(
+ type,
+ configName,
+ plugin,
+ subDirectoryPath,
+ source,
+ requiresChangesToSave
+ )
+
+ override fun createUpdatableConfig(
+ configName: String,
+ plugin: PluginLike,
+ subDirectoryPath: String,
+ source: Class<*>,
+ removeUnused: Boolean,
+ type: ConfigType,
+ requiresChangesToSave: Boolean,
+ vararg updateBlacklist: String
+ ) = EcoUpdatableConfig(
+ type,
+ configName,
+ plugin,
+ subDirectoryPath,
+ source,
+ removeUnused,
+ requiresChangesToSave,
+ *updateBlacklist
+ )
+
+ override fun wrapConfigurationSection(bukkit: ConfigurationSection): Config {
+ val config = createConfig(emptyMap(), ConfigType.YAML)
+ for (key in bukkit.getKeys(true)) {
+ config.set(key, bukkit.get(key))
+ }
+
+ return config
+ }
+
+ override fun createDropQueue(player: Player) =
+ EcoDropQueue(player)
+
+ override fun getPersistentDataKeyFrom(namespacedKey: NamespacedKey) =
+ KeyRegistry.getKeyFrom(namespacedKey)
+
+ override fun getRegisteredPersistentDataKeys() =
+ KeyRegistry.getRegisteredKeys()
+
+ override fun registerPersistentKey(key: PersistentDataKey<*>) =
+ KeyRegistry.registerKey(key)
+
+ override fun createMenuBuilder(rows: Int, type: MenuType) =
+ EcoMenuBuilder(rows, type.columns)
+
+ override fun createSlotBuilder(provider: SlotProvider) =
+ EcoSlotBuilder(provider)
+
+ override fun blendMenuState(base: Menu, additional: Menu) =
+ MergedStateMenu(base, additional)
override fun getCleaner(): EcoCleaner =
cleaner
- override fun createProxyFactory(plugin: EcoPlugin): EcoProxyFactory =
+ override fun createProxyFactory(plugin: EcoPlugin) =
EcoProxyFactory(plugin)
override fun addNewPlugin(plugin: EcoPlugin) {
@@ -139,49 +210,60 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
override fun getPluginByName(name: String): EcoPlugin? =
loaded[name.lowercase()]
- override fun createFastItemStack(itemStack: ItemStack): FastItemStack =
+ override fun createFastItemStack(itemStack: ItemStack) =
getProxy(FastItemStackFactoryProxy::class.java).create(itemStack)
override fun registerBStats(plugin: EcoPlugin) =
MetricHandler.createMetrics(plugin)
- override fun getAdventure(): BukkitAudiences? =
+ override fun getAdventure() =
adventure
- override fun getKeyRegistry(): EcoKeyRegistry =
- keyRegistry
+ override fun getServerProfile() =
+ profileHandler.loadServerProfile()
- override fun getProfileHandler(): EcoProfileHandler =
- playerProfileHandler
+ override fun loadPlayerProfile(uuid: UUID) =
+ profileHandler.load(uuid)
- fun setAdventure(adventure: BukkitAudiences) {
- this.adventure = adventure
- }
+ override fun saveAllProfiles() =
+ profileHandler.save()
+
+ override fun savePersistentDataKeysFor(uuid: UUID, keys: Set>) =
+ profileHandler.saveKeysFor(uuid, keys)
+
+ override fun unloadPlayerProfile(uuid: UUID) =
+ profileHandler.unloadPlayer(uuid)
override fun createDummyEntity(location: Location): Entity =
getProxy(DummyEntityFactoryProxy::class.java).createDummyEntity(location)
@Suppress("DEPRECATION")
- override fun createNamespacedKey(namespace: String, key: String): NamespacedKey =
+ override fun createNamespacedKey(namespace: String, key: String) =
keyFactory?.create(namespace, key) ?: NamespacedKey(namespace, key)
- override fun getProps(existing: PluginProps?, plugin: Class): PluginProps =
+ override fun getProps(existing: PluginProps?, plugin: Class) =
existing ?: EcoPropsParser.parseForPlugin(plugin)
- override fun createEntityController(mob: T): EntityController =
+ override fun createEntityController(mob: T) =
getProxy(EntityControllerFactoryProxy::class.java).createEntityController(mob)
- override fun formatMiniMessage(message: String): String =
+ override fun formatMiniMessage(message: String) =
getProxy(MiniMessageTranslatorProxy::class.java).format(message)
- override fun adaptPdc(container: PersistentDataContainer): ExtendedPersistentDataContainer =
+ override fun adaptPdc(container: PersistentDataContainer) =
getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).adapt(container)
- override fun newPdc(): PersistentDataContainer =
+ override fun newPdc() =
getProxy(ExtendedPersistentDataContainerFactoryProxy::class.java).newPdc()
- override fun getSNBTHandler(): SNBTHandler =
- snbtHandler
+ override fun toSNBT(itemStack: ItemStack) =
+ snbtHandler.toSNBT(itemStack)
+
+ override fun fromSNBT(snbt: String) =
+ snbtHandler.fromSNBT(snbt)
+
+ override fun testableItemFromSNBT(snbt: String) =
+ snbtHandler.createTestable(snbt)
override fun getSkullTexture(meta: SkullMeta): String? =
getProxy(SkullProxy::class.java).getSkullTexture(meta)
@@ -189,7 +271,7 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
override fun setSkullTexture(meta: SkullMeta, base64: String) =
getProxy(SkullProxy::class.java).setSkullTexture(meta, base64)
- override fun getTPS(): Double =
+ override fun getTPS() =
getProxy(TPSProxy::class.java).getTPS()
override fun evaluate(
@@ -197,8 +279,8 @@ class EcoHandler : EcoSpigotPlugin(), Handler {
player: Player?,
injectable: PlaceholderInjectable,
additionalPlayers: MutableCollection
- ): Double = evaluateExpression(expression, player, injectable, additionalPlayers)
+ ) = evaluateExpression(expression, player, injectable, additionalPlayers)
- override fun getOpenMenu(player: Player): Menu? =
+ override fun getOpenMenu(player: Player) =
player.renderedInventory?.menu
}
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt
index 3fc90d28..7af3500e 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/EcoSpigotPlugin.kt
@@ -4,7 +4,6 @@ import com.willfp.eco.core.AbstractPacketAdapter
import com.willfp.eco.core.Eco
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.Prerequisite
-import com.willfp.eco.core.display.Display
import com.willfp.eco.core.entities.Entities
import com.willfp.eco.core.integrations.IntegrationLoader
import com.willfp.eco.core.integrations.afk.AFKManager
@@ -17,8 +16,6 @@ import com.willfp.eco.core.integrations.hologram.HologramManager
import com.willfp.eco.core.integrations.mcmmo.McmmoManager
import com.willfp.eco.core.integrations.shop.ShopManager
import com.willfp.eco.core.items.Items
-import com.willfp.eco.internal.display.EcoDisplayHandler
-import com.willfp.eco.internal.drops.DropManager
import com.willfp.eco.internal.entities.EntityArgParserAdult
import com.willfp.eco.internal.entities.EntityArgParserAttackDamage
import com.willfp.eco.internal.entities.EntityArgParserAttackSpeed
@@ -129,6 +126,7 @@ import org.bukkit.inventory.ItemStack
abstract class EcoSpigotPlugin : EcoPlugin() {
abstract val dataYml: DataYml
+ protected abstract val profileHandler: EcoProfileHandler
init {
Items.registerArgParser(ArgParserEnchantment())
@@ -169,12 +167,6 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
SegmentParserUseIfPresent().register()
CustomItemsManager.registerProviders()
-
- postInit()
- }
-
- private fun postInit() {
- Display.setHandler(EcoDisplayHandler(this))
}
override fun handleEnable() {
@@ -201,36 +193,36 @@ abstract class EcoSpigotPlugin : EcoPlugin() {
CustomItemsManager.registerProviders() // Do it again here
// Register events for ShopSellEvent
- ShopManager.registerEvents(this)
-
- if (!Prerequisite.HAS_PAPER.isMet) {
- (Eco.getHandler() as EcoHandler).setAdventure(BukkitAudiences.create(this))
+ for (integration in ShopManager.getRegisteredIntegrations()) {
+ val listener = integration.sellEventAdapter
+ if (listener != null) {
+ this.eventManager.registerListener(listener)
+ }
}
// Init FIS
this.getProxy(FastItemStackFactoryProxy::class.java).create(ItemStack(Material.AIR)).unwrap()
// Preload categorized persistent data keys
- (Eco.getHandler().profileHandler as EcoProfileHandler).initialize()
+ profileHandler.initialize()
}
override fun handleDisable() {
this.logger.info("Saving player data...")
val start = System.currentTimeMillis()
- Eco.getHandler().profileHandler.save()
+ profileHandler.save()
this.logger.info("Saved player data! Took ${System.currentTimeMillis() - start}ms")
- Eco.getHandler().adventure?.close()
+ Eco.get().adventure?.close()
}
override fun handleReload() {
CollatedRunnable(this)
- DropManager.update(this)
this.scheduler.runLater(3) {
- (Eco.getHandler().profileHandler as EcoProfileHandler).migrateIfNeeded()
+ profileHandler.migrateIfNeeded()
}
- ProfileSaver(this, Eco.getHandler().profileHandler)
+ ProfileSaver(this, profileHandler)
this.scheduler.runTimer(
{ clearFrames() },
this.configYml.getInt("display-frame-ttl").toLong(),
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataListener.kt
index 03132f1d..92971924 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataListener.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/DataListener.kt
@@ -15,7 +15,7 @@ class DataListener(
) : Listener {
@EventHandler(priority = EventPriority.HIGHEST)
fun onLeave(event: PlayerQuitEvent) {
- Eco.getHandler().profileHandler.unloadPlayer(event.player.uniqueId)
+ Eco.get().unloadPlayerProfile(event.player.uniqueId)
}
@EventHandler
@@ -27,6 +27,6 @@ class DataListener(
@EventHandler(priority = EventPriority.LOWEST)
fun onLogin(event: PlayerLoginEvent) {
- Eco.getHandler().profileHandler.unloadPlayer(event.player.uniqueId)
+ Eco.get().unloadPlayerProfile(event.player.uniqueId)
}
}
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt
index d0636d98..3d1a4059 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoProfileHandler.kt
@@ -2,7 +2,6 @@ package com.willfp.eco.internal.spigot.data
import com.willfp.eco.core.data.PlayerProfile
import com.willfp.eco.core.data.Profile
-import com.willfp.eco.core.data.ProfileHandler
import com.willfp.eco.core.data.ServerProfile
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.profile
@@ -22,7 +21,7 @@ val serverProfileUUID = UUID(0, 0)
class EcoProfileHandler(
private val type: HandlerType,
private val plugin: EcoSpigotPlugin
-) : ProfileHandler {
+) {
private val loaded = mutableMapOf()
val handler: DataHandler = when (type) {
@@ -47,23 +46,23 @@ class EcoProfileHandler(
return profile
}
- override fun load(uuid: UUID): PlayerProfile {
+ fun load(uuid: UUID): PlayerProfile {
return loadGenericProfile(uuid) as PlayerProfile
}
- override fun loadServerProfile(): ServerProfile {
+ fun loadServerProfile(): ServerProfile {
return loadGenericProfile(serverProfileUUID) as ServerProfile
}
- override fun saveKeysFor(uuid: UUID, keys: Set>) {
+ fun saveKeysFor(uuid: UUID, keys: Set>) {
handler.saveKeysFor(uuid, keys)
}
- override fun unloadPlayer(uuid: UUID) {
+ fun unloadPlayer(uuid: UUID) {
loaded.remove(uuid)
}
- override fun save() {
+ fun save() {
handler.save()
}
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyRegistry.kt
similarity index 84%
rename from eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt
rename to eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyRegistry.kt
index d9748d42..c96afb3e 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/EcoKeyRegistry.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/KeyRegistry.kt
@@ -1,14 +1,13 @@
package com.willfp.eco.internal.spigot.data
-import com.willfp.eco.core.data.keys.KeyRegistry
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.core.data.keys.PersistentDataKeyType
import org.bukkit.NamespacedKey
-class EcoKeyRegistry : KeyRegistry {
+object KeyRegistry {
private val registry = mutableMapOf>()
- override fun registerKey(key: PersistentDataKey<*>) {
+ fun registerKey(key: PersistentDataKey<*>) {
if (this.registry.containsKey(key.key)) {
this.registry.remove(key.key)
}
@@ -18,7 +17,7 @@ class EcoKeyRegistry : KeyRegistry {
this.registry[key.key] = key
}
- override fun getRegisteredKeys(): MutableSet> {
+ fun getRegisteredKeys(): MutableSet> {
return registry.values.toMutableSet()
}
@@ -46,7 +45,7 @@ class EcoKeyRegistry : KeyRegistry {
}
}
- override fun getKeyFrom(namespacedKey: NamespacedKey): PersistentDataKey<*>? {
+ fun getKeyFrom(namespacedKey: NamespacedKey): PersistentDataKey<*>? {
return registry[namespacedKey]
}
}
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/LegacyMySQLDataHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/LegacyMySQLDataHandler.kt
index f6c342d5..5b8aea8b 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/LegacyMySQLDataHandler.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/LegacyMySQLDataHandler.kt
@@ -48,7 +48,7 @@ the worst bodge I've shipped in production.
@Suppress("UNCHECKED_CAST")
class LegacyMySQLDataHandler(
- private val plugin: EcoSpigotPlugin,
+ plugin: EcoSpigotPlugin,
handler: EcoProfileHandler
) : DataHandler(HandlerType.LEGACY_MYSQL) {
private val playerHandler: ImplementedMySQLHandler
@@ -197,7 +197,7 @@ private class ImplementedMySQLHandler(
doRead.call()
- return if (Eco.getHandler().ecoPlugin.configYml.getBool("mysql.async-reads")) {
+ return if (Eco.get().ecoPlugin.configYml.getBool("mysql.async-reads")) {
executor.submit(doRead).get()
} else {
doRead.call()
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt
index 44f66c0a..7d8997cd 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/data/storage/ProfileSaver.kt
@@ -1,12 +1,12 @@
package com.willfp.eco.internal.spigot.data.storage
import com.willfp.eco.core.EcoPlugin
-import com.willfp.eco.core.data.ProfileHandler
import com.willfp.eco.internal.spigot.data.EcoProfile
+import com.willfp.eco.internal.spigot.data.EcoProfileHandler
class ProfileSaver(
plugin: EcoPlugin,
- handler: ProfileHandler
+ handler: EcoProfileHandler
) {
init {
plugin.scheduler.runTimer(1, 1) {
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/drops/CollatedRunnable.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/drops/CollatedRunnable.kt
index e052b7e7..ec08f56a 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/drops/CollatedRunnable.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/drops/CollatedRunnable.kt
@@ -1,8 +1,8 @@
package com.willfp.eco.internal.spigot.drops
import com.willfp.eco.core.EcoPlugin
-import com.willfp.eco.internal.drops.impl.EcoDropQueue
-import com.willfp.eco.internal.drops.impl.EcoFastCollatedDropQueue
+import com.willfp.eco.internal.drops.EcoDropQueue
+import com.willfp.eco.internal.drops.EcoFastCollatedDropQueue
class CollatedRunnable(plugin: EcoPlugin) {
init {
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsScyther.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsScyther.kt
index 960bcacc..ccc51608 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsScyther.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/customitems/CustomItemsScyther.kt
@@ -20,7 +20,7 @@ class CustomItemsScyther : CustomItemsIntegration {
}
private class ScytherProvider : ItemProvider("scyther") {
- override fun provideForKey(key: String): TestableItem? {
+ override fun provideForKey(key: String): TestableItem {
val material = Material.matchMaterial(key.uppercase()) ?: Material.WOODEN_HOE
val hoe = ScytherAPI.createHarvesterHoe(
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt
index 51d69b88..2ebaf307 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/items/EcoSNBTHandler.kt
@@ -1,20 +1,19 @@
package com.willfp.eco.internal.spigot.items
import com.willfp.eco.core.EcoPlugin
-import com.willfp.eco.core.items.SNBTHandler
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.internal.spigot.proxy.SNBTConverterProxy
import org.bukkit.inventory.ItemStack
class EcoSNBTHandler(
private val plugin: EcoPlugin
-) : SNBTHandler {
- override fun fromSNBT(snbt: String): ItemStack? =
+) {
+ fun fromSNBT(snbt: String): ItemStack? =
plugin.getProxy(SNBTConverterProxy::class.java).fromSNBT(snbt)
- override fun toSNBT(itemStack: ItemStack): String =
+ fun toSNBT(itemStack: ItemStack): String =
plugin.getProxy(SNBTConverterProxy::class.java).toSNBT(itemStack)
- override fun createTestable(snbt: String): TestableItem =
+ fun createTestable(snbt: String): TestableItem =
plugin.getProxy(SNBTConverterProxy::class.java).makeSNBTTestable(snbt)
}
\ No newline at end of file
diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt
index cc8a6351..417790cb 100644
--- a/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt
+++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/recipes/StackedRecipeListener.kt
@@ -4,7 +4,6 @@ import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.items.TestableItem
import com.willfp.eco.core.items.isEmpty
import com.willfp.eco.core.recipe.Recipes
-import com.willfp.eco.core.recipe.parts.EmptyTestableItem
import com.willfp.eco.core.recipe.parts.GroupedTestableItems
import com.willfp.eco.core.recipe.parts.TestableStack
import com.willfp.eco.core.recipe.recipes.CraftingRecipe
diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml
index 6ef4618c..758db3e0 100644
--- a/eco-core/core-plugin/src/main/resources/plugin.yml
+++ b/eco-core/core-plugin/src/main/resources/plugin.yml
@@ -1,6 +1,6 @@
name: eco
version: ${projectVersion}
-main: com.willfp.eco.internal.spigot.EcoHandler
+main: com.willfp.eco.internal.spigot.EcoImpl
api-version: 1.17
authors: [ Auxilor ]
website: willfp.com