From 6f400e505c7c8a32db842dc27f438f82a91d44e2 Mon Sep 17 00:00:00 2001 From: Paul Reilly Date: Mon, 15 May 2023 01:30:37 -0500 Subject: [PATCH] Upgrades --- {Commons => Corvo}/.gitignore | 0 Corvo/build.gradle | 21 +++ .../java/me/totalfreedom/corvo/Corvo.java | 23 ++++ Datura/build.gradle | 6 +- Datura/src/main/resources/plugin.yml | 8 ++ Fossil/.gitignore | 42 ++++++ Fossil/build.gradle | 21 +++ .../java/me/totalfreedom/fossil/Fossil.java | 16 +++ .../fossil/command/KickCommand.java | 36 ++++++ Patchwork/.gitignore | 42 ++++++ {Commons => Patchwork}/build.gradle | 3 +- .../java/me/totalfreedom/api/Context.java | 59 ++++++++- .../me/totalfreedom/api/Serializable.java | 0 .../me/totalfreedom/base/CommonsBase.java | 0 .../me/totalfreedom/base/Registration.java | 0 .../totalfreedom/command/BukkitDelegator.java | 120 ++++++++++++++++++ .../me/totalfreedom/command/CommandBase.java | 72 +++++++++++ .../totalfreedom/command/CommandHandler.java | 25 ++++ .../totalfreedom/command/annotation/Base.java | 13 ++ .../totalfreedom/command/annotation/Info.java | 16 +++ .../command/annotation/Permissive.java | 14 ++ .../command/annotation/Subcommand.java | 14 ++ .../me/totalfreedom/config/Configuration.java | 0 .../me/totalfreedom/data/CommandRegistry.java | 0 .../me/totalfreedom/data/ConfigRegistry.java | 0 .../me/totalfreedom/data/EventRegistry.java | 0 .../me/totalfreedom/data/GroupRegistry.java | 0 .../me/totalfreedom/data/ModuleRegistry.java | 4 + .../me/totalfreedom/data/ServiceRegistry.java | 0 .../me/totalfreedom/data/UserRegistry.java | 0 .../java/me/totalfreedom/event/Callback.java | 0 .../java/me/totalfreedom/event/EventBus.java | 0 .../totalfreedom/event/EventSubscription.java | 0 .../java/me/totalfreedom/event/FEvent.java | 0 .../totalfreedom/event/SubscriptionBox.java | 0 .../provider/ContextProvider.java | 120 ++++++++++++++++++ .../totalfreedom/provider/EventProvider.java | 0 .../totalfreedom/provider/ModuleProvider.java | 0 .../provider/ServiceProvider.java | 0 .../java/me/totalfreedom/security/Group.java | 0 .../java/me/totalfreedom/security/Node.java | 0 .../me/totalfreedom/security/NodeBuilder.java | 0 .../me/totalfreedom/security/NodeType.java | 0 .../security/PermissionHolder.java | 0 .../totalfreedom/service/FreedomExecutor.java | 0 .../java/me/totalfreedom/service/Service.java | 0 .../java/me/totalfreedom/service/Task.java | 0 .../main/java/me/totalfreedom/sql/SQL.java | 0 .../me/totalfreedom/sql/SQLProperties.java | 0 .../main/java/me/totalfreedom/user/User.java | 0 .../java/me/totalfreedom/user/UserData.java | 0 .../me/totalfreedom/utils/FreedomLogger.java | 0 .../java/me/totalfreedom/utils/Identity.java | 0 .../main/java/me/totalfreedom/utils/Pair.java | 22 ++++ .../java/me/totalfreedom/utils/Shaper.java | 0 build.gradle | 8 +- settings.gradle | 4 +- 57 files changed, 699 insertions(+), 10 deletions(-) rename {Commons => Corvo}/.gitignore (100%) create mode 100644 Corvo/build.gradle create mode 100644 Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java create mode 100644 Datura/src/main/resources/plugin.yml create mode 100644 Fossil/.gitignore create mode 100644 Fossil/build.gradle create mode 100644 Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java create mode 100644 Fossil/src/main/java/me/totalfreedom/fossil/command/KickCommand.java create mode 100644 Patchwork/.gitignore rename {Commons => Patchwork}/build.gradle (86%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/api/Context.java (67%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/api/Serializable.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/base/CommonsBase.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/base/Registration.java (100%) create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/CommandBase.java create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java create mode 100644 Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java rename {Commons => Patchwork}/src/main/java/me/totalfreedom/config/Configuration.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/CommandRegistry.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/ConfigRegistry.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/EventRegistry.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/GroupRegistry.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/ModuleRegistry.java (89%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/ServiceRegistry.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/data/UserRegistry.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/event/Callback.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/event/EventBus.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/event/EventSubscription.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/event/FEvent.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/event/SubscriptionBox.java (100%) create mode 100644 Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java rename {Commons => Patchwork}/src/main/java/me/totalfreedom/provider/EventProvider.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/provider/ModuleProvider.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/provider/ServiceProvider.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/security/Group.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/security/Node.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/security/NodeBuilder.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/security/NodeType.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/security/PermissionHolder.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/service/FreedomExecutor.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/service/Service.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/service/Task.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/sql/SQL.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/sql/SQLProperties.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/user/User.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/user/UserData.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/utils/FreedomLogger.java (100%) rename {Commons => Patchwork}/src/main/java/me/totalfreedom/utils/Identity.java (100%) create mode 100644 Patchwork/src/main/java/me/totalfreedom/utils/Pair.java rename {Commons => Patchwork}/src/main/java/me/totalfreedom/utils/Shaper.java (100%) diff --git a/Commons/.gitignore b/Corvo/.gitignore similarity index 100% rename from Commons/.gitignore rename to Corvo/.gitignore diff --git a/Corvo/build.gradle b/Corvo/build.gradle new file mode 100644 index 0000000..609c4f3 --- /dev/null +++ b/Corvo/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' +} + +group = 'me.totalfreedom' +version = '1.0.0' + +repositories { + mavenCentral() +} + +dependencies { + compileOnly project(":Patchwork") + + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java b/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java new file mode 100644 index 0000000..eb9f414 --- /dev/null +++ b/Corvo/src/main/java/me/totalfreedom/corvo/Corvo.java @@ -0,0 +1,23 @@ +package me.totalfreedom.corvo; + +import me.totalfreedom.base.CommonsBase; +import org.bukkit.plugin.java.JavaPlugin; + +public class Corvo extends JavaPlugin +{ + @Override + public void onEnable() { + CommonsBase.getInstance() + .getRegistrations() + .getModuleRegistry() + .addModule(this); + } + + @Override + public void onDisable() { + CommonsBase.getInstance() + .getRegistrations() + .getModuleRegistry() + .removeModule(this); + } +} diff --git a/Datura/build.gradle b/Datura/build.gradle index da7c50b..99b4399 100644 --- a/Datura/build.gradle +++ b/Datura/build.gradle @@ -10,12 +10,16 @@ repositories { } dependencies { - compileOnly project(":Commons") + compileOnly project(":Patchwork") + compileOnly "com.discord4j:discord4j-core:3.2.3" + compileOnly "com.discord4j:discord4j-commons:3.2.3" testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter' } +var weight = 2 + test { useJUnitPlatform() } \ No newline at end of file diff --git a/Datura/src/main/resources/plugin.yml b/Datura/src/main/resources/plugin.yml new file mode 100644 index 0000000..22bb0aa --- /dev/null +++ b/Datura/src/main/resources/plugin.yml @@ -0,0 +1,8 @@ +name: Datura +main: me.totalfreedom.datura.Datura +version: 1.0.0 +author: TotalFreedom +description: Data Manager for the Freedom Network Suite +libraries: + - com.discord4j:discord4j-core:3.2.3 + - com.discord4j:discord4j-commons:3.2.3 \ No newline at end of file diff --git a/Fossil/.gitignore b/Fossil/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/Fossil/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Fossil/build.gradle b/Fossil/build.gradle new file mode 100644 index 0000000..609c4f3 --- /dev/null +++ b/Fossil/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java' +} + +group = 'me.totalfreedom' +version = '1.0.0' + +repositories { + mavenCentral() +} + +dependencies { + compileOnly project(":Patchwork") + + testImplementation platform('org.junit:junit-bom:5.9.1') + testImplementation 'org.junit.jupiter:junit-jupiter' +} + +test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java b/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java new file mode 100644 index 0000000..06e9b8a --- /dev/null +++ b/Fossil/src/main/java/me/totalfreedom/fossil/Fossil.java @@ -0,0 +1,16 @@ +package me.totalfreedom.fossil; + +import me.totalfreedom.base.CommonsBase; +import org.bukkit.plugin.java.JavaPlugin; + +public class Fossil extends JavaPlugin +{ + @Override + public void onEnable() + { + CommonsBase.getInstance() + .getRegistrations() + .getModuleRegistry() + .addModule(this); + } +} diff --git a/Fossil/src/main/java/me/totalfreedom/fossil/command/KickCommand.java b/Fossil/src/main/java/me/totalfreedom/fossil/command/KickCommand.java new file mode 100644 index 0000000..8efbf00 --- /dev/null +++ b/Fossil/src/main/java/me/totalfreedom/fossil/command/KickCommand.java @@ -0,0 +1,36 @@ +package me.totalfreedom.fossil.command; + +import me.totalfreedom.command.*; +import me.totalfreedom.command.annotation.Base; +import me.totalfreedom.command.annotation.Info; +import me.totalfreedom.command.annotation.Permissive; +import me.totalfreedom.command.annotation.Subcommand; +import me.totalfreedom.fossil.Fossil; +import net.kyori.adventure.text.Component; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@Info(name = "kick", description = "Kick a player", usage = "/ ") +@Permissive(perm = "fossil.kick") +public class KickCommand extends CommandBase +{ + public KickCommand(Fossil plugin) { + super(plugin); + } + + @Base + public void run(CommandSender sender) { + sender.sendMessage(Component.text("You must specify a player to kick.")); + } + + @Subcommand(permission = "fossil.kick", args = {Player.class, String.class}) + public void kickPlayer(Player player, String string) { + player.kick(Component.text(string)); + } + + // TODO: Write the code to make this work properly. + @Subcommand(name = "info", permission = "fossil.kick.info", args = {Player.class}) + public void playerinfo(Player player) { + + } +} diff --git a/Patchwork/.gitignore b/Patchwork/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/Patchwork/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/Commons/build.gradle b/Patchwork/build.gradle similarity index 86% rename from Commons/build.gradle rename to Patchwork/build.gradle index fa1aaaa..24b6581 100644 --- a/Commons/build.gradle +++ b/Patchwork/build.gradle @@ -9,13 +9,12 @@ dependencies { api 'io.projectreactor:reactor-core:3.5.4' api 'org.reflections:reflections:0.10.2' api 'org.slf4j:slf4j-api:1.7.36' - api 'co.aikar:acf-paper:0.5.1-SNAPSHOT' testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter' } -ext.weight = 1 +var weight = 1 test { useJUnitPlatform() diff --git a/Commons/src/main/java/me/totalfreedom/api/Context.java b/Patchwork/src/main/java/me/totalfreedom/api/Context.java similarity index 67% rename from Commons/src/main/java/me/totalfreedom/api/Context.java rename to Patchwork/src/main/java/me/totalfreedom/api/Context.java index e5c870f..e574434 100644 --- a/Commons/src/main/java/me/totalfreedom/api/Context.java +++ b/Patchwork/src/main/java/me/totalfreedom/api/Context.java @@ -16,6 +16,63 @@ public interface Context { T get(); + default @Nullable String asString() + { + if (get() instanceof String string) + { + return string; + } else + { + return null; + } + } + + default @Nullable Boolean asBoolean() + { + if (get() instanceof Boolean bool) + { + return bool; + } else + { + return null; + } + } + + default @Nullable Double asDouble() + { + if (get() instanceof Double doub) + { + return doub; + } else + { + return null; + } + } + + default @Nullable Integer asInt() { + if (get() instanceof Integer integer) { + return integer; + } else { + return null; + } + } + + default @Nullable Long asLong() { + if (get() instanceof Long longg) { + return longg; + } else { + return null; + } + } + + default @Nullable Float asFloat() { + if (get() instanceof Float floatt) { + return floatt; + } else { + return null; + } + } + default @Nullable Player asPlayer() { if (get() instanceof Player player) @@ -38,7 +95,7 @@ public interface Context } } - default @NotNull String asLiteral() + default @NotNull String literal() { return get().toString(); } diff --git a/Commons/src/main/java/me/totalfreedom/api/Serializable.java b/Patchwork/src/main/java/me/totalfreedom/api/Serializable.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/api/Serializable.java rename to Patchwork/src/main/java/me/totalfreedom/api/Serializable.java diff --git a/Commons/src/main/java/me/totalfreedom/base/CommonsBase.java b/Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/base/CommonsBase.java rename to Patchwork/src/main/java/me/totalfreedom/base/CommonsBase.java diff --git a/Commons/src/main/java/me/totalfreedom/base/Registration.java b/Patchwork/src/main/java/me/totalfreedom/base/Registration.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/base/Registration.java rename to Patchwork/src/main/java/me/totalfreedom/base/Registration.java diff --git a/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java b/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java new file mode 100644 index 0000000..fdaeb3f --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/BukkitDelegator.java @@ -0,0 +1,120 @@ +package me.totalfreedom.command; + +import jdk.jshell.MethodSnippet; +import me.totalfreedom.api.Context; +import me.totalfreedom.command.annotation.Subcommand; +import me.totalfreedom.provider.ContextProvider; +import me.totalfreedom.utils.FreedomLogger; +import net.kyori.adventure.text.Component; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.command.PluginIdentifiableCommand; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +public class BukkitDelegator extends Command implements PluginIdentifiableCommand +{ + private final JavaPlugin plugin; + private final CommandBase command; + private final boolean noConsole; + + BukkitDelegator(final JavaPlugin plugin, final CommandBase command) + { + super(command.getInfo().name()); + this.plugin = plugin; + this.command = command; + this.setDescription(command.getInfo().description()); + this.setUsage(command.getInfo().usage()); + this.setPermission(command.getPerms().perm()); + this.setAliases(Arrays.asList(command.getInfo().aliases())); + this.permissionMessage(Component.text(command.getPerms().noPerms())); + this.noConsole = command.getPerms().onlyPlayers(); + } + + @Override + public boolean execute(@NotNull CommandSender sender, @NotNull String commandLabel, @NotNull String[] args) + { + if (commandLabel.isEmpty() || !commandLabel.equalsIgnoreCase(getName())) + return false; + + if (sender instanceof ConsoleCommandSender && noConsole) + { + sender.sendMessage(Component.text("This command can only be run by players.")); + return true; + } + + if (getPermission() != null && !sender.hasPermission(getPermission())) + { + Component permissionMessage = permissionMessage(); + if (permissionMessage == null) + permissionMessage = Component.text("You do not have permission to use this command."); + sender.sendMessage(permissionMessage); + return true; + } + + if (args.length > 0) + { + ContextProvider provider = new ContextProvider(); + Set nodes = command.getSubcommands().keySet(); + for (Subcommand node : nodes) { + Class[] argTypes = node.args(); + if (argTypes.length != args.length) + continue; + + Object[] objects = new Object[0]; + + for (int i = 0; i < argTypes.length; i++) { + Class argType = argTypes[i]; + String arg = args[i]; + if (argType == String.class) + continue; + + Context context = () -> provider.fromString(arg); + if (!argType.isInstance(context.get())) { + throw new IllegalStateException(); + } + objects = Arrays.copyOf(objects, objects.length + 1); + objects[objects.length - 1] = context.get(); + } + try + { + command.getSubcommands().get(node).invoke(command, objects); + } catch (Exception ex) + { + FreedomLogger.getLogger("Patchwork") + .error(ex); + } + } + + return false; + } + + if (command.getBaseMethodPair() != null) { + try + { + command.getBaseMethodPair().getValue().invoke(command, sender); + } catch (Exception ex) + { + FreedomLogger.getLogger("Patchwork") + .error(ex); + } + } + + return true; + } + + @Override + public @NotNull Plugin getPlugin() + { + return this.plugin; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/CommandBase.java b/Patchwork/src/main/java/me/totalfreedom/command/CommandBase.java new file mode 100644 index 0000000..7c6a9ee --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/CommandBase.java @@ -0,0 +1,72 @@ +package me.totalfreedom.command; + +import me.totalfreedom.command.annotation.Base; +import me.totalfreedom.command.annotation.Info; +import me.totalfreedom.command.annotation.Permissive; +import me.totalfreedom.command.annotation.Subcommand; +import me.totalfreedom.utils.Pair; +import org.bukkit.plugin.java.JavaPlugin; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public abstract class CommandBase +{ + private final JavaPlugin plugin; + private final Info info; + private final Permissive perms; + private final Map subcommands; + private final Pair baseMethodPair; + + protected CommandBase(final JavaPlugin plugin) + { + this.info = this.getClass().getDeclaredAnnotation(Info.class); + this.perms = this.getClass().getDeclaredAnnotation(Permissive.class); + this.plugin = plugin; + this.subcommands = new HashMap<>(); + + if (this.getClass().isAnnotationPresent(Base.class)) + { + Method method = Stream.of(this.getClass().getDeclaredMethods()) + .filter(m -> m.isAnnotationPresent(Base.class)) + .findFirst() + .orElseThrow(() -> new RuntimeException("Base annotation present but no method found.")); + + this.baseMethodPair = new Pair<>(method.getDeclaredAnnotation(Base.class), method); + } else + { + this.baseMethodPair = null; + } + + Stream.of(this.getClass().getDeclaredMethods()) + .filter(method -> method.isAnnotationPresent(Subcommand.class)) + .forEach(method -> this.subcommands.put(method.getDeclaredAnnotation(Subcommand.class), method)); + } + + public Pair getBaseMethodPair() + { + return baseMethodPair; + } + + Info getInfo() + { + return this.info; + } + + Permissive getPerms() + { + return this.perms; + } + + public JavaPlugin getPlugin() + { + return this.plugin; + } + + Map getSubcommands() + { + return this.subcommands; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java b/Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java new file mode 100644 index 0000000..a2bd595 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/CommandHandler.java @@ -0,0 +1,25 @@ +package me.totalfreedom.command; + +import org.bukkit.Bukkit; +import org.bukkit.command.PluginCommand; +import org.bukkit.plugin.java.JavaPlugin; + +public class CommandHandler +{ + private final JavaPlugin plugin; + + public CommandHandler(JavaPlugin plugin) + { + this.plugin = plugin; + } + + // TODO: Figure out how to use CommandExecutor and TabCompleter. + // We need to find a way to resolve PluginCommands so we can + // set the executor and tab completer as necessary. + // OR we need to find an alternative way to process tab completions. + public void registerCommand(T command) { + BukkitDelegator delegate = new BukkitDelegator(plugin, command); + + Bukkit.getCommandMap().register(plugin.getName(), delegate); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java new file mode 100644 index 0000000..cd76252 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Base.java @@ -0,0 +1,13 @@ +package me.totalfreedom.command.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * This annotation is used to mark a method as the command's default method. + * This is the method that will be run to execute the command when a user inputs /{command} + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface Base +{ +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java new file mode 100644 index 0000000..478a5ad --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Info.java @@ -0,0 +1,16 @@ +package me.totalfreedom.command.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Info +{ + String name(); + + String description() default "This is the default command description."; + + String usage() default "/"; + + String[] aliases() default {}; +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java new file mode 100644 index 0000000..470569d --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Permissive.java @@ -0,0 +1,14 @@ +package me.totalfreedom.command.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Permissive +{ + String perm(); + + boolean onlyPlayers() default false; + + String noPerms() default "You do not have permission to use this command."; +} diff --git a/Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java new file mode 100644 index 0000000..de4945e --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/command/annotation/Subcommand.java @@ -0,0 +1,14 @@ +package me.totalfreedom.command.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface Subcommand +{ + String name() default ""; + + String permission(); + + Class[] args() default {}; +} diff --git a/Commons/src/main/java/me/totalfreedom/config/Configuration.java b/Patchwork/src/main/java/me/totalfreedom/config/Configuration.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/config/Configuration.java rename to Patchwork/src/main/java/me/totalfreedom/config/Configuration.java diff --git a/Commons/src/main/java/me/totalfreedom/data/CommandRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/CommandRegistry.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/data/CommandRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/CommandRegistry.java diff --git a/Commons/src/main/java/me/totalfreedom/data/ConfigRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/ConfigRegistry.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/data/ConfigRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/ConfigRegistry.java diff --git a/Commons/src/main/java/me/totalfreedom/data/EventRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/data/EventRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/EventRegistry.java diff --git a/Commons/src/main/java/me/totalfreedom/data/GroupRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/data/GroupRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java diff --git a/Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/ModuleRegistry.java similarity index 89% rename from Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/ModuleRegistry.java index 1fd11d2..b3d6d8d 100644 --- a/Commons/src/main/java/me/totalfreedom/data/ModuleRegistry.java +++ b/Patchwork/src/main/java/me/totalfreedom/data/ModuleRegistry.java @@ -24,6 +24,10 @@ public class ModuleRegistry this.plugins.add(plugin); } + public void removeModule(final JavaPlugin plugin) { + this.plugins.remove(plugin); + } + @SuppressWarnings("unchecked") public ModuleProvider getModule(Class clazz) { diff --git a/Commons/src/main/java/me/totalfreedom/data/ServiceRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/ServiceRegistry.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/data/ServiceRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/ServiceRegistry.java diff --git a/Commons/src/main/java/me/totalfreedom/data/UserRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/data/UserRegistry.java rename to Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java diff --git a/Commons/src/main/java/me/totalfreedom/event/Callback.java b/Patchwork/src/main/java/me/totalfreedom/event/Callback.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/event/Callback.java rename to Patchwork/src/main/java/me/totalfreedom/event/Callback.java diff --git a/Commons/src/main/java/me/totalfreedom/event/EventBus.java b/Patchwork/src/main/java/me/totalfreedom/event/EventBus.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/event/EventBus.java rename to Patchwork/src/main/java/me/totalfreedom/event/EventBus.java diff --git a/Commons/src/main/java/me/totalfreedom/event/EventSubscription.java b/Patchwork/src/main/java/me/totalfreedom/event/EventSubscription.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/event/EventSubscription.java rename to Patchwork/src/main/java/me/totalfreedom/event/EventSubscription.java diff --git a/Commons/src/main/java/me/totalfreedom/event/FEvent.java b/Patchwork/src/main/java/me/totalfreedom/event/FEvent.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/event/FEvent.java rename to Patchwork/src/main/java/me/totalfreedom/event/FEvent.java diff --git a/Commons/src/main/java/me/totalfreedom/event/SubscriptionBox.java b/Patchwork/src/main/java/me/totalfreedom/event/SubscriptionBox.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/event/SubscriptionBox.java rename to Patchwork/src/main/java/me/totalfreedom/event/SubscriptionBox.java diff --git a/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java b/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java new file mode 100644 index 0000000..a8e14a4 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/provider/ContextProvider.java @@ -0,0 +1,120 @@ +package me.totalfreedom.provider; + +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; + +import java.util.Objects; +import java.util.stream.Stream; + +public class ContextProvider +{ + public Object fromString(String string) + { + return Stream.of(toBoolean(string), + toDouble(string), + toInt(string), + toLong(string), + toFloat(string), + toPlayer(string), + toWorld(string), + toLocation(string), + toCommandSender(string), + toComponent(string)) + .filter(Objects::nonNull) + .findFirst() + .orElse(string); + } + + private @Nullable Boolean toBoolean(String string) + { + try + { + return Boolean.parseBoolean(string); + } catch (Exception e) + { + return null; + } + } + + private @Nullable Double toDouble(String string) + { + try + { + return Double.parseDouble(string); + } catch (Exception e) + { + return null; + } + } + + private @Nullable Integer toInt(String string) + { + try + { + return Integer.parseInt(string); + } catch (Exception e) + { + return null; + } + } + + private @Nullable Long toLong(String string) + { + try + { + return Long.parseLong(string); + } catch (Exception e) + { + return null; + } + } + + private @Nullable Float toFloat(String string) + { + try + { + return Float.parseFloat(string); + } catch (Exception e) + { + return null; + } + } + + private @Nullable Player toPlayer(String string) + { + return Bukkit.getPlayer(string); + } + + private @Nullable CommandSender toCommandSender(String string) + { + if (toPlayer(string) == null) return null; + + return toPlayer(string); + } + + private @Nullable World toWorld(String string) + { + return Bukkit.getWorld(string); + } + + private @Nullable Location toLocation(String string) + { + String[] split = string.split(","); + if (split.length != 4 || toWorld(split[0]) == null) return null; + if (toDouble(split[1]) == null + || toDouble(split[2]) == null + || toDouble(split[3]) == null) return null; + + return new Location(toWorld(split[0]), toDouble(split[1]), toDouble(split[2]), toDouble(split[3])); + } + + private @Nullable Component toComponent(String string) + { + return Component.text(string); + } +} diff --git a/Commons/src/main/java/me/totalfreedom/provider/EventProvider.java b/Patchwork/src/main/java/me/totalfreedom/provider/EventProvider.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/provider/EventProvider.java rename to Patchwork/src/main/java/me/totalfreedom/provider/EventProvider.java diff --git a/Commons/src/main/java/me/totalfreedom/provider/ModuleProvider.java b/Patchwork/src/main/java/me/totalfreedom/provider/ModuleProvider.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/provider/ModuleProvider.java rename to Patchwork/src/main/java/me/totalfreedom/provider/ModuleProvider.java diff --git a/Commons/src/main/java/me/totalfreedom/provider/ServiceProvider.java b/Patchwork/src/main/java/me/totalfreedom/provider/ServiceProvider.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/provider/ServiceProvider.java rename to Patchwork/src/main/java/me/totalfreedom/provider/ServiceProvider.java diff --git a/Commons/src/main/java/me/totalfreedom/security/Group.java b/Patchwork/src/main/java/me/totalfreedom/security/Group.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/security/Group.java rename to Patchwork/src/main/java/me/totalfreedom/security/Group.java diff --git a/Commons/src/main/java/me/totalfreedom/security/Node.java b/Patchwork/src/main/java/me/totalfreedom/security/Node.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/security/Node.java rename to Patchwork/src/main/java/me/totalfreedom/security/Node.java diff --git a/Commons/src/main/java/me/totalfreedom/security/NodeBuilder.java b/Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/security/NodeBuilder.java rename to Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java diff --git a/Commons/src/main/java/me/totalfreedom/security/NodeType.java b/Patchwork/src/main/java/me/totalfreedom/security/NodeType.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/security/NodeType.java rename to Patchwork/src/main/java/me/totalfreedom/security/NodeType.java diff --git a/Commons/src/main/java/me/totalfreedom/security/PermissionHolder.java b/Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/security/PermissionHolder.java rename to Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java diff --git a/Commons/src/main/java/me/totalfreedom/service/FreedomExecutor.java b/Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/service/FreedomExecutor.java rename to Patchwork/src/main/java/me/totalfreedom/service/FreedomExecutor.java diff --git a/Commons/src/main/java/me/totalfreedom/service/Service.java b/Patchwork/src/main/java/me/totalfreedom/service/Service.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/service/Service.java rename to Patchwork/src/main/java/me/totalfreedom/service/Service.java diff --git a/Commons/src/main/java/me/totalfreedom/service/Task.java b/Patchwork/src/main/java/me/totalfreedom/service/Task.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/service/Task.java rename to Patchwork/src/main/java/me/totalfreedom/service/Task.java diff --git a/Commons/src/main/java/me/totalfreedom/sql/SQL.java b/Patchwork/src/main/java/me/totalfreedom/sql/SQL.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/sql/SQL.java rename to Patchwork/src/main/java/me/totalfreedom/sql/SQL.java diff --git a/Commons/src/main/java/me/totalfreedom/sql/SQLProperties.java b/Patchwork/src/main/java/me/totalfreedom/sql/SQLProperties.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/sql/SQLProperties.java rename to Patchwork/src/main/java/me/totalfreedom/sql/SQLProperties.java diff --git a/Commons/src/main/java/me/totalfreedom/user/User.java b/Patchwork/src/main/java/me/totalfreedom/user/User.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/user/User.java rename to Patchwork/src/main/java/me/totalfreedom/user/User.java diff --git a/Commons/src/main/java/me/totalfreedom/user/UserData.java b/Patchwork/src/main/java/me/totalfreedom/user/UserData.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/user/UserData.java rename to Patchwork/src/main/java/me/totalfreedom/user/UserData.java diff --git a/Commons/src/main/java/me/totalfreedom/utils/FreedomLogger.java b/Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/utils/FreedomLogger.java rename to Patchwork/src/main/java/me/totalfreedom/utils/FreedomLogger.java diff --git a/Commons/src/main/java/me/totalfreedom/utils/Identity.java b/Patchwork/src/main/java/me/totalfreedom/utils/Identity.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/utils/Identity.java rename to Patchwork/src/main/java/me/totalfreedom/utils/Identity.java diff --git a/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java b/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java new file mode 100644 index 0000000..681d640 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/utils/Pair.java @@ -0,0 +1,22 @@ +package me.totalfreedom.utils; + +public class Pair +{ + private final K key; + private final V value; + + public Pair(K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() + { + return key; + } + + public V getValue() + { + return value; + } +} diff --git a/Commons/src/main/java/me/totalfreedom/utils/Shaper.java b/Patchwork/src/main/java/me/totalfreedom/utils/Shaper.java similarity index 100% rename from Commons/src/main/java/me/totalfreedom/utils/Shaper.java rename to Patchwork/src/main/java/me/totalfreedom/utils/Shaper.java diff --git a/build.gradle b/build.gradle index 4ad34a0..5e98b08 100644 --- a/build.gradle +++ b/build.gradle @@ -39,10 +39,10 @@ subprojects { compileOnly 'com.google.code.gson:gson:2.8.8' compileOnly 'org.reflections:reflections:0.10.2' compileOnly 'org.slf4j:slf4j-api:1.7.36' - compileOnly 'co.aikar:acf-paper:0.5.1-SNAPSHOT' } - sourceCompatibility = 1.17 + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' @@ -52,9 +52,7 @@ subprojects { useJUnitPlatform() } - ext { - weight = -1 - } + var weight = -1; afterEvaluate { if (weight == -1) { diff --git a/settings.gradle b/settings.gradle index 046d807..d401c15 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'FreedomNetworkSuite' -include 'Commons' +include 'Patchwork' include 'Datura' +include 'Fossil' +include 'Corvo'