From 43f9efb9e45cdbcb12651b0b714d5864e04b9001 Mon Sep 17 00:00:00 2001 From: cyberpwn Date: Tue, 31 Aug 2021 10:12:23 -0400 Subject: [PATCH] Fix commands --- .../volmit/iris/core/service/CommandSVC.java | 30 ++++++- .../volmit/iris/util/collection/KList.java | 6 +- .../iris/util/decree/DecreeParameter.java | 2 +- .../util/decree/DecreeParameterHandler.java | 15 +++- .../volmit/iris/util/decree/DecreeSystem.java | 4 +- .../util/decree/handlers/BiomeHandler.java | 35 +++++--- .../decree/handlers/BlockVectorHandler.java | 2 +- .../util/decree/handlers/BooleanHandler.java | 2 +- .../util/decree/handlers/ByteHandler.java | 2 +- .../decree/handlers/DimensionHandler.java | 35 +++++--- .../util/decree/handlers/DoubleHandler.java | 2 +- .../util/decree/handlers/EntityHandler.java | 35 +++++--- .../util/decree/handlers/FloatHandler.java | 2 +- .../decree/handlers/GeneratorHandler.java | 35 +++++--- .../util/decree/handlers/IntegerHandler.java | 2 +- .../util/decree/handlers/LongHandler.java | 2 +- .../util/decree/handlers/PlayerHandler.java | 33 ++++--- .../util/decree/handlers/RegionHandler.java | 35 +++++--- .../util/decree/handlers/ScriptHandler.java | 35 +++++--- .../util/decree/handlers/ShortHandler.java | 2 +- .../util/decree/handlers/StringHandler.java | 2 +- .../util/decree/handlers/VectorHandler.java | 2 +- .../util/decree/handlers/WorldHandler.java | 36 +++++--- .../decree/specialhandlers/DummyHandler.java | 2 +- .../decree/specialhandlers/ObjectHandler.java | 35 +++++--- .../decree/virtual/VirtualDecreeCommand.java | 85 ++++++++++++++----- .../volmit/iris/util/plugin/VolmitSender.java | 2 +- 27 files changed, 332 insertions(+), 148 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/service/CommandSVC.java b/src/main/java/com/volmit/iris/core/service/CommandSVC.java index 314c7d363..2c5b2478e 100644 --- a/src/main/java/com/volmit/iris/core/service/CommandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/CommandSVC.java @@ -22,11 +22,19 @@ import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; import com.volmit.iris.core.commands.CommandIris; import com.volmit.iris.engine.data.cache.AtomicCache; +import com.volmit.iris.util.collection.KMap; import com.volmit.iris.util.decree.DecreeSystem; import com.volmit.iris.util.decree.virtual.VirtualDecreeCommand; import com.volmit.iris.util.plugin.IrisService; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import java.util.concurrent.CompletableFuture; public class CommandSVC implements IrisService, DecreeSystem { + private final KMap> futures = new KMap<>(); + private final transient AtomicCache commandCache = new AtomicCache<>(); + @Override public void onEnable() { Iris.instance.getCommand("iris").setExecutor(this); @@ -38,10 +46,30 @@ public class CommandSVC implements IrisService, DecreeSystem { } - private final transient AtomicCache commandCache = new AtomicCache<>(); + @EventHandler + public void on(PlayerCommandPreprocessEvent e) + { + String msg = e.getMessage().startsWith("/") ? e.getMessage().substring(1) : e.getMessage(); + + if(msg.startsWith("irisdecree ")) + { + String[] args = msg.split("\\Q \\E"); + CompletableFuture future = futures.get(args[1]); + + if(future != null) + { + future.complete(args[2]); + e.setCancelled(true); + } + } + } @Override public VirtualDecreeCommand getRoot() { return commandCache.aquireNastyPrint(() -> VirtualDecreeCommand.createRoot(new CommandIris())); } + + public void post(String password, CompletableFuture future) { + futures.put(password, future); + } } diff --git a/src/main/java/com/volmit/iris/util/collection/KList.java b/src/main/java/com/volmit/iris/util/collection/KList.java index cf6baac33..cbf114148 100644 --- a/src/main/java/com/volmit/iris/util/collection/KList.java +++ b/src/main/java/com/volmit/iris/util/collection/KList.java @@ -246,13 +246,13 @@ public class KList extends ArrayList implements List { } if (size() == 1) { - return get(0).toString(); + return get(0) + ""; } StringBuilder b = new StringBuilder(); for (String i : toStringList()) { - b.append(split).append(i); + b.append(split).append(i == null ? "null" : i); } return b.substring(split.length()); @@ -264,7 +264,7 @@ public class KList extends ArrayList implements List { * @return the string list */ public KList toStringList() { - return convert((t) -> t.toString()); + return convert((t) -> t + ""); } /** 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 896de1713..b8fa4f183 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -92,7 +92,7 @@ public class DecreeParameter { } public Object getDefaultValue() throws DecreeParsingException, DecreeWhichException { - return param.defaultValue().trim().isEmpty() ? null : getHandler().parse(param.defaultValue().trim()); + return param.defaultValue().trim().isEmpty() ? null : getHandler().parse(param.defaultValue().trim(), true); } public boolean hasDefault() { 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 e980a0fba..1ba681705 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -62,7 +62,20 @@ public interface DecreeParameterHandler { * @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; + default T parse(String in) throws DecreeParsingException, DecreeWhichException { + return parse(in, false); + } + + /** + * Should parse a String into the designated type. You can force it to not throw a whichexception + * + * @param in The string to parse + * @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; /** * Returns whether a certain type is supported by this handler
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 dd2c66794..6c1f1dc67 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -83,8 +83,8 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { { if(sender instanceof Player) { - ((Player)sender).playSound(((Player)sender).getLocation(), Sound.BLOCK_ANCIENT_DEBRIS_BREAK, 1f, 0.25f); - ((Player)sender).playSound(((Player)sender).getLocation(), Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, 0.2f, 1.95f); + ((Player)sender).playSound(((Player)sender).getLocation(), Sound.BLOCK_AMETHYST_CLUSTER_BREAK, 0.77f, 0.25f); + ((Player)sender).playSound(((Player)sender).getLocation(), Sound.BLOCK_BEACON_DEACTIVATE, 0.2f, 0.45f); } } 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 a63a6babc..ae2164bf1 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 @@ -28,6 +28,7 @@ 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; public class BiomeHandler implements DecreeParameterHandler { @Override @@ -55,25 +56,35 @@ public class BiomeHandler implements DecreeParameterHandler { } @Override - public IrisBiome parse(String in) throws DecreeParsingException, DecreeWhichException { + public IrisBiome parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { if (in.equals("null")) { return null; } - try { - KList options = getPossibilities(in); + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Biome \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Biome \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + return options.get(0); } @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 61adc04b0..f3718ac56 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 @@ -54,7 +54,7 @@ public class BlockVectorHandler implements DecreeParameterHandler { } @Override - public BlockVector parse(String in) throws DecreeParsingException, DecreeWhichException { + public BlockVector parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { try { if (in.contains(",")) { String[] comp = in.split("\\Q,\\E"); diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java index d53bb1555..1dba545bd 100644 --- a/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/handlers/BooleanHandler.java @@ -35,7 +35,7 @@ public class BooleanHandler implements DecreeParameterHandler { } @Override - public Boolean parse(String in) throws DecreeParsingException { + public Boolean parse(String in, boolean force) throws DecreeParsingException { try { if (in.equals("null") || in.equals("other") || in.equals("flip")) { return null; 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 4321013f7..8c47798b0 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 @@ -35,7 +35,7 @@ public class ByteHandler implements DecreeParameterHandler { } @Override - public Byte parse(String in) throws DecreeParsingException { + public Byte parse(String in, boolean force) throws DecreeParsingException { try { return Byte.parseByte(in); } catch (Throwable 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 95892cbf4..372e3aa7a 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 @@ -28,6 +28,7 @@ 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; public class DimensionHandler implements DecreeParameterHandler { @Override @@ -55,22 +56,32 @@ public class DimensionHandler implements DecreeParameterHandler { } @Override - public IrisDimension parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public IrisDimension parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Dimension \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Dimension \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + return options.get(0); } @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 51a0f06fe..fea306295 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 @@ -33,7 +33,7 @@ public class DoubleHandler implements DecreeParameterHandler { } @Override - public Double parse(String in) throws DecreeParsingException { + public Double parse(String in, boolean force) throws DecreeParsingException { try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); 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 2ef8ded93..f7e56ad81 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 @@ -28,6 +28,7 @@ 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; public class EntityHandler implements DecreeParameterHandler { @@ -75,22 +76,32 @@ public class EntityHandler implements DecreeParameterHandler { * @throws DecreeWhichException Thrown when multiple results are possible */ @Override - public IrisEntity parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public IrisEntity parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Entity \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Entity \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + return options.get(0); } /** 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 e2a4d4901..88481b988 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 @@ -33,7 +33,7 @@ public class FloatHandler implements DecreeParameterHandler { } @Override - public Float parse(String in) throws DecreeParsingException { + public Float parse(String in, boolean force) throws DecreeParsingException { try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); 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 e83213d35..0974ea4d9 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 @@ -28,6 +28,7 @@ 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; public class GeneratorHandler implements DecreeParameterHandler { @Override @@ -55,22 +56,32 @@ public class GeneratorHandler implements DecreeParameterHandler { } @Override - public IrisGenerator parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public IrisGenerator parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Generator \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Generator \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + return options.get(0); } @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 1c7588675..846d3921d 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 @@ -32,7 +32,7 @@ public class IntegerHandler implements DecreeParameterHandler { } @Override - public Integer parse(String in) throws DecreeParsingException { + public Integer parse(String in, boolean force) throws DecreeParsingException { try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); 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 51c88bbda..8c0ef12d2 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 @@ -32,7 +32,7 @@ public class LongHandler implements DecreeParameterHandler { } @Override - public Long parse(String in) throws DecreeParsingException { + public Long parse(String in, boolean force) throws DecreeParsingException { try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); 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 fde4d88cb..f9b139516 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 @@ -26,6 +26,7 @@ import org.bukkit.Bukkit; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.stream.Collectors; public class PlayerHandler implements DecreeParameterHandler { @Override @@ -39,20 +40,32 @@ public class PlayerHandler implements DecreeParameterHandler { } @Override - public Player parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public Player parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Player \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Player \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + 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 dd7fd4446..abe6018b5 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 @@ -28,6 +28,7 @@ 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; public class RegionHandler implements DecreeParameterHandler { @Override @@ -55,25 +56,35 @@ public class RegionHandler implements DecreeParameterHandler { } @Override - public IrisRegion parse(String in) throws DecreeParsingException, DecreeWhichException { + public IrisRegion parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { if (in.equals("null")) { return null; } - try { - KList options = getPossibilities(in); + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Region \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Region \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + 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 b09c6bb5f..7c7ac365c 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 @@ -28,6 +28,7 @@ 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; public class ScriptHandler implements DecreeParameterHandler { @Override @@ -55,22 +56,32 @@ public class ScriptHandler implements DecreeParameterHandler { } @Override - public IrisScript parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public IrisScript parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Script \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Script \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + return options.get(0); } @Override 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 42472aa73..b9dfc4c66 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 @@ -32,7 +32,7 @@ public class ShortHandler implements DecreeParameterHandler { } @Override - public Short parse(String in) throws DecreeParsingException { + public Short parse(String in, boolean force) throws DecreeParsingException { try { AtomicReference r = new AtomicReference<>(in); double m = getMultiplier(r); 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 f960db407..932052ca7 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 @@ -37,7 +37,7 @@ public class StringHandler implements DecreeParameterHandler { } @Override - public String parse(String in) throws DecreeParsingException { + public String parse(String in, boolean force) throws DecreeParsingException { return in; } 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 1ecce6b9e..34999a7f8 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 @@ -55,7 +55,7 @@ public class VectorHandler implements DecreeParameterHandler { } @Override - public Vector parse(String in) throws DecreeParsingException, DecreeWhichException { + public Vector parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { 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 21e9d00a6..3c3bf898f 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 @@ -25,6 +25,8 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import org.bukkit.Bukkit; import org.bukkit.World; +import java.util.stream.Collectors; + public class WorldHandler implements DecreeParameterHandler { @Override public KList getPossibilities() { @@ -43,22 +45,32 @@ public class WorldHandler implements DecreeParameterHandler { } @Override - public World parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public World parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find World \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find World \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + 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 1e0949983..c39461a98 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 @@ -39,7 +39,7 @@ public class DummyHandler implements DecreeParameterHandler { } @Override - public Object parse(String in) throws DecreeParsingException, DecreeWhichException { + public Object parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { 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 a88ca4e2c..9ac6aaa58 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 @@ -26,6 +26,7 @@ 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; public class ObjectHandler implements DecreeParameterHandler { @Override @@ -49,22 +50,32 @@ public class ObjectHandler implements DecreeParameterHandler { } @Override - public String parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); + public String parse(String in, boolean force) throws DecreeParsingException, DecreeWhichException { + KList options = getPossibilities(in); - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Object \"" + in + "\""); - } else if (options.size() > 1) { - throw new DecreeWhichException(); + 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 + "\""); + } } - return options.get(0); - } catch (DecreeParsingException e) { - throw e; - } catch (Throwable e) { - throw new DecreeParsingException("Unable to find Object \"" + in + "\" because of an uncaught exception: " + e); + else + { + throw new DecreeWhichException(); + } } + + 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 dcf268bba..b15bd9718 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 @@ -20,12 +20,11 @@ package com.volmit.iris.util.decree.virtual; import com.volmit.iris.Iris; import com.volmit.iris.core.IrisSettings; +import com.volmit.iris.core.service.CommandSVC; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.collection.KMap; -import com.volmit.iris.util.decree.DecreeContext; -import com.volmit.iris.util.decree.DecreeContextHandler; -import com.volmit.iris.util.decree.DecreeNode; -import com.volmit.iris.util.decree.DecreeParameter; +import com.volmit.iris.util.collection.KSet; +import com.volmit.iris.util.decree.*; import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.exceptions.DecreeParsingException; import com.volmit.iris.util.decree.exceptions.DecreeWhichException; @@ -37,13 +36,16 @@ import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; import com.volmit.iris.util.stream.utility.SemaphoreStream; import lombok.Data; +import org.bukkit.Sound; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Objects; -import java.util.concurrent.Semaphore; +import java.util.UUID; +import java.util.concurrent.*; @Data public class VirtualDecreeCommand { @@ -279,9 +281,16 @@ public class VirtualDecreeCommand { private KMap map(VolmitSender sender, KList in) { KMap data = new KMap<>(); + KSet nowhich = new KSet<>(); for (int ix = 0; ix < in.size(); ix++) { String i = in.get(ix); + + if(i == null) + { + Iris.warn("Param " + ix + " is null? (" + in.toString(",") + ")"); + } + if (i.contains("=")) { String[] v = i.split("\\Q=\\E"); String key = v[0]; @@ -317,32 +326,35 @@ public class VirtualDecreeCommand { key = param.getName(); try { - data.put(key, param.getHandler().parse(value)); + data.put(key, param.getHandler().parse(value, nowhich.contains(ix))); } catch (DecreeParsingException e) { Iris.debug("Can't parse parameter value for " + key + "=" + value + " in " + getPath() + " using handler " + param.getHandler().getClass().getSimpleName()); 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 = null; // TODO: PICK ONE + String update = pickValidOption(sender, validOptions, param.getHandler(), param.getName(), param.getType().getSimpleName()); Iris.debug("Client chose " + update + " for " + key + "=" + value + " (old) in " + getPath()); + nowhich.add(ix); in.set(ix--, update); } } else { try { DecreeParameter par = getNode().getParameters().get(ix); try { - data.put(par.getName(), par.getHandler().parse(i)); + data.put(par.getName(), par.getHandler().parse(i, nowhich.contains(ix))); } catch (DecreeParsingException e) { Iris.debug("Can't parse parameter value for " + par.getName() + "=" + i + " in " + getPath() + " using handler " + par.getHandler().getClass().getSimpleName()); sender.sendMessage(C.RED + "Cannot convert \"" + i + "\" into a " + par.getType().getSimpleName()); + e.printStackTrace(); return null; } catch (DecreeWhichException e) { - Iris.debug("Can't parse parameter value for " + par.getName() + "=" + i + " in " + getPath() + " using handler " + par.getHandler().getClass().getSimpleName()); KList validOptions = par.getHandler().getPossibilities(i); - String update = null; // TODO: PICK ONE + String update = pickValidOption(sender, validOptions, par.getHandler(), par.getName(), par.getType().getSimpleName()); Iris.debug("Client chose " + update + " for " + par.getName() + "=" + i + " (old) in " + getPath()); + nowhich.add(ix); in.set(ix--, update); } } catch (IndexOutOfBoundsException e) { @@ -425,20 +437,10 @@ public class VirtualDecreeCommand { sender.sendMessage(C.RED + "Cannot convert \"" + i + "\" into a " + i.getType().getSimpleName()); return false; } catch (DecreeWhichException e) { - Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName()); KList validOptions = i.getHandler().getPossibilities(i.getParam().defaultValue()); - String update = null; // TODO: PICK ONE + String update = pickValidOption(sender, validOptions, i.getHandler(), i.getName(), i.getType().getSimpleName()); Iris.debug("Client chose " + update + " for " + i.getName() + "=" + i + " (old) in " + getPath()); - try { - value = i.getDefaultValue(); - } catch (DecreeParsingException x) { - x.printStackTrace(); - Iris.debug("Can't parse parameter value for " + i.getName() + "=" + i + " in " + getPath() + " using handler " + i.getHandler().getClass().getSimpleName()); - sender.sendMessage(C.RED + "Cannot convert \"" + i + "\" into a " + i.getType().getSimpleName()); - return false; - } catch (DecreeWhichException x) { - x.printStackTrace(); - } + value = update; } if (i.isContextual() && value == null) { @@ -495,6 +497,45 @@ public class VirtualDecreeCommand { return true; } + String[] gradients = new String[]{ + "", + "", + "", + "", + "", + "" + }; + + private String pickValidOption(VolmitSender sender, KList validOptions, DecreeParameterHandler handler, String name, String type) { + sender.sendHeader("Pick a " + name + " (" + type + ")"); + sender.sendMessageRaw("This query will expire in 15 seconds."); + 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<>(); + Iris.service(CommandSVC.class).post(password, future); + + if(IrisSettings.get().getGeneral().isCommandSounds() && sender.isPlayer()) + { + (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); + } + + try { + return future.get(15, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + + } + + return null; + } + public KList matchAllNodes(String in) { KList g = new KList<>(); diff --git a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java index 02164ec54..c5bce1585 100644 --- a/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java +++ b/src/main/java/com/volmit/iris/util/plugin/VolmitSender.java @@ -436,7 +436,7 @@ public class VolmitSender implements CommandSender { } public void sendHeader(String name) { - sendHeader(name, 46); + sendHeader(name, 44); }