Add missing files
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package exopandora.worldhandler.usercontent.factory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.argument.Arguments;
|
||||
import exopandora.worldhandler.builder.argument.IDeserializableArgument;
|
||||
import exopandora.worldhandler.usercontent.model.ArgumentType;
|
||||
import exopandora.worldhandler.usercontent.model.JsonArgument;
|
||||
|
||||
public class ArgumentFactory
|
||||
{
|
||||
private static final Map<ArgumentType, Supplier<IDeserializableArgument>> FACTORY = new HashMap<ArgumentType, Supplier<IDeserializableArgument>>();
|
||||
|
||||
static
|
||||
{
|
||||
FACTORY.put(ArgumentType.SHORT, Arguments::shortArg);
|
||||
FACTORY.put(ArgumentType.BYTE, Arguments::byteArg);
|
||||
FACTORY.put(ArgumentType.INT, Arguments::intArg);
|
||||
FACTORY.put(ArgumentType.FLOAT, Arguments::floatArg);
|
||||
FACTORY.put(ArgumentType.DOUBLE, Arguments::doubleArg);
|
||||
FACTORY.put(ArgumentType.LONG, Arguments::longArg);
|
||||
FACTORY.put(ArgumentType.BOOLEAN, Arguments::boolArg);
|
||||
FACTORY.put(ArgumentType.WORD, Arguments::word);
|
||||
FACTORY.put(ArgumentType.STRING, Arguments::string);
|
||||
FACTORY.put(ArgumentType.GREEDY_STRING, Arguments::greedyString);
|
||||
FACTORY.put(ArgumentType.RESOURCE_LOCATION, Arguments::resourceLocation);
|
||||
FACTORY.put(ArgumentType.ITEM, Arguments::item);
|
||||
FACTORY.put(ArgumentType.BLOCKSTATE, Arguments::blockState);
|
||||
FACTORY.put(ArgumentType.BLOCKPREDICATE, Arguments::blockPredicate);
|
||||
FACTORY.put(ArgumentType.NBT, Arguments::tag);
|
||||
FACTORY.put(ArgumentType.COORDINATE_INT, Arguments::intCoordinate);
|
||||
FACTORY.put(ArgumentType.COORDINATE_DOUBLE, Arguments::doubleCoordinate);
|
||||
FACTORY.put(ArgumentType.PLAYER, Arguments::word);
|
||||
FACTORY.put(ArgumentType.RANGE_INT, Arguments::intRange);
|
||||
FACTORY.put(ArgumentType.RANGE_DOUBLE, Arguments::doubleRange);
|
||||
FACTORY.put(ArgumentType.ANGLE, Arguments::angle);
|
||||
FACTORY.put(ArgumentType.ENCHANTMENT, Arguments::enchantment);
|
||||
FACTORY.put(ArgumentType.ENTITY, Arguments::entitySummon);
|
||||
FACTORY.put(ArgumentType.GAMEMODE, Arguments::gamemode);
|
||||
FACTORY.put(ArgumentType.TIME, Arguments::time);
|
||||
FACTORY.put(ArgumentType.EFFECT, Arguments::effect);
|
||||
FACTORY.put(ArgumentType.AXIS, Arguments::axis);
|
||||
FACTORY.put(ArgumentType.ANCHOR, Arguments::anchor);
|
||||
FACTORY.put(ArgumentType.DIFFICULTY, Arguments::difficulty);
|
||||
FACTORY.put(ArgumentType.RENDER_TYPE, Arguments::renderType);
|
||||
FACTORY.put(ArgumentType.OPERATION, Arguments::operation);
|
||||
FACTORY.put(ArgumentType.TEXT_COMPONENT, Arguments::textComponent);
|
||||
FACTORY.put(ArgumentType.RELATION, Arguments::relation);
|
||||
FACTORY.put(ArgumentType.TYPE, Arguments::type);
|
||||
FACTORY.put(ArgumentType.LINKAGE, Arguments::linkage);
|
||||
FACTORY.put(ArgumentType.NBT_PATH, Arguments::nbtPath);
|
||||
FACTORY.put(ArgumentType.ITEM_PREDICATE, Arguments::itemPredicate);
|
||||
FACTORY.put(ArgumentType.CRITERIA, Arguments::criteria);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static IDeserializableArgument createArgument(JsonArgument json)
|
||||
{
|
||||
Supplier<IDeserializableArgument> supplier = FACTORY.get(json.getType());
|
||||
|
||||
if(supplier == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return supplier.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package exopandora.worldhandler.usercontent.model;
|
||||
|
||||
public enum ArgumentType
|
||||
{
|
||||
SHORT,
|
||||
BYTE,
|
||||
INT,
|
||||
FLOAT,
|
||||
DOUBLE,
|
||||
LONG,
|
||||
BOOLEAN,
|
||||
WORD,
|
||||
STRING,
|
||||
GREEDY_STRING,
|
||||
RESOURCE_LOCATION,
|
||||
ITEM,
|
||||
BLOCKSTATE,
|
||||
BLOCKPREDICATE,
|
||||
NBT,
|
||||
COORDINATE_INT,
|
||||
COORDINATE_DOUBLE,
|
||||
PLAYER,
|
||||
RANGE_INT,
|
||||
RANGE_DOUBLE,
|
||||
ANGLE,
|
||||
ENCHANTMENT,
|
||||
ENTITY,
|
||||
GAMEMODE,
|
||||
TIME,
|
||||
EFFECT,
|
||||
AXIS,
|
||||
ANCHOR,
|
||||
DIFFICULTY,
|
||||
RENDER_TYPE,
|
||||
OPERATION,
|
||||
TEXT_COMPONENT,
|
||||
RELATION,
|
||||
TYPE,
|
||||
LINKAGE,
|
||||
NBT_PATH,
|
||||
ITEM_PREDICATE,
|
||||
CRITERIA;
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package exopandora.worldhandler.usercontent.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class JsonArgument
|
||||
{
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
@SerializedName("label")
|
||||
private String label;
|
||||
|
||||
@SerializedName("type")
|
||||
private ArgumentType type;
|
||||
|
||||
@SerializedName("children")
|
||||
private List<JsonArgument> children;
|
||||
|
||||
public JsonArgument(String name, String label, ArgumentType type, List<JsonArgument> children)
|
||||
{
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.type = type;
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getLabel()
|
||||
{
|
||||
return this.label;
|
||||
}
|
||||
|
||||
public void setLabel(String label)
|
||||
{
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public ArgumentType getType()
|
||||
{
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(ArgumentType type)
|
||||
{
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<JsonArgument> getChildren()
|
||||
{
|
||||
return this.children;
|
||||
}
|
||||
|
||||
public void setChildren(List<JsonArgument> children)
|
||||
{
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public void validate()
|
||||
{
|
||||
this.validate(this.name, new HashMap<String, ArgumentType>());
|
||||
}
|
||||
|
||||
private void validate(String path, Map<String, ArgumentType> typeMap)
|
||||
{
|
||||
if(this.name == null)
|
||||
{
|
||||
throw new IllegalStateException("Argument in path \"" + path + "\" has no name");
|
||||
}
|
||||
|
||||
if(this.children == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<ArgumentType> types = new ArrayList<ArgumentType>();
|
||||
List<String> names = new ArrayList<String>();
|
||||
|
||||
for(JsonArgument child : this.children)
|
||||
{
|
||||
if(child.getType() != null)
|
||||
{
|
||||
if(types.contains(child.getType()))
|
||||
{
|
||||
throw new IllegalStateException("\"" + path + "\" contains two or more branches with the same argument type \"" + child.getType() + "\"");
|
||||
}
|
||||
|
||||
types.add(child.getType());
|
||||
}
|
||||
|
||||
if(names.contains(child.getName()))
|
||||
{
|
||||
throw new IllegalStateException("\"" + path + "\" contains two or more branches with the same argument name \"" + child.getName() + "\"");
|
||||
}
|
||||
|
||||
if(child.getType() != null)
|
||||
{
|
||||
if(typeMap.containsKey(child.getName()) && !child.getType().equals(typeMap.get(child.getName())))
|
||||
{
|
||||
throw new IllegalStateException("\"" + path + "\" expects a different type for argument \"" + child.getName() + "\"");
|
||||
}
|
||||
|
||||
typeMap.put(child.getName(), child.getType());
|
||||
}
|
||||
|
||||
child.validate(path + "/" + child.getName(), typeMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user