From ff0d54e00b7601f92c47a97597a71be09cba58a8 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 27 Oct 2020 21:58:23 +0100 Subject: [PATCH] Set version automatically, channel cmd IDs Added support for using the IDs setting for channel commands --- Chroma-Core/pom.xml | 14 +- .../component/channel/ChannelComponent.java | 7 +- .../java/buttondevteam/lib/chat/Command2.java | 27 ++- .../buttondevteam/lib/chat/ICommand2.java | 12 + Chroma-Core/src/main/resources/plugin.yml | 2 +- CorePOM/pom.xml | 221 ++++++++++-------- 6 files changed, 166 insertions(+), 117 deletions(-) diff --git a/Chroma-Core/pom.xml b/Chroma-Core/pom.xml index c8d0e79..5db6df5 100755 --- a/Chroma-Core/pom.xml +++ b/Chroma-Core/pom.xml @@ -1,15 +1,16 @@ 4.0.0 - - com.github.TBMCPlugins.ChromaCore - CorePOM - master-SNAPSHOT - ../CorePOM - + + com.github.TBMCPlugins.ChromaCore + CorePOM + master-SNAPSHOT + ../CorePOM + Chroma-Core Chroma-Core Chroma-Core + v${noprefix.version}-SNAPSHOT src/main/java @@ -218,6 +219,7 @@ github UTF-8 + 1.0 https://github.com/TBMCPlugins/mvn-repo diff --git a/Chroma-Core/src/main/java/buttondevteam/core/component/channel/ChannelComponent.java b/Chroma-Core/src/main/java/buttondevteam/core/component/channel/ChannelComponent.java index e3cc011..4f580ac 100644 --- a/Chroma-Core/src/main/java/buttondevteam/core/component/channel/ChannelComponent.java +++ b/Chroma-Core/src/main/java/buttondevteam/core/component/channel/ChannelComponent.java @@ -47,7 +47,12 @@ public class ChannelComponent extends Component { @Override public String getCommandPath() { - return channel.ID; //TODO: IDs + return channel.ID; + } + + @Override + public String[] getCommandPaths() { + return channel.IDs.get(); } @Command2.Subcommand diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java index b1b923f..54e0e11 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/chat/Command2.java @@ -322,9 +322,9 @@ public abstract class Command2, TP extends Command2Send var params = new String[method.getParameterCount() - 1]; ht = getParameterHelp(method, ht, subcommand, params); var sd = new SubcommandData<>(method, command, params, ht); - subcommands.put(subcommand, sd); //Result of the above (def) is that it will show the help text - for (String alias : ann.aliases()) - subcommands.put(commandChar + path + alias, sd); + registerCommand(path, method.getName(), ann, sd); + for (String p : command.getCommandPaths()) + registerCommand(p, method.getName(), ann, sd); addedSubcommands.add(sd); scmdHelpList.add(subcommand); nosubs = false; @@ -380,6 +380,13 @@ public abstract class Command2, TP extends Command2Send return ht; } + private void registerCommand(String path, String methodName, Subcommand ann, SubcommandData sd) { + val subcommand = commandChar + path + getCommandPath(methodName, ' '); + subcommands.put(subcommand, sd); + for (String alias : ann.aliases()) + subcommands.put(commandChar + path + alias, sd); + } + public abstract boolean hasPermission(TP sender, TC command, Method subcommand); public String[] getCommandsText() { @@ -406,13 +413,19 @@ public abstract class Command2, TP extends Command2Send for (val method : command.getClass().getMethods()) { val ann = method.getAnnotation(Subcommand.class); if (ann == null) continue; - val subcommand = commandChar + path + getCommandPath(method.getName(), ' '); - subcommands.remove(subcommand); - for (String alias : ann.aliases()) - subcommands.remove(alias); + unregisterCommand(path, method.getName(), ann); + for (String p : command.getCommandPaths()) + unregisterCommand(p, method.getName(), ann); } } + private void unregisterCommand(String path, String methodName, Subcommand ann) { + val subcommand = commandChar + path + getCommandPath(methodName, ' '); + subcommands.remove(subcommand); + for (String alias : ann.aliases()) + subcommands.remove(commandChar + path + alias); + } + /** * It will start with the given replace char. * diff --git a/Chroma-Core/src/main/java/buttondevteam/lib/chat/ICommand2.java b/Chroma-Core/src/main/java/buttondevteam/lib/chat/ICommand2.java index 2672b7f..54dd0ff 100644 --- a/Chroma-Core/src/main/java/buttondevteam/lib/chat/ICommand2.java +++ b/Chroma-Core/src/main/java/buttondevteam/lib/chat/ICommand2.java @@ -63,6 +63,18 @@ public abstract class ICommand2 { return path; } + private static final String[] EMPTY_PATHS = new String[0]; + + /** + * All of the command's paths it will be invoked on. Does not include aliases or the default path. + * Must be lowercase and must include the full path. + * + * @return The full command paths that this command should be registered under in addition to the default one. + */ + public String[] getCommandPaths() { + return EMPTY_PATHS; + } + private String getcmdpath() { if (!getClass().isAnnotationPresent(CommandClass.class)) throw new RuntimeException( diff --git a/Chroma-Core/src/main/resources/plugin.yml b/Chroma-Core/src/main/resources/plugin.yml index 94e61ef..fe800ef 100755 --- a/Chroma-Core/src/main/resources/plugin.yml +++ b/Chroma-Core/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: ChromaCore main: buttondevteam.core.MainPlugin -version: '1.0' +version: '${noprefix.version}' author: NorbiPeti commands: updateplugin: diff --git a/CorePOM/pom.xml b/CorePOM/pom.xml index 00c90ab..3c4e49e 100644 --- a/CorePOM/pom.xml +++ b/CorePOM/pom.xml @@ -1,110 +1,127 @@ - 4.0.0 + 4.0.0 - com.github.TBMCPlugins.ChromaCore - CorePOM - pom - master-SNAPSHOT - - 1.18.10 - - Core POM for Chroma + com.github.TBMCPlugins.ChromaCore + CorePOM + pom + master-SNAPSHOT + + 1.18.10 + + Core POM for Chroma - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 8 - - - com.github.bsideup.jabel - jabel-javac-plugin - 0.2.0 - - - org.projectlombok - lombok - ${lombok.version} - - - com.github.TBMCPlugins.ChromaCore - ButtonProcessor - master-SNAPSHOT - - - - com.github.bsideup.jabel.JabelJavacProcessor - lombok.launch.AnnotationProcessorHider$AnnotationProcessor - - buttondevteam.buttonproc.ButtonProcessor - - - - - maven-surefire-plugin - - false - - - - - - + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 8 + + + com.github.bsideup.jabel + jabel-javac-plugin + 0.2.0 + + + org.projectlombok + lombok + ${lombok.version} + + + com.github.TBMCPlugins.ChromaCore + ButtonProcessor + master-SNAPSHOT + + + + com.github.bsideup.jabel.JabelJavacProcessor + lombok.launch.AnnotationProcessorHider$AnnotationProcessor + + buttondevteam.buttonproc.ButtonProcessor + + + + + maven-surefire-plugin + + false + + + + + + + - - - jitpack.io - https://jitpack.io/ - - + + + jitpack.io + https://jitpack.io/ + + - - - junit - junit - 4.13.1 - test - - - - org.projectlombok - lombok - ${lombok.version} - provided - - + + + junit + junit + 4.13.1 + test + + + + org.projectlombok + lombok + ${lombok.version} + provided + + - - - intellij-idea-only - - - idea.maven.embedder.version - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 11 - - - - - - - + + + intellij-idea-only + + + idea.maven.embedder.version + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + + + + + + +