Felt cute, might delete later

This commit is contained in:
Paldiu 2021-01-27 13:33:10 -06:00
parent aea26ef2f3
commit 0f71a93b54
13 changed files with 133 additions and 24 deletions

View File

@ -5,8 +5,9 @@ import io.github.paldiu.simplexcore.plugin.Addon;
import io.github.paldiu.simplexcore.utils.Constants;
public final class SimplexCore extends Addon<SimplexCore> {
protected SimplexCore(SimplexCore plugin) {
super(plugin);
@Override
public SimplexCore getPlugin() {
return this;
}
@Override

View File

@ -1,5 +1,6 @@
package io.github.paldiu.simplexcore.command;
import io.github.paldiu.simplexcore.command.defaults.DefaultCommand;
import io.github.paldiu.simplexcore.utils.Constants;
import org.bukkit.Bukkit;
import org.bukkit.command.*;
@ -19,7 +20,7 @@ import java.util.MissingResourceException;
public class CommandLoader {
private Reflections reflections;
public CommandLoader classpath(Class<?> clazz) {
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");
}
@ -32,7 +33,7 @@ public class CommandLoader {
return this;
}
public void load() {
public synchronized void load() {
reflections.getTypesAnnotatedWith(CommandInfo.class).forEach(annotated -> {
CommandInfo info = annotated.getDeclaredAnnotation(CommandInfo.class);
@ -52,7 +53,7 @@ public class CommandLoader {
});
}
public CommandExecutor getFromSetName(String name) {
public synchronized CommandExecutor getFromSetName(String name) {
for (Class<? extends CommandExecutor> obj : reflections.getSubTypesOf(CommandExecutor.class)) {
if (!obj.isAnnotationPresent(CommandInfo.class)) {
throw new RuntimeException("Missing annotation CommandInfo!");
@ -65,7 +66,7 @@ public class CommandLoader {
Constructor<? extends CommandExecutor> constr = obj.getDeclaredConstructor();
return constr.newInstance();
} catch (NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new RuntimeException(e);
return new DefaultCommand();
}
}
}
@ -73,7 +74,7 @@ public class CommandLoader {
}
@Nullable
public TabCompleter getTabFromName(String name) {
public synchronized TabCompleter getTabFromName(String name) {
for (Class<? extends TabCompleter> obj : reflections.getSubTypesOf(TabCompleter.class)) {
if (!obj.isAnnotationPresent(CommandInfo.class)) {
throw new RuntimeException("Missing annotation CommandInfo!");
@ -85,7 +86,7 @@ public class CommandLoader {
Constructor<? extends TabCompleter> constr = obj.getDeclaredConstructor();
return constr.newInstance();
} catch (NoSuchMethodException | InstantiationException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
return new DefaultCommand();
}
}
}

View File

@ -0,0 +1,16 @@
package io.github.paldiu.simplexcore.command.defaults;
import io.github.paldiu.simplexcore.command.CommandBase;
import io.github.paldiu.simplexcore.command.CommandInfo;
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 {
@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.");
return true;
}
}

View File

@ -1,6 +1,11 @@
package io.github.paldiu.simplexcore.math;
import io.github.paldiu.simplexcore.utils.Constants;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.scheduler.BukkitTask;
import java.util.function.Consumer;
public class Cuboid {
private final int x, y, z;
@ -19,9 +24,28 @@ public class Cuboid {
this(size.getX(), size.getY(), size.getZ());
}
public void generate(Location location) {
int t1 = location.getBlockX();
int t2 = location.getBlockY();
int t3 = location.getBlockZ();
public synchronized 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;
while (t1 < a) {
while (t2 < b) {
while (t3 < c) {
t3++;
location.getWorld().getBlockAt(t1, t2, t3).setType(material);
}
t2++;
}
t1++;
}
};
Constants.getScheduler().runTaskLaterAsynchronously(Constants.getPlugin(), task, Constants.getTimeValues().SECOND());
}
}

View File

@ -3,20 +3,12 @@ package io.github.paldiu.simplexcore.plugin;
import org.bukkit.plugin.java.JavaPlugin;
public abstract class Addon<T extends Addon<T>> extends JavaPlugin {
private final T plugin;
protected Addon(T plugin) {
this.plugin = plugin;
}
/**
* Gets your plugin as an addon.
*
* @return The addon.
*/
public T getPlugin() {
return plugin;
}
public abstract T getPlugin();
@Override
public void onLoad() {

View File

@ -14,7 +14,7 @@ public class AddonRegistry {
return instance;
}
public <T extends Addon<T>> void register(T addon) {
public <T extends Addon<T>>void register(T addon) {
getComponents().add(addon);
}

View File

@ -37,11 +37,43 @@ public final class Constants {
return scheduler;
}
public static AddonRegistry getRegistry() {
public static synchronized AddonRegistry getRegistry() {
return AddonRegistry.getInstance();
}
public static CommandLoader getCommandLoader() {
public static synchronized CommandLoader getCommandLoader() {
return CommandLoader.getInstance();
}
public static TimeValues getTimeValues() {
return new TimeValues();
}
public static class TimeValues {
public long SECOND() {
return 20L;
}
public long MINUTE() {
return 1200L;
}
public long HOUR() {
return 72000L;
}
public long DAY() {
return 1728000L;
}
public long MONTH() {
return 51840000L;
}
public long YEAR() {
return 622080000L;
}
}
}

View File

@ -0,0 +1,7 @@
name: SimplexCore
version: 1.0.0-BLEEDING
main: pw.coomer.simplexcore.SimplexCore
api-version: 1.16
prefix: Simplex
authors: [ Paldiu ]
description: Core for a group of plugins designed to enhance gameplay to the max

View File

@ -0,0 +1,5 @@
#Generated by Maven
#Wed Jan 27 08:29:34 CST 2021
groupId=io.github.paldiu.simplexcore
artifactId=SimplexCore
version=1.0.0-BLEEDING

View File

@ -0,0 +1,17 @@
io\github\paldiu\simplexcore\command\defaults\Command_info.class
io\github\paldiu\simplexcore\command\CommandLoader.class
io\github\paldiu\simplexcore\math\Size.class
io\github\paldiu\simplexcore\command\CommandBase.class
io\github\paldiu\simplexcore\command\CommandInfo.class
io\github\paldiu\simplexcore\plugin\AddonRegistry.class
io\github\paldiu\simplexcore\command\CommandLoader$Registry.class
io\github\paldiu\simplexcore\utils\Constants$TimeValues.class
io\github\paldiu\simplexcore\utils\Bean.class
io\github\paldiu\simplexcore\utils\Constants.class
io\github\paldiu\simplexcore\SimplexCore.class
io\github\paldiu\simplexcore\utils\Trio.class
io\github\paldiu\simplexcore\plugin\AddonManager.class
io\github\paldiu\simplexcore\math\Cuboid.class
io\github\paldiu\simplexcore\plugin\Addon.class
io\github\paldiu\simplexcore\command\defaults\DefaultCommand.class
io\github\paldiu\simplexcore\utils\Utilities.class

View File

@ -0,0 +1,14 @@
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Utilities.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\CommandInfo.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\AddonManager.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\math\Size.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Trio.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\CommandBase.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\Addon.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\plugin\AddonRegistry.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Bean.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\CommandLoader.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\command\defaults\Command_info.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\SimplexCore.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\math\Cuboid.java
C:\Users\Samantha\IdeaProjects\SimplexCore\src\main\java\io\github\paldiu\simplexcore\utils\Constants.java