From c969f277ee61fe5b9a3f62aaa7c1d9540dcede5d Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Sun, 15 Aug 2021 00:33:52 +0200 Subject: [PATCH] Add new handlers (Which don't work for no reason) I'm getting stuck help plz. All commands that require any IrisRegistrant, including the dimensions (of which I did not modify the handler), give an invocationtargetexception --- .../iris/util/decree/DecreeParameter.java | 1 - .../volmit/iris/util/decree/DecreeSystem.java | 6 +- .../util/decree/handlers/EntityHandler.java | 105 ++++++++++++++++++ .../decree/handlers/GeneratorHandler.java | 78 +++++++++++++ .../util/decree/handlers/ScriptHandler.java | 78 +++++++++++++ 5 files changed, 264 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java create mode 100644 src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java 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 0ec241f1b..6fb356055 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -25,7 +25,6 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException; import lombok.Data; import java.lang.reflect.Parameter; -import java.util.Arrays; @Data public class DecreeParameter { 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 ea7cb4275..547b6cbd1 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeSystem.java @@ -61,7 +61,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { @Override default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { J.aBukkit(() -> { - if(!call(new VolmitSender(sender, Iris.instance.getTag()), args)) + if(!call(new VolmitSender(sender), args)) { sender.sendMessage(C.RED + "Unknown Iris Command"); } @@ -174,8 +174,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { * @param type The type to handle * @return The corresponding {@link DecreeParameterHandler}, or null */ - static DecreeParameterHandler getHandler(Class type) - { + static DecreeParameterHandler getHandler(Class type) { for(DecreeParameterHandler i : handlers) { if(i.supports(type)) @@ -183,6 +182,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter { return i; } } + Iris.error("Unhandled type in Decree Parameter: " + type.getName() + ". This is bad!"); return null; } } 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 new file mode 100644 index 000000000..ac4d35d56 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/EntityHandler.java @@ -0,0 +1,105 @@ +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.engine.object.dimensional.IrisDimension; +import com.volmit.iris.engine.object.entity.IrisEntity; +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; + +public class EntityHandler implements DecreeParameterHandler { + + /** + * Should return the possible values for this type + * + * @return Possibilities for this type. + */ + @Override + public KList getPossibilities() { + KMap p = new KMap<>(); + + //noinspection ConstantConditions + for(File i : Iris.instance.getDataFolder("packs").listFiles()) + { + if(i.isDirectory()) { + IrisData data = new IrisData(i, true); + for (IrisEntity j : data.getEntityLoader().loadAll(data.getEntityLoader().getPossibleKeys())) + { + p.putIfAbsent(j.getLoadKey(), j); + } + + data.close(); + } + } + + return p.v(); + } + + /** + * Converting the type back to a string (inverse of the {@link #parse(String) parse} method) + * + * @param entity The input of the designated type to convert to a String + * @return The resulting string + */ + @Override + public String toString(IrisEntity entity) { + return entity.getLoadKey(); + } + + /** + * 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 + */ + @Override + public IrisEntity parse(String in) throws DecreeParsingException, DecreeWhichException { + try + { + KList options = getPossibilities(in); + + if(options.isEmpty()) + { + throw new DecreeParsingException("Unable to find Entity \"" + in + "\""); + } + + else if(options.size() > 1) + { + throw new DecreeWhichException(); + } + + 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); + } + } + + /** + * Returns whether a certain type is supported by this handler
+ * + * @param type The type to check + * @return True if supported, false if not + */ + @Override + public boolean supports(Class type) { + return type.equals(IrisEntity.class); + } + + @Override + public String getRandomDefault() + { + return "entity"; + } +} 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 new file mode 100644 index 000000000..62d0c2545 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/GeneratorHandler.java @@ -0,0 +1,78 @@ +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.engine.object.noise.IrisGenerator; +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; + +public class GeneratorHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + KMap p = new KMap<>(); + + //noinspection ConstantConditions + for(File i : Iris.instance.getDataFolder("packs").listFiles()) + { + if(i.isDirectory()) { + IrisData data = new IrisData(i, true); + for (IrisGenerator j : data.getGeneratorLoader().loadAll(data.getGeneratorLoader().getPossibleKeys())) + { + p.putIfAbsent(j.getLoadKey(), j); + } + + data.close(); + } + } + + return p.v(); + } + + @Override + public String toString(IrisGenerator gen) { + return gen.getLoadKey(); + } + + @Override + public IrisGenerator parse(String in) throws DecreeParsingException, DecreeWhichException { + try + { + KList options = getPossibilities(in); + + if(options.isEmpty()) + { + throw new DecreeParsingException("Unable to find Generator \"" + in + "\""); + } + + else if(options.size() > 1) + { + throw new DecreeWhichException(); + } + + 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); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(IrisGenerator.class); + } + + @Override + public String getRandomDefault() + { + return "generator"; + } +} 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 new file mode 100644 index 000000000..3e8315d0c --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/handlers/ScriptHandler.java @@ -0,0 +1,78 @@ +package com.volmit.iris.util.decree.handlers; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.project.loader.IrisData; +import com.volmit.iris.engine.object.common.IrisScript; +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; + +public class ScriptHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + KMap p = new KMap<>(); + + //noinspection ConstantConditions + for(File i : Iris.instance.getDataFolder("packs").listFiles()) + { + if(i.isDirectory()) { + IrisData data = new IrisData(i, true); + for (IrisScript j : data.getScriptLoader().loadAll(data.getScriptLoader().getPossibleKeys())) + { + p.putIfAbsent(j.getLoadKey(), j); + } + + data.close(); + } + } + + return p.v(); + } + + @Override + public String toString(IrisScript script) { + return script.getLoadKey(); + } + + @Override + public IrisScript parse(String in) throws DecreeParsingException, DecreeWhichException { + try + { + KList options = getPossibilities(in); + + if(options.isEmpty()) + { + throw new DecreeParsingException("Unable to find Script \"" + in + "\""); + } + + else if(options.size() > 1) + { + throw new DecreeWhichException(); + } + + 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); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(IrisScript.class); + } + + @Override + public String getRandomDefault() + { + return "script"; + } +}