BLEEDING EDGE 1.3_08

- Merged Instances and Constants into SimplexCorePlugin
 - Created a singleton instance for SimplexCorePlugin
 - Added JavaDocs and updated classes to reflect the new merge
 - Upcoming: converting the majority of classes to some form of Dependency Injection
This commit is contained in:
Paldiu 2021-03-05 21:59:56 -06:00
parent a31093d3f8
commit 7f75586cd6
21 changed files with 151 additions and 156 deletions

View File

@ -1,7 +1,5 @@
package io.github.simplexdev.simplexcore; package io.github.simplexdev.simplexcore;
import io.github.simplexdev.simplexcore.utils.Constants;
public class CoreState { public class CoreState {
String message; String message;
@ -27,7 +25,7 @@ public class CoreState {
return State.DEBUG; return State.DEBUG;
} }
if (Constants.getPlugin().isEnabled()) { if (SimplexCorePlugin.getInstance().isEnabled()) {
return State.ON; return State.ON;
} }

View File

@ -1,18 +1,32 @@
package io.github.simplexdev.simplexcore; 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.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.DependencyListener;
import io.github.simplexdev.simplexcore.listener.SimplexListener; import io.github.simplexdev.simplexcore.listener.SimplexListener;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon; import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.Constants; import io.github.simplexdev.simplexcore.utils.TimeValues;
import io.github.simplexdev.simplexcore.utils.Instances; 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<SimplexCorePlugin> { public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
protected static boolean debug = false; protected static boolean debug = false;
protected static boolean suspended = 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 @Override
public SimplexCorePlugin getPlugin() { public SimplexCorePlugin getPlugin() {
@ -21,16 +35,19 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
@Override @Override
public void init() { 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 @Override
public void start() { public void start() {
try { try {
instances.getRegistry().register(this); getRegistry().register(this);
instances.getCommandLoader().classpath(Command_info.class).load(); getCommandLoader().classpath(Command_info.class).load(this);
instances.getConfig().reload(); getYamlConfig().reload();
instances.getInternals().reload(); getInternals().reload();
// //
SimplexListener.register(new DependencyListener(), this); SimplexListener.register(new DependencyListener(), this);
new Announcer(); new Announcer();
@ -40,7 +57,7 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
} }
CoreState state = new CoreState(); CoreState state = new CoreState();
Constants.getLogger().info(state.getMessage()); getLogger().info(state.getMessage());
} }
@Override @Override
@ -60,7 +77,45 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
return suspended; return suspended;
} }
public final Instances getInstances() { public static SimplexCorePlugin getInstance() {
return instances; 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; }
} }

View File

@ -1,10 +1,10 @@
package io.github.simplexdev.simplexcore.ban; package io.github.simplexdev.simplexcore.ban;
import io.github.simplexdev.api.IBan; import io.github.simplexdev.api.IBan;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.chat.Messages; import io.github.simplexdev.simplexcore.chat.Messages;
import io.github.simplexdev.simplexcore.config.Yaml; import io.github.simplexdev.simplexcore.config.Yaml;
import io.github.simplexdev.simplexcore.config.YamlFactory; 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.utils.Utilities;
import io.github.simplexdev.simplexcore.listener.SimplexListener; import io.github.simplexdev.simplexcore.listener.SimplexListener;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -37,7 +37,7 @@ public abstract class Ban implements IBan {
} }
public Ban(Player player, CommandSender sender, BanType type) { 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) { 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) { public void writeToFile(boolean separateFiles) {
File fileLocation = new File(Constants.getPlugin().getDataFolder(), "bans"); File fileLocation = new File(SimplexCorePlugin.getInstance().getParentFolder(), "bans");
if (separateFiles) { 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()); yaml.getConfig().createSection(getOffender().toString());
ConfigurationSection section = yaml.getConfigurationSection(getOffender()::toString); ConfigurationSection section = yaml.getConfigurationSection(getOffender()::toString);
section.set("name", player.getName()); section.set("name", player.getName());
@ -71,12 +71,12 @@ public abstract class Ban implements IBan {
try { try {
yaml.save(); yaml.save();
} catch (IOException e) { } catch (IOException e) {
Constants.getLogger().severe(e.getMessage()); SimplexCorePlugin.getInstance().getLogger().severe(e.getMessage());
} }
yaml.reload(); yaml.reload();
} else { } else {
// TODO: Write to a single file as separate sections per UUID. // 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");
} }
} }
} }

View File

@ -2,9 +2,9 @@ package io.github.simplexdev.simplexcore.ban;
import io.github.simplexdev.api.IBan; import io.github.simplexdev.api.IBan;
import io.github.simplexdev.api.func.VoidSupplier; 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.chat.Messages;
import io.github.simplexdev.simplexcore.config.Yaml; import io.github.simplexdev.simplexcore.config.Yaml;
import io.github.simplexdev.simplexcore.utils.Constants;
import io.github.simplexdev.simplexcore.utils.Utilities; import io.github.simplexdev.simplexcore.utils.Utilities;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -126,11 +126,11 @@ public final class BanFactory {
private VoidSupplier assignBanDuration() { private VoidSupplier assignBanDuration() {
return () -> { return () -> {
if (type.equals(BanType.PERMANENT)) { if (type.equals(BanType.PERMANENT)) {
banDuration = Constants.getPlugin().getInstances().getTimeValues().YEAR() * 99; banDuration = SimplexCorePlugin.getInstance().getTimeValues().YEAR() * 99;
} else if (type.equals(BanType.TEMPORARY)) { } else if (type.equals(BanType.TEMPORARY)) {
banDuration = Constants.getPlugin().getInstances().getTimeValues().DAY(); banDuration = SimplexCorePlugin.getInstance().getTimeValues().DAY();
} else { } else {
banDuration = Constants.getPlugin().getInstances().getTimeValues().MINUTE() * 5; banDuration = SimplexCorePlugin.getInstance().getTimeValues().MINUTE() * 5;
} }
}; };
} }

View File

@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.command;
import io.github.simplexdev.api.annotations.CommandInfo; import io.github.simplexdev.api.annotations.CommandInfo;
import io.github.simplexdev.simplexcore.command.defaults.DefaultCommand; 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 io.github.simplexdev.simplexcore.utils.ReflectionTools;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.*; import org.bukkit.command.*;
@ -19,22 +19,33 @@ import java.util.Map;
import java.util.MissingResourceException; import java.util.MissingResourceException;
public final class CommandLoader { public final class CommandLoader {
private static final CommandLoader instance = new CommandLoader();
private Reflections reflections; private Reflections reflections;
private static final CommandLoader instance = new CommandLoader();
protected CommandLoader() {
}
public static CommandLoader getInstance() { public static CommandLoader getInstance() {
return instance; 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.
* <p>
* 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.
* </p>
* @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) { public synchronized CommandLoader classpath(Class<?> clazz) {
if (!clazz.isAnnotationPresent(CommandInfo.class)) { if (!clazz.isAnnotationPresent(CommandInfo.class)) {
throw new MissingResourceException("Cannot register this class as the main resource location!", clazz.getSimpleName(), "@CommandInfo"); 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!"); throw new RuntimeException("Unable to assign an executor!");
} }
@ -42,14 +53,21 @@ public final class CommandLoader {
return this; 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 -> { reflections.getTypesAnnotatedWith(CommandInfo.class).forEach(annotated -> {
CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class); CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class);
if (info == null) return; if (info == null) return;
if (!SimplexCommand.class.isAssignableFrom(annotated)) 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.setAliases(Arrays.asList(info.aliases().split(",")));
objectToRegister.setDescription(info.description()); objectToRegister.setDescription(info.description());
objectToRegister.setExecutor(getExecutorFromName(info.name())); objectToRegister.setExecutor(getExecutorFromName(info.name()));
@ -104,6 +122,9 @@ public final class CommandLoader {
return null; return null;
} }
/**
* Registry class, which forces all necessary fields to accessible.
*/
private static class Registry { private static class Registry {
private static final Constructor<PluginCommand> constructor; private static final Constructor<PluginCommand> constructor;
private static final Field cmdMapField; private static final Field cmdMapField;

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.simplexcore.command; 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 io.github.simplexdev.simplexcore.utils.Utilities;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -22,12 +22,12 @@ public abstract class SimplexCommand implements CommandExecutor, TabCompleter {
@Nullable @Nullable
public Player getPlayer(String name) { public Player getPlayer(String name) {
return Constants.getServer().getPlayer(name); return SimplexCorePlugin.getInstance().getServer().getPlayer(name);
} }
@Nullable @Nullable
public Player getPlayer(UUID uuid) { public Player getPlayer(UUID uuid) {
return Constants.getServer().getPlayer(uuid); return SimplexCorePlugin.getInstance().getServer().getPlayer(uuid);
} }
@Nullable @Nullable

View File

@ -1,4 +0,0 @@
package io.github.simplexdev.simplexcore.concurrent;
public final class TaskFactory {
}

View File

@ -2,8 +2,8 @@ package io.github.simplexdev.simplexcore.config;
import io.github.simplexdev.api.IConfig; import io.github.simplexdev.api.IConfig;
import io.github.simplexdev.api.func.Path; 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.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.Constants;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -150,13 +150,13 @@ public final class Yaml implements IConfig {
* Called when a file is created. * Called when a file is created.
*/ */
public void create() { public void create() {
Constants.getLogger().info("File created!"); SimplexCorePlugin.getInstance().getLogger().info("File created!");
} }
/** /**
* Called when then file is reloaded * Called when then file is reloaded
*/ */
public void onReload() { public void onReload() {
Constants.getLogger().info("The plugin configuration has been reloaded!"); SimplexCorePlugin.getInstance().getLogger().info("The plugin configuration has been reloaded!");
} }
} }

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.simplexcore.listener; 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.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.server.PluginEnableEvent; import org.bukkit.event.server.PluginEnableEvent;
@ -34,11 +34,11 @@ public final class DependencyListener extends SimplexListener {
BooleanSupplier temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName()); BooleanSupplier temp2 = () -> PAPI_NAMES.contains(event.getPlugin().getName());
if (temp.getAsBoolean()) { if (temp.getAsBoolean()) {
Constants.getPlugin().getInstances().getDependencyManager().registerProtocolLib(); SimplexCorePlugin.getInstance().getDependencyManager().registerProtocolLib();
} }
if (temp2.getAsBoolean()) { if (temp2.getAsBoolean()) {
Constants.getPlugin().getInstances().getDependencyManager().registerPAPI(); SimplexCorePlugin.getInstance().getDependencyManager().registerPAPI();
} }
} }
} }

View File

@ -1,7 +1,7 @@
package io.github.simplexdev.simplexcore.listener; package io.github.simplexdev.simplexcore.listener;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon; import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.Constants;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
@ -16,7 +16,7 @@ public abstract class SimplexListener implements Listener {
*/ */
public static void registerFromClass(Class<? extends SimplexListener> cls, SimplexAddon<?> plugin) { public static void registerFromClass(Class<? extends SimplexListener> cls, SimplexAddon<?> plugin) {
if (!SimplexListener.class.isAssignableFrom(cls)) { 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; return;
} }
@ -24,7 +24,7 @@ public abstract class SimplexListener implements Listener {
Constructor<? extends SimplexListener> constr = cls.getDeclaredConstructor(); Constructor<? extends SimplexListener> constr = cls.getDeclaredConstructor();
register(constr.newInstance(), plugin); register(constr.newInstance(), plugin);
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) { } 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 <T> Type of which extends SimplexListener. * @param <T> Type of which extends SimplexListener.
*/ */
public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) { public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) {
Constants.getManager().registerEvents(listener, plugin); SimplexCorePlugin.getInstance().getManager().registerEvents(listener, plugin);
} }
} }

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.simplexcore.math; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.scheduler.BukkitTask; 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());
} }
} }

View File

@ -1,6 +1,6 @@
package io.github.simplexdev.simplexcore.math; 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.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
@ -50,7 +50,7 @@ public final class Pyramid {
createOddFull(); createOddFull();
}; };
Constants.getScheduler().runTaskLater(Constants.getPlugin(), consumer, 20L); SimplexCorePlugin.getInstance().getScheduler().runTaskLater(SimplexCorePlugin.getInstance(), consumer, 20L);
} }
private void createOddFull() { private void createOddFull() {

View File

@ -1,17 +1,17 @@
package io.github.simplexdev.simplexcore.plugin; package io.github.simplexdev.simplexcore.plugin;
import io.github.simplexdev.simplexcore.utils.Constants; import io.github.simplexdev.simplexcore.SimplexCorePlugin;
public final class AddonManager { public final class AddonManager {
public AddonManager() { public AddonManager() {
} }
public void disable(SimplexAddon<?> simplexAddon) { public void disable(SimplexAddon<?> simplexAddon) {
Constants.getManager().disablePlugin(simplexAddon); SimplexCorePlugin.getInstance().getManager().disablePlugin(simplexAddon);
} }
public void enable(SimplexAddon<?> simplexAddon) { public void enable(SimplexAddon<?> simplexAddon) {
Constants.getManager().enablePlugin(simplexAddon); SimplexCorePlugin.getInstance().getManager().enablePlugin(simplexAddon);
} }
public void reload(SimplexAddon<?> simplexAddon) { public void reload(SimplexAddon<?> simplexAddon) {

View File

@ -2,7 +2,7 @@ package io.github.simplexdev.simplexcore.plugin;
import io.github.simplexdev.api.annotations.ReqType; import io.github.simplexdev.api.annotations.ReqType;
import io.github.simplexdev.api.annotations.Requires; 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.HashSet;
import java.util.Set; import java.util.Set;
@ -24,7 +24,7 @@ public final class AddonRegistry {
return true; return true;
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
addon.stop(); 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; return false;
} }
} }
@ -35,7 +35,7 @@ public final class AddonRegistry {
return true; return true;
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
addon.stop(); 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; return false;
} }
} }
@ -46,7 +46,7 @@ public final class AddonRegistry {
return true; return true;
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
addon.stop(); 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; return false;
} }
} }

View File

@ -2,9 +2,9 @@ package io.github.simplexdev.simplexcore.sign;
import io.github.simplexdev.api.IUsableSign; import io.github.simplexdev.api.IUsableSign;
import io.github.simplexdev.api.func.VoidSupplier; 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.listener.SimplexListener;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon; import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.Constants;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -41,7 +41,7 @@ public class SignFactory {
private SignData signData = null; private SignData signData = null;
public void activateBasicSignDataListener() { public void activateBasicSignDataListener() {
signData = new SignData(Constants.getPlugin()); signData = new SignData(SimplexCorePlugin.getInstance());
} }
public SignData getSignData() { public SignData getSignData() {

View File

@ -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.chat.Messages;
import io.github.simplexdev.simplexcore.utils.Constants;
import org.apache.commons.lang.math.RandomUtils; import org.apache.commons.lang.math.RandomUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -14,12 +14,12 @@ public class Announcer extends SimplexTask {
private final List<String> stringList = new ArrayList<>() {{ private final List<String> stringList = new ArrayList<>() {{
add("Join our discord!" + Messages.DISCORD.getMessage()); add("Join our discord!" + Messages.DISCORD.getMessage());
add("Thank you for using SimplexCore!"); add("Thank you for using SimplexCore!");
add("https://github.com/Paldiu/SimplexCore"); add("https://github.com/SimplexDevelopment/SimplexCore");
}}; }};
public Announcer() { public Announcer() {
super(20L); super(20L);
register(this, Constants.getPlugin(), true, false); register(this, SimplexCorePlugin.getInstance(), true, false);
} }
@Override @Override

View File

@ -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.plugin.SimplexAddon;
import io.github.simplexdev.simplexcore.utils.Constants;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.Date; import java.util.Date;
@ -24,19 +24,19 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
} }
protected SimplexTask() { protected SimplexTask() {
DELAY = Constants.getPlugin().getInstances().getTimeValues().SECOND() * 30; // 30 seconds until the task triggers for the first time. DELAY = SimplexCorePlugin.getInstance().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. INTERVAL = SimplexCorePlugin.getInstance().getTimeValues().MINUTE() * 5; // Task will run at 5 minute intervals once the first trigger has been called.
} }
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean repeating, boolean delayed) { public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean repeating, boolean delayed) {
if (delayed && repeating) { if (delayed && repeating) {
Constants.getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL); SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, DELAY, INTERVAL);
} else if (delayed) { } else if (delayed) {
Constants.getScheduler().runTaskLater(plugin, task, DELAY); SimplexCorePlugin.getInstance().getScheduler().runTaskLater(plugin, task, DELAY);
} else if (repeating) { } else if (repeating) {
Constants.getScheduler().runTaskTimer(plugin, task, 0L, INTERVAL); SimplexCorePlugin.getInstance().getScheduler().runTaskTimer(plugin, task, 0L, INTERVAL);
} else { } else {
Constants.getScheduler().runTask(plugin, task); SimplexCorePlugin.getInstance().getScheduler().runTask(plugin, task);
} }
} }

View File

@ -0,0 +1,4 @@
package io.github.simplexdev.simplexcore.task;
public final class TaskFactory {
}

View File

@ -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();
}
}

View File

@ -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; }
}

View File

@ -1,6 +1,7 @@
package io.github.simplexdev.simplexcore.utils; package io.github.simplexdev.simplexcore.utils;
import io.github.simplexdev.api.func.Path; import io.github.simplexdev.api.func.Path;
import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.ban.BanType; import io.github.simplexdev.simplexcore.ban.BanType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -15,7 +16,7 @@ import java.util.stream.Stream;
public final class Utilities { public final class Utilities {
private static final SplittableRandom random = new SplittableRandom(); private static final SplittableRandom random = new SplittableRandom();
private static final SplittableRandom numbers = new SplittableRandom(); private static final SplittableRandom numbers = new SplittableRandom();
private static final List<String> versions = Constants.getPlugin().getInstances().getInternals().getStringList(pathway("supported_versions")); private static final List<String> versions = SimplexCorePlugin.getInstance().getInternals().getStringList(pathway("supported_versions"));
private static final List<Character> list = new ArrayList<>() {{ private static final List<Character> list = new ArrayList<>() {{
add('0'); add('0');