Attempt to support main command aliases
This commit is contained in:
parent
731065fe2a
commit
1aa9cd3552
2 changed files with 14 additions and 5 deletions
|
@ -284,7 +284,11 @@ public abstract class Command2<TC extends ICommand2<TP>, TP extends Command2Send
|
||||||
|
|
||||||
public abstract void registerCommand(TC command);
|
public abstract void registerCommand(TC command);
|
||||||
|
|
||||||
protected List<SubcommandData<TC>> registerCommand(TC command, @SuppressWarnings("SameParameterValue") char commandChar) {
|
protected List<SubcommandData<TC>> registerCommand(TC command, char commandChar) {
|
||||||
|
return registerCommand(command, command.getCommandPath(), commandChar);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected List<SubcommandData<TC>> registerCommand(TC command, String commandPath, @SuppressWarnings("SameParameterValue") char commandChar) {
|
||||||
this.commandChar = commandChar;
|
this.commandChar = commandChar;
|
||||||
val path = command.getCommandPath();
|
val path = command.getCommandPath();
|
||||||
int x = path.indexOf(' ');
|
int x = path.indexOf(' ');
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.util.Optional;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -52,6 +53,10 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
|
||||||
mainpath = cpath.substring(0, i == -1 ? cpath.length() : i);
|
mainpath = cpath.substring(0, i == -1 ? cpath.length() : i);
|
||||||
}*/
|
}*/
|
||||||
var subcmds = super.registerCommand(command, '/');
|
var subcmds = super.registerCommand(command, '/');
|
||||||
|
var bcmd = registerOfficially(command, subcmds);
|
||||||
|
if (bcmd != null)
|
||||||
|
for (String alias : bcmd.getAliases())
|
||||||
|
super.registerCommand(command, command.getCommandPath().replaceFirst("^" + bcmd.getName(), Matcher.quoteReplacement(alias)), '/');
|
||||||
|
|
||||||
var perm = "chroma.command." + command.getCommandPath().replace(' ', '.');
|
var perm = "chroma.command." + command.getCommandPath().replace(' ', '.');
|
||||||
if (Bukkit.getPluginManager().getPermission(perm) == null) //Check needed for plugin reset
|
if (Bukkit.getPluginManager().getPermission(perm) == null) //Check needed for plugin reset
|
||||||
|
@ -73,8 +78,6 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
|
||||||
Bukkit.getPluginManager().addPermission(new Permission(permGroup,
|
Bukkit.getPluginManager().addPermission(new Permission(permGroup,
|
||||||
PermissionDefault.OP)); //Do not allow any commands that belong to a group
|
PermissionDefault.OP)); //Do not allow any commands that belong to a group
|
||||||
}
|
}
|
||||||
|
|
||||||
registerOfficially(command, subcmds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,8 +209,8 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
|
||||||
|
|
||||||
private boolean shouldRegisterOfficially = true;
|
private boolean shouldRegisterOfficially = true;
|
||||||
|
|
||||||
private void registerOfficially(ICommand2MC command, List<SubcommandData<ICommand2MC>> subcmds) {
|
private Command registerOfficially(ICommand2MC command, List<SubcommandData<ICommand2MC>> subcmds) {
|
||||||
if (!shouldRegisterOfficially || command.getPlugin() == null) return;
|
if (!shouldRegisterOfficially || command.getPlugin() == null) return null;
|
||||||
try {
|
try {
|
||||||
var cmdmap = (SimpleCommandMap) Bukkit.getServer().getClass().getMethod("getCommandMap").invoke(Bukkit.getServer());
|
var cmdmap = (SimpleCommandMap) Bukkit.getServer().getClass().getMethod("getCommandMap").invoke(Bukkit.getServer());
|
||||||
var path = command.getCommandPath();
|
var path = command.getCommandPath();
|
||||||
|
@ -231,12 +234,14 @@ public class Command2MC extends Command2<ICommand2MC, Command2MCSender> implemen
|
||||||
//System.out.println("Registering to " + command.getPlugin().getName());
|
//System.out.println("Registering to " + command.getPlugin().getName());
|
||||||
if (CommodoreProvider.isSupported())
|
if (CommodoreProvider.isSupported())
|
||||||
TabcompleteHelper.registerTabcomplete(command, subcmds, bukkitCommand);
|
TabcompleteHelper.registerTabcomplete(command, subcmds, bukkitCommand);
|
||||||
|
return bukkitCommand;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (command.getComponent() == null)
|
if (command.getComponent() == null)
|
||||||
TBMCCoreAPI.SendException("Failed to register command in command map!", e, command.getPlugin());
|
TBMCCoreAPI.SendException("Failed to register command in command map!", e, command.getPlugin());
|
||||||
else
|
else
|
||||||
TBMCCoreAPI.SendException("Failed to register command in command map!", e, command.getComponent());
|
TBMCCoreAPI.SendException("Failed to register command in command map!", e, command.getComponent());
|
||||||
shouldRegisterOfficially = false;
|
shouldRegisterOfficially = false;
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue