diff --git a/src/main/java/io/github/simplexdev/simplexcore/CoreState.java b/src/main/java/io/github/simplexdev/simplexcore/CoreState.java index f624451..2bcb306 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/CoreState.java +++ b/src/main/java/io/github/simplexdev/simplexcore/CoreState.java @@ -1,7 +1,5 @@ package io.github.simplexdev.simplexcore; -import io.github.simplexdev.simplexcore.utils.Constants; - public class CoreState { String message; @@ -27,7 +25,7 @@ public class CoreState { return State.DEBUG; } - if (Constants.getPlugin().isEnabled()) { + if (SimplexCorePlugin.getInstance().isEnabled()) { return State.ON; } diff --git a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java index 5902940..4dba056 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java +++ b/src/main/java/io/github/simplexdev/simplexcore/SimplexCorePlugin.java @@ -1,18 +1,32 @@ package io.github.simplexdev.simplexcore; +import io.github.simplexdev.simplexcore.command.CommandLoader; import io.github.simplexdev.simplexcore.command.defaults.Command_info; -import io.github.simplexdev.simplexcore.concurrent.Announcer; +import io.github.simplexdev.simplexcore.config.Yaml; +import io.github.simplexdev.simplexcore.config.YamlFactory; +import io.github.simplexdev.simplexcore.plugin.AddonRegistry; +import io.github.simplexdev.simplexcore.plugin.DependencyManagement; +import io.github.simplexdev.simplexcore.task.Announcer; import io.github.simplexdev.simplexcore.listener.DependencyListener; import io.github.simplexdev.simplexcore.listener.SimplexListener; import io.github.simplexdev.simplexcore.plugin.SimplexAddon; -import io.github.simplexdev.simplexcore.utils.Constants; -import io.github.simplexdev.simplexcore.utils.Instances; +import io.github.simplexdev.simplexcore.utils.TimeValues; +import org.bukkit.plugin.PluginManager; +import org.bukkit.scheduler.BukkitScheduler; + +import java.io.File; +import java.util.logging.Logger; public final class SimplexCorePlugin extends SimplexAddon { protected static boolean debug = false; protected static boolean suspended = false; + private DependencyManagement dpm; + private Yaml config; + private TimeValues time; + private Yaml internals; - protected Instances instances; + // should this just be 'new SimplexCorePlugin()' ? + protected static final SimplexCorePlugin instance = getPlugin(SimplexCorePlugin.class); @Override public SimplexCorePlugin getPlugin() { @@ -21,16 +35,19 @@ public final class SimplexCorePlugin extends SimplexAddon { @Override public void init() { - instances = new Instances(); + this.dpm = new DependencyManagement(); + this.config = new YamlFactory(this).setDefaultPathways(); + this.time = new TimeValues(); + this.internals = new YamlFactory(this).from("internals.yml", getParentFolder(), "internals.yml"); } @Override public void start() { try { - instances.getRegistry().register(this); - instances.getCommandLoader().classpath(Command_info.class).load(); - instances.getConfig().reload(); - instances.getInternals().reload(); + getRegistry().register(this); + getCommandLoader().classpath(Command_info.class).load(this); + getYamlConfig().reload(); + getInternals().reload(); // SimplexListener.register(new DependencyListener(), this); new Announcer(); @@ -40,7 +57,7 @@ public final class SimplexCorePlugin extends SimplexAddon { } CoreState state = new CoreState(); - Constants.getLogger().info(state.getMessage()); + getLogger().info(state.getMessage()); } @Override @@ -60,7 +77,45 @@ public final class SimplexCorePlugin extends SimplexAddon { return suspended; } - public final Instances getInstances() { - return instances; + public static SimplexCorePlugin getInstance() { + return instance; } + + public Logger getLogger() { + return this.getServer().getLogger(); + } + + public PluginManager getManager() { + return this.getServer().getPluginManager(); + } + + public BukkitScheduler getScheduler() { + return this.getServer().getScheduler(); + } + + public File getParentFolder() { + return this.getDataFolder(); + } + + public synchronized AddonRegistry getRegistry() { + return AddonRegistry.getInstance(); + } + + public synchronized CommandLoader getCommandLoader() { + return CommandLoader.getInstance(); + } + + public DependencyManagement getDependencyManager() { + return dpm; + } + + public TimeValues getTimeValues() { + return time; + } + + public Yaml getYamlConfig() { + return config; + } + + public Yaml getInternals() { return internals; } } \ No newline at end of file diff --git a/src/main/java/io/github/simplexdev/simplexcore/ban/Ban.java b/src/main/java/io/github/simplexdev/simplexcore/ban/Ban.java index 5fd95d0..f70535d 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/ban/Ban.java +++ b/src/main/java/io/github/simplexdev/simplexcore/ban/Ban.java @@ -1,10 +1,10 @@ package io.github.simplexdev.simplexcore.ban; import io.github.simplexdev.api.IBan; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.chat.Messages; import io.github.simplexdev.simplexcore.config.Yaml; import io.github.simplexdev.simplexcore.config.YamlFactory; -import io.github.simplexdev.simplexcore.utils.Constants; import io.github.simplexdev.simplexcore.utils.Utilities; import io.github.simplexdev.simplexcore.listener.SimplexListener; import org.bukkit.command.CommandSender; @@ -37,7 +37,7 @@ public abstract class Ban implements IBan { } public Ban(Player player, CommandSender sender, BanType type) { - this(player, sender, type, Constants.getPlugin().getInstances().getTimeValues().DAY()); + this(player, sender, type, SimplexCorePlugin.getInstance().getTimeValues().DAY()); } public Ban(Player player, CommandSender sender, BanType type, long banDuration) { @@ -55,10 +55,10 @@ public abstract class Ban implements IBan { } public void writeToFile(boolean separateFiles) { - File fileLocation = new File(Constants.getPlugin().getDataFolder(), "bans"); + File fileLocation = new File(SimplexCorePlugin.getInstance().getParentFolder(), "bans"); if (separateFiles) { - Yaml yaml = new YamlFactory(Constants.getPlugin()).from(null, fileLocation, player.getName() + ".yml"); + Yaml yaml = new YamlFactory(SimplexCorePlugin.getInstance()).from(null, fileLocation, player.getName() + ".yml"); yaml.getConfig().createSection(getOffender().toString()); ConfigurationSection section = yaml.getConfigurationSection(getOffender()::toString); section.set("name", player.getName()); @@ -71,12 +71,12 @@ public abstract class Ban implements IBan { try { yaml.save(); } catch (IOException e) { - Constants.getLogger().severe(e.getMessage()); + SimplexCorePlugin.getInstance().getLogger().severe(e.getMessage()); } yaml.reload(); } else { // TODO: Write to a single file as separate sections per UUID. - Yaml yaml = new YamlFactory(Constants.getPlugin()).from(null, fileLocation, "bans.yml"); + Yaml yaml = new YamlFactory(SimplexCorePlugin.getInstance()).from(null, fileLocation, "bans.yml"); } } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/ban/BanFactory.java b/src/main/java/io/github/simplexdev/simplexcore/ban/BanFactory.java index dd52756..0e49615 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/ban/BanFactory.java +++ b/src/main/java/io/github/simplexdev/simplexcore/ban/BanFactory.java @@ -2,9 +2,9 @@ package io.github.simplexdev.simplexcore.ban; import io.github.simplexdev.api.IBan; import io.github.simplexdev.api.func.VoidSupplier; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.chat.Messages; import io.github.simplexdev.simplexcore.config.Yaml; -import io.github.simplexdev.simplexcore.utils.Constants; import io.github.simplexdev.simplexcore.utils.Utilities; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -126,11 +126,11 @@ public final class BanFactory { private VoidSupplier assignBanDuration() { return () -> { if (type.equals(BanType.PERMANENT)) { - banDuration = Constants.getPlugin().getInstances().getTimeValues().YEAR() * 99; + banDuration = SimplexCorePlugin.getInstance().getTimeValues().YEAR() * 99; } else if (type.equals(BanType.TEMPORARY)) { - banDuration = Constants.getPlugin().getInstances().getTimeValues().DAY(); + banDuration = SimplexCorePlugin.getInstance().getTimeValues().DAY(); } else { - banDuration = Constants.getPlugin().getInstances().getTimeValues().MINUTE() * 5; + banDuration = SimplexCorePlugin.getInstance().getTimeValues().MINUTE() * 5; } }; } diff --git a/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java b/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java index fac7c8b..0a37924 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java +++ b/src/main/java/io/github/simplexdev/simplexcore/command/CommandLoader.java @@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.command; import io.github.simplexdev.api.annotations.CommandInfo; import io.github.simplexdev.simplexcore.command.defaults.DefaultCommand; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.plugin.SimplexAddon; import io.github.simplexdev.simplexcore.utils.ReflectionTools; import org.bukkit.Bukkit; import org.bukkit.command.*; @@ -19,22 +19,33 @@ import java.util.Map; import java.util.MissingResourceException; public final class CommandLoader { - private static final CommandLoader instance = new CommandLoader(); private Reflections reflections; - - protected CommandLoader() { - } + private static final CommandLoader instance = new CommandLoader(); public static CommandLoader getInstance() { return instance; } + /** + * Prepares the CommandLoader to load your plugin's commands from its own package location. + * This is synchronized, so it only registers commands from one plugin at a time. + * All your commands MUST be placed in their own package. + *

+ * If your command classes do not have the {@link CommandInfo} annotation, they will not be loaded. + * If the class provided does not have the {@link CommandInfo} annotation, the loader will throw a new + * {@link MissingResourceException} and will not load your plugin's commands. + * If the class provided does not extend {@link SimplexCommand}, the loader will throw a new + * {@link RuntimeException} and your commands will not be loaded. + *

+ * @param clazz The command class to load from + * @return An instance of this where the classpath has been prepared for loading the commands. + */ 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"); } - if (!clazz.isAssignableFrom(CommandExecutor.class)) { + if (!clazz.isAssignableFrom(SimplexCommand.class)) { throw new RuntimeException("Unable to assign an executor!"); } @@ -42,14 +53,21 @@ public final class CommandLoader { return this; } - public synchronized void load() { + /** + * Loads all the commands from the specified classpath. + * This should be used immediately after {@link CommandLoader#classpath(Class)} has been called. + * If used before, an exception will be thrown, and your commands will not be loaded. + * + * @param plugin An instance of your plugin to assign as the parent plugin for each command. + */ + public synchronized void load(SimplexAddon plugin) { reflections.getTypesAnnotatedWith(CommandInfo.class).forEach(annotated -> { CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class); if (info == null) return; if (!SimplexCommand.class.isAssignableFrom(annotated)) return; - PluginCommand objectToRegister = Registry.create(Constants.getPlugin(), info.name().toLowerCase()); + PluginCommand objectToRegister = Registry.create(plugin, info.name().toLowerCase()); objectToRegister.setAliases(Arrays.asList(info.aliases().split(","))); objectToRegister.setDescription(info.description()); objectToRegister.setExecutor(getExecutorFromName(info.name())); @@ -104,6 +122,9 @@ public final class CommandLoader { return null; } + /** + * Registry class, which forces all necessary fields to accessible. + */ private static class Registry { private static final Constructor constructor; private static final Field cmdMapField; diff --git a/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java b/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java index 92c1bdb..1ad8b30 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java +++ b/src/main/java/io/github/simplexdev/simplexcore/command/SimplexCommand.java @@ -1,6 +1,6 @@ package io.github.simplexdev.simplexcore.command; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.utils.Utilities; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; @@ -22,12 +22,12 @@ public abstract class SimplexCommand implements CommandExecutor, TabCompleter { @Nullable public Player getPlayer(String name) { - return Constants.getServer().getPlayer(name); + return SimplexCorePlugin.getInstance().getServer().getPlayer(name); } @Nullable public Player getPlayer(UUID uuid) { - return Constants.getServer().getPlayer(uuid); + return SimplexCorePlugin.getInstance().getServer().getPlayer(uuid); } @Nullable diff --git a/src/main/java/io/github/simplexdev/simplexcore/concurrent/TaskFactory.java b/src/main/java/io/github/simplexdev/simplexcore/concurrent/TaskFactory.java deleted file mode 100644 index f2bbee7..0000000 --- a/src/main/java/io/github/simplexdev/simplexcore/concurrent/TaskFactory.java +++ /dev/null @@ -1,4 +0,0 @@ -package io.github.simplexdev.simplexcore.concurrent; - -public final class TaskFactory { -} diff --git a/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java b/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java index 0af5e9f..8be8003 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java +++ b/src/main/java/io/github/simplexdev/simplexcore/config/Yaml.java @@ -2,8 +2,8 @@ package io.github.simplexdev.simplexcore.config; import io.github.simplexdev.api.IConfig; import io.github.simplexdev.api.func.Path; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.plugin.SimplexAddon; -import io.github.simplexdev.simplexcore.utils.Constants; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -150,13 +150,13 @@ public final class Yaml implements IConfig { * Called when a file is created. */ public void create() { - Constants.getLogger().info("File created!"); + SimplexCorePlugin.getInstance().getLogger().info("File created!"); } /** * Called when then file is reloaded */ public void onReload() { - Constants.getLogger().info("The plugin configuration has been reloaded!"); + SimplexCorePlugin.getInstance().getLogger().info("The plugin configuration has been reloaded!"); } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/listener/DependencyListener.java b/src/main/java/io/github/simplexdev/simplexcore/listener/DependencyListener.java index b504a76..e59f65f 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/listener/DependencyListener.java +++ b/src/main/java/io/github/simplexdev/simplexcore/listener/DependencyListener.java @@ -1,6 +1,6 @@ package io.github.simplexdev.simplexcore.listener; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.server.PluginEnableEvent; @@ -34,11 +34,11 @@ public final class DependencyListener extends SimplexListener { BooleanSupplier temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName()); if (temp.getAsBoolean()) { - Constants.getPlugin().getInstances().getDependencyManager().registerProtocolLib(); + SimplexCorePlugin.getInstance().getDependencyManager().registerProtocolLib(); } if (temp2.getAsBoolean()) { - Constants.getPlugin().getInstances().getDependencyManager().registerPAPI(); + SimplexCorePlugin.getInstance().getDependencyManager().registerPAPI(); } } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java b/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java index 9f03aae..30e2332 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java +++ b/src/main/java/io/github/simplexdev/simplexcore/listener/SimplexListener.java @@ -1,7 +1,7 @@ package io.github.simplexdev.simplexcore.listener; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.plugin.SimplexAddon; -import io.github.simplexdev.simplexcore.utils.Constants; import org.bukkit.event.Listener; import java.lang.reflect.Constructor; @@ -16,7 +16,7 @@ public abstract class SimplexListener implements Listener { */ public static void registerFromClass(Class cls, SimplexAddon plugin) { if (!SimplexListener.class.isAssignableFrom(cls)) { - Constants.getLogger().severe("You can only register subclasses of SimplexListener with this method."); + SimplexCorePlugin.getInstance().getLogger().severe("You can only register subclasses of SimplexListener with this method."); return; } @@ -24,7 +24,7 @@ public abstract class SimplexListener implements Listener { Constructor constr = cls.getDeclaredConstructor(); register(constr.newInstance(), plugin); } catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { - Constants.getLogger().severe("Could not register this listener!"); + SimplexCorePlugin.getInstance().getLogger().severe("Could not register this listener!"); } } @@ -36,6 +36,6 @@ public abstract class SimplexListener implements Listener { * @param Type of which extends SimplexListener. */ public static void register(T listener, SimplexAddon plugin) { - Constants.getManager().registerEvents(listener, plugin); + SimplexCorePlugin.getInstance().getManager().registerEvents(listener, plugin); } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/math/Cuboid.java b/src/main/java/io/github/simplexdev/simplexcore/math/Cuboid.java index dfa9564..d776e5a 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/math/Cuboid.java +++ b/src/main/java/io/github/simplexdev/simplexcore/math/Cuboid.java @@ -1,6 +1,6 @@ package io.github.simplexdev.simplexcore.math; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.scheduler.BukkitTask; @@ -44,6 +44,6 @@ public final class Cuboid { }; - Constants.getScheduler().runTaskLaterAsynchronously(Constants.getPlugin(), task, Constants.getPlugin().getInstances().getTimeValues().SECOND()); + SimplexCorePlugin.getInstance().getScheduler().runTaskLaterAsynchronously(SimplexCorePlugin.getInstance(), task, SimplexCorePlugin.getInstance().getTimeValues().SECOND()); } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/math/Pyramid.java b/src/main/java/io/github/simplexdev/simplexcore/math/Pyramid.java index 88e47da..24c2268 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/math/Pyramid.java +++ b/src/main/java/io/github/simplexdev/simplexcore/math/Pyramid.java @@ -1,6 +1,6 @@ package io.github.simplexdev.simplexcore.math; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; @@ -50,7 +50,7 @@ public final class Pyramid { createOddFull(); }; - Constants.getScheduler().runTaskLater(Constants.getPlugin(), consumer, 20L); + SimplexCorePlugin.getInstance().getScheduler().runTaskLater(SimplexCorePlugin.getInstance(), consumer, 20L); } private void createOddFull() { diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java index 74080ce..efcb584 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java +++ b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonManager.java @@ -1,17 +1,17 @@ package io.github.simplexdev.simplexcore.plugin; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; public final class AddonManager { public AddonManager() { } public void disable(SimplexAddon simplexAddon) { - Constants.getManager().disablePlugin(simplexAddon); + SimplexCorePlugin.getInstance().getManager().disablePlugin(simplexAddon); } public void enable(SimplexAddon simplexAddon) { - Constants.getManager().enablePlugin(simplexAddon); + SimplexCorePlugin.getInstance().getManager().enablePlugin(simplexAddon); } public void reload(SimplexAddon simplexAddon) { diff --git a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java index 1b9c76d..3f37545 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/simplexdev/simplexcore/plugin/AddonRegistry.java @@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.plugin; import io.github.simplexdev.api.annotations.ReqType; import io.github.simplexdev.api.annotations.Requires; -import io.github.simplexdev.simplexcore.utils.Constants; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import java.util.HashSet; import java.util.Set; @@ -24,7 +24,7 @@ public final class AddonRegistry { return true; } catch (ClassNotFoundException ignored) { addon.stop(); - Constants.getLogger().severe(addon.getName() + " has been disabled: This module requires Paper!"); + SimplexCorePlugin.getInstance().getLogger().severe(addon.getName() + " has been disabled: This module requires Paper!"); return false; } } @@ -35,7 +35,7 @@ public final class AddonRegistry { return true; } catch (ClassNotFoundException ignored) { addon.stop(); - Constants.getLogger().severe(addon.getName() + " has been disabled: This module requires Bungeecord!"); + SimplexCorePlugin.getInstance().getLogger().severe(addon.getName() + " has been disabled: This module requires Bungeecord!"); return false; } } @@ -46,7 +46,7 @@ public final class AddonRegistry { return true; } catch (ClassNotFoundException ignored) { addon.stop(); - Constants.getLogger().severe(addon.getName() + " has been disabled: This module requires Waterfall!"); + SimplexCorePlugin.getInstance().getLogger().severe(addon.getName() + " has been disabled: This module requires Waterfall!"); return false; } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java b/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java index 123f9b0..1f5a657 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java +++ b/src/main/java/io/github/simplexdev/simplexcore/sign/SignFactory.java @@ -2,9 +2,9 @@ package io.github.simplexdev.simplexcore.sign; import io.github.simplexdev.api.IUsableSign; import io.github.simplexdev.api.func.VoidSupplier; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.listener.SimplexListener; import io.github.simplexdev.simplexcore.plugin.SimplexAddon; -import io.github.simplexdev.simplexcore.utils.Constants; import org.bukkit.Material; import org.bukkit.block.Sign; import org.bukkit.event.EventHandler; @@ -41,7 +41,7 @@ public class SignFactory { private SignData signData = null; public void activateBasicSignDataListener() { - signData = new SignData(Constants.getPlugin()); + signData = new SignData(SimplexCorePlugin.getInstance()); } public SignData getSignData() { diff --git a/src/main/java/io/github/simplexdev/simplexcore/concurrent/Announcer.java b/src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java similarity index 73% rename from src/main/java/io/github/simplexdev/simplexcore/concurrent/Announcer.java rename to src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java index 655e007..8d705cb 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/concurrent/Announcer.java +++ b/src/main/java/io/github/simplexdev/simplexcore/task/Announcer.java @@ -1,7 +1,7 @@ -package io.github.simplexdev.simplexcore.concurrent; +package io.github.simplexdev.simplexcore.task; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.chat.Messages; -import io.github.simplexdev.simplexcore.utils.Constants; import org.apache.commons.lang.math.RandomUtils; import org.bukkit.Bukkit; import org.bukkit.scheduler.BukkitTask; @@ -14,12 +14,12 @@ public class Announcer extends SimplexTask { 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"); + add("https://github.com/SimplexDevelopment/SimplexCore"); }}; public Announcer() { super(20L); - register(this, Constants.getPlugin(), true, false); + register(this, SimplexCorePlugin.getInstance(), true, false); } @Override diff --git a/src/main/java/io/github/simplexdev/simplexcore/concurrent/SimplexTask.java b/src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java similarity index 63% rename from src/main/java/io/github/simplexdev/simplexcore/concurrent/SimplexTask.java rename to src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java index 244c190..6592098 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/concurrent/SimplexTask.java +++ b/src/main/java/io/github/simplexdev/simplexcore/task/SimplexTask.java @@ -1,7 +1,7 @@ -package io.github.simplexdev.simplexcore.concurrent; +package io.github.simplexdev.simplexcore.task; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.plugin.SimplexAddon; -import io.github.simplexdev.simplexcore.utils.Constants; import org.bukkit.scheduler.BukkitTask; import java.util.Date; @@ -24,19 +24,19 @@ public abstract class SimplexTask implements Consumer { } protected SimplexTask() { - DELAY = Constants.getPlugin().getInstances().getTimeValues().SECOND() * 30; // 30 seconds until the task triggers for the first time. - INTERVAL = Constants.getPlugin().getInstances().getTimeValues().MINUTE() * 5; // Task will run at 5 minute intervals once the first trigger has been called. + DELAY = SimplexCorePlugin.getInstance().getTimeValues().SECOND() * 30; // 30 seconds until the task triggers for the first time. + INTERVAL = SimplexCorePlugin.getInstance().getTimeValues().MINUTE() * 5; // Task will run at 5 minute intervals once the first trigger has been called. } public void register(T task, SimplexAddon plugin, boolean repeating, boolean delayed) { if (delayed && repeating) { - Constants.getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); + SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); } else if (delayed) { - Constants.getScheduler().runTaskLater(plugin, task, DELAY); + SimplexCorePlugin.getInstance().getScheduler().runTaskLater(plugin, task, DELAY); } else if (repeating) { - Constants.getScheduler().runTaskTimer(plugin, task, 0L, INTERVAL); + SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, 0L, INTERVAL); } else { - Constants.getScheduler().runTask(plugin, task); + SimplexCorePlugin.getInstance().getScheduler().runTask(plugin, task); } } diff --git a/src/main/java/io/github/simplexdev/simplexcore/task/TaskFactory.java b/src/main/java/io/github/simplexdev/simplexcore/task/TaskFactory.java new file mode 100644 index 0000000..ef862e1 --- /dev/null +++ b/src/main/java/io/github/simplexdev/simplexcore/task/TaskFactory.java @@ -0,0 +1,4 @@ +package io.github.simplexdev.simplexcore.task; + +public final class TaskFactory { +} diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java deleted file mode 100644 index d168297..0000000 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Constants.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.simplexdev.simplexcore.utils; - -import io.github.simplexdev.simplexcore.SimplexCorePlugin; -import io.github.simplexdev.simplexcore.command.CommandLoader; -import io.github.simplexdev.simplexcore.config.Yaml; -import io.github.simplexdev.simplexcore.config.YamlFactory; -import io.github.simplexdev.simplexcore.plugin.AddonRegistry; -import io.github.simplexdev.simplexcore.plugin.DependencyManagement; -import org.bukkit.Server; -import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.scheduler.BukkitScheduler; - -import java.io.File; -import java.util.logging.Logger; - -public final class Constants { - private static final SimplexCorePlugin plugin = JavaPlugin.getPlugin(SimplexCorePlugin.class); - - public static SimplexCorePlugin getPlugin() { - return plugin; - } - - public static Server getServer() { - return plugin.getServer(); - } - - public static Logger getLogger() { - return plugin.getServer().getLogger(); - } - - public static PluginManager getManager() { - return plugin.getServer().getPluginManager(); - } - - public static BukkitScheduler getScheduler() { - return plugin.getServer().getScheduler(); - } - - public static File getDataFolder() { - return plugin.getDataFolder(); - } -} - diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java deleted file mode 100644 index 063246b..0000000 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Instances.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.simplexdev.simplexcore.utils; - -import io.github.simplexdev.simplexcore.command.CommandLoader; -import io.github.simplexdev.simplexcore.config.Yaml; -import io.github.simplexdev.simplexcore.config.YamlFactory; -import io.github.simplexdev.simplexcore.plugin.AddonRegistry; -import io.github.simplexdev.simplexcore.plugin.DependencyManagement; - -public final class Instances { - private final DependencyManagement dpm = new DependencyManagement(); - private final Yaml config = new YamlFactory(Constants.getPlugin()).setDefaultPathways(); - private final TimeValues time = new TimeValues(); - private final Yaml internals = new YamlFactory(Constants.getPlugin()).from("internals.yml", Constants.getDataFolder(), "internals.yml"); - - public synchronized AddonRegistry getRegistry() { - return AddonRegistry.getInstance(); - } - - public synchronized CommandLoader getCommandLoader() { - return CommandLoader.getInstance(); - } - - public DependencyManagement getDependencyManager() { - return dpm; - } - - public TimeValues getTimeValues() { - return time; - } - - public Yaml getConfig() { - return config; - } - - public Yaml getInternals() { return internals; } -} diff --git a/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java b/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java index cbb659a..40fb52e 100644 --- a/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java +++ b/src/main/java/io/github/simplexdev/simplexcore/utils/Utilities.java @@ -1,6 +1,7 @@ package io.github.simplexdev.simplexcore.utils; import io.github.simplexdev.api.func.Path; +import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.ban.BanType; import org.bukkit.Bukkit; @@ -15,7 +16,7 @@ import java.util.stream.Stream; public final class Utilities { private static final SplittableRandom random = new SplittableRandom(); private static final SplittableRandom numbers = new SplittableRandom(); - private static final List versions = Constants.getPlugin().getInstances().getInternals().getStringList(pathway("supported_versions")); + private static final List versions = SimplexCorePlugin.getInstance().getInternals().getStringList(pathway("supported_versions")); private static final List list = new ArrayList<>() {{ add('0');