diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..4514551 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,6 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Project exclude paths +/inspectionProfiles/ +/libraries/ diff --git a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java index e45804e..2066e18 100644 --- a/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java +++ b/src/main/java/io/github/paldiu/simplexcore/SimplexCore.java @@ -1,10 +1,10 @@ package io.github.paldiu.simplexcore; import io.github.paldiu.simplexcore.command.defaults.Command_info; -import io.github.paldiu.simplexcore.plugin.Addon; +import io.github.paldiu.simplexcore.plugin.SimplexAddon; import io.github.paldiu.simplexcore.utils.Constants; -public final class SimplexCore extends Addon { +public final class SimplexCore extends SimplexAddon { @Override public SimplexCore getPlugin() { return this; diff --git a/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java b/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java index 9da0e92..3d2a947 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/CommandLoader.java @@ -38,7 +38,7 @@ public class CommandLoader { CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class); if (info == null) return; - if (!CommandBase.class.isAssignableFrom(annotated)) return; + if (!SimplexCommand.class.isAssignableFrom(annotated)) return; PluginCommand objectToRegister = Registry.create(Constants.getPlugin(), info.name().toLowerCase()); objectToRegister.setAliases(Arrays.asList(info.aliases().split(","))); diff --git a/src/main/java/io/github/paldiu/simplexcore/command/CommandBase.java b/src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java similarity index 94% rename from src/main/java/io/github/paldiu/simplexcore/command/CommandBase.java rename to src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java index 82fa42e..51ff47c 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/CommandBase.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/SimplexCommand.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -public abstract class CommandBase implements CommandExecutor, TabCompleter { +public abstract class SimplexCommand implements CommandExecutor, TabCompleter { public boolean checkSender(CommandSender sender) { return sender instanceof Player; } diff --git a/src/main/java/io/github/paldiu/simplexcore/command/defaults/Command_info.java b/src/main/java/io/github/paldiu/simplexcore/command/defaults/Command_info.java index e2e5b8a..da318a6 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/defaults/Command_info.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/defaults/Command_info.java @@ -1,13 +1,13 @@ package io.github.paldiu.simplexcore.command.defaults; -import io.github.paldiu.simplexcore.command.CommandBase; import io.github.paldiu.simplexcore.command.CommandInfo; +import io.github.paldiu.simplexcore.command.SimplexCommand; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @CommandInfo(name = "Info", description = "Gets info on this API / Library.", usage = "/", permission = "simplex.core.info") -public class Command_info extends CommandBase { +public class Command_info extends SimplexCommand { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { sender.sendMessage("This is an API!"); diff --git a/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java b/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java index f424ff1..91b4a7a 100644 --- a/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java +++ b/src/main/java/io/github/paldiu/simplexcore/command/defaults/DefaultCommand.java @@ -1,13 +1,13 @@ package io.github.paldiu.simplexcore.command.defaults; -import io.github.paldiu.simplexcore.command.CommandBase; import io.github.paldiu.simplexcore.command.CommandInfo; +import io.github.paldiu.simplexcore.command.SimplexCommand; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @CommandInfo(name = "defaultcommand", usage = "/", description = "Default plugin command.") -public class DefaultCommand extends CommandBase { +public class DefaultCommand extends SimplexCommand { @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { sender.sendMessage("If you are seeing this when running your command, your command didn't register properly."); diff --git a/src/main/java/io/github/paldiu/simplexcore/future/FutureFactory.java b/src/main/java/io/github/paldiu/simplexcore/future/FutureFactory.java deleted file mode 100644 index 32eaa9f..0000000 --- a/src/main/java/io/github/paldiu/simplexcore/future/FutureFactory.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.paldiu.simplexcore.future; - -import java.util.LinkedList; -import java.util.concurrent.CompletionStage; - -public class FutureFactory { - private final T object; - private final LinkedList> tree = new LinkedList<>(); - - public FutureFactory(T object) { - this.object = object; - } - - public T getObject() { - return object; - } -} diff --git a/src/main/java/io/github/paldiu/simplexcore/future/ScheduledTask.java b/src/main/java/io/github/paldiu/simplexcore/future/ScheduledTask.java deleted file mode 100644 index 5c20035..0000000 --- a/src/main/java/io/github/paldiu/simplexcore/future/ScheduledTask.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.paldiu.simplexcore.future; - -import io.github.paldiu.simplexcore.utils.Constants; -import io.github.paldiu.simplexcore.utils.Utilities; -import org.bukkit.Bukkit; -import org.bukkit.scheduler.BukkitTask; - -import java.util.Date; -import java.util.function.Consumer; - -public abstract class ScheduledTask implements Consumer { - protected Date lastRan = new Date(); - - protected ScheduledTask() { - - } - - public Date getLastRan() { - return lastRan; - } - - public void setLastRan(Date lastRan) { - this.lastRan = lastRan; - } -} diff --git a/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java b/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java new file mode 100644 index 0000000..4086910 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/future/SimplexTask.java @@ -0,0 +1,52 @@ +package io.github.paldiu.simplexcore.future; + +import io.github.paldiu.simplexcore.plugin.SimplexAddon; +import io.github.paldiu.simplexcore.utils.Constants; +import org.bukkit.scheduler.BukkitTask; + +import java.util.Date; +import java.util.function.Consumer; + +public abstract class SimplexTask implements Consumer { + protected Date lastRan = new Date(); + protected final long DELAY; + protected final long INTERVAL; + + protected SimplexTask(long initialDelay, long interval) { + DELAY = initialDelay; + INTERVAL = interval; + } + + protected SimplexTask() { + DELAY = Constants.getTimeValues().SECOND() * 30; // 30 seconds until the task triggers for the first time. + INTERVAL = Constants.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().runTaskTimerAsynchronously(plugin, task, DELAY, INTERVAL); + } else if (delayed) { + Constants.getScheduler().runTaskLaterAsynchronously(plugin, task, DELAY); + } else if (repeating) { + Constants.getScheduler().runTaskTimerAsynchronously(plugin, task, 0L, INTERVAL); + } else { + Constants.getScheduler().runTaskAsynchronously(plugin, task); + } + } + + public void register(T task, SimplexAddon plugin, boolean delayed) { + register(task, plugin, false, delayed); + } + + public void register(T task, SimplexAddon plugin) { + register(task, plugin, false, false); + } + + public Date getLastRan() { + return lastRan; + } + + public void setLastRan(Date lastRan) { + this.lastRan = lastRan; + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/listeners/SimplexListener.java b/src/main/java/io/github/paldiu/simplexcore/listeners/SimplexListener.java new file mode 100644 index 0000000..53aaec2 --- /dev/null +++ b/src/main/java/io/github/paldiu/simplexcore/listeners/SimplexListener.java @@ -0,0 +1,29 @@ +package io.github.paldiu.simplexcore.listeners; + +import io.github.paldiu.simplexcore.plugin.SimplexAddon; +import io.github.paldiu.simplexcore.utils.Constants; +import io.github.paldiu.simplexcore.utils.Utilities; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.server.PluginEnableEvent; + +public abstract class SimplexListener implements Listener { + @EventHandler + public void pluginRegister(PluginEnableEvent event) { + if (SimplexAddon.class.isAssignableFrom(event.getPlugin().getClass())) { + if (!Constants.getRegistry().getComponents().contains(event.getPlugin())) { + Constants.getRegistry().getComponents().add((SimplexAddon) event.getPlugin()); + } + } + } + + public static void registerAll(T[] sl, SimplexAddon plugin) { + Utilities.primitiveFE(sl, action -> { + SimplexListener.register(action, plugin); + }); + } + + public static void register(T listener, SimplexAddon plugin) { + Constants.getManager().registerEvents(listener, plugin); + } +} diff --git a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java index 3af3f5a..99338a7 100644 --- a/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java +++ b/src/main/java/io/github/paldiu/simplexcore/math/Cuboid.java @@ -24,15 +24,15 @@ public class Cuboid { this(size.getX(), size.getY(), size.getZ()); } - public synchronized void generate(Location location, Material material) { + public void generate(Location location, Material material) { Consumer task = bukkitTask -> { int t1 = location.getBlockX(); int t2 = location.getBlockY(); int t3 = location.getBlockZ(); - int a = t1+x; - int b = t2+y; - int c = t3+z; + int a = t1 + x; + int b = t2 + y; + int c = t3 + z; while (t1 < a) { while (t2 < b) { diff --git a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java index 4060a5f..96a785a 100644 --- a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java +++ b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonManager.java @@ -1,21 +1,20 @@ package io.github.paldiu.simplexcore.plugin; import io.github.paldiu.simplexcore.utils.Constants; -import io.github.paldiu.simplexcore.utils.Utilities; public class AddonManager { public AddonManager() { } - public void disable(Addon addon) { - Constants.getManager().disablePlugin(addon); + public void disable(SimplexAddon simplexAddon) { + Constants.getManager().disablePlugin(simplexAddon); } - public void enable(Addon addon) { - Constants.getManager().enablePlugin(addon); + public void enable(SimplexAddon simplexAddon) { + Constants.getManager().enablePlugin(simplexAddon); } - public void reload(Addon addon) { - disable(addon); - enable(addon); + public void reload(SimplexAddon simplexAddon) { + disable(simplexAddon); + enable(simplexAddon); } } diff --git a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java index 15c9a7f..3e34d00 100644 --- a/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java +++ b/src/main/java/io/github/paldiu/simplexcore/plugin/AddonRegistry.java @@ -4,7 +4,7 @@ import java.util.HashSet; import java.util.Set; public class AddonRegistry { - private final Set> components = new HashSet<>(); + private final Set> components = new HashSet<>(); private static final AddonRegistry instance = new AddonRegistry(); protected AddonRegistry() { @@ -14,11 +14,11 @@ public class AddonRegistry { return instance; } - public >void register(T addon) { + public >void register(T addon) { getComponents().add(addon); } - public Set> getComponents() { + public Set> getComponents() { return components; } } \ No newline at end of file diff --git a/src/main/java/io/github/paldiu/simplexcore/plugin/Addon.java b/src/main/java/io/github/paldiu/simplexcore/plugin/SimplexAddon.java similarity index 88% rename from src/main/java/io/github/paldiu/simplexcore/plugin/Addon.java rename to src/main/java/io/github/paldiu/simplexcore/plugin/SimplexAddon.java index e08a636..230e53f 100644 --- a/src/main/java/io/github/paldiu/simplexcore/plugin/Addon.java +++ b/src/main/java/io/github/paldiu/simplexcore/plugin/SimplexAddon.java @@ -2,7 +2,7 @@ package io.github.paldiu.simplexcore.plugin; import org.bukkit.plugin.java.JavaPlugin; -public abstract class Addon> extends JavaPlugin { +public abstract class SimplexAddon> extends JavaPlugin { /** * Gets your plugin as an addon. *