From 259d6fef99b4e6c063aaada7ddd157d7969a9bf5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 5 May 2021 09:56:30 +0200 Subject: [PATCH] Streamify SWCommand --- .../src/de/steamwar/command/SWCommand.java | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 6ec6fb1..5e73a02 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -47,8 +47,8 @@ public abstract class SWCommand { this.command = new Command(command, "", "/" + command, Arrays.asList(aliases)) { @Override public boolean execute(CommandSender sender, String alias, String[] args) { - // if (commandList.stream().filter(s -> s.invoke(sender, args)).findFirst().isEmpty()) return false; - // if (commandHelpList.stream().filter(s -> s.invoke(sender, args)).findFirst().isEmpty()) return false; + // if (commandList.stream().filter(s -> s.invoke(sender, args)).findFirst().isPresent()) return false; + // if (commandHelpList.stream().filter(s -> s.invoke(sender, args)).findFirst().isPresent()) return false; for (SubCommand subCommand : commandList) { if (subCommand.invoke(sender, args)) return false; } @@ -109,10 +109,7 @@ public abstract class SWCommand { if (clazz.isEnum() && mapper == null && !SWCommandUtils.MAPPER_FUNCTIONS.containsKey(clazz.getTypeName())) { continue; } - String name = clazz.getTypeName(); - if (mapper != null) { - name = mapper.value(); - } + String name = mapper != null ? mapper.value() : clazz.getTypeName(); if (!SWCommandUtils.MAPPER_FUNCTIONS.containsKey(name) && !localTypeMapper.containsKey(name)) { Bukkit.getLogger().log(Level.WARNING, "The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'"); return; @@ -126,9 +123,8 @@ public abstract class SWCommand { if (compare != 0) { return compare; } else { - int i1 = o1.varArgType != null ? Integer.MAX_VALUE : o1.arguments.length; - int i2 = o2.varArgType != null ? Integer.MAX_VALUE : o2.arguments.length; - return Integer.compare(i1, i2); + return Integer.compare(o1.varArgType != null ? Integer.MAX_VALUE : o1.arguments.length, + o2.varArgType != null ? Integer.MAX_VALUE : o2.arguments.length); } }); commandHelpList.sort(Comparator.comparingInt(o -> -o.subCommand.length));