diff --git a/.gradle/7.4.2/checksums/checksums.lock b/.gradle/7.4.2/checksums/checksums.lock new file mode 100644 index 0000000..4ee5002 Binary files /dev/null and b/.gradle/7.4.2/checksums/checksums.lock differ diff --git a/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock b/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock new file mode 100644 index 0000000..8fee67a Binary files /dev/null and b/.gradle/7.4.2/dependencies-accessors/dependencies-accessors.lock differ diff --git a/.gradle/7.4.2/dependencies-accessors/gc.properties b/.gradle/7.4.2/dependencies-accessors/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/7.4.2/executionHistory/executionHistory.bin b/.gradle/7.4.2/executionHistory/executionHistory.bin new file mode 100644 index 0000000..e32a2ec Binary files /dev/null and b/.gradle/7.4.2/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.4.2/executionHistory/executionHistory.lock b/.gradle/7.4.2/executionHistory/executionHistory.lock new file mode 100644 index 0000000..6c64cd4 Binary files /dev/null and b/.gradle/7.4.2/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.4.2/fileChanges/last-build.bin b/.gradle/7.4.2/fileChanges/last-build.bin new file mode 100644 index 0000000..f76dd23 Binary files /dev/null and b/.gradle/7.4.2/fileChanges/last-build.bin differ diff --git a/.gradle/7.4.2/fileHashes/fileHashes.bin b/.gradle/7.4.2/fileHashes/fileHashes.bin new file mode 100644 index 0000000..d573bed Binary files /dev/null and b/.gradle/7.4.2/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.4.2/fileHashes/fileHashes.lock b/.gradle/7.4.2/fileHashes/fileHashes.lock new file mode 100644 index 0000000..d1c7542 Binary files /dev/null and b/.gradle/7.4.2/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.4.2/fileHashes/resourceHashesCache.bin b/.gradle/7.4.2/fileHashes/resourceHashesCache.bin new file mode 100644 index 0000000..5d7225d Binary files /dev/null and b/.gradle/7.4.2/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/7.4.2/gc.properties b/.gradle/7.4.2/gc.properties new file mode 100644 index 0000000..e69de29 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 176f18d..36e89cb 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java b/src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java index f32ac7c..f8e033f 100644 --- a/src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java +++ b/src/main/java/mikeshafter/mikestcaddons/MikesTCAddons.java @@ -1,16 +1,25 @@ package mikeshafter.mikestcaddons; +import cloud.commandframework.CommandTree; +import cloud.commandframework.annotations.AnnotationParser; +import cloud.commandframework.arguments.parser.ParserParameters; +import cloud.commandframework.arguments.parser.StandardParameters; +import cloud.commandframework.execution.CommandExecutionCoordinator; +import cloud.commandframework.meta.CommandMeta; +import cloud.commandframework.paper.PaperCommandManager; import com.bergerkiller.bukkit.common.map.MapResourcePack; import com.bergerkiller.bukkit.tc.signactions.SignAction; +import mikeshafter.mikestcaddons.attachments.SignActionAttachment; import mikeshafter.mikestcaddons.signactions.SignActionRHStation; import mikeshafter.mikestcaddons.signactions.SignActionSwap; import mikeshafter.mikestcaddons.throttle.ThrottleManager; import mikeshafter.mikestcaddons.util.Util; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; -import java.util.Objects; +import java.util.function.Function; import java.util.logging.Level; @@ -18,12 +27,34 @@ public final class MikesTCAddons extends JavaPlugin { private final SignActionSwap signActionSwap = new SignActionSwap(); private final SignActionRHStation signActionRHStation = new SignActionRHStation(); + private final SignActionAttachment signActionAttachment = new SignActionAttachment(); -@Override + private void registerCommands(Commands commands) { + final Function, CommandExecutionCoordinator> executionCoordinatorFunction = CommandExecutionCoordinator.simpleCoordinator(); + PaperCommandManager manager; + try { + manager = new PaperCommandManager<>(this, executionCoordinatorFunction, Function.identity(), Function.identity()); + } catch (Exception e) { + this.getLogger().log(Level.SEVERE, "Failed to create command manager:"); + this.getLogger().warning(e.getLocalizedMessage()); + return; + } + //if (manager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {manager.registerBrigadier();} + parseCommandAnnotations(commands, manager); + } + + private void parseCommandAnnotations(Commands commands, PaperCommandManager manager) { + final Function commandMetaFunction = p -> CommandMeta.simple().with(CommandMeta.DESCRIPTION, p.get(StandardParameters.DESCRIPTION, "Description not specified.")).build(); + AnnotationParser annotationParser = new AnnotationParser<>(manager, CommandSender.class, commandMetaFunction); + annotationParser.parse(commands); + } + + + @Override public void onDisable() { // Plugin shutdown logic SignAction.unregister(signActionSwap); - SignAction.unregister(signActionRHStation); + SignAction.unregister(signActionAttachment); Util.gates.forEach((gate) -> gate.closeGate(true)); this.getLogger().log(Level.INFO, "Mike's TC Addons has been disabled!"); for (Player player : Bukkit.getOnlinePlayers()) ThrottleManager.removeThrottle(player); @@ -39,21 +70,10 @@ public void onEnable() { MapResourcePack.SERVER.load(); SignAction.register(signActionSwap); - SignAction.register(signActionRHStation); - Commands manager = new Commands(); - Objects.requireNonNull(getCommand("throttle")).setExecutor(manager); - Objects.requireNonNull(getCommand("door")).setExecutor(manager); - Objects.requireNonNull(getCommand("swap")).setExecutor(manager); - Objects.requireNonNull(getCommand("decouple")).setExecutor(manager); - Objects.requireNonNull(getCommand("opengate")).setExecutor(manager); - Objects.requireNonNull(getCommand("reload")).setExecutor(manager); - this.getServer().getPluginManager().registerEvents(new ThrottleManager(), this); - Objects.requireNonNull(getCommand("throttle")).setTabCompleter(manager); - Objects.requireNonNull(getCommand("door")).setTabCompleter(manager); - Objects.requireNonNull(getCommand("swap")).setTabCompleter(manager); - Objects.requireNonNull(getCommand("decouple")).setTabCompleter(manager); - Objects.requireNonNull(getCommand("opengate")).setTabCompleter(manager); - Objects.requireNonNull(getCommand("reload")).setTabCompleter(manager); + SignAction.register(signActionAttachment); + + registerCommands(new Commands()); + this.getLogger().log(Level.INFO, "Mike's TC Addons has been enabled!"); } }