diff --git a/src/main/java/com/volmit/iris/util/decree/Decree.java b/src/main/java/com/volmit/iris/util/decree/Decree.java deleted file mode 100644 index 2b6a73ccb..000000000 --- a/src/main/java/com/volmit/iris/util/decree/Decree.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.util.decree; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface Decree { - String name() default "methodName"; - - String description() default "No Description Provided"; - - DecreeOrigin origin() default DecreeOrigin.BOTH; - - String[] aliases() default ""; -} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeContext.java b/src/main/java/com/volmit/iris/util/decree/DecreeContext.java index 16380897f..8f9a427e7 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeContext.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeContext.java @@ -18,11 +18,7 @@ package com.volmit.iris.util.decree; -import com.volmit.iris.core.project.loader.IrisData; -import com.volmit.iris.engine.IrisComplex; -import com.volmit.iris.engine.framework.Engine; import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.context.IrisContext; import com.volmit.iris.util.plugin.VolmitSender; import com.volmit.iris.util.scheduling.ChronoLatch; import lombok.AllArgsConstructor; @@ -33,7 +29,6 @@ import lombok.Data; public class DecreeContext { private static ChronoLatch cl = new ChronoLatch(60000); private static final KMap context = new KMap<>(); - private final VolmitSender sender; public static VolmitSender get() { return context.get(Thread.currentThread()); diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java index 02b1b440a..6e11a33c2 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeNode.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeNode.java @@ -19,64 +19,72 @@ package com.volmit.iris.util.decree; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.annotations.Decree; +import com.volmit.iris.util.decree.annotations.Param; +import com.volmit.iris.util.decree.exceptions.DecreeInstanceException; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.util.Arrays; public class DecreeNode { private final Method method; + private final Decree decree; - public DecreeNode(Method method) - { + public DecreeNode(Method method) throws DecreeInstanceException { this.method = method; + this.decree = method.getDeclaredAnnotation(Decree.class); + if (decree == null){ + throw new DecreeInstanceException("Cannot instantiate DecreeNode on method not annotated by @Decree"); + } } - public KList getParameters() - { + /** + * Get the parameters of this decree node + * @return The list of parameters if ALL are annotated by @{@link Param}, else null + */ + public KList getParameters() { KList p = new KList<>(); for(Parameter i : method.getParameters()) { - p.add(new DecreeParameter(i)); + try { + p.add(new DecreeParameter(i)); + } catch (DecreeInstanceException ignored) { + return null; + } } return p; } - public String getName() - { - Decree p = method.getDeclaredAnnotation(Decree.class); - return p == null || p.name().equals("methodName") ? method.getName() : p.name(); + public String getName() { + return decree.name().equals(Decree.METHOD_NAME) ? method.getName() : decree.name(); } - public DecreeOrigin getOrigin() - { - Decree p = method.getDeclaredAnnotation(Decree.class); - return p == null ? DecreeOrigin.BOTH : p.origin(); + public DecreeOrigin getOrigin() { + return decree.origin(); } - public String getDescription() - { - Decree p = method.getDeclaredAnnotation(Decree.class); - return p != null ? p.description() : "No Description Provided"; + public String getDescription() { + return decree.description().isEmpty() ? Decree.DEFAULT_DESCRIPTION : decree.description(); } - public KList getAliases() - { - Decree p = method.getDeclaredAnnotation(Decree.class); + public KList getAliases() { KList d = new KList<>(); - if(p != null) - { - for(String i : p.aliases()) - { - if(i.isEmpty()) - { - continue; - } + if (Arrays.equals(decree.aliases(), new String[]{Decree.NO_ALIASES})){ + return d; + } - d.add(i); + for(String i : decree.aliases()) + { + if(i.isEmpty()) + { + continue; } + + d.add(i); } return d; diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java b/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java index e9e5a688c..eae213916 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeOrigin.java @@ -18,8 +18,26 @@ package com.volmit.iris.util.decree; +import com.volmit.iris.util.plugin.VolmitSender; + public enum DecreeOrigin { PLAYER, CONSOLE, - BOTH + /** + * Both the player and the console + */ + BOTH; + + /** + * Check if the origin is valid for a sender + * @param sender The sender to check + * @return True if valid for origin + */ + public boolean validFor(VolmitSender sender){ + if (sender.isPlayer()){ + return this.equals(PLAYER) || this.equals(BOTH); + } else { + return this.equals(CONSOLE) || this.equals(BOTH); + } + } } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java index 47dffbd2d..de55ba881 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -19,55 +19,59 @@ package com.volmit.iris.util.decree; import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.decree.annotations.Param; +import com.volmit.iris.util.decree.exceptions.DecreeInstanceException; import java.lang.reflect.Parameter; +import java.util.Arrays; public class DecreeParameter { private final Parameter parameter; + private final Param param; - public DecreeParameter(Parameter parameter) - { + public DecreeParameter(Parameter parameter) throws DecreeInstanceException { this.parameter = parameter; + this.param = parameter.getDeclaredAnnotation(Param.class); + if (param == null){ + throw new DecreeInstanceException("Cannot instantiate DecreeParameter on parameter not annotated by @Param"); + } } - public DecreeParameterHandler getHandler() - { - return DecreeSystem.handle(getType()); + public DecreeParameterHandler getHandler() { + return DecreeSystem.getHandler(getType()); } - public Class getType() - { + public Class getType() { return parameter.getType(); } - public String getName() - { - Param p = parameter.getDeclaredAnnotation(Param.class); - return p == null ? parameter.getName() : p.name().isEmpty() ? parameter.getName() : p.name(); + public String getName() { + return param.name().isEmpty() ? parameter.getName() : param.name(); } - public String getDescription() - { - Param p = parameter.getDeclaredAnnotation(Param.class); - return p.name().isEmpty() ? parameter.getName() : p.name(); + public String getDescription() { + return param.description().isEmpty() ? Param.DEFAULT_DESCRIPTION : param.description(); } - public KList getAliases() - { - Param p = parameter.getDeclaredAnnotation(Param.class); - KList d= new KList<>(); + public boolean isRequired() { + return param.value().equals(Param.REQUIRED); + } - if(p != null) + public KList getAliases() { + KList d = new KList<>(); + + if (Arrays.equals(param.aliases(), new String[]{Param.NO_ALIAS})){ + return d; + } + + for(String i : param.aliases()) { - for(String i : p.aliases()) + if(i.isEmpty()) { - if(i.isEmpty()) - { - continue; - } - - d.add(i); + continue; } + + d.add(i); } return d; diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java index e7f789254..7929f0163 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -19,52 +19,84 @@ package com.volmit.iris.util.decree; import com.volmit.iris.util.collection.KList; -import com.volmit.iris.util.collection.KSet; - -import java.util.Locale; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeWhichException; +import org.jetbrains.annotations.NotNull; public interface DecreeParameterHandler { + /** + * Should return the possible values for this type + * @return Possibilities for this type. + */ KList getPossibilities(); + /** + * Converting the type back to a string (inverse of the {@link #parse(String) parse} method) + * @param t The input of the designated type to convert to a String + * @return The resulting string + */ String toString(T t); + /** + * Should parse a String into the designated type + * @param in The string to parse + * @return The value extracted from the string, of the designated type + * @throws DecreeParsingException Thrown when the parsing fails (ex: "oop" translated to an integer throws this) + * @throws DecreeWhichException Thrown when multiple results are possible + */ T parse(String in) throws DecreeParsingException, DecreeWhichException; - boolean supports(Class type); + /** + * Returns whether a certain type is supported by this handler
+ * By default, this checks if the {@link #parse(String) parse} method returns the corresponding type. + * Hence, this should only be overwritten if multiple types, outside the designated one, are supported. + * @param type The type to check + * @return True if supported, false if not + */ + default boolean supports(Class type){ + try { + if (this.getClass().getMethod("parse", String.class).getReturnType().equals(type)){ + return true; + } + } catch (NoSuchMethodException ignored){} + return false; + } + /** + * The possible entries for the inputted string (support for autocomplete on partial entries) + * @param input The inputted string to check against + * @return A {@link KList} of possibilities + */ default KList getPossibilities(String input) { - KList p = getPossibilities(); - KList m = new KList<>(); + input = input.trim(); + KList possible = getPossibilities(); + KList matches = new KList<>(); - if(p != null) + if (possible == null || possible.isEmpty()){ + return matches; + } + + if (input.isEmpty()) { - if(input.trim().isEmpty()) - { - return getPossibilities(); - } + return getPossibilities(); + } - KList f = p.convert(this::toString); + KList converted = possible.convert(v -> toString(v).trim()); - for(int i = 0; i < f.size(); i++) + for(int i = 0; i < converted.size(); i++) + { + String g = converted.get(i); + // if + // G == I or + // I in G or + // G in I + if(g.equalsIgnoreCase(input) || g.toLowerCase().contains(input.toLowerCase()) || input.toLowerCase().contains(g.toLowerCase())) { - String g = f.get(i); - if(g.equalsIgnoreCase(input)) - { - m.add(p.get(i)); - } - } - - for(int i = 0; i < f.size(); i++) - { - String g = f.get(i); - if(g.toLowerCase().contains(input.toLowerCase()) || input.toLowerCase().contains(g.toLowerCase())) - { - m.addIfMissing(p.get(i)); - } + matches.add(possible.get(i)); } } - return m; + return matches; } } diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java index 35b141865..2eb987ab5 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -24,7 +24,12 @@ import com.volmit.iris.util.collection.KList; public class DecreeSystem { private static final KList> handlers = Iris.initialize("com.volmit.iris.util.decree.handlers", null).convert((i) -> (DecreeParameterHandler) i); - public static DecreeParameterHandler handle(Class type) + /** + * Get the handler for the specified type + * @param type The type to handle + * @return The corresponding {@link DecreeParameterHandler}, or null + */ + public static DecreeParameterHandler getHandler(Class type) { for(DecreeParameterHandler i : handlers) { @@ -33,7 +38,6 @@ public class DecreeSystem { return i; } } - return null; } } diff --git a/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java b/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java index bd65c3919..13df0f1f1 100644 --- a/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java +++ b/src/main/java/com/volmit/iris/util/decree/EXAMPLE.java @@ -18,26 +18,19 @@ package com.volmit.iris.util.decree; +import com.volmit.iris.util.decree.annotations.Decree; +import com.volmit.iris.util.decree.annotations.Param; import org.bukkit.entity.Player; -public class EXAMPLE -{ +public class EXAMPLE extends DecreeCommand { @Decree public void kick( @Param(name = "player", description = "The Player to kick from the server", aliases = "p") Player player, - @Param(name = "reason", description = "A reason to kick the player for", aliases = "r") + @Param(name = "reason", description = "A reason to kick the player for", value = "No reason!", aliases = "k") String reason) { player.kickPlayer(reason); DecreeContext.get().sendMessage("Kicked " + player.getName()); } - - @Decree - public void kick( - @Param(name = "player", description = "The Player to kick from the server", aliases = "p") - Player player) - { - kick(player, "No Reason!"); - } } diff --git a/src/main/java/com/volmit/iris/util/decree/Param.java b/src/main/java/com/volmit/iris/util/decree/Param.java deleted file mode 100644 index 9b3b5f532..000000000 --- a/src/main/java/com/volmit/iris/util/decree/Param.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Iris is a World Generator for Minecraft Bukkit Servers - * Copyright (c) 2021 Arcane Arts (Volmit Software) - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.volmit.iris.util.decree; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.PARAMETER) -public @interface Param { - String name(); - String description() default "No Description Provided"; - String[] aliases() default ""; -} diff --git a/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java b/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java new file mode 100644 index 000000000..8825e1f82 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/annotations/Decree.java @@ -0,0 +1,62 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.decree.annotations; + +import com.volmit.iris.util.decree.DecreeOrigin; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.FIELD}) +public @interface Decree { + + String METHOD_NAME = "Default Method Name"; + + String DEFAULT_DESCRIPTION = "No Description Provided"; + + String NO_ALIASES = "No Aliases"; + + /** + * The name of this command, which is the Method's name by default + */ + String name() default METHOD_NAME; + + /** + * The description of this command.
+ * Is {@link #DEFAULT_DESCRIPTION} by default + */ + String description() default DEFAULT_DESCRIPTION; + + /** + * The origin this command must come from.
+ * Must be elements of the {@link DecreeOrigin} enum
+ * By default, is {@link DecreeOrigin#BOTH}, meaning both console & player can send the command + */ + DecreeOrigin origin() default DecreeOrigin.BOTH; + + /** + * The aliases of this parameter (instead of just the {@link #name() name} (if specified) or Method Name (name of method))
+ * Can be initialized as just a string (ex. "alias") or as an array (ex. {"alias1", "alias2"})
+ * If someone uses /plugin foo and you specify alias="f" here, /plugin f will do the exact same. + */ + String[] aliases() default {NO_ALIASES}; +} diff --git a/src/main/java/com/volmit/iris/util/decree/annotations/Param.java b/src/main/java/com/volmit/iris/util/decree/annotations/Param.java new file mode 100644 index 000000000..79b682a7c --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/annotations/Param.java @@ -0,0 +1,62 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.decree.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface Param { + String REQUIRED = "REQUIRED"; + + String NO_ALIAS = "No Aliases Provided"; + + String DEFAULT_DESCRIPTION = "No Description Provided"; + + /** + * The main name of this command.
+ * Required parameter.
+ * This is what is used in game, alongside any (if specified) {@link #aliases() aliases} + */ + String name(); + + /** + * The description of this parameter, used in help-popups in game.
+ * The default value is {@link #DEFAULT_DESCRIPTION} + */ + String description() default DEFAULT_DESCRIPTION; + + /** + * The default value for this argument.
+ * The entered string is parsed to the value similarly to how commandline-text would be.
+ * Default is {@link #REQUIRED}, which indicates the variable MUST be defined by the person running the command.
+ * If you define this, the variable automatically becomes non-required, but can still be set. + */ + String value() default REQUIRED; + + /** + * The aliases of this parameter (instead of just the {@link #name() name} (if specified) or Method Name (name of method))
+ * Can be initialized as just a string (ex. "alias") or as an array (ex. {"alias1", "alias2"})
+ * If someone uses /plugin foo bar=baz and you specify alias="b" here, /plugin foo b=baz will do the exact same. + */ + String[] aliases() default {NO_ALIAS}; +} diff --git a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeInstanceException.java b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeInstanceException.java new file mode 100644 index 000000000..f15bd3720 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeInstanceException.java @@ -0,0 +1,10 @@ +package com.volmit.iris.util.decree.exceptions; + +/** + * Thrown when classes are instantiated that fail because of a missing or faulty decree component + */ +public class DecreeInstanceException extends Exception { + public DecreeInstanceException(String message){ + super(message); + } +} diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java similarity index 88% rename from src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java rename to src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java index 4971809b4..42dcf7a67 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParsingException.java +++ b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeParsingException.java @@ -16,8 +16,11 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.decree; +package com.volmit.iris.util.decree.exceptions; +/** + * Thrown when a decree parameter is parsed, but parsing fails + */ public class DecreeParsingException extends Exception{ public DecreeParsingException(String message) { super(message); diff --git a/src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java similarity index 77% rename from src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java rename to src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java index 9ec282769..3401fdd9a 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeWhichException.java +++ b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java @@ -16,10 +16,14 @@ * along with this program. If not, see . */ -package com.volmit.iris.util.decree; +package com.volmit.iris.util.decree.exceptions; +/** + * Thrown when more than one option is available for a singular mapping
+ * Like having a hashmap where one input maps to two outputs. + */ public class DecreeWhichException extends Exception{ public DecreeWhichException() { - super(); + super("More than one option for the entered input"); } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java index 448f0c603..d61e368a4 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ByteHandler.java @@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; public class ByteHandler implements DecreeParameterHandler { @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java index 947482fc0..43db64528 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/DoubleHandler.java @@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; public class DoubleHandler implements DecreeParameterHandler { @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java index 93d21ea19..ef107f3d0 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/FloatHandler.java @@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; public class FloatHandler implements DecreeParameterHandler { @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java index c5329b4ba..09a1a86b3 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/IntegerHandler.java @@ -20,8 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; -import net.kyori.adventure.text.minimessage.parser.ParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; public class IntegerHandler implements DecreeParameterHandler { @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java index 0efc70992..69ff82222 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/LongHandler.java @@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; public class LongHandler implements DecreeParameterHandler { @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java index be3f34d51..5045ea822 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/PlayerHandler.java @@ -20,13 +20,12 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; -import com.volmit.iris.util.decree.DecreeWhichException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.ArrayList; -import java.util.stream.Collectors; public class PlayerHandler implements DecreeParameterHandler { @Override @@ -60,7 +59,7 @@ public class PlayerHandler implements DecreeParameterHandler { catch(Throwable e) { - throw new DecreeParsingException("Unable to find Player \"" + in + "\""); + throw new DecreeParsingException("Unable to find Player \"" + in + "\" because of an uncaught exception: " + e); } } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java index de364981d..ad7714bfe 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ShortHandler.java @@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; public class ShortHandler implements DecreeParameterHandler { @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java index 6c481dd1d..27e7ee567 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/StringHandler.java @@ -20,7 +20,7 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; /** * Abstraction can sometimes breed stupidity diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java index 0b26f4e45..b3f437799 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/WorldHandler.java @@ -20,22 +20,20 @@ package com.volmit.iris.util.decree.handlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; -import com.volmit.iris.util.decree.DecreeParsingException; -import com.volmit.iris.util.decree.DecreeWhichException; +import com.volmit.iris.util.decree.exceptions.DecreeParsingException; +import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import org.bukkit.Bukkit; import org.bukkit.World; -import java.util.ArrayList; - public class WorldHandler implements DecreeParameterHandler { @Override public KList getPossibilities() { - return new KList<>(new ArrayList<>(Bukkit.getWorlds())); + return new KList<>(Bukkit.getWorlds()); } @Override - public String toString(World player) { - return player.getName(); + public String toString(World world) { + return world.getName(); } @Override @@ -56,10 +54,12 @@ public class WorldHandler implements DecreeParameterHandler { return options.get(0); } - + catch(DecreeParsingException e){ + throw e; + } catch(Throwable e) { - throw new DecreeParsingException("Unable to find World \"" + in + "\""); + throw new DecreeParsingException("Unable to find World \"" + in + "\" because of an uncaught exception: " + e); } }