mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
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
This commit is contained in:
parent
a750241ec3
commit
c969f277ee
@ -25,7 +25,6 @@ import com.volmit.iris.util.decree.exceptions.DecreeWhichException;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.lang.reflect.Parameter;
|
import java.lang.reflect.Parameter;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class DecreeParameter {
|
public class DecreeParameter {
|
||||||
|
@ -61,7 +61,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
@Override
|
@Override
|
||||||
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
default boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||||
J.aBukkit(() -> {
|
J.aBukkit(() -> {
|
||||||
if(!call(new VolmitSender(sender, Iris.instance.getTag()), args))
|
if(!call(new VolmitSender(sender), args))
|
||||||
{
|
{
|
||||||
sender.sendMessage(C.RED + "Unknown Iris Command");
|
sender.sendMessage(C.RED + "Unknown Iris Command");
|
||||||
}
|
}
|
||||||
@ -174,8 +174,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
* @param type The type to handle
|
* @param type The type to handle
|
||||||
* @return The corresponding {@link DecreeParameterHandler}, or null
|
* @return The corresponding {@link DecreeParameterHandler}, or null
|
||||||
*/
|
*/
|
||||||
static DecreeParameterHandler<?> getHandler(Class<?> type)
|
static DecreeParameterHandler<?> getHandler(Class<?> type) {
|
||||||
{
|
|
||||||
for(DecreeParameterHandler<?> i : handlers)
|
for(DecreeParameterHandler<?> i : handlers)
|
||||||
{
|
{
|
||||||
if(i.supports(type))
|
if(i.supports(type))
|
||||||
@ -183,6 +182,7 @@ public interface DecreeSystem extends CommandExecutor, TabCompleter {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Iris.error("Unhandled type in Decree Parameter: " + type.getName() + ". This is bad!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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<IrisEntity> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should return the possible values for this type
|
||||||
|
*
|
||||||
|
* @return Possibilities for this type.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public KList<IrisEntity> getPossibilities() {
|
||||||
|
KMap<String, IrisEntity> 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<IrisEntity> 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<br>
|
||||||
|
*
|
||||||
|
* @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";
|
||||||
|
}
|
||||||
|
}
|
@ -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<IrisGenerator> {
|
||||||
|
@Override
|
||||||
|
public KList<IrisGenerator> getPossibilities() {
|
||||||
|
KMap<String, IrisGenerator> 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<IrisGenerator> 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";
|
||||||
|
}
|
||||||
|
}
|
@ -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<IrisScript> {
|
||||||
|
@Override
|
||||||
|
public KList<IrisScript> getPossibilities() {
|
||||||
|
KMap<String, IrisScript> 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<IrisScript> 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";
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user