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 b8fa4f183..aaa19c519 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -22,7 +22,6 @@ import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.decree.specialhandlers.DummyHandler; import lombok.Data; @@ -91,7 +90,7 @@ public class DecreeParameter { return d; } - public Object getDefaultValue() throws DecreeParsingException, DecreeWhichException { + public Object getDefaultValue() throws DecreeParsingException { return param.defaultValue().trim().isEmpty() ? null : getHandler().parse(param.defaultValue().trim(), true); } 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 d2b06d6bf..c2d340e51 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -20,7 +20,6 @@ package com.volmit.iris.util.decree; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.util.concurrent.atomic.AtomicReference; @@ -60,9 +59,8 @@ public interface DecreeParameterHandler { * @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 */ - default T parse(String in) throws DecreeParsingException, DecreeWhichException { + default T parse(String in) throws DecreeParsingException { return parse(in, false); } @@ -73,9 +71,8 @@ public interface DecreeParameterHandler { * @param force force an option instead of throwing decreewhich * @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, boolean force) throws DecreeParsingException, DecreeWhichException; + T parse(String in, boolean force) throws DecreeParsingException; /** * Returns whether a certain type is supported by this handler
diff --git a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java b/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java deleted file mode 100644 index 36486a937..000000000 --- a/src/main/java/com/volmit/iris/util/decree/exceptions/DecreeWhichException.java +++ /dev/null @@ -1,29 +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.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(); - } -} diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java index 445f6db3b..af0e17512 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BiomeHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,7 +55,7 @@ public class BiomeHandler implements DecreeParameterHandler { } @Override - public IrisBiome parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public IrisBiome parse(String in, boolean force) throws DecreeParsingException { if (in.equals("null")) { return null; } @@ -64,19 +63,13 @@ public class BiomeHandler implements DecreeParameterHandler { if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Biome \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } } - return options.get(0); + try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); + } } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java index f3718ac56..362e0af3a 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BlockVectorHandler.java @@ -23,7 +23,6 @@ import com.volmit.iris.util.decree.DecreeContext; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.DecreeSystem; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.math.M; import com.volmit.iris.util.plugin.VolmitSender; @@ -54,7 +53,7 @@ public class BlockVectorHandler implements DecreeParameterHandler { } @Override - public BlockVector parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public BlockVector parse(String in, boolean force) throws DecreeParsingException { try { if (in.contains(",")) { String[] comp = in.split("\\Q,\\E"); diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java index 0d3df912f..469f012b8 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/DimensionHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,24 +55,16 @@ public class DimensionHandler implements DecreeParameterHandler { } @Override - public IrisDimension parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public IrisDimension parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Dimension \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java index 1526eaa66..edb976673 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -73,27 +72,18 @@ public class EntityHandler implements DecreeParameterHandler { * @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 */ @Override - public IrisEntity parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public IrisEntity parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Entity \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } /** diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java index 062047a1c..edba57652 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,24 +55,16 @@ public class GeneratorHandler implements DecreeParameterHandler { } @Override - public IrisGenerator parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public IrisGenerator parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Generator \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/JigsawPieceHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/JigsawPieceHandler.java index 759f32933..01f747f59 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/JigsawPieceHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/JigsawPieceHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,7 +55,7 @@ public class JigsawPieceHandler implements DecreeParameterHandler 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Jigsaw Piece \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + }try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Jigsaw Piece \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/JigsawStructureHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/JigsawStructureHandler.java index f58cb7cca..ac4b4582f 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/JigsawStructureHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/JigsawStructureHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,7 +55,7 @@ public class JigsawStructureHandler implements DecreeParameterHandler 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Jigsaw Structure \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Jigsaw Structure \"" + in + "\""); } - - return options.get(0); } @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 c2d499c09..fe3ebb3c2 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 @@ -21,7 +21,6 @@ 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.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -40,24 +39,16 @@ public class PlayerHandler implements DecreeParameterHandler { } @Override - public Player parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public Player parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Player \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java index ea0482516..9857fd984 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/RegionHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,7 +55,7 @@ public class RegionHandler implements DecreeParameterHandler { } @Override - public IrisRegion parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public IrisRegion parse(String in, boolean force) throws DecreeParsingException { if (in.equals("null")) { return null; } @@ -64,19 +63,11 @@ public class RegionHandler implements DecreeParameterHandler { if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Region \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java index eef7beb57..79f287806 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -56,24 +55,16 @@ public class ScriptHandler implements DecreeParameterHandler { } @Override - public IrisScript parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public IrisScript parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Script \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java index 34999a7f8..fe4e2ab8e 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/VectorHandler.java @@ -23,7 +23,6 @@ import com.volmit.iris.util.decree.DecreeContext; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.DecreeSystem; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.Form; import org.bukkit.FluidCollisionMode; import org.bukkit.entity.Player; @@ -55,7 +54,7 @@ public class VectorHandler implements DecreeParameterHandler { } @Override - public Vector parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public Vector parse(String in, boolean force) throws DecreeParsingException { try { if (in.contains(",")) { String[] comp = in.split("\\Q,\\E"); 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 c3393c17f..f8ef462e8 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 @@ -21,7 +21,6 @@ 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.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import org.bukkit.Bukkit; import org.bukkit.World; @@ -45,24 +44,16 @@ public class WorldHandler implements DecreeParameterHandler { } @Override - public World parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public World parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find World \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java b/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java index c39461a98..906f0747d 100644 --- a/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java @@ -21,7 +21,6 @@ package com.volmit.iris.util.decree.specialhandlers; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; public class DummyHandler implements DecreeParameterHandler { @Override @@ -39,7 +38,7 @@ public class DummyHandler implements DecreeParameterHandler { } @Override - public Object parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public Object parse(String in, boolean force) throws DecreeParsingException { return null; } diff --git a/src/main/java/com/volmit/iris/util/decree/specialhandlers/ObjectHandler.java b/src/main/java/com/volmit/iris/util/decree/specialhandlers/ObjectHandler.java index 1fd2b4252..56b4bbbf2 100644 --- a/src/main/java/com/volmit/iris/util/decree/specialhandlers/ObjectHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/specialhandlers/ObjectHandler.java @@ -23,7 +23,6 @@ import com.volmit.iris.core.loader.IrisData; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import java.io.File; import java.util.stream.Collectors; @@ -50,24 +49,16 @@ public class ObjectHandler implements DecreeParameterHandler { } @Override - public String parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + public String parse(String in, boolean force) throws DecreeParsingException { KList options = getPossibilities(in); if (options.isEmpty()) { throw new DecreeParsingException("Unable to find Object \"" + in + "\""); - } else if (options.size() > 1) { - if (force) { - try { - return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); - } - } else { - throw new DecreeWhichException(); - } + } try { + return options.stream().filter((i) -> toString(i).equalsIgnoreCase(in)).collect(Collectors.toList()).get(0); + } catch (Throwable e) { + throw new DecreeParsingException("Unable to filter which Biome \"" + in + "\""); } - - return options.get(0); } @Override diff --git a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java index 054786ee2..8f231e48f 100644 --- a/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java +++ b/src/main/java/com/volmit/iris/util/decree/virtual/VirtualDecreeCommand.java @@ -31,7 +31,6 @@ import com.volmit.iris.util.decree.DecreeParameter; import com.volmit.iris.util.decree.DecreeParameterHandler; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; -import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.Form; import com.volmit.iris.util.plugin.CommandDummy; @@ -350,18 +349,6 @@ public class VirtualDecreeCommand { sender.sendMessage(C.RED + "Cannot convert \"" + value + "\" into a " + param.getType().getSimpleName()); e.printStackTrace(); return null; - } catch (DecreeWhichException e) { - KList validOptions = param.getHandler().getPossibilities(value); - Iris.debug("Found multiple results for " + key + "=" + value + " in " + getPath() + " using the handler " + param.getHandler().getClass().getSimpleName() + " with potential matches [" + validOptions.toString(",") + "]. Asking client to define one"); - String update = pickValidOption(sender, validOptions, param.getHandler(), param.getName(), param.getType().getSimpleName()); - - if (update == null) { - return null; - } - - Iris.debug("Client chose " + update + " for " + key + "=" + value + " (old) in " + getPath()); - nowhich.add(original); - in.set(original, update); } } @@ -382,17 +369,6 @@ public class VirtualDecreeCommand { sender.sendMessage(C.RED + "Cannot convert \"" + stringParam + "\" into a " + par.getType().getSimpleName()); e.printStackTrace(); return null; - } catch (DecreeWhichException e) { - KList validOptions = par.getHandler().getPossibilities(stringParam); - String update = pickValidOption(sender, validOptions, par.getHandler(), par.getName(), par.getType().getSimpleName()); - - if (update == null) { - return null; - } - - Iris.debug("Client chose " + update + " for " + par.getName() + "=" + stringParam + " (old) in " + getPath()); - nowhich.add(original); - in.set(original, update); } } catch (IndexOutOfBoundsException e) { sender.sendMessage(C.YELLOW + "Unknown Parameter: " + stringParam + " (" + Form.getNumberSuffixThStRd(x + 1) + " argument)"); @@ -467,16 +443,6 @@ public class VirtualDecreeCommand { Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i.getParam().defaultValue() + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName()); sender.sendMessage(C.RED + "Cannot convert \"" + i.getParam().defaultValue() + "\" into a " + i.getType().getSimpleName()); return false; - } catch (DecreeWhichException e) { - KList validOptions = i.getHandler().getPossibilities(i.getParam().defaultValue()); - String update = pickValidOption(sender, validOptions, i.getHandler(), i.getName(), i.getType().getSimpleName()); - - if (update == null) { - return false; - } - - Iris.debug("Client chose " + update + " for " + i.getName() + "=" + i + " (old) in " + getPath()); - value = update; } if (sender.isPlayer() && i.isContextual() && value == null) { @@ -536,53 +502,6 @@ public class VirtualDecreeCommand { return true; } - private String pickValidOption(VolmitSender sender, KList validOptions, DecreeParameterHandler handler, String name, String type) { - int tries = 3; - KList options = validOptions.convert(handler::toStringForce); - String result = null; - - sender.sendHeader("Pick a " + name + " (" + type + ")"); - sender.sendMessageRaw("This query will expire in 15 seconds."); - - while (tries-- > 0 && (result == null || !options.contains(result))) { - sender.sendMessage("Please pick a valid option."); - String password = UUID.randomUUID().toString().replaceAll("\\Q-\\E", ""); - int m = 0; - - for (String i : validOptions.convert(handler::toStringForce)) { - sender.sendMessage("'>" + "- " + gradients[m % gradients.length] + i + ""); - m++; - } - - CompletableFuture future = new CompletableFuture<>(); - if (sender.isPlayer()) { - Iris.service(CommandSVC.class).post(password, future); - - if (IrisSettings.get().getGeneral().isCommandSounds()) { - (sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.65f); - (sender.player()).playSound((sender.player()).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.125f, 1.99f); - } - } else { - Iris.service(CommandSVC.class).postConsole(future); - } - - try { - result = future.get(15, TimeUnit.SECONDS); - } catch (InterruptedException | ExecutionException | TimeoutException ignored) { - - } - } - - if (result != null && options.contains(result)) { - return result; - } else { - sender.sendMessage(C.RED + "You did not enter a correct option within 3 tries."); - sender.sendMessage(C.RED + "Please double-check your arguments & option picking."); - } - - return null; - } - public KList matchAllNodes(String in) { KList g = new KList<>();