Community Update #1

This commit is contained in:
Paldiu 2021-01-29 11:43:43 -06:00
parent a932f60a24
commit 4fd134f86b
14 changed files with 110 additions and 66 deletions

6
.idea/.gitignore generated vendored Normal file
View File

@ -0,0 +1,6 @@
# Default ignored files
/shelf/
/workspace.xml
# Project exclude paths
/inspectionProfiles/
/libraries/

View File

@ -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<SimplexCore> {
public final class SimplexCore extends SimplexAddon<SimplexCore> {
@Override
public SimplexCore getPlugin() {
return this;

View File

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

View File

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

View File

@ -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 = "/<command>", 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!");

View File

@ -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 = "/<command>", 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.");

View File

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

View File

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

View File

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

View File

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

View File

@ -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<BukkitTask> 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) {

View File

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

View File

@ -4,7 +4,7 @@ import java.util.HashSet;
import java.util.Set;
public class AddonRegistry {
private final Set<Addon<?>> components = new HashSet<>();
private final Set<SimplexAddon<?>> components = new HashSet<>();
private static final AddonRegistry instance = new AddonRegistry();
protected AddonRegistry() {
@ -14,11 +14,11 @@ public class AddonRegistry {
return instance;
}
public <T extends Addon<T>>void register(T addon) {
public <T extends SimplexAddon<T>>void register(T addon) {
getComponents().add(addon);
}
public Set<Addon<?>> getComponents() {
public Set<SimplexAddon<?>> getComponents() {
return components;
}
}

View File

@ -2,7 +2,7 @@ package io.github.paldiu.simplexcore.plugin;
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.
*