mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Merge remote-tracking branch 'upstream/master' into DecreeCommands
This commit is contained in:
commit
74625a8d65
@ -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<DecreeParameterHandler<?>> handlerCache = new AtomicCache<>();
|
||||
|
||||
public DecreeParameter(Parameter parameter) {
|
||||
this.parameter = parameter;
|
||||
@ -40,9 +43,26 @@ public class DecreeParameter {
|
||||
}
|
||||
|
||||
public DecreeParameterHandler<?> getHandler() {
|
||||
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() {
|
||||
return parameter.getType();
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ public interface DecreeParameterHandler<T> {
|
||||
*/
|
||||
KList<T> getPossibilities();
|
||||
|
||||
default boolean isDummy()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converting the type back to a string (inverse of the {@link #parse(String) parse} method)
|
||||
*
|
||||
|
@ -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<? extends DecreeParameterHandler<?>> customHandler() default DummyHandler.class;
|
||||
}
|
||||
|
@ -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<IrisObject> {
|
||||
@Override
|
||||
public KList<IrisObject> getPossibilities() {
|
||||
KMap<String, IrisObject> 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<IrisObject> 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";
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Object> {
|
||||
@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;
|
||||
}
|
||||
}
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String> {
|
||||
@Override
|
||||
public KList<String> getPossibilities() {
|
||||
KList<String> 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<String> 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;
|
||||
}
|
||||
}
|
@ -147,7 +147,7 @@ public class Mantle {
|
||||
throw new RuntimeException("The Mantle is closed");
|
||||
}
|
||||
|
||||
if (y < 0) {
|
||||
if (y < 0 || y >= worldHeight) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user