From c523ff7a5b1d1ec7c739dac59db488a4dfcc836c Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 13 Aug 2018 13:33:18 +0200 Subject: [PATCH 1/4] Added components with deps Copied from ButtonPresents and extended @alisolarflare #48 --- .../lib/architecture/Component.java | 118 ++++++++++++++++++ .../lib/architecture/ComponentMetadata.java | 12 ++ 2 files changed, 130 insertions(+) create mode 100644 ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java create mode 100644 ButtonCore/src/main/java/buttondevteam/lib/architecture/ComponentMetadata.java diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java new file mode 100644 index 0000000..5c2824b --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java @@ -0,0 +1,118 @@ +package buttondevteam.lib.architecture; + +import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.chat.TBMCCommandBase; +import lombok.val; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; + +import java.util.HashMap; + +public abstract class Component { + private static HashMap, Component> components; + + /** + * Registers a component checking it's dependencies and calling {@link #register(JavaPlugin)}.
+ * Make sure to register the dependencies first. + * + * @param component The component to register + */ + public static void registerComponent(JavaPlugin plugin, Component component) { + val metaAnn = component.getClass().getAnnotation(ComponentMetadata.class); + if (metaAnn != null) { + Class[] dependencies = metaAnn.depends(); + for (val dep : dependencies) { + if (!components.containsKey(dep)) { + plugin.getLogger().warning("Failed to register component " + component.getClassName() + " as a required dependency is missing/disabled: " + dep.getSimpleName()); + return; + } + } + } + component.register(plugin); + components.put(component.getClass(), component); + } + + /** + * Unregisters a component by calling {@link #unregister(JavaPlugin)}.
+ * Make sure to unregister the dependencies last. + * + * @param componentClass The component class to unregister + */ + public static void unregisterComponent(JavaPlugin plugin, Class componentClass) { + val component = components.get(componentClass); + if (component == null) + return; //Failed to load + val metaAnn = componentClass.getAnnotation(ComponentMetadata.class); + if (metaAnn != null) { + Class[] dependencies = metaAnn.depends(); + for (val dep : dependencies) { + if (!components.containsKey(dep)) { + plugin.getLogger().warning("Failed to unregister component " + component.getClassName() + " as a required dependency is missing/disabled: " + dep.getSimpleName()); + return; + } + } + } + component.unregister(plugin); + components.remove(componentClass); + } + + /** + * This is used to send a warning if there are registered components on shutdown.
+ * + * @return If there are any registered components + */ + public static boolean haveRegisteredComponents() { + return components.size() > 0; + } + + /** + * Registers the module, when called by the JavaPlugin class. Call + * registerCommand() and registerListener() within this method. + * + * @param plugin Plugin class called to register commands and listeners + */ + public abstract void register(JavaPlugin plugin); + + /** + * Registers a TBMCCommand to the plugin. Make sure to add it to plugin.yml and use {@link buttondevteam.lib.chat.CommandClass}. + * + * @param plugin Main plugin responsible for stuff + * @param commandBase Custom coded command class + */ + protected void registerCommand(JavaPlugin plugin, TBMCCommandBase commandBase) { + TBMCChatAPI.AddCommand(plugin, commandBase); + } + + /** + * Registers a Listener to this plugin + * + * @param plugin Main plugin responsible for stuff + * @param listener The event listener to register + * @return The provided listener + */ + protected Listener registerListener(JavaPlugin plugin, Listener listener) { + TBMCCoreAPI.RegisterEventsForExceptions(listener, plugin); + return listener; + } + + public void saveData(FileConfiguration config, String pathToData, Object data) { + config.set("moduledata." + this.getClassName() + "." + pathToData, data); + } + + public Object getData(FileConfiguration config, String pathToData, Object data) { + return config.get("moduledata." + this.getClassName() + "." + pathToData, data); + } + + private String getClassName() { + Class enclosingClass = getClass().getEnclosingClass(); + String className; + if (enclosingClass != null) { + className = (enclosingClass.getName()); + } else { + className = (getClass().getName()); + } + return className; + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/ComponentMetadata.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ComponentMetadata.java new file mode 100644 index 0000000..6519fca --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ComponentMetadata.java @@ -0,0 +1,12 @@ +package buttondevteam.lib.architecture; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +public @interface ComponentMetadata { + Class[] depends(); +} From ae849940250bb5320940f990ab4a6f2f3478ad66 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 5 Oct 2018 22:19:29 +0200 Subject: [PATCH 2/4] Continued refactoring --- ...tonCore_Towny_master_v1_0_g8d3b6b6_296.xml | 13 ++ ...milkbowl_VaultAPI_master_c8cb88f27a_1.xml} | 8 +- ..._javax_persistence_persistence_api_1_0.xml | 13 -- .../Maven__org_avaje_ebean_2_8_1.xml | 13 -- ...org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml | 13 ++ ...n__org_bukkit_bukkit_1_9_R0_1_SNAPSHOT.xml | 13 -- .idea/markdown-navigator.xml | 82 ++++++++++++ .../markdown-navigator/profiles_settings.xml | 3 + .idea/uiDesigner.xml | 124 ++++++++++++++++++ BuildConfigUpdater/BuildConfigUpdater.iml | 1 - BuildConfigUpdater/src/main/java/BCUMain.java | 2 +- .../component/commands/CommandComponent.java | 16 +++ .../component/restart/RestartComponent.java | 21 +++ .../updater}/PluginUpdater.java | 5 +- .../updater/PluginUpdaterComponent.java | 17 +++ .../updater}/UpdatePluginCommand.java | 4 +- .../java/buttondevteam/core/MainPlugin.java | 5 +- .../buttondevteam/core/PlayerListener.java | 4 +- .../java/buttondevteam/lib/TBMCCoreAPI.java | 1 + .../lib/architecture/Component.java | 8 ++ .../buttondevteam/lib/chat/ChatMessage.java | 67 +++++----- .../{IDiscordSender.java => IFakePlayer.java} | 2 +- .../buttondevteam/lib/chat/TBMCChatAPI.java | 4 +- 23 files changed, 349 insertions(+), 90 deletions(-) create mode 100644 .idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml rename .idea/libraries/{Maven__com_github_milkbowl_VaultAPI_master_8dc0859cba_1.xml => Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml} (55%) mode change 100755 => 100644 delete mode 100755 .idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml delete mode 100755 .idea/libraries/Maven__org_avaje_ebean_2_8_1.xml create mode 100644 .idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml delete mode 100755 .idea/libraries/Maven__org_bukkit_bukkit_1_9_R0_1_SNAPSHOT.xml create mode 100644 .idea/markdown-navigator.xml create mode 100644 .idea/markdown-navigator/profiles_settings.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java create mode 100644 ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java rename ButtonCore/src/main/java/buttondevteam/{lib => component/updater}/PluginUpdater.java (97%) create mode 100644 ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java rename ButtonCore/src/main/java/buttondevteam/{core => component/updater}/UpdatePluginCommand.java (94%) rename ButtonCore/src/main/java/buttondevteam/lib/chat/{IDiscordSender.java => IFakePlayer.java} (71%) diff --git a/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml b/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml new file mode 100644 index 0000000..8991a67 --- /dev/null +++ b/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_8dc0859cba_1.xml b/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml old mode 100755 new mode 100644 similarity index 55% rename from .idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_8dc0859cba_1.xml rename to .idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml index 2f453df..b5aaa43 --- a/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_8dc0859cba_1.xml +++ b/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml b/.idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml deleted file mode 100755 index e60370e..0000000 --- a/.idea/libraries/Maven__javax_persistence_persistence_api_1_0.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml b/.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml deleted file mode 100755 index 91f161a..0000000 --- a/.idea/libraries/Maven__org_avaje_ebean_2_8_1.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml new file mode 100644 index 0000000..4f2c5e4 --- /dev/null +++ b/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_bukkit_bukkit_1_9_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_bukkit_bukkit_1_9_R0_1_SNAPSHOT.xml deleted file mode 100755 index 2fb4911..0000000 --- a/.idea/libraries/Maven__org_bukkit_bukkit_1_9_R0_1_SNAPSHOT.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator.xml b/.idea/markdown-navigator.xml new file mode 100644 index 0000000..3e62462 --- /dev/null +++ b/.idea/markdown-navigator.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml new file mode 100644 index 0000000..57927c5 --- /dev/null +++ b/.idea/markdown-navigator/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index 4902d56..73696cd 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -12,7 +12,6 @@ - diff --git a/BuildConfigUpdater/src/main/java/BCUMain.java b/BuildConfigUpdater/src/main/java/BCUMain.java index bca7209..07666d3 100644 --- a/BuildConfigUpdater/src/main/java/BCUMain.java +++ b/BuildConfigUpdater/src/main/java/BCUMain.java @@ -1,4 +1,4 @@ -import buttondevteam.lib.PluginUpdater; +import buttondevteam.component.updater.PluginUpdater; import java.util.List; import java.util.stream.Collectors; diff --git a/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java b/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java new file mode 100644 index 0000000..b3f1059 --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java @@ -0,0 +1,16 @@ +package buttondevteam.component.commands; + +import buttondevteam.lib.architecture.Component; +import org.bukkit.plugin.java.JavaPlugin; + +public class CommandComponent extends Component { //TODO: Do we just move everything here? + @Override + public void register(JavaPlugin plugin) { + + } + + @Override + public void unregister(JavaPlugin plugin) { + + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java b/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java new file mode 100644 index 0000000..3061824 --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java @@ -0,0 +1,21 @@ +package buttondevteam.component.restart; + +import buttondevteam.core.PrimeRestartCommand; +import buttondevteam.core.ScheduledRestartCommand; +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.chat.TBMCChatAPI; +import org.bukkit.plugin.java.JavaPlugin; + +public class RestartComponent extends Component { + @Override + public void register(JavaPlugin plugin) { + //TODO: Separately (dis)allow commands + TBMCChatAPI.AddCommand(plugin, ScheduledRestartCommand.class); + TBMCChatAPI.AddCommand(plugin, PrimeRestartCommand.class); + } + + @Override + public void unregister(JavaPlugin plugin) { + + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/lib/PluginUpdater.java b/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdater.java similarity index 97% rename from ButtonCore/src/main/java/buttondevteam/lib/PluginUpdater.java rename to ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdater.java index ca758f8..ce2e993 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/PluginUpdater.java +++ b/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdater.java @@ -1,5 +1,6 @@ -package buttondevteam.lib; +package buttondevteam.component.updater; +import buttondevteam.lib.TBMCCoreAPI; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -136,7 +137,7 @@ public class PluginUpdater { public static List GetPluginNames() { List ret = new ArrayList<>(); try { - String resp = TBMCCoreAPI.DownloadString("https://api.github.com/orgs/TBMCPlugins/repos"); + String resp = TBMCCoreAPI.DownloadString("https://api.github.com/orgs/" + "TBMCPlugins" + "/repos"); //TODO: PluginUpdater JsonArray arr = new JsonParser().parse(resp).getAsJsonArray(); for (JsonElement obj : arr) { JsonObject jobj = obj.getAsJsonObject(); diff --git a/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java b/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java new file mode 100644 index 0000000..1427927 --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java @@ -0,0 +1,17 @@ +package buttondevteam.component.updater; + +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.chat.TBMCChatAPI; +import org.bukkit.plugin.java.JavaPlugin; + +public class PluginUpdaterComponent extends Component { + @Override + public void register(JavaPlugin plugin) { + TBMCChatAPI.AddCommand(plugin, UpdatePluginCommand.class); + } + + @Override + public void unregister(JavaPlugin plugin) { + + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/core/UpdatePluginCommand.java b/ButtonCore/src/main/java/buttondevteam/component/updater/UpdatePluginCommand.java similarity index 94% rename from ButtonCore/src/main/java/buttondevteam/core/UpdatePluginCommand.java rename to ButtonCore/src/main/java/buttondevteam/component/updater/UpdatePluginCommand.java index ba5b309..ee006c4 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/UpdatePluginCommand.java +++ b/ButtonCore/src/main/java/buttondevteam/component/updater/UpdatePluginCommand.java @@ -1,6 +1,6 @@ -package buttondevteam.core; +package buttondevteam.component.updater; -import buttondevteam.lib.PluginUpdater; +import buttondevteam.core.MainPlugin; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java index beb7651..b25ed1f 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java +++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java @@ -1,6 +1,6 @@ package buttondevteam.core; -import buttondevteam.lib.PluginUpdater; +import buttondevteam.component.updater.PluginUpdater; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.ChatRoom; @@ -40,9 +40,6 @@ public class MainPlugin extends JavaPlugin { setupPermissions(); Test = getConfig().getBoolean("test", true); saveConfig(); - TBMCChatAPI.AddCommand(this, UpdatePluginCommand.class); - TBMCChatAPI.AddCommand(this, ScheduledRestartCommand.class); - TBMCChatAPI.AddCommand(this, PrimeRestartCommand.class); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class); TBMCChatAPI.RegisterChatChannel(Channel.GlobalChat = new Channel("§fOOC§f", Color.White, "ooc", null)); diff --git a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java index af8220e..be7c10b 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java +++ b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java @@ -1,7 +1,7 @@ package buttondevteam.core; import buttondevteam.lib.TBMCSystemChatEvent; -import buttondevteam.lib.chat.IDiscordSender; +import buttondevteam.lib.chat.IFakePlayer; import buttondevteam.lib.player.TBMCPlayerBase; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -43,7 +43,7 @@ public class PlayerListener implements Listener { if (PrimeRestartCommand.isLoud()) Bukkit.broadcastMessage("§cNobody is online anymore. Restarting."); Bukkit.spigot().restart(); - } else if (!(event.getPlayer() instanceof IDiscordSender) && System.nanoTime() - 10 * 1000000000L - lasttime > 0) { //Ten seconds passed since last reminder + } else if (!(event.getPlayer() instanceof IFakePlayer) && System.nanoTime() - 10 * 1000000000L - lasttime > 0) { //Ten seconds passed since last reminder lasttime = System.nanoTime(); if (PrimeRestartCommand.isLoud()) Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online."); diff --git a/ButtonCore/src/main/java/buttondevteam/lib/TBMCCoreAPI.java b/ButtonCore/src/main/java/buttondevteam/lib/TBMCCoreAPI.java index 76498d5..e114196 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/TBMCCoreAPI.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/TBMCCoreAPI.java @@ -1,5 +1,6 @@ package buttondevteam.lib; +import buttondevteam.component.updater.PluginUpdater; import buttondevteam.core.MainPlugin; import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.potato.DebugPotato; diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java index 5c2824b..33c6788 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java @@ -75,6 +75,14 @@ public abstract class Component { */ public abstract void register(JavaPlugin plugin); + /** + * Unregisters the module, when called by the JavaPlugin class. Do + * any cleanups needed within this method. + * + * @param plugin Plugin class called to register commands and listeners + */ + public abstract void unregister(JavaPlugin plugin); + /** * Registers a TBMCCommand to the plugin. Make sure to add it to plugin.yml and use {@link buttondevteam.lib.chat.CommandClass}. * diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatMessage.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatMessage.java index a6fc3f1..056674a 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatMessage.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/ChatMessage.java @@ -9,38 +9,41 @@ import org.bukkit.command.CommandSender; @Builder @Getter public class ChatMessage { - /** - * The MC channel to send the message to. - */ - private final Channel channel; - /** - * The sender which sends the message. - */ - private final CommandSender sender; - /** - * The Chroma user which sends the message. - */ - private final ChromaGamerBase user; - /** - * The message to send as the user. - */ - private final String message; - /** - * Indicates whether the message comes from running a command (like /tableflip). Implemented to be used from Discord. - */ - private boolean fromCommand; - /** - * The sender which we should check for permissions. Same as {@link #sender} by default. - */ - private CommandSender permCheck; + /** + * The MC channel to send the message to. + */ + private final Channel channel; + /** + * The sender which sends the message. + */ + private final CommandSender sender; + /** + * The Chroma user which sends the message. + */ + private final ChromaGamerBase user; + /** + * The message to send as the user. + */ + private final String message; + /** + * Indicates whether the message comes from running a command (like /tableflip). Implemented to be used from Discord. + */ + private boolean fromCommand; + /** + * The sender which we should check for permissions. Same as {@link #sender} by default. + */ + private CommandSender permCheck; + /** + * The origin of the message, "minecraft" or "discord" for example. + */ + private final String origin; - private static ChatMessageBuilder builder() { - return new ChatMessageBuilder(); - } - - @NonNull - public static ChatMessageBuilder builder(Channel channel, CommandSender sender, ChromaGamerBase user, String message) { - return builder().channel(channel).sender(sender).user(user).message(message); - } + private static ChatMessageBuilder builder() { + return new ChatMessageBuilder(); + } + @NonNull + public static ChatMessageBuilder builder(Channel channel, CommandSender sender, ChromaGamerBase user, String message) { + return builder().channel(channel).sender(sender).user(user).message(message); + } } diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/IDiscordSender.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/IFakePlayer.java similarity index 71% rename from ButtonCore/src/main/java/buttondevteam/lib/chat/IDiscordSender.java rename to ButtonCore/src/main/java/buttondevteam/lib/chat/IFakePlayer.java index fd41c90..4f9318c 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/IDiscordSender.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/IFakePlayer.java @@ -7,6 +7,6 @@ import org.bukkit.command.CommandSender; * @author Norbi * */ -public interface IDiscordSender extends CommandSender { +public interface IFakePlayer extends CommandSender { } diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index f1fcd98..18b0487 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -35,7 +35,7 @@ public class TBMCChatAPI { /** * Returns messages formatted for Minecraft chat listing the subcommands of the command. - * + * * @param command * The command which we want the subcommands of * @param sender @@ -49,7 +49,7 @@ public class TBMCChatAPI { /** * Returns messages formatted for Minecraft chat listing the subcommands of the command.
* Returns a header if subcommands were found, otherwise returns an empty array. - * + * * @param command * The command which we want the subcommands of * @param sender From 5ef5bf47a20d20feafa0cb0033a4c78c870e4bd3 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 11 Nov 2018 00:58:18 +0100 Subject: [PATCH 3/4] Component data improvements & enable Separated enabling the component from registering it - a component will be always registerd, even if it's disabled Component data implemented similarily to player data, just kind of better Bunch of changes, less code repetition --- ..._ButtonCore_Towny_master_248b0d8d0a_1.xml} | 8 +- ...milkbowl_VaultAPI_master_431c5273c2_1.xml} | 8 +- ...org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml | 6 +- ...igotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml | 6 +- BuildConfigUpdater/BuildConfigUpdater.iml | 1 + .../buttondevteam/core/ComponentCommand.java | 30 ++++ .../buttondevteam/core/ComponentManager.java | 33 +++++ .../java/buttondevteam/core/MainPlugin.java | 2 + .../lib/architecture/Component.java | 136 +++++++++++++++--- .../lib/architecture/ConfigData.java | 43 ++++++ .../UnregisteredComponentException.java | 10 ++ 11 files changed, 246 insertions(+), 37 deletions(-) rename .idea/libraries/{Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml => Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_248b0d8d0a_1.xml} (55%) rename .idea/libraries/{Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml => Maven__com_github_milkbowl_VaultAPI_master_431c5273c2_1.xml} (55%) create mode 100644 ButtonCore/src/main/java/buttondevteam/core/ComponentCommand.java create mode 100644 ButtonCore/src/main/java/buttondevteam/core/ComponentManager.java create mode 100644 ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java create mode 100644 ButtonCore/src/main/java/buttondevteam/lib/architecture/exceptions/UnregisteredComponentException.java diff --git a/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml b/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_248b0d8d0a_1.xml similarity index 55% rename from .idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml rename to .idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_248b0d8d0a_1.xml index 8991a67..0d3e00e 100644 --- a/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_v1_0_g8d3b6b6_296.xml +++ b/.idea/libraries/Maven__com_github_TBMCPlugins_ButtonCore_Towny_master_248b0d8d0a_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml b/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_431c5273c2_1.xml similarity index 55% rename from .idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml rename to .idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_431c5273c2_1.xml index b5aaa43..19b24a3 100644 --- a/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_c8cb88f27a_1.xml +++ b/.idea/libraries/Maven__com_github_milkbowl_VaultAPI_master_431c5273c2_1.xml @@ -1,13 +1,13 @@ - + - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml index 4f2c5e4..63108e8 100644 --- a/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_bukkit_bukkit_1_13_1_R0_1_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml b/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml index 42f0d6f..b6f88ae 100644 --- a/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml +++ b/.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml @@ -1,13 +1,13 @@ - + - + - + \ No newline at end of file diff --git a/BuildConfigUpdater/BuildConfigUpdater.iml b/BuildConfigUpdater/BuildConfigUpdater.iml index 73696cd..4902d56 100644 --- a/BuildConfigUpdater/BuildConfigUpdater.iml +++ b/BuildConfigUpdater/BuildConfigUpdater.iml @@ -12,6 +12,7 @@ + diff --git a/ButtonCore/src/main/java/buttondevteam/core/ComponentCommand.java b/ButtonCore/src/main/java/buttondevteam/core/ComponentCommand.java new file mode 100644 index 0000000..a83037b --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/core/ComponentCommand.java @@ -0,0 +1,30 @@ +package buttondevteam.core; + +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.TBMCCommandBase; +import org.bukkit.command.CommandSender; + +@CommandClass(modOnly = true) +public class ComponentCommand extends TBMCCommandBase { + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (args.length < 2) + return false; + switch (args[0]) { + case "enable": + break; + case "disable": + break; + case "list": + break; + default: + return false; + } + return true; + } + + @Override + public String[] GetHelpText(String alias) { + return new String[0]; + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/core/ComponentManager.java b/ButtonCore/src/main/java/buttondevteam/core/ComponentManager.java new file mode 100644 index 0000000..023dee4 --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/core/ComponentManager.java @@ -0,0 +1,33 @@ +package buttondevteam.core; + +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.architecture.exceptions.UnregisteredComponentException; + +public final class ComponentManager { + private ComponentManager() {} + + /** + * Enables components based on a configuration + */ + public static void enableComponents() { + //Component.getComponents().values().stream().filter(c->cs.getConfigurationSection(c.getClass().getSimpleName()).getBoolean("enabled")).forEach(c-> { + Component.getComponents().values().stream().filter(c -> c.shouldBeEnabled().get()).forEach(c -> { + try { + Component.setComponentEnabled(c, true); + } catch (UnregisteredComponentException ignored) { //This *should* never happen + } + }); + } + + /** + * Disables all components that are enabled + */ + public static void disableComponents() { + Component.getComponents().values().stream().filter(Component::isEnabled).forEach(c -> { + try { + Component.setComponentEnabled(c, false); + } catch (UnregisteredComponentException ignored) { //This *should* never happen + } + }); + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java index b25ed1f..ec130f1 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java +++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java @@ -40,6 +40,7 @@ public class MainPlugin extends JavaPlugin { setupPermissions(); Test = getConfig().getBoolean("test", true); saveConfig(); + ComponentManager.enableComponents(); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class); TBMCChatAPI.RegisterChatChannel(Channel.GlobalChat = new Channel("§fOOC§f", Color.White, "ooc", null)); @@ -67,6 +68,7 @@ public class MainPlugin extends JavaPlugin { @Override public void onDisable() { + ComponentManager.disableComponents(); logger.info("Saving player data..."); TBMCPlayerBase.savePlayers(); logger.info("Player data saved."); diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java index 33c6788..d59cbd9 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java @@ -1,17 +1,75 @@ package buttondevteam.lib.architecture; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.architecture.exceptions.UnregisteredComponentException; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.experimental.var; import lombok.val; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; +import java.util.Collections; import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; +/** + * Configuration is based on class name + */ public abstract class Component { - private static HashMap, Component> components; + private static HashMap, Component> components = new HashMap<>(); + + @Getter + private boolean enabled = false; + @Getter(value = AccessLevel.PROTECTED) + @NonNull + private JavaPlugin plugin; + @NonNull + private ConfigurationSection config; + + public ConfigData shouldBeEnabled() { + return getData("enabled", true); + } + + private HashMap> datamap = new HashMap<>(); + + /** + * This method overload should only be used with primitves or String. + * + * @param path The path in config to use + * @param def The value to use by default + * @param The type of this variable (only use primitives or String) + * @return The data object that can be used to get or set the value + */ + @SuppressWarnings("unchecked") + protected ConfigData getData(String path, T def) { + ConfigData data = datamap.get(path); + if (data == null) datamap.put(path, data = new ConfigData<>(config, path, def)); + return (ConfigData) data; + } + + /** + * This method overload may be used with any class. + * + * @param path The path in config to use + * @param def The value to use by default + * @param getter A function that converts a primitive representation to the correct value + * @param setter A function that converts a value to a primitive representation + * @param The type of this variable (can be any class) + * @return The data object that can be used to get or set the value + */ + @SuppressWarnings("unchecked") + protected ConfigData getData(String path, T def, Function getter, Function setter) { + ConfigData data = datamap.get(path); + if (data == null) datamap.put(path, data = new ConfigData<>(config, path, def, getter, setter)); + return (ConfigData) data; + } /** * Registers a component checking it's dependencies and calling {@link #register(JavaPlugin)}.
@@ -20,18 +78,7 @@ public abstract class Component { * @param component The component to register */ public static void registerComponent(JavaPlugin plugin, Component component) { - val metaAnn = component.getClass().getAnnotation(ComponentMetadata.class); - if (metaAnn != null) { - Class[] dependencies = metaAnn.depends(); - for (val dep : dependencies) { - if (!components.containsKey(dep)) { - plugin.getLogger().warning("Failed to register component " + component.getClassName() + " as a required dependency is missing/disabled: " + dep.getSimpleName()); - return; - } - } - } - component.register(plugin); - components.put(component.getClass(), component); + registerUnregisterComponent(plugin, component, true); } /** @@ -44,27 +91,56 @@ public abstract class Component { val component = components.get(componentClass); if (component == null) return; //Failed to load - val metaAnn = componentClass.getAnnotation(ComponentMetadata.class); + registerUnregisterComponent(plugin, component, false); + } + + public static void registerUnregisterComponent(JavaPlugin plugin, Component component, boolean register) { + val metaAnn = component.getClass().getAnnotation(ComponentMetadata.class); if (metaAnn != null) { Class[] dependencies = metaAnn.depends(); for (val dep : dependencies) { if (!components.containsKey(dep)) { - plugin.getLogger().warning("Failed to unregister component " + component.getClassName() + " as a required dependency is missing/disabled: " + dep.getSimpleName()); + plugin.getLogger().warning("Failed to " + (register ? "" : "un") + "register component " + component.getClassName() + " as a required dependency is missing/disabled: " + dep.getSimpleName()); return; } } } - component.unregister(plugin); - components.remove(componentClass); + if (register) { + component.plugin = plugin; + var compconf = plugin.getConfig().getConfigurationSection("components"); + if (compconf == null) compconf = plugin.getConfig().createSection("components"); + component.config = compconf.getConfigurationSection(component.getClassName()); + if (component.config == null) component.config = compconf.createSection(component.getClassName()); + component.register(plugin); + components.put(component.getClass(), component); + } else { + component.unregister(plugin); + components.remove(component.getClass()); + } } /** - * This is used to send a warning if there are registered components on shutdown.
+ * Registers a component checking it's dependencies and calling {@link #register(JavaPlugin)}.
+ * Make sure to register the dependencies first. * - * @return If there are any registered components + * @param component The component to register */ - public static boolean haveRegisteredComponents() { - return components.size() > 0; + public static void setComponentEnabled(Component component, boolean enabled) throws UnregisteredComponentException { + if (!components.containsKey(component.getClass())) + throw new UnregisteredComponentException(component); + if (component.enabled = enabled) + component.enable(); + else + component.disable(); + } + + /** + * Returns the currently registered components
+ * + * @return The currently registered components + */ + public static Map, Component> getComponents() { + return Collections.unmodifiableMap(components); } /** @@ -73,7 +149,7 @@ public abstract class Component { * * @param plugin Plugin class called to register commands and listeners */ - public abstract void register(JavaPlugin plugin); + protected abstract void register(JavaPlugin plugin); /** * Unregisters the module, when called by the JavaPlugin class. Do @@ -81,7 +157,21 @@ public abstract class Component { * * @param plugin Plugin class called to register commands and listeners */ - public abstract void unregister(JavaPlugin plugin); + protected abstract void unregister(JavaPlugin plugin); + + /** + * Enables the module, when called by the JavaPlugin class. Call + * registerCommand() and registerListener() within this method.
+ * To access the plugin, use {@link #getPlugin()}. + */ + protected abstract void enable(); + + /** + * Disables the module, when called by the JavaPlugin class. Do + * any cleanups needed within this method. + * To access the plugin, use {@link #getPlugin()}. + */ + protected abstract void disable(); /** * Registers a TBMCCommand to the plugin. Make sure to add it to plugin.yml and use {@link buttondevteam.lib.chat.CommandClass}. diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java new file mode 100644 index 0000000..829ea2b --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java @@ -0,0 +1,43 @@ +package buttondevteam.lib.architecture; + +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.util.function.Function; + +/** + * Use the getter/setter constructor if {@link T} isn't a primitive type or String. + */ +@RequiredArgsConstructor +@AllArgsConstructor +public class ConfigData { //TODO: Save after a while + private final ConfigurationSection config; + private final String path; + private final T def; + /** + * The parameter is of a primitive type as returned by {@link YamlConfiguration#get(String)} + */ + private Function getter; + /** + * The result should be a primitive type or string that can be retrieved correctly later + */ + private Function setter; + + @SuppressWarnings("unchecked") + public T get() { + Object val = config.get(path, def); + if (getter != null) + return getter.apply(val); + return (T) val; + } + + public void set(T value) { + Object val; + if (setter != null) + val = setter.apply(value); + else val = value; + config.set(path, val); + } +} diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/exceptions/UnregisteredComponentException.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/exceptions/UnregisteredComponentException.java new file mode 100644 index 0000000..e86c302 --- /dev/null +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/exceptions/UnregisteredComponentException.java @@ -0,0 +1,10 @@ +package buttondevteam.lib.architecture.exceptions; + +import buttondevteam.lib.architecture.Component; + +public class UnregisteredComponentException extends Throwable { + + public UnregisteredComponentException(Component component) { + super("The component '" + component.getClass().getSimpleName() + "' isn't registered!"); + } +} From 81cb364ddcaaf256479236ecfaa2dad47cf2316c Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 18 Nov 2018 02:58:26 +0100 Subject: [PATCH 4/4] Fixes, should be ready to merge --- ButtonCore/lombok.config | 1 + ButtonCore/pom.xml | 8 ++++++++ .../component/commands/CommandComponent.java | 5 ++--- .../component/restart/RestartComponent.java | 11 +++++------ .../updater/PluginUpdaterComponent.java | 7 +++---- .../java/buttondevteam/core/MainPlugin.java | 5 +++++ .../lib/architecture/Component.java | 19 +++++++++++-------- ButtonProcessor/pom.xml | 8 ++++++++ 8 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 ButtonCore/lombok.config diff --git a/ButtonCore/lombok.config b/ButtonCore/lombok.config new file mode 100644 index 0000000..d959b09 --- /dev/null +++ b/ButtonCore/lombok.config @@ -0,0 +1 @@ +lombok.var.flagUsage = ALLOW diff --git a/ButtonCore/pom.xml b/ButtonCore/pom.xml index 3750f03..2ae8ac3 100755 --- a/ButtonCore/pom.xml +++ b/ButtonCore/pom.xml @@ -72,6 +72,14 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + diff --git a/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java b/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java index b3f1059..b85ad34 100644 --- a/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java +++ b/ButtonCore/src/main/java/buttondevteam/component/commands/CommandComponent.java @@ -1,16 +1,15 @@ package buttondevteam.component.commands; import buttondevteam.lib.architecture.Component; -import org.bukkit.plugin.java.JavaPlugin; public class CommandComponent extends Component { //TODO: Do we just move everything here? @Override - public void register(JavaPlugin plugin) { + public void enable() { } @Override - public void unregister(JavaPlugin plugin) { + public void disable() { } } diff --git a/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java b/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java index 3061824..8184b8a 100644 --- a/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java +++ b/ButtonCore/src/main/java/buttondevteam/component/restart/RestartComponent.java @@ -4,18 +4,17 @@ import buttondevteam.core.PrimeRestartCommand; import buttondevteam.core.ScheduledRestartCommand; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.TBMCChatAPI; -import org.bukkit.plugin.java.JavaPlugin; public class RestartComponent extends Component { @Override - public void register(JavaPlugin plugin) { - //TODO: Separately (dis)allow commands - TBMCChatAPI.AddCommand(plugin, ScheduledRestartCommand.class); - TBMCChatAPI.AddCommand(plugin, PrimeRestartCommand.class); + public void enable() { + //TODO: Permissions for the commands + TBMCChatAPI.AddCommand(getPlugin(), ScheduledRestartCommand.class); + TBMCChatAPI.AddCommand(getPlugin(), PrimeRestartCommand.class); } @Override - public void unregister(JavaPlugin plugin) { + public void disable() { } } diff --git a/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java b/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java index 1427927..2425631 100644 --- a/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java +++ b/ButtonCore/src/main/java/buttondevteam/component/updater/PluginUpdaterComponent.java @@ -2,16 +2,15 @@ package buttondevteam.component.updater; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.TBMCChatAPI; -import org.bukkit.plugin.java.JavaPlugin; public class PluginUpdaterComponent extends Component { @Override - public void register(JavaPlugin plugin) { - TBMCChatAPI.AddCommand(plugin, UpdatePluginCommand.class); + public void enable() { + TBMCChatAPI.AddCommand(getPlugin(), UpdatePluginCommand.class); } @Override - public void unregister(JavaPlugin plugin) { + public void disable() { //TODO: Unregister commands and such } } diff --git a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java index ec130f1..9de7993 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java +++ b/ButtonCore/src/main/java/buttondevteam/core/MainPlugin.java @@ -1,7 +1,10 @@ package buttondevteam.core; +import buttondevteam.component.restart.RestartComponent; import buttondevteam.component.updater.PluginUpdater; +import buttondevteam.component.updater.PluginUpdaterComponent; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.ChatRoom; import buttondevteam.lib.chat.Color; @@ -40,6 +43,8 @@ public class MainPlugin extends JavaPlugin { setupPermissions(); Test = getConfig().getBoolean("test", true); saveConfig(); + Component.registerComponent(this, new PluginUpdaterComponent()); + Component.registerComponent(this, new RestartComponent()); ComponentManager.enableComponents(); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterUserClass(TBMCPlayerBase.class); diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java index d59cbd9..faeb6a8 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/Component.java @@ -144,20 +144,23 @@ public abstract class Component { } /** - * Registers the module, when called by the JavaPlugin class. Call - * registerCommand() and registerListener() within this method. + * Registers the module, when called by the JavaPlugin class. + * This gets fired when the plugin is enabled. Use {@link #enable()} to register commands and such. * - * @param plugin Plugin class called to register commands and listeners + * @param plugin Plugin object */ - protected abstract void register(JavaPlugin plugin); + protected void register(JavaPlugin plugin) { + } /** - * Unregisters the module, when called by the JavaPlugin class. Do - * any cleanups needed within this method. + * Unregisters the module, when called by the JavaPlugin class. + * This gets fired when the plugin is disabled. + * Do any cleanups needed within this method. * - * @param plugin Plugin class called to register commands and listeners + * @param plugin Plugin object */ - protected abstract void unregister(JavaPlugin plugin); + protected void unregister(JavaPlugin plugin) { + } /** * Enables the module, when called by the JavaPlugin class. Call diff --git a/ButtonProcessor/pom.xml b/ButtonProcessor/pom.xml index 6a14248..a4ce7fa 100755 --- a/ButtonProcessor/pom.xml +++ b/ButtonProcessor/pom.xml @@ -23,6 +23,14 @@ -proc:none + + org.apache.maven.plugins + maven-surefire-plugin + + false + + +