Merge pull request #59 from ThisTestUser/fixes

Small fixes
This commit is contained in:
Badbird5907
2023-01-10 09:02:04 -05:00
committed by GitHub
4 changed files with 11 additions and 4 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); CommandMethod commandMethod = new CommandMethod(methodName, Sets.newHashSet(cmd.aliases()), cmd.desc(), perm, command, method, autofiller);
command.addMethod(methodName, commandMethod); 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; protected final CommandHandler commandHandler;
private final Map<String, CommandMethod> methods; private final Map<String, CommandMethod> methods;
private final Map<String, String> aliasesToNames;
private static final String MANAGE_PERMISSION = "terminatorplus.manage"; private static final String MANAGE_PERMISSION = "terminatorplus.manage";
@@ -35,6 +36,7 @@ public abstract class CommandInstance extends BukkitCommand {
this.commandHandler = handler; this.commandHandler = handler;
this.methods = new HashMap<>(); this.methods = new HashMap<>();
this.aliasesToNames = new HashMap<>();
} }
public Map<String, CommandMethod> getMethods() { public Map<String, CommandMethod> getMethods() {
@@ -44,6 +46,10 @@ public abstract class CommandInstance extends BukkitCommand {
protected void addMethod(String name, CommandMethod method) { protected void addMethod(String name, CommandMethod method) {
methods.put(name, method); methods.put(name, method);
} }
protected void addAlias(String alias, String name) {
aliasesToNames.put(alias, name);
}
@Override @Override
public boolean execute(@Nonnull CommandSender sender, @Nonnull String label, @Nonnull String[] args) { public boolean execute(@Nonnull CommandSender sender, @Nonnull String label, @Nonnull String[] args) {
@@ -61,8 +67,8 @@ public abstract class CommandInstance extends BukkitCommand {
if (args.length == 0) { if (args.length == 0) {
method = methods.get(""); method = methods.get("");
} else if (methods.containsKey(args[0])) { } else if (methods.containsKey(aliasesToNames.getOrDefault(args[0], args[0]))) {
method = methods.get(args[0]); method = methods.get(aliasesToNames.getOrDefault(args[0], args[0]));
} else { } else {
method = methods.get(""); method = methods.get("");
} }

View File

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

View File

@@ -24,7 +24,7 @@ tasks.processResources {
} }
tasks.jar { tasks.jar {
from(configurations.compileClasspath.get().map { if (it.isDirectory()) it else zipTree(it) }) from(configurations.compileClasspath.get().map { if (it.getName().endsWith(".jar")) zipTree(it) else it })
archiveFileName.set(jarName + ".jar") archiveFileName.set(jarName + ".jar")
} }