From aab1f31ca06cc36ba1ac3dfa839ba3fb5bef12ee Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 27 Jun 2021 14:39:29 +0100 Subject: [PATCH] More changes to EcoPlugin --- .../java/com/willfp/eco/core/EcoPlugin.java | 148 +++++++++++++++--- .../eco/core/display/DisplayModule.java | 2 +- .../willfp/eco/spigot/EcoSpigotPlugin.java | 31 +--- 3 files changed, 125 insertions(+), 56 deletions(-) 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 7c754080..6b2b5625 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 @@ -26,9 +26,11 @@ import com.willfp.eco.internal.integrations.PlaceholderIntegrationPAPI; import com.willfp.eco.internal.logging.EcoLogger; import com.willfp.eco.internal.scheduling.EcoScheduler; import lombok.Getter; +import org.apache.commons.lang.Validate; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; @@ -194,6 +196,19 @@ public abstract class EcoPlugin extends JavaPlugin { this(0, 0, proxyPackage, color); } + /** + * Create a new plugin without proxy support. + * + * @param resourceId The spigot resource ID for the plugin. + * @param bStatsId The bStats resource ID for the plugin. + * @param color The color of the plugin (used in messages, such as &a, &b) + */ + protected EcoPlugin(final int resourceId, + final int bStatsId, + @NotNull final String color) { + this(resourceId, bStatsId, "", color); + } + /** * Create a new plugin. * @@ -209,19 +224,6 @@ public abstract class EcoPlugin extends JavaPlugin { this("", resourceId, bStatsId, proxyPackage, color); } - /** - * Create a new plugin without proxy support. - * - * @param resourceId The spigot resource ID for the plugin. - * @param bStatsId The bStats resource ID for the plugin. - * @param color The color of the plugin (used in messages, such as &a, &b) - */ - protected EcoPlugin(final int resourceId, - final int bStatsId, - @NotNull final String color) { - this(resourceId, bStatsId, "", color); - } - /** * Create a new plugin. * @@ -233,6 +235,7 @@ public abstract class EcoPlugin extends JavaPlugin { * @deprecated pluginName is redundant. */ @Deprecated + @SuppressWarnings("unused") protected EcoPlugin(@NotNull final String pluginName, final int resourceId, final int bStatsId, @@ -267,7 +270,7 @@ public abstract class EcoPlugin extends JavaPlugin { super.onEnable(); this.getLogger().info(""); - this.getLogger().info("Loading " + this.color + this.pluginName); + this.getLogger().info("Loading " + this.getColor() + this.getName()); this.getEventManager().registerListener(new ArrowDataListener(this)); @@ -278,7 +281,7 @@ public abstract class EcoPlugin extends JavaPlugin { if (!(currentVersion.compareTo(mostRecentVersion) > 0 || currentVersion.equals(mostRecentVersion))) { this.outdated = true; this.getScheduler().runTimer(() -> { - this.getLogger().info("&c " + this.pluginName + " is out of date! (Version " + this.getDescription().getVersion() + ")"); + this.getLogger().info("&c " + this.getName() + " is out of date! (Version " + this.getDescription().getVersion() + ")"); this.getLogger().info("&cThe newest version is &f" + version); this.getLogger().info("&cDownload the new version!"); }, 0, 864000); @@ -287,7 +290,7 @@ public abstract class EcoPlugin extends JavaPlugin { } if (this.getBStatsId() != 0) { - new Metrics(this, this.bStatsId); + new Metrics(this, this.getBStatsId()); } Set enabledPlugins = Arrays.stream(Bukkit.getPluginManager().getPlugins()).map(Plugin::getName).collect(Collectors.toSet()); @@ -405,42 +408,68 @@ public abstract class EcoPlugin extends JavaPlugin { /** * The plugin-specific code to be executed on enable. + *

+ * Override when needed. */ - public abstract void enable(); + public void enable() { + + } /** * The plugin-specific code to be executed on disable. + *

+ * Override when needed. */ - public abstract void disable(); + public void disable() { + + } /** * The plugin-specific code to be executed on load. + *

+ * This is executed before enabling. + *

+ * Override when needed. */ - public abstract void load(); + public void load() { + + } /** * The plugin-specific code to be executed on reload. + *

+ * Override when needed. */ - public abstract void onReload(); + public void onReload() { + + } /** * The plugin-specific code to be executed after the server is up. + *

+ * Override when needed. */ - public abstract void postLoad(); + public void postLoad() { + + } /** * The plugin-specific integrations to be tested and loaded. * * @return A list of integrations. */ - public abstract List getIntegrationLoaders(); + public List getIntegrationLoaders() { + return new ArrayList<>(); + } /** * The command to be registered. * * @return A list of commands. */ - public abstract List getCommands(); + public List getCommands() { + return new ArrayList<>(); + } /** * ProtocolLib packet adapters to be registered. @@ -449,7 +478,9 @@ public abstract class EcoPlugin extends JavaPlugin { * * @return A list of packet adapters. */ - public abstract List getPacketAdapters(); + public List getPacketAdapters() { + return new ArrayList<>(); + } /** * All listeners to be registered. @@ -463,7 +494,9 @@ public abstract class EcoPlugin extends JavaPlugin { * * @return A list of all updatable classes. */ - public abstract List> getUpdatableClasses(); + public List> getUpdatableClasses() { + return new ArrayList<>(); + } /** * Create the display module for the plugin. @@ -472,12 +505,77 @@ public abstract class EcoPlugin extends JavaPlugin { */ @Nullable protected DisplayModule createDisplayModule() { + Validate.isTrue( + this.getDisplayModule() == null, + "Display module exists!" + ); + return null; } + /** + * Get the plugin's logger. + * + * @return The logger. + */ @NotNull @Override public Logger getLogger() { return logger; } + + /** + * Get unwrapped config. + * Does not use eco config system, don't use. + * + * @return The bukkit config. + * @deprecated Use {@link EcoPlugin#getConfigYml()} instead. + */ + @NotNull + @Override + @Deprecated + public final FileConfiguration getConfig() { + this.getLogger().warning("Call to default config method in eco plugin!"); + + return this.getConfigYml().getHandle(); + } + + /** + * Does not use eco config system, don't use. + * + * @deprecated Use eco config system. + */ + @Override + @Deprecated + public final void saveConfig() { + this.getLogger().warning("Call to default config method in eco plugin!"); + + super.saveConfig(); + } + + /** + * Does not use eco config system, don't use. + * + * @deprecated Use eco config system. + */ + @Override + @Deprecated + public final void saveDefaultConfig() { + this.getLogger().warning("Call to default config method in eco plugin!"); + + super.saveDefaultConfig(); + } + + /** + * Does not use eco config system, don't use. + * + * @deprecated Use eco config system. + */ + @Override + @Deprecated + public final void reloadConfig() { + this.getLogger().warning("Call to default config method in eco plugin!"); + + super.reloadConfig(); + } } diff --git a/eco-api/src/main/java/com/willfp/eco/core/display/DisplayModule.java b/eco-api/src/main/java/com/willfp/eco/core/display/DisplayModule.java index 84fa49f0..7c175b18 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/display/DisplayModule.java +++ b/eco-api/src/main/java/com/willfp/eco/core/display/DisplayModule.java @@ -61,6 +61,6 @@ public abstract class DisplayModule extends PluginDependent { * @return The plugin name. */ final String getPluginName() { - return super.getPlugin().getPluginName(); + return super.getPlugin().getName(); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java index eba2ab62..37d4337b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/eco/spigot/EcoSpigotPlugin.java @@ -2,10 +2,8 @@ package com.willfp.eco.spigot; import com.willfp.eco.core.AbstractPacketAdapter; import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.command.AbstractCommand; import com.willfp.eco.core.data.Data; import com.willfp.eco.core.display.Display; -import com.willfp.eco.core.display.DisplayModule; import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.eco.core.integrations.anticheat.AnticheatManager; import com.willfp.eco.core.integrations.antigrief.AntigriefManager; @@ -47,7 +45,6 @@ import com.willfp.eco.util.SkullUtils; import com.willfp.eco.util.TridentUtils; import lombok.Getter; import org.bukkit.event.Listener; -import org.jetbrains.annotations.Nullable; import java.io.IOException; import java.util.ArrayList; @@ -70,7 +67,7 @@ public class EcoSpigotPlugin extends EcoPlugin { * Create a new instance of eco. */ public EcoSpigotPlugin() { - super("eco", 87955, 10043, "com.willfp.eco.proxy", "&a"); + super(87955, 10043, "com.willfp.eco.proxy", "&a"); instance = this; Display.setFinalizeKey(this.getNamespacedKeyFactory().create("finalized")); @@ -103,21 +100,11 @@ public class EcoSpigotPlugin extends EcoPlugin { } } - @Override - public void load() { - - } - @Override public void onReload() { new CollatedRunnable(this); } - @Override - public void postLoad() { - - } - @Override public List getIntegrationLoaders() { return Arrays.asList( @@ -142,11 +129,6 @@ public class EcoSpigotPlugin extends EcoPlugin { ); } - @Override - public List getCommands() { - return new ArrayList<>(); - } - @Override public List getPacketAdapters() { List adapters = new ArrayList<>(Arrays.asList( @@ -176,15 +158,4 @@ public class EcoSpigotPlugin extends EcoPlugin { new GUIListener(this) ); } - - @Override - public List> getUpdatableClasses() { - return new ArrayList<>(); - } - - @Override - @Nullable - protected DisplayModule createDisplayModule() { - return null; - } }