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 d10dae774..9a050d229 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameter.java @@ -18,10 +18,12 @@ package com.volmit.iris.util.decree; +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; import java.lang.reflect.Parameter; @@ -30,6 +32,7 @@ import java.lang.reflect.Parameter; public class DecreeParameter { private final Parameter parameter; private final Param param; + private transient final AtomicCache> handlerCache = new AtomicCache<>(); public DecreeParameter(Parameter parameter) { this.parameter = parameter; @@ -40,7 +43,24 @@ public class DecreeParameter { } public DecreeParameterHandler getHandler() { - return DecreeSystem.getHandler(getType()); + return handlerCache.aquire(() -> { + try + { + if(param.customHandler().equals(DummyHandler.class)) + { + return DecreeSystem.getHandler(getType()); + } + + return param.customHandler().getConstructor().newInstance(); + } + + catch(Throwable e) + { + e.printStackTrace(); + } + + return null; + }); } public Class getType() { 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 5aa81c3ca..c47b48f73 100644 --- a/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java +++ b/src/main/java/com/volmit/iris/util/decree/DecreeParameterHandler.java @@ -32,6 +32,11 @@ public interface DecreeParameterHandler { */ KList getPossibilities(); + default boolean isDummy() + { + return false; + } + /** * Converting the type back to a string (inverse of the {@link #parse(String) parse} method) * 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 index cdb47ee9e..e05a751d5 100644 --- a/src/main/java/com/volmit/iris/util/decree/annotations/Param.java +++ b/src/main/java/com/volmit/iris/util/decree/annotations/Param.java @@ -18,6 +18,9 @@ package com.volmit.iris.util.decree.annotations; +import com.volmit.iris.util.decree.DecreeParameterHandler; +import com.volmit.iris.util.decree.specialhandlers.DummyHandler; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -60,4 +63,6 @@ public @interface Param { * Attempts to dynamically pull context from the player, default data or something else for supported types */ boolean contextual() default false; + + Class> customHandler() default DummyHandler.class; } diff --git a/src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java b/src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java deleted file mode 100644 index fde7f0d8b..000000000 --- a/src/main/java/com/volmit/iris/util/decree/handlers/ObjectHandler.java +++ /dev/null @@ -1,67 +0,0 @@ -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.objects.IrisObject; -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 ObjectHandler 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 = IrisData.get(i); - for (IrisObject j : data.getObjectLoader().loadAll(data.getObjectLoader().getPossibleKeys())) { - p.putIfAbsent(j.getLoadKey(), j); - } - - data.close(); - } - } - - return p.v(); - } - - @Override - public String toString(IrisObject irisObject) { - return irisObject.getLoadKey(); - } - - @Override - public IrisObject parse(String in) throws DecreeParsingException, DecreeWhichException { - try { - KList options = getPossibilities(in); - - if (options.isEmpty()) { - throw new DecreeParsingException("Unable to find Object \"" + 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 Object \"" + in + "\" because of an uncaught exception: " + e); - } - } - - @Override - public boolean supports(Class type) { - return type.equals(IrisObject.class); - } - - @Override - public String getRandomDefault() { - return "object"; - } -} 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 new file mode 100644 index 000000000..062d3b7d7 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/specialhandlers/DummyHandler.java @@ -0,0 +1,51 @@ +/* + * 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.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 + public KList getPossibilities() { + return null; + } + + public boolean isDummy() + { + return true; + } + + @Override + public String toString(Object o) { + return null; + } + + @Override + public Object parse(String in) throws DecreeParsingException, DecreeWhichException { + return null; + } + + @Override + public boolean supports(Class type) { + return false; + } +} 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 new file mode 100644 index 000000000..7d7af67fe --- /dev/null +++ b/src/main/java/com/volmit/iris/util/decree/specialhandlers/ObjectHandler.java @@ -0,0 +1,81 @@ +/* + * 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.specialhandlers; + +import com.volmit.iris.Iris; +import com.volmit.iris.core.project.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; + +public class ObjectHandler implements DecreeParameterHandler { + @Override + public KList getPossibilities() { + KList p = new KList<>(); + + //noinspection ConstantConditions + for (File i : Iris.instance.getDataFolder("packs").listFiles()) { + if (i.isDirectory()) { + IrisData data = IrisData.get(i); + p.add(data.getObjectLoader().getPossibleKeys()); + } + } + + return p; + } + + @Override + public String toString(String irisObject) { + return irisObject; + } + + @Override + public String parse(String in) throws DecreeParsingException, DecreeWhichException { + try { + KList options = getPossibilities(in); + + if (options.isEmpty()) { + throw new DecreeParsingException("Unable to find Object \"" + 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 Object \"" + in + "\" because of an uncaught exception: " + e); + } + } + + @Override + public boolean supports(Class type) { + return type.equals(String.class); + } + + @Override + public String getRandomDefault() { + String f = getPossibilities().getRandom(); + + return f == null ? "object" : f; + } +} diff --git a/src/main/java/com/volmit/iris/util/mantle/Mantle.java b/src/main/java/com/volmit/iris/util/mantle/Mantle.java index 06a8a8e4c..e17ae0b32 100644 --- a/src/main/java/com/volmit/iris/util/mantle/Mantle.java +++ b/src/main/java/com/volmit/iris/util/mantle/Mantle.java @@ -147,7 +147,7 @@ public class Mantle { throw new RuntimeException("The Mantle is closed"); } - if (y < 0) { + if (y < 0 || y >= worldHeight) { return; }