From 7ea204b2894334cc45fe37ef421c36aae59aa94c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 25 May 2021 13:07:10 +0200 Subject: [PATCH] Update SWCommand --- .../src/de/steamwar/command/SWCommand.java | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java index 1753470..72a83da 100644 --- a/SpigotCore_Main/src/de/steamwar/command/SWCommand.java +++ b/SpigotCore_Main/src/de/steamwar/command/SWCommand.java @@ -19,7 +19,6 @@ package de.steamwar.command; -import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; @@ -32,7 +31,6 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.IntPredicate; -import java.util.logging.Level; import java.util.stream.Collectors; public abstract class SWCommand { @@ -86,19 +84,14 @@ public abstract class SWCommand { }); add(Register.class, method, i -> i > 0, true, null, (anno, parameters) -> { if (!anno.help()) return; - List errors = new ArrayList<>(); if (parameters.length != 2) { - errors.add("The method '" + method.toString() + "' is lacking parameters or has too many"); + throw new SecurityException("The method '" + method.toString() + "' is lacking parameters or has too many"); } if (!parameters[parameters.length - 1].isVarArgs()) { - errors.add("The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument"); + throw new SecurityException("The method '" + method.toString() + "' is lacking the varArgs parameters as last Argument"); } if (parameters[parameters.length - 1].getType().getComponentType() != String.class) { - errors.add("The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); - } - if (!errors.isEmpty()) { - errors.forEach(s -> Bukkit.getLogger().log(Level.WARNING, s)); - return; + throw new SecurityException("The method '" + method.toString() + "' is lacking the varArgs parameters of type '" + String.class.getTypeName() + "' as last Argument"); } commandHelpList.add(new SubCommand(this, method, anno.description(), anno.value(), new HashMap<>())); }); @@ -118,8 +111,7 @@ public abstract class SWCommand { } 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; + throw new SecurityException("The parameter '" + parameter.toString() + "' is using an unsupported Mapper of type '" + name + "'"); } } commandList.add(new SubCommand(this, method, anno.description(), anno.value(), localTypeMapper)); @@ -174,19 +166,14 @@ public abstract class SWCommand { if (anno == null || anno.length == 0) return; Parameter[] parameters = method.getParameters(); - List errors = new ArrayList<>(); if (!parameterTester.test(parameters.length)) { - errors.add("The method '" + method.toString() + "' is lacking parameters or has too many"); + throw new SecurityException("The method '" + method.toString() + "' is lacking parameters or has too many"); } if (firstParameter && !CommandSender.class.isAssignableFrom(parameters[0].getType())) { - errors.add("The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'"); + throw new SecurityException("The method '" + method.toString() + "' is lacking the first parameter of type '" + CommandSender.class.getTypeName() + "'"); } if (returnType != null && method.getReturnType() != returnType) { - errors.add("The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); - } - if (!errors.isEmpty()) { - errors.forEach(s -> Bukkit.getLogger().log(Level.WARNING, s)); - return; + throw new SecurityException("The method '" + method.toString() + "' is lacking the desired return type '" + returnType.getTypeName() + "'"); } Arrays.stream(anno).forEach(t -> consumer.accept(t, parameters)); }