Set version automatically, channel cmd IDs

Added support for using the IDs setting for channel commands
This commit is contained in:
Norbi Peti 2020-10-27 21:58:23 +01:00
parent 5199482053
commit ff0d54e00b
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
6 changed files with 166 additions and 117 deletions

View file

@ -10,6 +10,7 @@
<artifactId>Chroma-Core</artifactId>
<name>Chroma-Core</name>
<description>Chroma-Core</description>
<version>v${noprefix.version}-SNAPSHOT</version>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
@ -218,6 +219,7 @@
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<noprefix.version>1.0</noprefix.version>
</properties>
<scm>
<url>https://github.com/TBMCPlugins/mvn-repo</url>

View file

@ -47,7 +47,12 @@ public class ChannelComponent extends Component<JavaPlugin> {
@Override
public String getCommandPath() {
return channel.ID; //TODO: IDs
return channel.ID;
}
@Override
public String[] getCommandPaths() {
return channel.IDs.get();
}
@Command2.Subcommand

View file

@ -322,9 +322,9 @@ public abstract class Command2<TC extends ICommand2<TP>, 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<TC extends ICommand2<TP>, TP extends Command2Send
return ht;
}
private void registerCommand(String path, String methodName, Subcommand ann, SubcommandData<TC> 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,11 +413,17 @@ public abstract class Command2<TC extends ICommand2<TP>, 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(), ' ');
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(alias);
}
subcommands.remove(commandChar + path + alias);
}
/**

View file

@ -63,6 +63,18 @@ public abstract class ICommand2<TP extends Command2Sender> {
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(

View file

@ -1,6 +1,6 @@
name: ChromaCore
main: buttondevteam.core.MainPlugin
version: '1.0'
version: '${noprefix.version}'
author: NorbiPeti
commands:
updateplugin:

View file

@ -54,6 +54,23 @@
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
</configuration>
</plugin>
<!-- <plugin>
<groupId>io.github.1tchy</groupId>
<artifactId>variable-search-replace-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<text>${project.version}</text>
<search>^v</search>
<variableName>noprefix.version</variableName>
</configuration>
</execution>
</executions>
</plugin> -->
</plugins>
</pluginManagement>
</build>