From 9fe9f8e2ae23ed3bb8b5a07fdb38d15d7d602242 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 8 Feb 2021 17:09:15 -0600 Subject: [PATCH] Bourgeoise --- .../github/paldiu/simplexcore/CoreState.java | 47 +++++++++---------- .../paldiu/simplexcore/SimplexCore.java | 24 +++++----- .../paldiu/simplexcore/chat/Messages.java | 4 +- .../simplexcore/command/CommandInfo.java | 2 - .../simplexcore/command/CommandLoader.java | 17 ++++--- .../simplexcore/config/JsonFactory.java | 1 - .../{utils => functional}/Validate.java | 2 +- .../paldiu/simplexcore/future/Announcer.java | 12 ++--- .../simplexcore/future/SimplexTask.java | 2 +- .../listener/ServerPluginListener.java | 27 +++++------ .../simplexcore/plugin/AddonManager.java | 3 +- .../simplexcore/plugin/AddonRegistry.java | 4 +- .../plugin/DependencyManagement.java | 31 +++++++++++- .../paldiu/simplexcore/utils/Complete.java | 6 --- .../paldiu/simplexcore/utils/Constants.java | 6 +++ .../paldiu/simplexcore/utils/Utilities.java | 3 +- 16 files changed, 106 insertions(+), 85 deletions(-) rename src/main/java/io/github/paldiu/simplexcore/{utils => functional}/Validate.java (60%) delete mode 100644 src/main/java/io/github/paldiu/simplexcore/utils/Complete.java diff --git a/src/main/java/io/github/paldiu/simplexcore/CoreState.java b/src/main/java/io/github/paldiu/simplexcore/CoreState.java index 999f9f0..4b0a852 100644 --- a/src/main/java/io/github/paldiu/simplexcore/CoreState.java +++ b/src/main/java/io/github/paldiu/simplexcore/CoreState.java @@ -1,32 +1,8 @@ package io.github.paldiu.simplexcore; import io.github.paldiu.simplexcore.utils.Constants; -import org.bukkit.Bukkit; public class CoreState { - enum State { - ON, - DEBUG, - SUSPENDED, - VOLATILE - } - - public State getState() { - if (SimplexCore.isDebug()) { - return State.DEBUG; - } - - if (Constants.getPlugin().isEnabled()) { - return State.ON; - } - - if (SimplexCore.isSuspended()) { - return State.SUSPENDED; - } - - return State.VOLATILE; - } - String message; public CoreState() { @@ -46,7 +22,30 @@ public class CoreState { } } + public State getState() { + if (SimplexCore.isDebug()) { + return State.DEBUG; + } + + if (Constants.getPlugin().isEnabled()) { + return State.ON; + } + + if (SimplexCore.isSuspended()) { + return State.SUSPENDED; + } + + return State.VOLATILE; + } + public String getMessage() { return message; } + + enum State { + ON, + DEBUG, + SUSPENDED, + VOLATILE + } } \ No newline at end of file diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java index 57fddc6..e8d9042 100644 --- a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -11,6 +11,18 @@ public final class SimplexCore extends SimplexAddon { protected static boolean debug = false; protected static boolean suspended = false; + public static boolean isDebug() { + return debug; + } + + public static void setDebug(boolean enable) { + debug = enable; + } + + public static boolean isSuspended() { + return suspended; + } + @Override public SimplexCore getPlugin() { return this; @@ -36,16 +48,4 @@ public final class SimplexCore extends SimplexAddon { public void stop() { } - - public static void setDebug(boolean enable) { - debug = enable; - } - - public static boolean isDebug() { - return debug; - } - - public static boolean isSuspended() { - return suspended; - } } \ No newline at end of file diff --git a/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java b/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java index 0368310..d0c7eef 100644 --- a/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java +++ b/src/main/java/io/github/paldiu/simplexcore/chat/Messages.java @@ -7,12 +7,12 @@ public enum Messages { KICK("You have been kicked by a moderator."), AFK_KICK("You were kicked to ensure space for active players."); + String message; + Messages(String message) { this.message = message; } - String message; - public String getMessage() { return message; } diff --git a/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java b/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java index e52dd43..cb3b2ae 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/CommandInfo.java @@ -1,7 +1,5 @@ package io.github.paldiu.simplexcore.command; -import org.bukkit.ChatColor; - import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java b/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java index 67d14cb..02d8d69 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java @@ -18,8 +18,16 @@ import java.util.Map; import java.util.MissingResourceException; public final class CommandLoader { + private static final CommandLoader instance = new CommandLoader(); private Reflections reflections; + protected CommandLoader() { + } + + public static CommandLoader getInstance() { + return instance; + } + public synchronized CommandLoader classpath(Class clazz) { if (!clazz.isAnnotationPresent(CommandInfo.class)) { throw new MissingResourceException("Cannot register this class as the main resource location!", clazz.getSimpleName(), "@CommandInfo"); @@ -150,13 +158,4 @@ public final class CommandLoader { } } } - - private static final CommandLoader instance = new CommandLoader(); - - protected CommandLoader() { - } - - public static CommandLoader getInstance() { - return instance; - } } diff --git a/src/main/java/io/github/paldiu/simplexcore/config/JsonFactory.java b/src/main/java/io/github/paldiu/simplexcore/config/JsonFactory.java index 431ece6..2a0f387 100644 --- a/src/main/java/io/github/paldiu/simplexcore/config/JsonFactory.java +++ b/src/main/java/io/github/paldiu/simplexcore/config/JsonFactory.java @@ -4,7 +4,6 @@ import io.github.paldiu.simplexcore.plugin.SimplexAddon; import io.github.paldiu.simplexcore.utils.Trio; import java.io.File; -import java.util.Map; public final class JsonFactory { private final SimplexAddon plugin; diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Validate.java b/src/main/java/io/github/paldiu/simplexcore/functional/Validate.java similarity index 60% rename from src/main/java/io/github/paldiu/simplexcore/utils/Validate.java rename to src/main/java/io/github/paldiu/simplexcore/functional/Validate.java index 1396148..213bde4 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Validate.java +++ b/src/main/java/io/github/paldiu/simplexcore/functional/Validate.java @@ -1,4 +1,4 @@ -package io.github.paldiu.simplexcore.utils; +package io.github.paldiu.simplexcore.functional; @FunctionalInterface public interface Validate { diff --git a/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java b/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java index a497072..0955332 100644 --- a/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java +++ b/src/main/java/io/github/paldiu/simplexcore/future/Announcer.java @@ -11,17 +11,17 @@ import java.util.List; public class Announcer extends SimplexTask { - public Announcer() { - super(20L); - register(this, Constants.getPlugin(), true, false); - } - - private List stringList = new ArrayList<>(){{ + private final List stringList = new ArrayList<>() {{ add("Join our discord!" + Messages.DISCORD.getMessage()); add("Thank you for using SimplexCore!"); add("https://github.com/Paldiu/SimplexCore"); }}; + public Announcer() { + super(20L); + register(this, Constants.getPlugin(), true, false); + } + @Override public void accept(BukkitTask bukkitTask) { Bukkit.getServer().broadcastMessage(stringList.get(RandomUtils.nextInt(stringList.size()))); diff --git a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java b/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java index ddbba27..8963614 100644 --- a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java +++ b/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java @@ -8,9 +8,9 @@ import java.util.Date; import java.util.function.Consumer; public abstract class SimplexTask implements Consumer { - protected Date lastRan = new Date(); protected final long DELAY; protected final long INTERVAL; + protected Date lastRan = new Date(); protected SimplexTask(long initialDelay, long interval) { DELAY = initialDelay; diff --git a/src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java b/src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java index 5e1de13..7a68fc8 100644 --- a/src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java +++ b/src/main/java/io/github/paldiu/simplexcore/listener/ServerPluginListener.java @@ -1,17 +1,16 @@ package io.github.paldiu.simplexcore.listener; -import io.github.paldiu.simplexcore.plugin.SimplexAddon; +import io.github.paldiu.simplexcore.functional.Validate; import io.github.paldiu.simplexcore.utils.Constants; -import io.github.paldiu.simplexcore.utils.Utilities; -import io.github.paldiu.simplexcore.utils.Validate; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.server.PluginEnableEvent; import java.util.ArrayList; import java.util.List; public final class ServerPluginListener extends SimplexListener { - public List PAPI_NAMES = new ArrayList<>(){{ + public List PAPI_NAMES = new ArrayList<>() {{ add("PlaceholderAPI"); add("PlaceHolderAPI"); add("placeholderapi"); @@ -20,26 +19,26 @@ public final class ServerPluginListener extends SimplexListener { add("papi"); }}; - public List PLIB_NAMES = new ArrayList<>(){{ + public List PLIB_NAMES = new ArrayList<>() {{ add("ProtocolLib"); add("PLib"); add("Protocollib"); add("plib"); + add("protocollib"); + add("PROTOCOLLIB"); }}; - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void pluginRegister(PluginEnableEvent event) { - Validate temp = () -> { - if (PLIB_NAMES.contains(event.getPlugin().getName())) { - return true; - } - - return PAPI_NAMES.contains(event.getPlugin().getName()); - }; + Validate temp = () -> PLIB_NAMES.contains(event.getPlugin().getName()); + Validate temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName()); if (temp.isValid()) { - + Constants.getDependencyManager().registerProtocolLib(); } + if (temp2.isValid()) { + Constants.getDependencyManager().registerPAPI(); + } } } diff --git a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java index 59a3df9..909a7af 100644 --- a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java +++ b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java @@ -3,7 +3,8 @@ package io.github.paldiu.simplexcore.plugin; import io.github.paldiu.simplexcore.utils.Constants; public final class AddonManager { - public AddonManager() { } + public AddonManager() { + } public void disable(SimplexAddon simplexAddon) { Constants.getManager().disablePlugin(simplexAddon); diff --git a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java index 0fb2238..6dd6feb 100644 --- a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java @@ -4,8 +4,8 @@ import java.util.HashSet; import java.util.Set; public final class AddonRegistry { - private final Set> components = new HashSet<>(); private static final AddonRegistry instance = new AddonRegistry(); + private final Set> components = new HashSet<>(); protected AddonRegistry() { } @@ -14,7 +14,7 @@ public final class AddonRegistry { return instance; } - public >void register(T addon) { + public > void register(T addon) { getComponents().add(addon); } diff --git a/src/main/java/io/github/paldiu/simplexcore/plugin/DependencyManagement.java b/src/main/java/io/github/paldiu/simplexcore/plugin/DependencyManagement.java index f19785c..6672c0a 100644 --- a/src/main/java/io/github/paldiu/simplexcore/plugin/DependencyManagement.java +++ b/src/main/java/io/github/paldiu/simplexcore/plugin/DependencyManagement.java @@ -1,7 +1,34 @@ package io.github.paldiu.simplexcore.plugin; -public class DependencyManagement { - public DependencyManagement() { +import com.comphenix.protocol.ProtocolLibrary; +import com.comphenix.protocol.ProtocolManager; +import me.clip.placeholderapi.PlaceholderAPIPlugin; +import org.jetbrains.annotations.Nullable; +public class DependencyManagement { + private ProtocolManager manager; + private PlaceholderAPIPlugin papi; + + public DependencyManagement() { + manager = null; + papi = null; + } + + public void registerProtocolLib() { + manager = ProtocolLibrary.getProtocolManager(); + } + + public void registerPAPI() { + papi = PlaceholderAPIPlugin.getInstance(); + } + + @Nullable + public PlaceholderAPIPlugin getPAPI() { + return papi; + } + + @Nullable + public ProtocolManager getProtocolManager() { + return manager; } } diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Complete.java b/src/main/java/io/github/paldiu/simplexcore/utils/Complete.java deleted file mode 100644 index bada3ad..0000000 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Complete.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.github.paldiu.simplexcore.utils; - -@FunctionalInterface -public interface Complete { - void toComplete(Void complete); -} diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java b/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java index 10dd905..ef34643 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java +++ b/src/main/java/io/github/paldiu/simplexcore/utils/Constants.java @@ -3,6 +3,7 @@ package io.github.paldiu.simplexcore.utils; import io.github.paldiu.simplexcore.SimplexCore; import io.github.paldiu.simplexcore.command.CommandLoader; import io.github.paldiu.simplexcore.plugin.AddonRegistry; +import io.github.paldiu.simplexcore.plugin.DependencyManagement; import org.bukkit.Server; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -16,6 +17,7 @@ public final class Constants { private static final Logger logger = plugin.getLogger(); private static final PluginManager manager = server.getPluginManager(); private static final BukkitScheduler scheduler = server.getScheduler(); + private static final DependencyManagement dpm = new DependencyManagement(); public static SimplexCore getPlugin() { return plugin; @@ -45,6 +47,10 @@ public final class Constants { return CommandLoader.getInstance(); } + public static DependencyManagement getDependencyManager() { + return dpm; + } + public static TimeValues getTimeValues() { return new TimeValues(); } diff --git a/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java b/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java index c1cea58..9a1605b 100644 --- a/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java +++ b/src/main/java/io/github/paldiu/simplexcore/utils/Utilities.java @@ -1,7 +1,6 @@ package io.github.paldiu.simplexcore.utils; -import io.github.paldiu.simplexcore.listener.SimplexListener; -import io.github.paldiu.simplexcore.plugin.SimplexAddon; +import io.github.paldiu.simplexcore.functional.Validate; import java.util.Arrays; import java.util.Collection;