mirror of
https://github.com/SimplexDevelopment/SimplexCore.git
synced 2024-12-22 08:37:37 +00:00
Community Update #1
This commit is contained in:
parent
a932f60a24
commit
4fd134f86b
6
.idea/.gitignore
generated
vendored
Normal file
6
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Project exclude paths
|
||||||
|
/inspectionProfiles/
|
||||||
|
/libraries/
|
@ -1,10 +1,10 @@
|
|||||||
package io.github.paldiu.simplexcore;
|
package io.github.paldiu.simplexcore;
|
||||||
|
|
||||||
import io.github.paldiu.simplexcore.command.defaults.Command_info;
|
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;
|
import io.github.paldiu.simplexcore.utils.Constants;
|
||||||
|
|
||||||
public final class SimplexCore extends Addon<SimplexCore> {
|
public final class SimplexCore extends SimplexAddon<SimplexCore> {
|
||||||
@Override
|
@Override
|
||||||
public SimplexCore getPlugin() {
|
public SimplexCore getPlugin() {
|
||||||
return this;
|
return this;
|
||||||
|
@ -38,7 +38,7 @@ public class CommandLoader {
|
|||||||
CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class);
|
CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class);
|
||||||
|
|
||||||
if (info == null) return;
|
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());
|
PluginCommand objectToRegister = Registry.create(Constants.getPlugin(), info.name().toLowerCase());
|
||||||
objectToRegister.setAliases(Arrays.asList(info.aliases().split(",")));
|
objectToRegister.setAliases(Arrays.asList(info.aliases().split(",")));
|
||||||
|
@ -14,7 +14,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public abstract class CommandBase implements CommandExecutor, TabCompleter {
|
public abstract class SimplexCommand implements CommandExecutor, TabCompleter {
|
||||||
public boolean checkSender(CommandSender sender) {
|
public boolean checkSender(CommandSender sender) {
|
||||||
return sender instanceof Player;
|
return sender instanceof Player;
|
||||||
}
|
}
|
@ -1,13 +1,13 @@
|
|||||||
package io.github.paldiu.simplexcore.command.defaults;
|
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.CommandInfo;
|
||||||
|
import io.github.paldiu.simplexcore.command.SimplexCommand;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@CommandInfo(name = "Info", description = "Gets info on this API / Library.", usage = "/<command>", permission = "simplex.core.info")
|
@CommandInfo(name = "Info", description = "Gets info on this API / Library.", usage = "/<command>", permission = "simplex.core.info")
|
||||||
public class Command_info extends CommandBase {
|
public class Command_info extends SimplexCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
sender.sendMessage("This is an API!");
|
sender.sendMessage("This is an API!");
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package io.github.paldiu.simplexcore.command.defaults;
|
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.CommandInfo;
|
||||||
|
import io.github.paldiu.simplexcore.command.SimplexCommand;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@CommandInfo(name = "defaultcommand", usage = "/<command>", description = "Default plugin command.")
|
@CommandInfo(name = "defaultcommand", usage = "/<command>", description = "Default plugin command.")
|
||||||
public class DefaultCommand extends CommandBase {
|
public class DefaultCommand extends SimplexCommand {
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
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.");
|
sender.sendMessage("If you are seeing this when running your command, your command didn't register properly.");
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
package io.github.paldiu.simplexcore.future;
|
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.concurrent.CompletionStage;
|
|
||||||
|
|
||||||
public class FutureFactory<T> {
|
|
||||||
private final T object;
|
|
||||||
private final LinkedList<CompletionStage<T>> tree = new LinkedList<>();
|
|
||||||
|
|
||||||
public FutureFactory(T object) {
|
|
||||||
this.object = object;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getObject() {
|
|
||||||
return object;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<BukkitTask> {
|
|
||||||
protected Date lastRan = new Date();
|
|
||||||
|
|
||||||
protected ScheduledTask() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getLastRan() {
|
|
||||||
return lastRan;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastRan(Date lastRan) {
|
|
||||||
this.lastRan = lastRan;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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<BukkitTask> {
|
||||||
|
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 <T extends SimplexTask> 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 <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin, boolean delayed) {
|
||||||
|
register(task, plugin, false, delayed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends SimplexTask> void register(T task, SimplexAddon<?> plugin) {
|
||||||
|
register(task, plugin, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastRan() {
|
||||||
|
return lastRan;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastRan(Date lastRan) {
|
||||||
|
this.lastRan = lastRan;
|
||||||
|
}
|
||||||
|
}
|
@ -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 <T extends SimplexListener> void registerAll(T[] sl, SimplexAddon<?> plugin) {
|
||||||
|
Utilities.primitiveFE(sl, action -> {
|
||||||
|
SimplexListener.register(action, plugin);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T extends SimplexListener> void register(T listener, SimplexAddon<?> plugin) {
|
||||||
|
Constants.getManager().registerEvents(listener, plugin);
|
||||||
|
}
|
||||||
|
}
|
@ -24,15 +24,15 @@ public class Cuboid {
|
|||||||
this(size.getX(), size.getY(), size.getZ());
|
this(size.getX(), size.getY(), size.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void generate(Location location, Material material) {
|
public void generate(Location location, Material material) {
|
||||||
Consumer<BukkitTask> task = bukkitTask -> {
|
Consumer<BukkitTask> task = bukkitTask -> {
|
||||||
int t1 = location.getBlockX();
|
int t1 = location.getBlockX();
|
||||||
int t2 = location.getBlockY();
|
int t2 = location.getBlockY();
|
||||||
int t3 = location.getBlockZ();
|
int t3 = location.getBlockZ();
|
||||||
|
|
||||||
int a = t1+x;
|
int a = t1 + x;
|
||||||
int b = t2+y;
|
int b = t2 + y;
|
||||||
int c = t3+z;
|
int c = t3 + z;
|
||||||
|
|
||||||
while (t1 < a) {
|
while (t1 < a) {
|
||||||
while (t2 < b) {
|
while (t2 < b) {
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
package io.github.paldiu.simplexcore.plugin;
|
package io.github.paldiu.simplexcore.plugin;
|
||||||
|
|
||||||
import io.github.paldiu.simplexcore.utils.Constants;
|
import io.github.paldiu.simplexcore.utils.Constants;
|
||||||
import io.github.paldiu.simplexcore.utils.Utilities;
|
|
||||||
|
|
||||||
public class AddonManager {
|
public class AddonManager {
|
||||||
public AddonManager() { }
|
public AddonManager() { }
|
||||||
|
|
||||||
public void disable(Addon<?> addon) {
|
public void disable(SimplexAddon<?> simplexAddon) {
|
||||||
Constants.getManager().disablePlugin(addon);
|
Constants.getManager().disablePlugin(simplexAddon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enable(Addon<?> addon) {
|
public void enable(SimplexAddon<?> simplexAddon) {
|
||||||
Constants.getManager().enablePlugin(addon);
|
Constants.getManager().enablePlugin(simplexAddon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload(Addon<?> addon) {
|
public void reload(SimplexAddon<?> simplexAddon) {
|
||||||
disable(addon);
|
disable(simplexAddon);
|
||||||
enable(addon);
|
enable(simplexAddon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import java.util.HashSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class AddonRegistry {
|
public class AddonRegistry {
|
||||||
private final Set<Addon<?>> components = new HashSet<>();
|
private final Set<SimplexAddon<?>> components = new HashSet<>();
|
||||||
private static final AddonRegistry instance = new AddonRegistry();
|
private static final AddonRegistry instance = new AddonRegistry();
|
||||||
|
|
||||||
protected AddonRegistry() {
|
protected AddonRegistry() {
|
||||||
@ -14,11 +14,11 @@ public class AddonRegistry {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Addon<T>>void register(T addon) {
|
public <T extends SimplexAddon<T>>void register(T addon) {
|
||||||
getComponents().add(addon);
|
getComponents().add(addon);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<Addon<?>> getComponents() {
|
public Set<SimplexAddon<?>> getComponents() {
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,7 @@ package io.github.paldiu.simplexcore.plugin;
|
|||||||
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public abstract class Addon<T extends Addon<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.
|
||||||
*
|
*
|
Loading…
Reference in New Issue
Block a user