Small fixes

-Fix relative coordinates for /bot settings region
-Fix command aliases
This commit is contained in:
ThisTestUser
2023-01-09 20:36:15 -05:00
parent 40096dfa03
commit 4c80a5df66
3 changed files with 10 additions and 3 deletions

View File

@@ -89,6 +89,7 @@ public class CommandHandler {
CommandMethod commandMethod = new CommandMethod(methodName, Sets.newHashSet(cmd.aliases()), cmd.desc(), perm, command, method, autofiller);
command.addMethod(methodName, commandMethod);
commandMethod.getAliases().forEach(alias -> command.addAlias(alias, methodName));
}
}

View File

@@ -27,6 +27,7 @@ public abstract class CommandInstance extends BukkitCommand {
protected final CommandHandler commandHandler;
private final Map<String, CommandMethod> methods;
private final Map<String, String> aliasesToNames;
private static final String MANAGE_PERMISSION = "terminatorplus.manage";
@@ -35,6 +36,7 @@ public abstract class CommandInstance extends BukkitCommand {
this.commandHandler = handler;
this.methods = new HashMap<>();
this.aliasesToNames = new HashMap<>();
}
public Map<String, CommandMethod> getMethods() {
@@ -45,6 +47,10 @@ public abstract class CommandInstance extends BukkitCommand {
methods.put(name, method);
}
protected void addAlias(String alias, String name) {
aliasesToNames.put(alias, name);
}
@Override
public boolean execute(@Nonnull CommandSender sender, @Nonnull String label, @Nonnull String[] args) {
if (!sender.hasPermission(MANAGE_PERMISSION)) {
@@ -61,8 +67,8 @@ public abstract class CommandInstance extends BukkitCommand {
if (args.length == 0) {
method = methods.get("");
} else if (methods.containsKey(args[0])) {
method = methods.get(args[0]);
} else if (methods.containsKey(aliasesToNames.getOrDefault(args[0], args[0]))) {
method = methods.get(aliasesToNames.getOrDefault(args[0], args[0]));
} else {
method = methods.get("");
}

View File

@@ -526,7 +526,7 @@ public class BotCommand extends CommandInstance {
private double parseDoubleOrRelative(String pos, Location loc, int type) {
if (loc == null || pos.length() == 0 || pos.charAt(0) != '~')
return Double.parseDouble(pos);
double relative = Double.parseDouble(pos.substring(1));
double relative = pos.length() == 1 ? 0 : Double.parseDouble(pos.substring(1));
switch (type) {
case 0:
return relative + Math.round(loc.getX() * 1000) / 1000D;