BLEEDING EDGE 1.3_09

- CommandLoader fix in which it was incorrectly attempting to assign a subclass to a superclass.
 - Added a friendly comment to Yaml which states the constructor is package private.
 - Fixed a problem in YamlFactory where fileName and resourcePath were swapped, resulting in the resourcePath to possibly be the fileName and the fileName to possibly be null.
 - Moved over some methods from SimplexCorePlugin so it is accessible by default to all modules.
 - A Timer instance and two methods operating on that timer instance were added to SimplexTask
This commit is contained in:
Paldiu 2021-03-12 01:24:11 -06:00
parent 2b1e9b7362
commit 9b60b20a0f
6 changed files with 57 additions and 31 deletions

View File

@ -25,10 +25,10 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
private TimeValues time; private TimeValues time;
private Yaml internals; private Yaml internals;
protected static SimplexCorePlugin instance; // = getPlugin(SimplexCorePlugin.class); protected static SimplexCorePlugin instance;
public static SimplexCorePlugin getInstance() { public static SimplexCorePlugin getInstance() {
return instance; return instance;
} } // I understand this could be an issue.
@Override @Override
public SimplexCorePlugin getPlugin() { public SimplexCorePlugin getPlugin() {
@ -37,7 +37,7 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
@Override @Override
public void init() { public void init() {
instance = this; instance = this; // However, if the module is written correctly, this wont be an issue.
this.dpm = new DependencyManagement(); this.dpm = new DependencyManagement();
this.config = new YamlFactory(this).setDefaultPathways(); this.config = new YamlFactory(this).setDefaultPathways();
this.time = new TimeValues(); this.time = new TimeValues();
@ -80,30 +80,6 @@ public final class SimplexCorePlugin extends SimplexAddon<SimplexCorePlugin> {
return suspended; return suspended;
} }
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() { public DependencyManagement getDependencyManager() {
return dpm; return dpm;
} }

View File

@ -48,8 +48,8 @@ public final class CommandLoader {
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(SimplexCommand.class)) { if (!SimplexCommand.class.isAssignableFrom(clazz)) {
throw new RuntimeException("Unable to assign an executor!"); throw new RuntimeException("Your command must extend SimplexCommand.class for it to be used as the reference point for loading commands.");
} }
reflections = new Reflections(clazz); reflections = new Reflections(clazz);

View File

@ -21,6 +21,7 @@ public final class Yaml implements IConfig {
private FileConfiguration config; private FileConfiguration config;
private File file; private File file;
// Package private ;)
Yaml(SimplexAddon<?> plugin, String fileName, File directory, String resourcePath) { Yaml(SimplexAddon<?> plugin, String fileName, File directory, String resourcePath) {
if (!fileName.endsWith(".yml")) { if (!fileName.endsWith(".yml")) {
fileName += ".yml"; fileName += ".yml";

View File

@ -21,7 +21,7 @@ public final class YamlFactory {
this.resourcePath = resourcePath; this.resourcePath = resourcePath;
this.directory = directory; this.directory = directory;
this.fileName = fileName; this.fileName = fileName;
return new Yaml(plugin, resourcePath, directory, fileName); return new Yaml(plugin, fileName, directory, resourcePath);
} }
public FileConfiguration load(File yamlFile) { public FileConfiguration load(File yamlFile) {

View File

@ -1,7 +1,19 @@
package io.github.simplexdev.simplexcore.plugin; package io.github.simplexdev.simplexcore.plugin;
import io.github.simplexdev.simplexcore.command.CommandLoader;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.logging.Logger;
/**
* This class represents a SimplexCore module.
* You should extend this instead of JavaPlugin if you are using the core as a dependency.
* @param <T>
*/
public abstract class SimplexAddon<T extends SimplexAddon<T>> extends JavaPlugin { public abstract class SimplexAddon<T extends SimplexAddon<T>> extends JavaPlugin {
/** /**
* Gets your plugin as an addon. * Gets your plugin as an addon.
@ -40,4 +52,24 @@ public abstract class SimplexAddon<T extends SimplexAddon<T>> extends JavaPlugin
*/ */
public void init() { public void init() {
} }
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();
}
} }

View File

@ -1,10 +1,13 @@
package io.github.simplexdev.simplexcore.task; package io.github.simplexdev.simplexcore.task;
import io.github.simplexdev.api.func.VoidSupplier;
import io.github.simplexdev.simplexcore.SimplexCorePlugin; import io.github.simplexdev.simplexcore.SimplexCorePlugin;
import io.github.simplexdev.simplexcore.plugin.SimplexAddon; import io.github.simplexdev.simplexcore.plugin.SimplexAddon;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.Date; import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.function.Consumer; import java.util.function.Consumer;
// TODO: Rewrite this entire class and the task system to have more control over tasks. // TODO: Rewrite this entire class and the task system to have more control over tasks.
@ -12,6 +15,7 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
protected final long DELAY; protected final long DELAY;
protected final long INTERVAL; protected final long INTERVAL;
protected Date lastRan = new Date(); protected Date lastRan = new Date();
protected Timer timer = new Timer();
protected SimplexTask(long initialDelay, long interval) { protected SimplexTask(long initialDelay, long interval) {
DELAY = initialDelay; DELAY = initialDelay;
@ -55,4 +59,17 @@ public abstract class SimplexTask implements Consumer<BukkitTask> {
public void setLastRan(Date lastRan) { public void setLastRan(Date lastRan) {
this.lastRan = lastRan; this.lastRan = lastRan;
} }
protected Timer getTimer() {
return timer;
}
protected TimerTask newTimer(VoidSupplier supplier) {
return new TimerTask() {
@Override
public void run() {
supplier.get();
}
};
}
} }