mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2024-12-22 08:37:37 +00:00
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:
parent
a31093d3f8
commit
7f75586cd6
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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<SimplexCorePlugin> {
|
||||
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<SimplexCorePlugin> {
|
||||
|
||||
@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<SimplexCorePlugin> {
|
||||
}
|
||||
|
||||
CoreState state = new CoreState();
|
||||
Constants.getLogger().info(state.getMessage());
|
||||
getLogger().info(state.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,7 +77,45 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
|
||||
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; }
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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.
|
||||
* <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) {
|
||||
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<PluginCommand> constructor;
|
||||
private static final Field cmdMapField;
|
||||
|
@ -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
|
||||
|
@ -1,4 +0,0 @@
|
||||
package io.github.simplexdev.simplexcore.concurrent;
|
||||
|
||||
public final class TaskFactory {
|
||||
}
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<? extends SimplexListener> 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<? extends SimplexListener> 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 <T> Type of which extends SimplexListener.
|
||||
*/
|
||||
public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) {
|
||||
Constants.getManager().registerEvents(listener, plugin);
|
||||
SimplexCorePlugin.getInstance().getManager().registerEvents(listener, plugin);
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
|
@ -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<String> 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
|
@ -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<BukkitTask> {
|
||||
}
|
||||
|
||||
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 <T extends SimplexTask> 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);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
package io.github.simplexdev.simplexcore.task;
|
||||
|
||||
public final class TaskFactory {
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
@ -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<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<>() {{
|
||||
add('0');
|
||||
|
Loading…
Reference in New Issue
Block a user