Make the recent command changes backwards compatible

This commit is contained in:
Luck 2016-10-14 20:42:00 +01:00
parent f1d670dc46
commit 73f10cad66
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
3 changed files with 101 additions and 3 deletions

View File

@ -133,8 +133,11 @@ public class CommandManager {
return CommandResult.INVALID_ARGS; return CommandResult.INVALID_ARGS;
} }
List<String> arguments = new ArrayList<>(args);
handleRewrites(arguments);
try { try {
return main.execute(plugin, sender, new ArrayList<>(args.subList(1, args.size())), label); return main.execute(plugin, sender, arguments.subList(1, arguments.size()), label);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return CommandResult.FAILURE; return CommandResult.FAILURE;
@ -184,4 +187,93 @@ public class CommandManager {
.filter(c -> c.isAuthorized(sender)) .filter(c -> c.isAuthorized(sender))
.forEach(c -> Util.sendPluginMessage(sender, "&3> &a" + String.format(c.getUsage(), label))); .forEach(c -> Util.sendPluginMessage(sender, "&3> &a" + String.format(c.getUsage(), label)));
} }
private static void handleRewrites(List<String> args) {
if (args.size() >= 3) {
if (!args.get(0).equalsIgnoreCase("user") && !args.get(0).equalsIgnoreCase("group")) {
return;
}
String s = args.get(2).toLowerCase();
switch (s) {
// Provide aliases
case "p":
case "perm":
case "perms":
args.remove(2);
args.add(2, "permission");
break;
case "m":
args.remove(2);
args.add(2, "meta");
break;
case "i":
case "inherit":
case "inheritances":
case "group":
case "rank":
args.remove(2);
args.add(2, "parent");
break;
// Provide backwards compatibility
case "listnodes":
args.remove(2);
args.add(2, "permission");
args.add(3, "info");
break;
case "set":
case "unset":
case "settemp":
case "unsettemp":
args.add(2, "permission");
break;
case "listgroups":
args.remove(2);
args.add(2, "parent");
args.add(3, "info");
break;
case "addgroup":
case "setinherit":
args.remove(2);
args.add(2, "parent");
args.add(3, "add");
break;
case "removegroup":
case "unsetinherit":
args.remove(2);
args.add(2, "parent");
args.add(3, "remove");
break;
case "addtempgroup":
case "settempinherit":
args.remove(2);
args.add(2, "parent");
args.add(3, "addtemp");
break;
case "removetempgroup":
case "unsettempinherit":
args.remove(2);
args.add(2, "parent");
args.add(3, "removetemp");
break;
case "chatmeta":
args.remove(2);
args.add(2, "meta");
args.add(3, "info");
break;
case "addprefix":
case "addsuffix":
case "removeprefix":
case "removesuffix":
case "addtempprefix":
case "addtempsuffix":
case "removetempprefix":
case "removetempsuffix":
args.add(2, "meta");
break;
}
}
}
} }

View File

@ -103,7 +103,7 @@ public abstract class SubCommand<T> {
} }
} }
Util.sendPluginMessage(sender, "&3> &a" + getName() + usage); Util.sendPluginMessage(sender, "&3> &a" + getName().toLowerCase() + usage);
} }
public void sendDetailedUsage(Sender sender) { public void sendDetailedUsage(Sender sender) {

View File

@ -22,6 +22,7 @@
package me.lucko.luckperms.common.commands.generic; package me.lucko.luckperms.common.commands.generic;
import com.google.common.collect.ImmutableList;
import me.lucko.luckperms.common.LuckPermsPlugin; import me.lucko.luckperms.common.LuckPermsPlugin;
import me.lucko.luckperms.common.commands.*; import me.lucko.luckperms.common.commands.*;
import me.lucko.luckperms.common.constants.Message; import me.lucko.luckperms.common.constants.Message;
@ -38,7 +39,12 @@ public class SecondaryMainCommand<T extends PermissionHolder> extends SubCommand
private final List<SecondarySubCommand> secondaryCommands; private final List<SecondarySubCommand> secondaryCommands;
public SecondaryMainCommand(String name, String description, boolean user, List<SecondarySubCommand> secondaryCommands) { public SecondaryMainCommand(String name, String description, boolean user, List<SecondarySubCommand> secondaryCommands) {
super(name, description, null, Predicate.alwaysFalse(), null); super(name, description, null, Predicate.alwaysFalse(),
!name.equals("Meta") ? ImmutableList.copyOf(secondaryCommands.stream()
.map(s -> Arg.create(s.getName(), false, s.getDescription()))
.collect(Collectors.toList())
) : null
);
this.secondaryCommands = secondaryCommands; this.secondaryCommands = secondaryCommands;
this.user = user; this.user = user;
} }