diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..f811f6a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Disable autocrlf on generated files, they always generate with LF +# Add any extra files or paths here to make git stop saying they +# are changed when only line endings change. +src/generated/**/.cache/cache text eol=lf +src/generated/**/*.json text eol=lf diff --git a/.gitignore b/.gitignore index 4c34b44..238a096 100644 --- a/.gitignore +++ b/.gitignore @@ -1,15 +1,129 @@ -# Ignore Everything -/* +### Eclipse ### +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders -# Except +# External tool builders +.externalToolBuilders/ -!/src/main/ -!/gradle/ -!/run/config/worldhandler/usercontent/ -!build.gradle -!curseforge.html -!gradlew -!gradlew.bat -!LICENSE.txt -!README.md -!version.json \ No newline at end of file +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ +.apt_generated_test/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +# Uncomment this line if you wish to ignore the project description file. +# Typically, this file would be tracked if it contains build/dependency configurations: +#.project + +### Eclipse Patch ### +# Spring Boot Tooling +.sts4-cache/ + +### ForgeGradle ### +# Minecraft client/server files +run/ + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +### Gradle ### +.gradle +build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties + +### Gradle Patch ### +**/build/ + +# Eclipse Gradle plugin generated files +# Eclipse Core +.project +# JDT-specific (Eclipse Java Development Tools) +.classpath + +### Wiki ### +wiki/ + +### Test ### +src/test/ + +### ForgeGradle ### +run/ +bin/ diff --git a/src/main/java/exopandora/worldhandler/builder/CommandNode.java b/src/main/java/exopandora/worldhandler/builder/CommandNode.java new file mode 100644 index 0000000..9102cfe --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/CommandNode.java @@ -0,0 +1,119 @@ +package exopandora.worldhandler.builder; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.argument.IArgument; + +public abstract class CommandNode> +{ + private final String name; + private CommandNode parent; + private List> children; + private Object label; + + protected CommandNode(String name) + { + if(name == null || name.isBlank()) + { + throw new IllegalArgumentException("Name cannot be null or blank"); + } + + this.name = name; + } + + public T then(CommandNode node) + { + if(this.children == null) + { + this.children = new ArrayList>(); + } + + node.parent = this.getThis(); + this.children.add(node); + return this.getThis(); + } + + public T label(Object label) + { + this.label = label; + return this.getThis(); + } + + public Optional> find(Object label) + { + if(label != null && label.equals(this.label)) + { + return Optional.of(this.getThis()); + } + + if(this.hasChildren()) + { + for(CommandNode child : this.children) + { + Optional> result = child.find(label); + + if(result.isPresent()) + { + return result; + } + } + } + + return Optional.empty(); + } + + public String getName() + { + return this.name; + } + + @Nullable + public Object getLabel() + { + return this.label; + } + + public boolean isOptional(Object label) + { + return this.parent.label != null && (this.label != null && this.label.equals(label) || this.parent.label.equals(label)); + } + + @Nullable + public CommandNode getParent() + { + return this.parent; + } + + @Nullable + public List> getChildren() + { + return this.children; + } + + public boolean hasChildren() + { + return this.children != null && !this.children.isEmpty(); + } + + public abstract boolean isDefault(Object label); + + public abstract String toKey(Object label); + + public abstract String toValue(Object label); + + protected abstract T getThis(); + + public static CommandNodeLiteral literal(String label) + { + return new CommandNodeLiteral(label); + } + + public static CommandNodeArgument argument(String label, IArgument argument) + { + return new CommandNodeArgument(label, argument); + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/CommandNodeArgument.java b/src/main/java/exopandora/worldhandler/builder/CommandNodeArgument.java new file mode 100644 index 0000000..ab3c3b1 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/CommandNodeArgument.java @@ -0,0 +1,60 @@ +package exopandora.worldhandler.builder; + +import exopandora.worldhandler.builder.argument.IArgument; + +public class CommandNodeArgument extends CommandNode +{ + private final IArgument argument; + + protected CommandNodeArgument(String name, IArgument value) + { + super(name); + this.argument = value; + } + + @Override + public String toKey(Object label) + { + if(this.isOptional(label)) + { + return "[" + this.getName() + "]"; + } + + return "<" + this.getName() + ">"; + } + + @Override + public String toValue(Object label) + { + if(this.argument == null || this.argument.isDefault()) + { + return this.toKey(label); + } + + String argument = this.argument.serialize(); + + if(argument != null) + { + return argument; + } + + return this.toKey(label); + } + + @Override + public boolean isDefault(Object label) + { + if(this.argument != null) + { + return this.argument.isDefault(); + } + + return true; + } + + @Override + protected CommandNodeArgument getThis() + { + return this; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/CommandNodeLiteral.java b/src/main/java/exopandora/worldhandler/builder/CommandNodeLiteral.java new file mode 100644 index 0000000..dcf0677 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/CommandNodeLiteral.java @@ -0,0 +1,33 @@ +package exopandora.worldhandler.builder; + +public class CommandNodeLiteral extends CommandNode +{ + protected CommandNodeLiteral(String literal) + { + super(literal); + } + + @Override + public boolean isDefault(Object label) + { + return false; + } + + @Override + public String toKey(Object label) + { + return this.getName(); + } + + @Override + public String toValue(Object label) + { + return this.getName(); + } + + @Override + protected CommandNodeLiteral getThis() + { + return this; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/argument/AngleArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/AngleArgument.java new file mode 100644 index 0000000..096aaa0 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/AngleArgument.java @@ -0,0 +1,102 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.coordinates.WorldCoordinate; + +public class AngleArgument implements IDeserializableArgument +{ + private Float angle; + private boolean relative; + + protected AngleArgument() + { + super(); + } + + public void setAngle(@Nullable Float angle) + { + this.angle = angle; + } + + public void setRelative(boolean relative) + { + this.relative = relative; + } + + public void setAngle(@Nullable Float angle, boolean relative) + { + this.angle = angle; + this.relative = relative; + } + + @Nullable + public Float getAngle() + { + return this.angle; + } + + public boolean isRelative() + { + return this.relative; + } + + @Override + public void deserialize(@Nullable String string) + { + if(string == null) + { + this.reset(); + } + else + { + try + { + StringReader reader = new StringReader(string); + boolean relative = WorldCoordinate.isRelative(reader); + float angle = reader.canRead() && reader.peek() != ' ' ? reader.readFloat() : 0.0F; + + if(!Float.isNaN(angle) && !Float.isInfinite(angle)) + { + this.angle = angle; + this.relative = relative; + } + else + { + this.reset(); + } + } + catch(CommandSyntaxException e) + { + this.reset(); + } + } + } + + private void reset() + { + this.angle = null; + this.relative = false; + } + + @Override + @Nullable + public String serialize() + { + if(this.angle == null) + { + return null; + } + + return this.relative ? "~" : "" + Float.toString(this.angle); + } + + @Override + public boolean isDefault() + { + return this.angle == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/ArgumentListArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/ArgumentListArgument.java new file mode 100644 index 0000000..4d71725 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/ArgumentListArgument.java @@ -0,0 +1,63 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.CommandBuilder; + +public class ArgumentListArgument implements IArgument +{ + private final List> arguments = new ArrayList>(); + + public void add(OptionalCommandBuilder argument) + { + this.arguments.add(argument); + } + + @Override + @Nullable + public String serialize() + { + if(this.arguments.isEmpty()) + { + return null; + } + + return this.arguments.stream().map(builder -> builder.toCommand(builder.getLabel(), false)).collect(Collectors.joining(" ")); + } + + @Override + public boolean isDefault() + { + return this.arguments.isEmpty(); + } + + public abstract static class OptionalCommandBuilder extends CommandBuilder + { + private T label; + + public OptionalCommandBuilder(T label) + { + this.label = label; + } + + public void setLabel(T label) + { + this.label = label; + } + + public T getLabel() + { + return this.label; + } + + @Override + public String toCommand(Object label, boolean preview) + { + return super.toCommand(label, preview).substring(1); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/Arguments.java b/src/main/java/exopandora/worldhandler/builder/argument/Arguments.java new file mode 100644 index 0000000..3b90f3c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/Arguments.java @@ -0,0 +1,338 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.function.Function; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.arguments.StringArgumentType; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Linkage; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Operation; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Relation; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Type; +import exopandora.worldhandler.util.EnumHelper; +import net.minecraft.advancements.critereon.MinMaxBounds; +import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor; +import net.minecraft.core.Direction.Axis; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.Difficulty; +import net.minecraft.world.scores.criteria.ObjectiveCriteria.RenderType; + +public class Arguments +{ + public static PrimitiveArgument shortArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Short.parseShort(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument byteArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Byte.parseByte(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument intArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Integer.parseInt(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument floatArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Float.parseFloat(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument doubleArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Double.parseDouble(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument longArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Long.parseLong(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument boolArg() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Boolean.parseBoolean(string); + } + catch(NumberFormatException e) + { + return null; + } + }).build(); + } + + public static PrimitiveArgument string() + { + return new PrimitiveArgument.Builder(Function.identity()) + .serializer(string -> string.isBlank() ? null : StringArgumentType.escapeIfRequired(string)) + .build(); + } + + public static PrimitiveArgument greedyString() + { + return new PrimitiveArgument.Builder(string -> string == null || string.isBlank() ? null : string) + .serializer(string -> string.isBlank() ? null : string) + .defaultOverride(string -> string == null || string.isBlank()) + .build(); + } + + public static PrimitiveArgument word() + { + return new PrimitiveArgument.Builder(string -> string == null || string.isBlank() ? null : string) + .serializer(string -> string.isBlank() ? null : string.replaceAll("[^0-9A-Za-z_\\-.+]", "_")) + .defaultOverride(string -> string == null || string.isBlank()) + .build(); + } + + public static PrimitiveArgument resourceLocation() + { + return new PrimitiveArgument.Builder(string -> string.isEmpty() ? null : new ResourceLocation(string)).build(); + } + + public static ItemArgument item() + { + return new ItemArgument(); + } + + public static BlockStateArgument blockState() + { + return new BlockStateArgument(); + } + + public static BlockPredicateArgument blockPredicate() + { + return new BlockPredicateArgument(); + } + + public static TagArgument tag() + { + return new TagArgument(); + } + + public static PrimitiveArgument> intCoordinate() + { + return new PrimitiveArgument.Builder>(Coordinate.Ints::parse).build(); + } + + public static PrimitiveArgument> doubleCoordinate() + { + return new PrimitiveArgument.Builder>(Coordinate.Doubles::parse).build(); + } + + public static RangeArgument intRange() + { + return new RangeArgument(string -> + { + try + { + return MinMaxBounds.Ints.fromReader(new StringReader(string)); + } + catch(CommandSyntaxException e) + { + return null; + } + }); + } + + public static RangeArgument doubleRange() + { + return new RangeArgument(string -> + { + try + { + return MinMaxBounds.Doubles.fromReader(new StringReader(string)); + } + catch(CommandSyntaxException e) + { + return null; + } + }); + } + + public static AngleArgument angle() + { + return new AngleArgument(); + } + + public static EnchantmentArgument enchantment() + { + return new EnchantmentArgument(); + } + + public static EntitySummonArgument entitySummon() + { + return new EntitySummonArgument(); + } + + public static PrimitiveArgument gamemode() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Gamemode.values(), Gamemode::toString)).build(); + } + + public static TimeArgument time() + { + return new TimeArgument(); + } + + public static EffectArgument effect() + { + return new EffectArgument(); + } + + public static PrimitiveArgument axis() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Axis.values(), Axis::getName)) + .serializer(Axis::getName) + .build(); + } + + public static PrimitiveArgument anchor() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Anchor.values(), anchor -> anchor.name)) + .serializer(anchor -> anchor.name) + .build(); + } + + public static PrimitiveArgument difficulty() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Difficulty.values(), Difficulty::getKey)) + .serializer(Difficulty::getKey) + .build(); + } + + public static PrimitiveArgument renderType() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, RenderType.values(), RenderType::getId)) + .serializer(RenderType::getId) + .build(); + } + + public static PrimitiveArgument operation() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Operation.values(), Operation::toString)).build(); + } + + public static PrimitiveArgument textComponent() + { + return new PrimitiveArgument.Builder(string -> + { + try + { + return Component.Serializer.fromJson(string); + } + catch(Exception e) + { + return new TextComponent(string); + } + }).serializer(Component.Serializer::toJson).build(); + } + + public static PrimitiveArgument relation() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Relation.values(), Relation::toString)).build(); + } + + public static PrimitiveArgument type() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Type.values(), Type::toString)).build(); + } + + public static PrimitiveArgument linkage() + { + return new PrimitiveArgument.Builder(string -> EnumHelper.find(string, Linkage.values(), Linkage::toString)).build(); + } + + public static NbtPathArgument nbtPath() + { + return new NbtPathArgument(); + } + + public static ItemPredicateArgument itemPredicate() + { + return new ItemPredicateArgument(); + } + + public static PrimitiveArgument criteria() + { + return new PrimitiveArgument.Builder(string -> string == null || string.isBlank() ? null : string) + .serializer(string -> string.isBlank() ? null : string.replaceAll(" ", "_")) + .defaultOverride(string -> string == null || string.isBlank()) + .build(); + } + + public static TargetArgument target() + { + return new TargetArgument(); + } + + public static BlockPosArgument blockPos() + { + return new BlockPosArgument(); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/BlockPosArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/BlockPosArgument.java new file mode 100644 index 0000000..4657c1c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/BlockPosArgument.java @@ -0,0 +1,95 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import net.minecraft.core.BlockPos; + +public class BlockPosArgument implements IArgument +{ + private Coordinate x; + private Coordinate y; + private Coordinate z; + + protected BlockPosArgument() + { + super(); + } + + public void setX(@Nullable Coordinate x) + { + this.x = x; + } + + public void setY(@Nullable Coordinate y) + { + this.y = y; + } + + public void setZ(@Nullable Coordinate z) + { + this.z = z; + } + + public void set(@Nullable BlockPos pos) + { + if(pos != null) + { + this.x = new Coordinate.Ints(pos.getX()); + this.y = new Coordinate.Ints(pos.getY()); + this.z = new Coordinate.Ints(pos.getZ()); + } + else + { + this.x = null; + this.y = null; + this.z = null; + } + } + + @Nullable + public Coordinate getX() + { + return this.x; + } + + @Nullable + public Coordinate getY() + { + return this.y; + } + + @Nullable + public Coordinate getZ() + { + return this.z; + } + + @Nullable + public BlockPos getBlockPos() + { + if(this.x == null && this.y == null && this.z == null) + { + return null; + } + + return new BlockPos(this.x.getValue().doubleValue(), this.y.getValue().doubleValue(), this.z.getValue().doubleValue()); + } + + @Override + @Nullable + public String serialize() + { + if(this.x == null || this.y == null || this.z == null) + { + return null; + } + + return this.x.serialize() + " " + this.y.serialize() + " " + this.z.serialize(); + } + + @Override + public boolean isDefault() + { + return this.x == null && this.y == null && this.z == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/BlockPredicateArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/BlockPredicateArgument.java new file mode 100644 index 0000000..49148d8 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/BlockPredicateArgument.java @@ -0,0 +1,218 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.AbstractMap.SimpleEntry; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.blocks.BlockStateParser; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.Property; + +public class BlockPredicateArgument extends TagArgument +{ + private ResourceLocation resource; + private boolean isTag; + private Map properties; + + protected BlockPredicateArgument() + { + super(); + } + + public void set(@Nullable ResourceLocation resource) + { + this.resource = resource; + } + + public void set(@Nullable BlockState state) + { + if(state != null) + { + this.resource = state.getBlock().getRegistryName(); + this.properties = propertiesToString(state.getValues()); + } + else + { + this.resource = null; + this.properties = null; + } + + this.isTag = false; + } + + public void set(@Nullable Map, Comparable> properties) + { + if(properties != null) + { + this.properties = propertiesToString(properties); + } + else + { + this.properties = null; + } + } + + public void set(Property key, @Nullable Comparable value) + { + String name = key.getName(); + + if(value == null) + { + if(this.properties != null && this.properties.containsKey(name)) + { + this.properties.remove(name); + } + } + else + { + if(this.properties == null) + { + this.properties = new HashMap(); + } + + this.properties.put(name, getName(key, value)); + } + } + + public void set(@Nullable BlockState state, CompoundTag tag) + { + this.set(state); + this.setTag(tag); + this.isTag = false; + } + + public void set(boolean isTag) + { + this.isTag = isTag; + } + + @Nullable + public ResourceLocation getResourceLocation() + { + return this.resource; + } + + public boolean isTag() + { + return this.isTag; + } + + public Map getProperties() + { + if(this.properties == null) + { + return Collections.emptyMap(); + } + + return Collections.unmodifiableMap(this.properties); + } + + @Override + public void deserialize(@Nullable String predicate) + { + if(predicate == null) + { + this.reset(); + } + else + { + try + { + BlockStateParser parser = new BlockStateParser(new StringReader(predicate), true).parse(true); + + if(parser.getState() != null) + { + this.resource = parser.getState().getBlock().getRegistryName(); + this.isTag = false; + this.properties = propertiesToString(parser.getProperties()); + this.setTag(parser.getNbt()); + } + else + { + this.resource = parser.getTag(); + this.isTag = true; + this.properties = parser.getVagueProperties(); + this.setTag(parser.getNbt()); + } + } + catch(CommandSyntaxException e) + { + this.reset(); + } + } + } + + private void reset() + { + this.resource = null; + this.properties = null; + this.isTag = false; + this.setTag(null); + } + + @Override + @Nullable + public String serialize() + { + if(this.resource == null || this.resource.getPath().isEmpty()) + { + return null; + } + + StringBuilder builder = new StringBuilder(); + + if(this.isTag) + { + builder.append('#'); + } + + builder.append(this.resource.toString()); + + if(this.properties != null && !this.properties.isEmpty()) + { + builder.append('['); + builder.append(this.properties.entrySet().stream().map(entry -> entry.getKey() + "=" + entry.getValue()).collect(Collectors.joining(","))); + builder.append(']'); + } + + String nbt = super.serialize(); + + if(nbt != null) + { + builder.append(nbt); + } + + return builder.toString(); + } + + @Override + public boolean isDefault() + { + return super.isDefault() && this.resource == null && (this.properties == null || this.properties.isEmpty()); + } + + private static Map propertiesToString(Map, Comparable> properties) + { + return properties.entrySet().stream().map(entry -> + { + Property property = entry.getKey(); + return new SimpleEntry(property.getName(), getName(property, entry.getValue())); + }).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); + } + + @SuppressWarnings("unchecked") + private static > String getName(Property key, Comparable value) + { + return key.getName((T) value); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/BlockStateArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/BlockStateArgument.java new file mode 100644 index 0000000..c74ab5e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/BlockStateArgument.java @@ -0,0 +1,120 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.blocks.BlockStateParser; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraftforge.registries.ForgeRegistries; + +public class BlockStateArgument extends TagArgument +{ + private BlockState state; + + protected BlockStateArgument() + { + super(); + } + + public void set(@Nullable ResourceLocation block) + { + if(block != null) + { + this.set(ForgeRegistries.BLOCKS.getValue(block)); + } + else + { + this.state = null; + } + } + + public void set(@Nullable Block block) + { + if(block != null) + { + this.state = block.defaultBlockState(); + } + else + { + this.state = null; + } + } + + public void set(@Nullable BlockState state) + { + this.state = state; + } + + public void set(@Nullable BlockState state, CompoundTag tag) + { + this.set(state); + this.setTag(tag); + } + + @Nullable + public BlockState getBlockState() + { + return this.state; + } + + @Override + public void deserialize(@Nullable String block) + { + if(block == null) + { + this.reset(); + } + else + { + try + { + BlockStateParser parser = new BlockStateParser(new StringReader(block), false).parse(true); + this.state = parser.getState(); + this.setTag(parser.getNbt()); + } + catch(CommandSyntaxException e) + { + this.reset(); + } + } + } + + private void reset() + { + this.state = null; + this.setTag(null); + } + + @Override + @Nullable + public String serialize() + { + if(this.state == null) + { + return null; + } + + StringBuilder builder = new StringBuilder(this.state.toString()); + String block = this.state.getBlock().toString(); + builder.replace(0, block.length(), this.state.getBlock().getRegistryName().toString()); + String nbt = super.serialize(); + + if(nbt != null && this.state.hasBlockEntity()) + { + builder.append(nbt); + } + + return builder.toString(); + } + + @Override + public boolean isDefault() + { + return super.isDefault() && this.state == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/CommandArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/CommandArgument.java new file mode 100644 index 0000000..a74dd90 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/CommandArgument.java @@ -0,0 +1,52 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.ICommandBuilder; + +public class CommandArgument implements IArgument +{ + private ICommandBuilder command; + private Object label; + + public void set(ICommandBuilder command, Object label) + { + this.command = command; + this.label = label; + } + + public void set(Object label) + { + this.label = label; + } + + @Nullable + public ICommandBuilder getCommand() + { + return this.command; + } + + @Nullable + public Object getLabel() + { + return this.label; + } + + @Override + @Nullable + public String serialize() + { + if(this.command == null) + { + return null; + } + + return this.command.toCommand(this.label, false).substring(1); + } + + @Override + public boolean isDefault() + { + return false; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/Coordinate.java b/src/main/java/exopandora/worldhandler/builder/argument/Coordinate.java new file mode 100644 index 0000000..c23bf45 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/Coordinate.java @@ -0,0 +1,191 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.coordinates.LocalCoordinates; +import net.minecraft.commands.arguments.coordinates.WorldCoordinate; + +public abstract class Coordinate +{ + protected T value; + protected Type type; + + protected Coordinate(T value) + { + this(value, Type.ABSOLUTE); + } + + protected Coordinate(T value, Type type) + { + this.value = value; + this.type = type; + } + + public void setValue(T value) + { + this.value = value; + } + + public T getValue() + { + return this.value; + } + + public void setType(Type type) + { + this.type = type; + } + + public Type getType() + { + return this.type; + } + + @Nullable + public String serialize() + { + if(this.value == null) + { + return null; + } + + if(this.zero().equals(this.value) && !Type.ABSOLUTE.equals(this.type)) + { + return this.type.getPrefix(); + } + + return this.type.getPrefix() + this.value.toString(); + } + + public abstract T zero(); + + public static class Ints extends Coordinate + { + public static final Ints ZERO = new Ints(); + + public Ints() + { + super(0); + } + + public Ints(Integer value) + { + super(value); + } + + public Ints(Type type) + { + super(0, type); + } + + public Ints(Integer value, Type type) + { + super(value, type); + } + + @Override + public Integer zero() + { + return 0; + } + + @Nullable + public static Ints parse(String string) + { + try + { + StringReader reader = new StringReader(string); + + if(reader.canRead() && reader.peek() == '^') + { + return new Coordinate.Ints((int) LocalCoordinates.readDouble(reader, 0), Coordinate.Type.LOCAL); + } + else + { + WorldCoordinate wc = WorldCoordinate.parseInt(reader); + return new Coordinate.Ints((int) wc.get(0), wc.isRelative() ? Coordinate.Type.RELATIVE : Coordinate.Type.ABSOLUTE); + } + } + catch(CommandSyntaxException e) + { + return null; + } + } + } + + public static class Doubles extends Coordinate + { + public static final Doubles ZERO = new Doubles(); + + public Doubles() + { + super(0.0D); + } + + public Doubles(Double value) + { + super(value); + } + + public Doubles(Type type) + { + super(0.0D, type); + } + + public Doubles(Double value, Type type) + { + super(value, type); + } + + @Override + public Double zero() + { + return 0.0D; + } + + @Nullable + public static Doubles parse(String string) + { + try + { + StringReader reader = new StringReader(string); + + if(reader.canRead() && reader.peek() == '^') + { + return new Coordinate.Doubles(LocalCoordinates.readDouble(reader, 0), Coordinate.Type.LOCAL); + } + else + { + WorldCoordinate wc = WorldCoordinate.parseInt(reader); + return new Coordinate.Doubles(wc.get(0), wc.isRelative() ? Coordinate.Type.RELATIVE : Coordinate.Type.ABSOLUTE); + } + } + catch(CommandSyntaxException e) + { + return null; + } + } + } + + public static enum Type + { + ABSOLUTE(""), + RELATIVE("~"), + LOCAL("^"); + + private final String prefix; + + private Type(String prefix) + { + this.prefix = prefix; + } + + public String getPrefix() + { + return this.prefix; + } + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/DimensionArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/DimensionArgument.java new file mode 100644 index 0000000..7ab6094 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/DimensionArgument.java @@ -0,0 +1,71 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.util.ResourceHelper; +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.Level; + +public class DimensionArgument implements IDeserializableArgument +{ + private ResourceKey dimension; + + protected DimensionArgument() + { + super(); + } + + public void set(@Nullable ResourceKey dimension) + { + this.dimension = dimension; + } + + public void set(@Nullable ResourceLocation dimension) + { + if(dimension != null) + { + this.set(ResourceKey.create(Registry.DIMENSION_REGISTRY, dimension)); + } + else + { + this.dimension = null; + } + } + + @Nullable + public ResourceKey getDimension() + { + return this.dimension; + } + + @Override + public void deserialize(@Nullable String string) + { + this.set(ResourceHelper.stringToResourceLocation(string)); + } + + @Override + @Nullable + public String serialize() + { + if(this.dimension == null) + { + return null; + } + + return this.dimension.getRegistryName().toString(); + } + + @Override + public boolean isDefault() + { + return false; + } + + public static DimensionArgument dimension() + { + return new DimensionArgument(); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/EffectArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/EffectArgument.java new file mode 100644 index 0000000..04899ff --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/EffectArgument.java @@ -0,0 +1,65 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.util.ResourceHelper; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffect; +import net.minecraftforge.registries.ForgeRegistries; + +public class EffectArgument implements IDeserializableArgument +{ + private MobEffect effect; + + protected EffectArgument() + { + super(); + } + + public void set(@Nullable MobEffect effect) + { + this.effect = effect; + } + + public void set(@Nullable ResourceLocation effect) + { + if(effect != null) + { + this.set(ForgeRegistries.MOB_EFFECTS.getValue(effect)); + } + else + { + this.effect = null; + } + } + + @Nullable + public MobEffect getEffect() + { + return this.effect; + } + + @Override + public void deserialize(@Nullable String string) + { + this.set(ResourceHelper.stringToResourceLocation(string)); + } + + @Override + @Nullable + public String serialize() + { + if(this.effect == null) + { + return null; + } + + return this.effect.getRegistryName().toString(); + } + + @Override + public boolean isDefault() + { + return this.effect == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/EnchantmentArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/EnchantmentArgument.java new file mode 100644 index 0000000..c43fa3a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/EnchantmentArgument.java @@ -0,0 +1,65 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.util.ResourceHelper; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraftforge.registries.ForgeRegistries; + +public class EnchantmentArgument implements IDeserializableArgument +{ + private Enchantment enchantment; + + protected EnchantmentArgument() + { + super(); + } + + public void set(@Nullable Enchantment enchantment) + { + this.enchantment = enchantment; + } + + public void set(@Nullable ResourceLocation enchantment) + { + if(enchantment != null) + { + this.set(ForgeRegistries.ENCHANTMENTS.getValue(enchantment)); + } + else + { + this.enchantment = null; + } + } + + @Nullable + public Enchantment getEnchantment() + { + return this.enchantment; + } + + @Override + public void deserialize(@Nullable String string) + { + this.set(ResourceHelper.stringToResourceLocation(string)); + } + + @Override + @Nullable + public String serialize() + { + if(this.enchantment == null) + { + return null; + } + + return this.enchantment.getRegistryName().toString(); + } + + @Override + public boolean isDefault() + { + return false; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/EntitySummonArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/EntitySummonArgument.java new file mode 100644 index 0000000..4591754 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/EntitySummonArgument.java @@ -0,0 +1,134 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.util.ResourceHelper; +import net.minecraft.Util; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EntityType; +import net.minecraftforge.registries.ForgeRegistries; + +public class EntitySummonArgument implements IDeserializableArgument +{ + private static final Map ALIASES = Util.make(new HashMap(), map -> + { + map.put("RedCow", EntityType.MOOSHROOM.getRegistryName()); + map.put("ChickenJockey", EntityType.CHICKEN.getRegistryName()); + map.put("Pigman", EntityType.PIGLIN.getRegistryName()); + map.put("ZombiePig", EntityType.PIGLIN.getRegistryName()); + map.put("ZombiePigman", EntityType.PIGLIN.getRegistryName()); + map.put("Dog", EntityType.WOLF.getRegistryName()); + map.put("Dragon", EntityType.ENDER_DRAGON.getRegistryName()); + map.put("SnowMan", EntityType.SNOW_GOLEM.getRegistryName()); + map.put("LavaCube", EntityType.MAGMA_CUBE.getRegistryName()); + map.put("MagmaSlime", EntityType.MAGMA_CUBE.getRegistryName()); + map.put("LavaSlime", EntityType.MAGMA_CUBE.getRegistryName()); + map.put("SpiderJockey", EntityType.SPIDER.getRegistryName()); + map.put("VillagerGolem", EntityType.IRON_GOLEM.getRegistryName()); + map.put("Ozelot", EntityType.OCELOT.getRegistryName()); + map.put("Kitty", EntityType.CAT.getRegistryName()); + map.put("Kitten", EntityType.CAT.getRegistryName()); + map.put("TESTIFICATE", EntityType.VILLAGER.getRegistryName()); + map.put("Octopus", EntityType.SQUID.getRegistryName()); + map.put("GlowingOctopus", EntityType.SQUID.getRegistryName()); + map.put("Exwife", EntityType.GHAST.getRegistryName()); + map.put("CommandMinecart", EntityType.COMMAND_BLOCK_MINECART.getRegistryName()); + map.put("Wizard", EntityType.EVOKER.getRegistryName()); + map.put("Johnny", EntityType.VINDICATOR.getRegistryName()); + map.put("BabyZombie", EntityType.ZOMBIE.getRegistryName()); + + ForgeRegistries.PROFESSIONS.getKeys().stream().forEach(profession -> map.put(profession.getPath(), EntityType.VILLAGER.getRegistryName())); + }); + + private EntityType entity; + + protected EntitySummonArgument() + { + super(); + } + + public void set(@Nullable EntityType entity) + { + if(entity != null && entity.canSummon()) + { + this.entity = entity; + } + else + { + this.entity = null; + } + } + + public void set(@Nullable ResourceLocation entity) + { + if(entity != null) + { + EntityType type = ForgeRegistries.ENTITIES.getValue(entity); + + if(!ForgeRegistries.ENTITIES.getDefaultKey().equals(type.getRegistryName()) || type.getRegistryName().equals(entity)) + { + this.set(type); + } + else + { + this.entity = null; + } + } + else + { + this.entity = null; + } + } + + @Nullable + public EntityType getEntity() + { + return this.entity; + } + + @Override + public void deserialize(@Nullable String entity) + { + if(entity == null) + { + this.entity = null; + } + else + { + String stripped = entity.replace(" ", ""); + + for(Entry entry : ALIASES.entrySet()) + { + if(entry.getKey().equalsIgnoreCase(stripped)) + { + this.set(entry.getValue()); + return; + } + } + + this.set(ResourceHelper.stringToResourceLocation(entity)); + } + } + + @Override + @Nullable + public String serialize() + { + if(this.entity == null) + { + return null; + } + + return this.entity.getRegistryName().toString(); + } + + @Override + public boolean isDefault() + { + return this.entity == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/Gamemode.java b/src/main/java/exopandora/worldhandler/builder/argument/Gamemode.java new file mode 100644 index 0000000..3ea47b7 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/Gamemode.java @@ -0,0 +1,15 @@ +package exopandora.worldhandler.builder.argument; + +public enum Gamemode +{ + SURVIVAL, + CREATIVE, + ADVENTURE, + SPECTATOR; + + @Override + public String toString() + { + return this.name().toLowerCase(); + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/argument/IArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/IArgument.java new file mode 100644 index 0000000..0696483 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/IArgument.java @@ -0,0 +1,16 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +public interface IArgument +{ + @Nullable + String serialize(); + + boolean isDefault(); + + default boolean hasValue() + { + return this.serialize() != null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/IDeserializableArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/IDeserializableArgument.java new file mode 100644 index 0000000..bf1e481 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/IDeserializableArgument.java @@ -0,0 +1,8 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +public interface IDeserializableArgument extends IArgument +{ + void deserialize(@Nullable String string); +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/ItemArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/ItemArgument.java new file mode 100644 index 0000000..6a58605 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/ItemArgument.java @@ -0,0 +1,92 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.item.ItemParser; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraftforge.registries.ForgeRegistries; + +public class ItemArgument extends TagArgument +{ + private Item item; + + protected ItemArgument() + { + super(); + } + + public void set(@Nullable Item item) + { + this.item = item; + } + + public void set(@Nullable ResourceLocation item) + { + if(item != null) + { + this.set(ForgeRegistries.ITEMS.getValue(item)); + } + else + { + this.item = null; + } + } + + public Item getItem() + { + return this.item; + } + + @Override + public void deserialize(@Nullable String item) + { + if(item != null) + { + try + { + ItemParser parser = new ItemParser(new StringReader(item), false).parse(); + this.item = parser.getItem(); + this.setTag(parser.getNbt()); + } + catch(CommandSyntaxException e) + { + this.item = null; + this.setTag(null); + } + } + else + { + this.item = null; + this.setTag(null); + } + } + + @Override + @Nullable + public String serialize() + { + if(this.item == null) + { + return null; + } + + String tag = super.serialize(); + + if(tag != null) + { + return this.item.getRegistryName().toString() + tag; + } + + return this.item.getRegistryName().toString(); + } + + @Override + public boolean isDefault() + { + return super.isDefault() && this.item == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/ItemPredicateArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/ItemPredicateArgument.java new file mode 100644 index 0000000..17e5e6c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/ItemPredicateArgument.java @@ -0,0 +1,125 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.item.ItemParser; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; + +public class ItemPredicateArgument extends TagArgument +{ + private ResourceLocation resource; + private boolean isTag; + + protected ItemPredicateArgument() + { + super(); + } + + public void set(@Nullable ResourceLocation resource) + { + this.resource = resource; + } + + public void set(@Nullable Item item) + { + if(item != null) + { + this.resource = item.getRegistryName(); + } + else + { + this.resource = null; + } + + this.isTag = false; + } + + @Nullable + public ResourceLocation getResourceLocation() + { + return this.resource; + } + + public boolean isTag() + { + return this.isTag; + } + + @Override + public void deserialize(@Nullable String predicate) + { + if(predicate == null) + { + this.reset(); + } + else + { + try + { + ItemParser parser = new ItemParser(new StringReader(predicate), true).parse(); + + if(parser.getItem() != null) + { + this.resource = parser.getItem().getRegistryName(); + this.setTag(parser.getNbt()); + this.isTag = false; + } + else + { + this.resource = parser.getTag(); + this.setTag(parser.getNbt()); + this.isTag = true; + } + } + catch(CommandSyntaxException e) + { + this.reset(); + } + } + } + + private void reset() + { + this.resource = null; + this.setTag(null); + this.isTag = false; + } + + @Override + @Nullable + public String serialize() + { + if(this.resource == null || this.resource.getPath().isEmpty()) + { + return null; + } + + StringBuilder builder = new StringBuilder(); + + if(this.isTag) + { + builder.append('#'); + } + + builder.append(this.resource.toString()); + + String nbt = super.serialize(); + + if(nbt != null) + { + builder.append(nbt); + } + + return builder.toString(); + } + + @Override + public boolean isDefault() + { + return super.isDefault() && this.resource == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/NbtPathArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/NbtPathArgument.java new file mode 100644 index 0000000..f603418 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/NbtPathArgument.java @@ -0,0 +1,62 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import net.minecraft.commands.arguments.NbtPathArgument.NbtPath; + +public class NbtPathArgument implements IDeserializableArgument +{ + private NbtPath path; + + protected NbtPathArgument() + { + super(); + } + + @Override + public void deserialize(@Nullable String string) + { + if(string != null) + { + try + { + this.path = net.minecraft.commands.arguments.NbtPathArgument.nbtPath().parse(new StringReader(string)); + } + catch(CommandSyntaxException e) + { + this.path = null; + } + } + else + { + this.path = null; + } + } + + @Nullable + public NbtPath getPath() + { + return this.path; + } + + @Override + @Nullable + public String serialize() + { + if(this.path == null) + { + return null; + } + + return this.path.toString(); + } + + @Override + public boolean isDefault() + { + return this.path == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/PrimitiveArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/PrimitiveArgument.java new file mode 100644 index 0000000..16785fb --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/PrimitiveArgument.java @@ -0,0 +1,178 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.function.Function; + +import javax.annotation.Nullable; + +public class PrimitiveArgument implements IDeserializableArgument +{ + private T value; + private final Function defaultOverride; + private final Function parser; + private final Function serializer; + + protected PrimitiveArgument(Function defaultOverride, Function parser, Function serializer) + { + this.defaultOverride = defaultOverride; + this.parser = parser; + this.serializer = serializer; + } + + public void set(@Nullable T value) + { + this.value = value; + } + + @Nullable + public T get() + { + return this.value; + } + + @Override + public void deserialize(@Nullable String string) + { + if(string == null) + { + this.value = null; + } + else + { + this.value = this.parser.apply(string); + } + } + + @Override + @Nullable + public String serialize() + { + if(this.value == null) + { + return null; + } + else if(this.serializer != null) + { + return this.serializer.apply(this.value); + } + + return this.value.toString(); + } + + @Override + public boolean isDefault() + { + if(this.defaultOverride != null) + { + return this.defaultOverride.apply(this.value); + } + + return this.value == null; + } + + public static class Builder + { + private Function defaultOverride; + private Function deserializer; + private Function serializer; + + public Builder(Function deserializer) + { + this.deserializer = deserializer; + } + + public Builder defaultOverride(Function defaultOverride) + { + this.defaultOverride = defaultOverride; + return this; + } + + public Builder serializer(Function serializer) + { + this.serializer = serializer; + return this; + } + + public PrimitiveArgument build() + { + return new PrimitiveArgument(this.defaultOverride, this.deserializer, this.serializer); + } + } + + public static enum Operation + { + SET("="), + ADD("+="), + SUB("-="), + MUL("*="), + DIV("/="), + MOD("%="), + LESS_THAN("<"), + GREATER_THAN(">"); + + private final String operator; + + private Operation(String operator) + { + this.operator = operator; + } + + @Override + public String toString() + { + return this.operator; + } + } + + public static enum Relation + { + LT("<"), + LE("<="), + EQ("="), + GE(">="), + GT(">"); + + private final String operator; + + private Relation(String operator) + { + this.operator = operator; + } + + @Override + public String toString() + { + return this.operator; + } + } + + public static enum Type + { + BYTE, + DOUBLE, + FLOAT, + INT, + LONG, + SHORT; + + @Override + public String toString() + { + return this.name().toLowerCase(); + } + } + + public static enum Linkage + { + APPEND, + INSERT, + MERGE, + PREPEND, + SET; + + @Override + public String toString() + { + return this.name().toLowerCase(); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/RangeArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/RangeArgument.java new file mode 100644 index 0000000..b23d340 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/RangeArgument.java @@ -0,0 +1,90 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.function.Function; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.util.Util; +import net.minecraft.advancements.critereon.MinMaxBounds; + +public class RangeArgument implements IDeserializableArgument +{ + private final Function> parser; + private T min; + private T max; + + protected RangeArgument(Function> parser) + { + this.parser = parser; + } + + public void setExact(@Nullable T value) + { + this.min = value; + this.max = value; + } + + public void setRange(@Nullable T min, @Nullable T max) + { + this.min = min; + this.max = max; + } + + public void setMin(@Nullable T min) + { + this.min = min; + } + + public void setMax(@Nullable T max) + { + this.max = max; + } + + public T getMin() + { + return this.min; + } + + public T getMax() + { + return this.max; + } + + @Override + public void deserialize(@Nullable String string) + { + if(string != null) + { + MinMaxBounds bounds = this.parser.apply(string); + + if(bounds != null) + { + this.min = bounds.getMin(); + this.max = bounds.getMax(); + } + else + { + this.min = null; + this.max = null; + } + } + else + { + this.min = null; + this.max = null; + } + } + + @Override + @Nullable + public String serialize() + { + return Util.serializeBounds(this.min, this.max); + } + + @Override + public boolean isDefault() + { + return this.min == null && this.max == null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/TagArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/TagArgument.java new file mode 100644 index 0000000..6ac0657 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/TagArgument.java @@ -0,0 +1,112 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import exopandora.worldhandler.builder.argument.tag.ITagProvider; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.Tag; +import net.minecraft.nbt.TagParser; + +public class TagArgument implements IDeserializableArgument +{ + private List providers; + private CompoundTag tag; + + protected TagArgument() + { + super(); + } + + public void addTagProvider(ITagProvider provider) + { + if(this.providers == null) + { + this.providers = new ArrayList(); + } + + this.providers.add(provider); + } + + public void setTag(@Nullable CompoundTag tag) + { + this.tag = tag; + } + + @Nullable + public CompoundTag getTag() + { + return this.tag; + } + + @Override + public void deserialize(@Nullable String string) + { + if(string != null) + { + try + { + this.tag = TagParser.parseTag(string); + } + catch(CommandSyntaxException e) + { + this.tag = null; + } + } + else + { + this.tag = null; + } + } + + @Override + @Nullable + public String serialize() + { + if(this.tag == null && (this.providers == null || this.providers.isEmpty())) + { + return null; + } + + CompoundTag compound = this.tag == null ? new CompoundTag() : this.tag.copy(); + + if(this.providers != null) + { + for(ITagProvider provider : this.providers) + { + Tag tag = provider.value(); + + if(tag != null) + { + String key = provider.key(); + + if(key != null) + { + compound.put(key, tag); + } + else if(tag instanceof CompoundTag) + { + compound.merge((CompoundTag) tag); + } + } + } + } + + if(compound.isEmpty()) + { + return null; + } + + return compound.toString(); + } + + @Override + public boolean isDefault() + { + return this.tag == null && (this.providers == null || this.providers.isEmpty()); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/TargetArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/TargetArgument.java new file mode 100644 index 0000000..56e7980 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/TargetArgument.java @@ -0,0 +1,652 @@ +package exopandora.worldhandler.builder.argument; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.function.Function; +import java.util.stream.Collectors; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.argument.tag.ITagProvider; +import exopandora.worldhandler.util.Util; +import net.minecraft.advancements.critereon.MinMaxBounds; +import net.minecraft.advancements.critereon.WrappedMinMaxBounds; +import net.minecraft.resources.ResourceLocation; + +public class TargetArgument implements IArgument +{ + @Nullable + private String target; // player name or entity UUID + @Nullable + private String selectorType; + private NegatableCriterion name = new NegatableCriterion(); + private MinMaxBounds.Doubles distance = MinMaxBounds.Doubles.ANY; + @Nullable + private Double x; + @Nullable + private Double y; + @Nullable + private Double z; + @Nullable + private Double deltaX; + @Nullable + private Double deltaY; + @Nullable + private Double deltaZ; + private WrappedMinMaxBounds rotX = WrappedMinMaxBounds.ANY; + private WrappedMinMaxBounds rotY = WrappedMinMaxBounds.ANY; + @Nullable + private Double level; + @Nullable + private Integer limit; + private NegatableCriterion nbt = new NegatableCriterion(); + private NegatableCriterion type = new NegatableCriterion(); + private Map advancements; + private List> predicates; + private NegatableCriterion team = new NegatableCriterion(); + private Map scores; + @Nullable + private NegatableCriterion gamemode = new NegatableCriterion(); + @Nullable + private Sort sort; + + protected TargetArgument() + { + super(); + } + + public void setTarget(@Nullable String target) + { + this.target = target; + } + + public void setSelectorType(@Nullable String type) + { + this.selectorType = type; + } + + public void setName(@Nullable String name) + { + this.name.setCriterion(name); + } + + public void setNameNegated(boolean negated) + { + this.name.setNegated(negated); + } + + public void setName(@Nullable String name, boolean negated) + { + this.setName(name); + this.setNameNegated(negated); + } + + public void setDistance(@Nullable Double distance) + { + this.distance = new MinMaxBounds.Doubles(distance, distance); + } + + public void setDistance(@Nullable Double min, @Nullable Double max) + { + this.distance = new MinMaxBounds.Doubles(min, max); + } + + public void setDistanceMin(@Nullable Double min) + { + this.distance = new MinMaxBounds.Doubles(min, this.distance.getMax()); + } + + public void setDistanceMax(@Nullable Double max) + { + this.distance = new MinMaxBounds.Doubles(this.distance.getMin(), max); + } + + public void setX(@Nullable Double x) + { + this.x = x; + } + + public void setY(@Nullable Double y) + { + this.y = y; + } + + public void setZ(@Nullable Double z) + { + this.z = z; + } + + public void setDeltaX(@Nullable Double deltaX) + { + this.deltaX = deltaX; + } + + public void setDeltaY(@Nullable Double deltaY) + { + this.deltaY = deltaY; + } + + public void setDeltaZ(@Nullable Double deltaZ) + { + this.deltaZ = deltaZ; + } + + public void setRotationX(@Nullable Float rotX) + { + this.rotX = WrappedMinMaxBounds.exactly(rotX); + } + + public void setRotationX(@Nullable Float min, @Nullable Float max) + { + this.rotX = WrappedMinMaxBounds.between(min, max); + } + + public void setRotationXMin(@Nullable Float min) + { + this.rotX = WrappedMinMaxBounds.between(min, this.rotX.getMax()); + } + + public void setRotationXMax(@Nullable Float max) + { + this.rotX = WrappedMinMaxBounds.between(this.rotX.getMin(), max); + } + + public void setRotationY(@Nullable Float rotY) + { + this.rotY = WrappedMinMaxBounds.exactly(rotY); + } + + public void setRotationY(@Nullable Float min, @Nullable Float max) + { + this.rotY = WrappedMinMaxBounds.between(min, max); + } + + public void setRotationYMin(@Nullable Float min) + { + this.rotY = WrappedMinMaxBounds.between(min, this.rotY.getMax()); + } + + public void setRotationYMax(@Nullable Float max) + { + this.rotY = WrappedMinMaxBounds.between(this.rotY.getMin(), max); + } + + public void setLevel(@Nullable Double level) + { + this.level = level; + } + + public void setLimit(@Nullable Integer limit) + { + this.limit = limit; + } + + public TargetArgument addTag(ITagProvider provider) + { + if(this.nbt.getCriterion() == null) + { + this.nbt.setCriterion(new TagArgument()); + } + + this.nbt.getCriterion().addTagProvider(provider); + return this; + } + + public void setType(@Nullable ResourceLocation type) + { + this.type.setCriterion(type); + } + + public void setTypeNegated(boolean negated) + { + this.type.setNegated(negated); + } + + public void setType(@Nullable ResourceLocation type, boolean negated) + { + this.setType(type); + this.setTypeNegated(negated); + } + + public void setAdvancement(ResourceLocation advancement, boolean unlocked) + { + if(this.advancements == null) + { + this.advancements = new HashMap(); + } + + this.advancements.put(advancement, unlocked); + } + + public void setPredicate(ResourceLocation predicate) + { + this.setPredicate(predicate, false); + } + + public void setPredicate(ResourceLocation predicate, boolean negated) + { + if(this.predicates == null) + { + this.predicates = new ArrayList>(); + } + + NegatableCriterion entry = this.findPredicate(predicate); + + if(entry == null) + { + this.predicates.add(new NegatableCriterion(predicate, negated)); + } + else if(entry.isNegated() != negated) + { + entry.setNegated(negated); + } + } + + private NegatableCriterion findPredicate(ResourceLocation predicate) + { + for(NegatableCriterion entry : this.predicates) + { + if(predicate.equals(entry.getCriterion())) + { + return entry; + } + } + + return null; + } + + public void setTeam(@Nullable String team) + { + this.team.setCriterion(team); + } + + public void setTeamNegated(boolean negated) + { + this.team.setNegated(negated); + } + + public void setTeam(@Nullable String team, boolean negated) + { + this.setTeam(team); + this.setTeamNegated(negated); + } + + public void setScore(String score, @Nullable Integer value) + { + if(this.scores == null) + { + this.scores = new HashMap(); + } + + this.scores.put(score, MinMaxBounds.Ints.exactly(value)); + } + + public void setScore(String score, @Nullable Integer min, @Nullable Integer max) + { + if(this.scores == null) + { + this.scores = new HashMap(); + } + + this.scores.put(score, MinMaxBounds.Ints.between(min, max)); + } + + public void setScoreMin(String score, @Nullable Integer min) + { + if(this.scores == null) + { + this.scores = new HashMap(); + } + + this.scores.put(score, MinMaxBounds.Ints.between(min, this.scores.getOrDefault(score, MinMaxBounds.Ints.ANY).getMax())); + } + + public void setScoreMax(String score, @Nullable Integer max) + { + if(this.scores == null) + { + this.scores = new HashMap(); + } + + this.scores.put(score, MinMaxBounds.Ints.between(this.scores.getOrDefault(score, MinMaxBounds.Ints.ANY).getMin(), max)); + } + + public void setGamemode(@Nullable Gamemode gamemode) + { + this.gamemode.setCriterion(gamemode); + } + + public void setGamemodeNegated(boolean negated) + { + this.gamemode.setNegated(negated); + } + + public void setGamemode(@Nullable Gamemode gamemode, boolean negated) + { + this.setGamemode(gamemode); + this.setGamemodeNegated(negated); + } + + public void setSort(@Nullable Sort sort) + { + this.sort = sort; + } + + @Nullable + public String getTarget() + { + return this.target; + } + + @Nullable + public String getSelectorType() + { + return this.selectorType; + } + + public NegatableCriterion getName() + { + return this.name; + } + + public MinMaxBounds.Doubles getDistance() + { + return this.distance; + } + + @Nullable + public Double getX() + { + return this.x; + } + + @Nullable + public Double getY() + { + return this.y; + } + + @Nullable + public Double getZ() + { + return this.z; + } + + @Nullable + public Double getDeltaX() + { + return this.deltaX; + } + + @Nullable + public Double getDeltaY() + { + return this.deltaY; + } + + @Nullable + public Double getDeltaZ() + { + return this.deltaZ; + } + + public WrappedMinMaxBounds getRotX() + { + return this.rotX; + } + + public WrappedMinMaxBounds getRotY() + { + return this.rotY; + } + + @Nullable + public Double getLevel() + { + return this.level; + } + + @Nullable + public Integer getLimit() + { + return this.limit; + } + + public NegatableCriterion getNbt() + { + return this.nbt; + } + + public NegatableCriterion getType() + { + return this.type; + } + + @Nullable + public Map getAdvancements() + { + return this.advancements; + } + + @Nullable + public List> getPredicates() + { + return this.predicates; + } + + public NegatableCriterion getTeam() + { + return this.team; + } + + @Nullable + public Map getScores() + { + return this.scores; + } + + public NegatableCriterion getGamemode() + { + return this.gamemode; + } + + @Nullable + public Sort getSort() + { + return this.sort; + } + + @Nullable + @Override + public String serialize() + { + if(this.selectorType == null) + { + if(this.target != null && !this.target.isBlank()) + { + return this.target; + } + + return null; + } + + List criteria = new ArrayList(); + + this.append("name", this.name, criteria, TargetArgument::serializeNegatableCriterion); + this.append("distance", this.distance, criteria, TargetArgument::serializeMinMaxBounds); + this.append("x", this.x, criteria); + this.append("y", this.y, criteria); + this.append("z", this.z, criteria); + this.append("dx", this.deltaX, criteria); + this.append("dy", this.deltaY, criteria); + this.append("dz", this.deltaZ, criteria); + this.append("x_rotation", this.rotX, criteria, TargetArgument::serializeWrappedMinMaxBounds); + this.append("y_rotation", this.rotY, criteria, TargetArgument::serializeWrappedMinMaxBounds); + this.append("level", this.level, criteria); + this.append("limit", this.limit, criteria); + this.append("nbt", this.nbt, criteria, nbt -> TargetArgument.serializeNegatableCriterion(nbt, TagArgument::serialize)); + this.append("type", this.type, criteria, TargetArgument::serializeNegatableCriterion); + this.appendMap("advancements", this.advancements, criteria, ResourceLocation::toString, b -> b.toString()); + this.appendList("predicate", this.predicates, criteria, TargetArgument::serializeNegatableCriterion); + this.append("team", this.team, criteria, TargetArgument::serializeNegatableCriterion); + this.appendMap("scores", this.scores, criteria, String::toString, TargetArgument::serializeMinMaxBounds); + this.append("gamemode", this.gamemode, criteria, TargetArgument::serializeNegatableCriterion); + this.append("sort", this.sort, criteria); + + if(criteria.isEmpty()) + { + return "@" + this.selectorType; + } + + return criteria.stream().collect(Collectors.joining(",", "@" + this.selectorType + "[", "]")); + } + + private void append(String name, T criterion, List criteria) + { + this.append(name, criterion, criteria, null); + } + + private void append(String name, T criterion, List criteria, Function serializer) + { + if(criterion != null) + { + String serialized = serializer == null ? criterion.toString() : serializer.apply(criterion); + + if(serialized != null) + { + criteria.add(name + "=" + serialized); + } + } + } + + private void appendList(String name, List criterion, List criteria, Function serializer) + { + if(criterion != null) + { + for(T entry : criterion) + { + criteria.add(name + "=" + serializer.apply(entry)); + } + } + } + + private void appendMap(String name, Map criterion, List criteria, Function keySerializer, Function valueSerializer) + { + if(criterion != null && !criterion.isEmpty()) + { + List entries = new ArrayList(); + + for(Entry entry : criterion.entrySet()) + { + entries.add(keySerializer.apply(entry.getKey()) + "=" + valueSerializer.apply(entry.getValue())); + } + + criteria.add(name + "=" + entries.stream().collect(Collectors.joining(",", "{", "}"))); + } + } + + @Nullable + private static String serializeMinMaxBounds(MinMaxBounds bounds) + { + return Util.serializeBounds(bounds.getMin(), bounds.getMax()); + } + + @Nullable + private static String serializeWrappedMinMaxBounds(WrappedMinMaxBounds bounds) + { + return Util.serializeBounds(bounds.getMin(), bounds.getMax()); + } + + @Nullable + private static String serializeNegatableCriterion(NegatableCriterion criterion) + { + return serializeNegatableCriterion(criterion, null); + } + + @Nullable + private static String serializeNegatableCriterion(NegatableCriterion criterion, Function serializer) + { + if(criterion.getCriterion() != null) + { + String serialized = serializer == null ? criterion.getCriterion().toString() : serializer.apply(criterion.getCriterion()); + + if(criterion.isNegated()) + { + serialized = '!' + serialized; + } + + return serialized; + } + + return null; + } + + public static class NegatableCriterion + { + private T criterion; + private boolean negated; + + public NegatableCriterion() + { + super(); + } + + public NegatableCriterion(T criterion, boolean negated) + { + this.criterion = criterion; + this.negated = negated; + } + + public T getCriterion() + { + return this.criterion; + } + + public void setCriterion(T criterion) + { + this.criterion = criterion; + } + + public boolean isNegated() + { + return this.negated; + } + + public void setNegated(boolean negated) + { + this.negated = negated; + } + } + + public static class SelectorTypes + { + public static final String NEAREST_PLAYER = "p"; + public static final String RANDOM_PLAYER = "r"; + public static final String ALL_PLAYERS = "a"; + public static final String ALL_ENTITIES = "e"; + public static final String SENDER = "s"; + } + + public static enum Sort + { + NEAREST, + FURTHEST, + RANDOM, + ARBITRARY; + + @Override + public String toString() + { + return this.name().toLowerCase(); + } + } + + @Override + public boolean isDefault() + { + return false; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/TimeArgument.java b/src/main/java/exopandora/worldhandler/builder/argument/TimeArgument.java new file mode 100644 index 0000000..9809ab4 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/TimeArgument.java @@ -0,0 +1,124 @@ +package exopandora.worldhandler.builder.argument; + +import javax.annotation.Nullable; + +import com.mojang.brigadier.StringReader; +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +public class TimeArgument implements IDeserializableArgument +{ + private Float time; + private Unit unit; + + protected TimeArgument() + { + super(); + } + + public void set(@Nullable Float time) + { + this.time = time; + } + + public void set(@Nullable Unit unit) + { + this.unit = unit; + } + + public void set(@Nullable Float time, @Nullable Unit unit) + { + this.time = time; + this.unit = unit; + } + + @Override + public void deserialize(@Nullable String string) + { + if(string == null) + { + this.reset(); + } + else + { + try + { + StringReader reader = new StringReader(string); + float time = reader.readFloat(); + String unit = reader.readUnquotedString(); + this.time = time; + + if(unit.isEmpty()) + { + this.unit = null; + } + } + catch(CommandSyntaxException e) + { + this.reset(); + } + } + } + + private void reset() + { + this.time = 0F; + this.unit = null; + } + + @Nullable + public Float getTime() + { + return this.time; + } + + @Nullable + public Unit getUnit() + { + return this.unit; + } + + @Override + @Nullable + public String serialize() + { + if(this.time == null) + { + return null; + } + + StringBuilder builder = new StringBuilder(); + builder.append(this.time); + + if(this.unit != null) + { + builder.append(this.unit.getSuffix()); + } + + return builder.toString(); + } + + @Override + public boolean isDefault() + { + return this.time == null; + } + + public static enum Unit + { + TICKS("t"), + SECONDS("s"), + DAYS("d"); + + private final String suffix; + + private Unit(String suffix) + { + this.suffix = suffix; + } + + public String getSuffix() + { + return this.suffix; + } + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/AbstractAttributeTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/AbstractAttributeTag.java new file mode 100644 index 0000000..e1c035e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/AbstractAttributeTag.java @@ -0,0 +1,45 @@ +package exopandora.worldhandler.builder.argument.tag; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraftforge.registries.ForgeRegistries; + +public abstract class AbstractAttributeTag implements ITagProvider +{ + public static final List ATTRIBUTES = ForgeRegistries.ATTRIBUTES.getValues().stream() + .filter(attribute -> !attribute.getDescriptionId().equals(I18n.get(attribute.getDescriptionId()))) + .collect(Collectors.toList()); + + protected final Map attributes = new HashMap(); + + public void set(Attribute attribute, double value) + { + this.attributes.put(attribute, value); + } + + public double get(Attribute value) + { + if(this.attributes.containsKey(value)) + { + return this.attributes.get(value); + } + + return 0; + } + + public void remove(Attribute attribute) + { + this.attributes.remove(attribute); + } + + public Set getAttributes() + { + return this.attributes.keySet(); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/AbstractEffectTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/AbstractEffectTag.java new file mode 100644 index 0000000..5c2c2d9 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/AbstractEffectTag.java @@ -0,0 +1,77 @@ +package exopandora.worldhandler.builder.argument.tag; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.annotation.Nullable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.effect.MobEffect; + +public abstract class AbstractEffectTag implements ITagProvider +{ + private final Map effects = new HashMap(); + + @Nullable + @Override + public Tag value() + { + ListTag list = new ListTag(); + + for(Entry entry : this.effects.entrySet()) + { + EffectInstance instance = entry.getValue(); + + if(instance.getAmplifier() > 0) + { + CompoundTag compound = new CompoundTag(); + int ticks = instance.toTicks(); + + compound.putByte("Id", (byte) MobEffect.getId(entry.getKey())); + compound.putByte("Amplifier", (byte) (instance.getAmplifier() - 1)); + compound.putInt("Duration", ticks > 0 ? ticks : 1000000); + compound.putBoolean("Ambient", instance.isAmbient()); + compound.putBoolean("ShowParticles", instance.doShowParticles()); + + list.add(compound); + } + } + + if(list.isEmpty()) + { + return null; + } + + return list; + } + + public EffectInstance getOrCreate(MobEffect effect) + { + return this.effects.computeIfAbsent(effect, key -> new EffectInstance()); + } + + public Set getMobEffects() + { + return this.effects.keySet(); + } + + public void remove(MobEffect potion) + { + this.effects.remove(potion); + } + + public Map getEffects() + { + return Collections.unmodifiableMap(this.effects); + } + + public void clear() + { + this.effects.clear(); + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/ActiveEffectsTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/ActiveEffectsTag.java new file mode 100644 index 0000000..78650fc --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/ActiveEffectsTag.java @@ -0,0 +1,10 @@ +package exopandora.worldhandler.builder.argument.tag; + +public class ActiveEffectsTag extends AbstractEffectTag +{ + @Override + public String key() + { + return "ActiveEffects"; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/AttributeModifiersTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/AttributeModifiersTag.java new file mode 100644 index 0000000..a782d2c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/AttributeModifiersTag.java @@ -0,0 +1,50 @@ +package exopandora.worldhandler.builder.argument.tag; + +import java.util.Map.Entry; +import java.util.UUID; + +import javax.annotation.Nullable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.entity.ai.attributes.Attribute; + +public class AttributeModifiersTag extends AbstractAttributeTag +{ + @Override + @Nullable + public Tag value() + { + ListTag attributes = new ListTag(); + + for(Entry entry : this.attributes.entrySet()) + { + if(entry.getValue() != 0) + { + CompoundTag attribute = new CompoundTag(); + String id = entry.getKey().getRegistryName().toString(); + + attribute.putString("AttributeName", id); + attribute.putDouble("Amount", entry.getValue() / 100); + attribute.putInt("Operation", 1); // 0 = additive, 1 = percentage + attribute.putUUID("UUID", UUID.nameUUIDFromBytes(id.getBytes())); + + attributes.add(attribute); + } + } + + if(attributes.isEmpty()) + { + return null; + } + + return attributes; + } + + @Override + public String key() + { + return "AttributeModifiers"; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/AttributesTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/AttributesTag.java new file mode 100644 index 0000000..abf187b --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/AttributesTag.java @@ -0,0 +1,47 @@ +package exopandora.worldhandler.builder.argument.tag; + +import java.util.Map.Entry; + +import javax.annotation.Nullable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.entity.ai.attributes.Attribute; + +public class AttributesTag extends AbstractAttributeTag +{ + @Override + @Nullable + public Tag value() + { + ListTag attributes = new ListTag(); + + for(Entry entry : this.attributes.entrySet()) + { + if(entry.getValue() != 0) + { + CompoundTag attribute = new CompoundTag(); + String id = entry.getKey().getRegistryName().toString(); + + attribute.putString("Name", id); + attribute.putDouble("Base", entry.getValue() / 100); + + attributes.add(attribute); + } + } + + if(attributes.isEmpty()) + { + return null; + } + + return attributes; + } + + @Override + public String key() + { + return "Attributes"; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/CustomPotionEffectsTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/CustomPotionEffectsTag.java new file mode 100644 index 0000000..151b98e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/CustomPotionEffectsTag.java @@ -0,0 +1,10 @@ +package exopandora.worldhandler.builder.argument.tag; + +public class CustomPotionEffectsTag extends AbstractEffectTag +{ + @Override + public String key() + { + return "CustomPotionEffects"; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/DisplayTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/DisplayTag.java new file mode 100644 index 0000000..0c3dcfe --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/DisplayTag.java @@ -0,0 +1,93 @@ +package exopandora.worldhandler.builder.argument.tag; + +import exopandora.worldhandler.util.MutableTextComponent; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; +import net.minecraft.network.chat.Component; + +public class DisplayTag implements ITagProvider +{ + private MutableTextComponent name = new MutableTextComponent(); + private Component[] lore = new Component[2]; + + @Override + public Tag value() + { + CompoundTag display = new CompoundTag(); + + if(this.name.getText() != null && !this.name.getText().isEmpty()) + { + display.putString("Name", Component.Serializer.toJson(this.name)); + } + + ListTag lore = new ListTag(); + + for(int x = 0; x < this.lore.length; x++) + { + if(this.lore[x] != null && !this.lore[x].getString().isEmpty()) + { + lore.add(StringTag.valueOf(Component.Serializer.toJson(this.lore[x]))); + } + } + + if(!lore.isEmpty()) + { + display.put("Lore", lore); + } + + if(!display.isEmpty()) + { + return display; + } + + return null; + } + + public void setName(MutableTextComponent name) + { + this.name = name; + } + + public MutableTextComponent getName() + { + return this.name; + } + + public void setLore(Component[] lore) + { + this.lore = lore; + } + + public Component[] getLore() + { + return this.lore; + } + + public void setLore1(Component lore) + { + this.lore[0] = lore; + } + + public Component getLore1() + { + return this.lore[0]; + } + + public void setLore2(Component lore) + { + this.lore[1] = lore; + } + + public Component getLore2() + { + return this.lore[1]; + } + + @Override + public String key() + { + return "display"; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/EnchantmentsTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/EnchantmentsTag.java new file mode 100644 index 0000000..ba1558c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/EnchantmentsTag.java @@ -0,0 +1,74 @@ +package exopandora.worldhandler.builder.argument.tag; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.annotation.Nullable; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; +import net.minecraft.world.item.enchantment.Enchantment; +import net.minecraftforge.registries.ForgeRegistries; + +public class EnchantmentsTag implements ITagProvider +{ + private final Map enchantments = new HashMap(); + + @Override + @Nullable + public Tag value() + { + ListTag enchantments = new ListTag(); + + for(Entry entry : this.enchantments.entrySet()) + { + if(entry.getValue() > 0) + { + CompoundTag enchantment = new CompoundTag(); + + enchantment.putString("id", ForgeRegistries.ENCHANTMENTS.getKey(entry.getKey()).toString()); + enchantment.putShort("lvl", entry.getValue()); + + enchantments.add(enchantment); + } + } + + if(enchantments.isEmpty()) + { + return null; + } + + return enchantments; + } + + public void set(Enchantment enchantment, short level) + { + if(level == 0) + { + this.enchantments.remove(enchantment); + } + else + { + this.enchantments.put(enchantment, level); + } + } + + public short get(Enchantment enchantment) + { + return this.enchantments.get(enchantment); + } + + public Set getEnchantments() + { + return this.enchantments.keySet(); + } + + @Override + public String key() + { + return "Enchantments"; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/EntityTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/EntityTag.java new file mode 100644 index 0000000..052752d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/EntityTag.java @@ -0,0 +1,433 @@ +package exopandora.worldhandler.builder.argument.tag; + +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; + +import exopandora.worldhandler.util.MutableTextComponent; +import exopandora.worldhandler.util.NBTHelper; +import net.minecraft.nbt.ByteTag; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.IntTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.nbt.Tag; +import net.minecraft.nbt.TagParser; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.state.BlockState; + +public class EntityTag implements ITagProvider +{ + private ResourceLocation id; + private String command; + private Integer time; + private double[] motion = {0.0, 0.0, 0.0}; + private boolean isBaby; + private BlockState blockState; + private AttributesTag attribute = new AttributesTag(); + private MutableTextComponent customName = new MutableTextComponent(); + private List passengers = new ArrayList(); + private Item[] armorItems = {Items.AIR, Items.AIR, Items.AIR, Items.AIR}; + private Item[] handItems = {Items.AIR, Items.AIR}; + private ActiveEffectsTag potion = new ActiveEffectsTag(); + private CompoundTag nbt; + + public EntityTag() + { + super(); + } + + public EntityTag(ResourceLocation id) + { + this.id = id; + } + + public void setId(ResourceLocation id) + { + this.id = id; + } + + public ResourceLocation getId() + { + return this.id; + } + + public void setAttribute(Attribute attribute, double ammount) + { + this.attribute.set(attribute, ammount); + } + + public void removeAttribute(Attribute attribute) + { + this.attribute.remove(attribute); + } + + public double getAttribute(Attribute attribute) + { + return this.attribute.get(attribute); + } + + public Set getAttributes() + { + return this.attribute.getAttributes(); + } + + public void setCustomName(String name) + { + this.customName.setText(name); + } + + @Nullable + public MutableTextComponent getCustomName() + { + return this.customName; + } + + public void setPassenger(int index, EntityTag entity) + { + if(index < 0 || index >= this.passengers.size()) + { + this.passengers.add(entity); + } + else + { + this.passengers.set(index, entity); + } + } + + public void setPassenger(int index, ResourceLocation id) + { + this.setPassenger(index, new EntityTag(id)); + } + + public void addPassenger(EntityTag entity) + { + this.passengers.add(entity); + } + + public void addPassenger(int index, EntityTag entity) + { + this.passengers.add(index, entity); + } + + public void removePassenger(int index) + { + this.passengers.remove(index); + } + + public int getPassengerCount() + { + return this.passengers.size(); + } + + public List getPassengers() + { + return this.passengers; + } + + @Nullable + public EntityTag getPassenger(int index) + { + if(index >= 0 && index <= this.passengers.size()) + { + return this.passengers.get(index); + } + + return null; + } + + public boolean hasPassengers() + { + for(EntityTag entity : this.passengers) + { + if(entity.value() != null) + { + return true; + } + } + + return false; + } + + public void setArmorItem(int index, Item location) + { + if(EntityTag.isArrayIndexValid(this.armorItems, index) && location != null) + { + this.armorItems[index] = location; + } + } + + public void setArmorItems(Item[] armor) + { + this.armorItems = armor; + } + + @Nonnull + public Item getArmorItem(int slot) + { + if(EntityTag.isArrayIndexValid(this.armorItems, slot)) + { + return this.armorItems[slot]; + } + + return Items.AIR; + } + + public void setHandItem(int index, Item location) + { + if(EntityTag.isArrayIndexValid(this.handItems, index) && location != null) + { + this.handItems[index] = location; + } + } + + @Nonnull + public Item getHandItem(int slot) + { + if(EntityTag.isArrayIndexValid(this.handItems, slot)) + { + return this.handItems[slot]; + } + + return Items.AIR; + } + + public double[] getMotion() + { + return this.motion; + } + + public void setMotion(double x, double y, double z) + { + this.setMotionX(x); + this.setMotionY(y); + this.setMotionZ(z); + } + + public double getMotionX() + { + return this.motion[0]; + } + + public double getMotionY() + { + return this.motion[1]; + } + + public double getMotionZ() + { + return this.motion[2]; + } + + public void setMotionX(double x) + { + this.motion[0] = x; + } + + public void setMotionY(double y) + { + this.motion[1] = y; + } + + public void setMotionZ(double z) + { + this.motion[2] = z; + } + + public void setAmplifier(MobEffect effect, byte amplifier) + { + this.potion.getOrCreate(effect).setAmplifier(amplifier); + } + + public void setSeconds(MobEffect effect, int seconds) + { + this.potion.getOrCreate(effect).setSeconds(seconds); + } + + public void setMinutes(MobEffect effect, int minutes) + { + this.potion.getOrCreate(effect).setMinutes(minutes); + } + + public void setHours(MobEffect effect, int hours) + { + this.potion.getOrCreate(effect).setHours(hours); + } + + public void setShowParticles(MobEffect effect, boolean showParticles) + { + this.potion.getOrCreate(effect).setShowParticles(showParticles); + } + + public void setAmbient(MobEffect effect, boolean ambient) + { + this.potion.getOrCreate(effect).setAmbient(ambient); + } + + public byte getAmplifier(MobEffect effect) + { + return this.potion.getOrCreate(effect).getAmplifier(); + } + + public int getSeconds(MobEffect effect) + { + return this.potion.getOrCreate(effect).getSeconds(); + } + + public int getMinutes(MobEffect effect) + { + return this.potion.getOrCreate(effect).getMinutes(); + } + + public int getHours(MobEffect effect) + { + return this.potion.getOrCreate(effect).getHours(); + } + + public boolean doShowParticles(MobEffect effect) + { + return this.potion.getOrCreate(effect).doShowParticles(); + } + + public boolean isAmbient(MobEffect effect) + { + return this.potion.getOrCreate(effect).isAmbient(); + } + + public Set getEffects() + { + return this.potion.getMobEffects(); + } + + public void setBlockState(BlockState blockState) + { + this.blockState = blockState; + } + + public BlockState getBlockState() + { + return this.blockState; + } + + public void setTime(int time) + { + this.time = time; + } + + public int getTime() + { + return this.time; + } + + public void setIsBaby(boolean baby) + { + this.isBaby = baby; + } + + public boolean isBaby() + { + return this.isBaby; + } + + public void setCommand(String command) + { + this.command = command; + } + + public String getCommand() + { + return this.command; + } + + public void setNBT(CompoundTag nbt) + { + this.nbt = nbt; + } + + public CompoundTag getNBT() + { + return this.nbt; + } + + public void setNBT(String nbt) + { + try + { + this.nbt = TagParser.parseTag("{" + nbt + "}"); + } + catch(CommandSyntaxException e) + { + this.nbt = null; + } + } + + @Override + public String key() + { + return null; + } + + @Override + public Tag value() + { + CompoundTag nbt = new CompoundTag(); + + if(this.time != null) + { + NBTHelper.append(nbt, "Time", IntTag.valueOf(this.time)); + } + + if(this.command != null) + { + NBTHelper.append(nbt, "Command", StringTag.valueOf(this.command)); + } + + if(this.isBaby) + { + NBTHelper.append(nbt, "IsBaby", ByteTag.valueOf(true)); + } + + NBTHelper.append(nbt, "id", NBTHelper.serialize(this.id)); + NBTHelper.append(nbt, "Motion", NBTHelper.serialize(this.motion)); + NBTHelper.append(nbt, "Passengers", NBTHelper.serialize(this.passengers)); + NBTHelper.append(nbt, "ArmorItems", NBTHelper.serialize(this.armorItems)); + NBTHelper.append(nbt, "HandItems", NBTHelper.serialize(this.handItems)); + NBTHelper.append(nbt, "BlockState", NBTHelper.serialize(this.blockState)); + + NBTHelper.append(nbt, "CustomName", this.customName.serialize()); + + NBTHelper.append(nbt, this.potion); + NBTHelper.append(nbt, this.attribute); + + if(this.nbt != null) + { + nbt.merge(this.nbt); + } + + if(nbt.isEmpty()) + { + return null; + } + + return nbt; + } + + private static boolean isArrayIndexValid(Object[] array, int index) + { + if(array != null && (Array.getLength(array) == 0 || array.length <= index)) + { + return false; + } + + return index >= 0; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/ITagProvider.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/ITagProvider.java new file mode 100644 index 0000000..8fb4aff --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/ITagProvider.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.argument.tag; + +import javax.annotation.Nullable; + +import net.minecraft.nbt.Tag; + +public interface ITagProvider +{ + @Nullable + String key(); + + @Nullable + Tag value(); +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/MutableTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/MutableTag.java new file mode 100644 index 0000000..c4c0916 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/MutableTag.java @@ -0,0 +1,37 @@ +package exopandora.worldhandler.builder.argument.tag; + +import net.minecraft.nbt.Tag; + +public class MutableTag implements ITagProvider +{ + private String key; + private Tag tag; + + public void setKey(String key) + { + this.key = key; + } + + public void setTag(Tag tag) + { + this.tag = tag; + } + + @Override + public String key() + { + return this.key; + } + + @Override + public Tag value() + { + return this.tag; + } + + public void reset() + { + this.key = null; + this.tag = null; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/argument/tag/TextTag.java b/src/main/java/exopandora/worldhandler/builder/argument/tag/TextTag.java new file mode 100644 index 0000000..dfda8ef --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/argument/tag/TextTag.java @@ -0,0 +1,32 @@ +package exopandora.worldhandler.builder.argument.tag; + +import exopandora.worldhandler.util.SignText; +import net.minecraft.nbt.Tag; + +public class TextTag implements ITagProvider +{ + private final int id; + private final SignText text = new SignText(); + + public TextTag(int id) + { + this.id = id; + } + + public SignText getText() + { + return this.text; + } + + @Override + public String key() + { + return "Text" + this.id; + } + + @Override + public Tag value() + { + return this.text.serialize(); + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/AdvancementCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/AdvancementCommandBuilder.java new file mode 100644 index 0000000..b0452da --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/AdvancementCommandBuilder.java @@ -0,0 +1,91 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; +import net.minecraft.resources.ResourceLocation; + +public class AdvancementCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final PrimitiveArgument advancement = Arguments.resourceLocation(); + private final PrimitiveArgument criterion = Arguments.greedyString(); + + private final CommandNodeLiteral root = CommandNode.literal("advancement") + .then(CommandNode.literal("grant") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.literal("only") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.GRANT_ONLY) + .then(CommandNode.argument("criterion", this.criterion) + .label(Label.GRANT_ONLY_CRITERION)))) + .then(CommandNode.literal("from") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.GRANT_FROM))) + .then(CommandNode.literal("until") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.GRANT_UNTIL))) + .then(CommandNode.literal("through") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.GRANT_THROUGH))) + .then(CommandNode.literal("everything") + .label(Label.GRANT_EVERYTHING)))) + .then(CommandNode.literal("revoke") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.literal("only") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.REVOKE_ONLY) + .then(CommandNode.argument("criterion", this.criterion) + .label(Label.REVOKE_ONLY_CRITERION)))) + .then(CommandNode.literal("from") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.REVOKE_FROM))) + .then(CommandNode.literal("until") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.REVOKE_UNTIL))) + .then(CommandNode.literal("through") + .then(CommandNode.argument("advancement", this.advancement) + .label(Label.REVOKE_THROUGH))) + .then(CommandNode.literal("everything") + .label(Label.REVOKE_EVERYTHING)))); + + public TargetArgument targets() + { + return this.targets; + } + + public PrimitiveArgument advancement() + { + return this.advancement; + } + + public PrimitiveArgument criterion() + { + return this.criterion; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + GRANT_ONLY, + GRANT_ONLY_CRITERION, + GRANT_FROM, + GRANT_UNTIL, + GRANT_THROUGH, + GRANT_EVERYTHING, + REVOKE_ONLY, + REVOKE_ONLY_CRITERION, + REVOKE_FROM, + REVOKE_UNTIL, + REVOKE_THROUGH, + REVOKE_EVERYTHING; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BanCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/BanCommandBuilder.java new file mode 100644 index 0000000..69fcaf0 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/BanCommandBuilder.java @@ -0,0 +1,15 @@ +package exopandora.worldhandler.builder.impl; + +public class BanCommandBuilder extends TargetReasonCommandBuilder +{ + public BanCommandBuilder() + { + super("ban", Label.BAN, Label.BAN_REASON); + } + + public static enum Label + { + BAN, + BAN_REASON; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/impl/ClearInventoryCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/ClearInventoryCommandBuilder.java new file mode 100644 index 0000000..89c8053 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/ClearInventoryCommandBuilder.java @@ -0,0 +1,54 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.ItemPredicateArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class ClearInventoryCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final ItemPredicateArgument item = Arguments.itemPredicate(); + private final PrimitiveArgument maxCount = Arguments.intArg(); + + private final CommandNodeLiteral root = CommandNode.literal("clear") + .label(Label.CLEAR) + .then(CommandNode.argument("targets", this.targets) + .label(Label.CLEAR_TARGETS) + .then(CommandNode.argument("item", this.item) + .label(Label.CLEAR_TARGETS_ITEM) + .then(CommandNode.argument("maxCount", this.maxCount) + .label(Label.CLEAR_TARGETS_IMTE_MAXCOUNT)))); + + public TargetArgument targets() + { + return this.targets; + } + + public ItemPredicateArgument item() + { + return this.item; + } + + public PrimitiveArgument maxCount() + { + return this.maxCount; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + CLEAR, + CLEAR_TARGETS, + CLEAR_TARGETS_ITEM, + CLEAR_TARGETS_IMTE_MAXCOUNT; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/CloneCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/CloneCommandBuilder.java new file mode 100644 index 0000000..5fc1b92 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/CloneCommandBuilder.java @@ -0,0 +1,90 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.BlockPredicateArgument; + +public class CloneCommandBuilder extends CommandBuilder +{ + private final BlockPosArgument begin = Arguments.blockPos(); + private final BlockPosArgument end = Arguments.blockPos(); + private final BlockPosArgument destination = Arguments.blockPos(); + private final BlockPredicateArgument filter = Arguments.blockPredicate(); + + private final CommandNodeLiteral root = CommandNode.literal("clone") + .then(CommandNode.argument("begin", this.begin) + .then(CommandNode.argument("end", this.end) + .then(CommandNode.argument("destination", this.destination) + .label(Label.CLONE) + .then(CommandNode.literal("replace") + .label(Label.REPLACE) + .then(CommandNode.literal("force") + .label(Label.REPLACE_FORCE)) + .then(CommandNode.literal("move") + .label(Label.REPLACE_MOVE)) + .then(CommandNode.literal("normal") + .label(Label.REPLACE_NORMAL))) + .then(CommandNode.literal("masked") + .label(Label.MASKED) + .then(CommandNode.literal("force") + .label(Label.MASKED_FORCE)) + .then(CommandNode.literal("move") + .label(Label.MASKED_MOVE)) + .then(CommandNode.literal("normal") + .label(Label.MASKED_NORMAL))) + .then(CommandNode.literal("filtered") + .then(CommandNode.argument("filter", this.filter) + .label(Label.FILTERED) + .then(CommandNode.literal("force") + .label(Label.FILTERED_FORCE)) + .then(CommandNode.literal("move") + .label(Label.FILTERED_MOVE)) + .then(CommandNode.literal("normal") + .label(Label.FILTERED_NORMAL))))))); + + public BlockPosArgument begin() + { + return this.begin; + } + + public BlockPosArgument end() + { + return this.end; + } + + public BlockPosArgument destination() + { + return this.destination; + } + + public BlockPredicateArgument filter() + { + return this.filter; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public enum Label + { + CLONE, + REPLACE, + REPLACE_FORCE, + REPLACE_MOVE, + REPLACE_NORMAL, + MASKED, + MASKED_FORCE, + MASKED_MOVE, + MASKED_NORMAL, + FILTERED, + FILTERED_FORCE, + FILTERED_MOVE, + FILTERED_NORMAL; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/DataCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/DataCommandBuilder.java new file mode 100644 index 0000000..c123052 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/DataCommandBuilder.java @@ -0,0 +1,248 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.NbtPathArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TagArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Linkage; + +public class DataCommandBuilder extends CommandBuilder +{ + private final BlockPosArgument targetPos = Arguments.blockPos(); + private final NbtPathArgument path = Arguments.nbtPath(); + private final PrimitiveArgument linkage = Arguments.linkage(); + private final PrimitiveArgument scale = Arguments.doubleArg(); + private final TargetArgument target = Arguments.target(); + private final TagArgument nbt = Arguments.tag(); + private final TargetArgument sourceTarget = Arguments.target(); + private final BlockPosArgument sourcePos = Arguments.blockPos(); + private final PrimitiveArgument sourcePath = Arguments.word(); + private final PrimitiveArgument value = Arguments.greedyString(); + private final PrimitiveArgument index = Arguments.intArg(); + + private final CommandNodeLiteral root = CommandNode.literal("data") + .then(CommandNode.literal("get") + .then(CommandNode.literal("block") + .then(CommandNode.argument("targetPos", this.targetPos) + .label(Label.GET_BLOCK) + .then(CommandNode.argument("path", this.path) + .label(Label.GET_BLOCK_PATH) + .then(CommandNode.argument("scale", this.scale) + .label(Label.GET_BLOCK_PATH_SCALE))))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("target", this.target) + .label(Label.GET_ENTITY) + .then(CommandNode.argument("path", this.path) + .label(Label.GET_ENTITY_PATH) + .then(CommandNode.argument("scale", this.scale) + .label(Label.GET_ENTITY_PATH_SCALE))))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("target", this.target) + .label(Label.GET_STORAGE) + .then(CommandNode.argument("path", this.path) + .label(Label.GET_STORAGE_PATH) + .then(CommandNode.argument("scale", this.scale) + .label(Label.GET_STORAGE_PATH_SCALE)))))) + .then(CommandNode.literal("merge") + .then(CommandNode.literal("block") + .then(CommandNode.argument("targetPos", this.targetPos) + .then(CommandNode.argument("nbt", this.nbt) + .label(Label.MERGE_BLOCK)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("nbt", this.nbt) + .label(Label.MERGE_ENTITY)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("nbt", this.nbt) + .label(Label.MERGE_STORAGE))))) + .then(CommandNode.literal("modify") + .then(CommandNode.literal("block") + .then(CommandNode.argument("targetPos", this.targetPos) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("linkage", this.linkage) + .then(CommandNode.literal("from") + .then(CommandNode.literal("block") + .then(CommandNode.argument("sourcePos", this.sourcePos) + .label(Label.MODIFY_BLOCK_FROM_BLOCK) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_BLOCK_FROM_BLOCK_PATH)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("sourceTarget", this.sourceTarget) + .label(Label.MODIFY_BLOCK_FROM_ENTITY) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_BLOCK_FROM_ENTITY_PATH)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("source", this.sourceTarget) + .label(Label.MODIFY_BLOCK_FROM_STORAGE) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_BLOCK_FROM_STORAGE_PATH))))) + .then(CommandNode.literal("value") + .then(CommandNode.argument("value", this.value) + .label(Label.MODIFY_BLOCK_VALUE))))))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("linkage", this.linkage) + .then(CommandNode.literal("from") + .then(CommandNode.literal("block") + .then(CommandNode.argument("sourcePos", this.sourcePos) + .label(Label.MODIFY_ENTITY_FROM_BLOCK) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_ENTITY_FROM_BLOCK_PATH)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("sourceTarget", this.sourceTarget) + .label(Label.MODIFY_ENTITY_FROM_ENTITY) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_ENTITY_FROM_ENTITY_PATH)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("source", this.sourceTarget) + .label(Label.MODIFY_ENTITY_FROM_STORAGE) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_ENTITY_FROM_STORAGE_PATH))))) + .then(CommandNode.literal("value") + .then(CommandNode.argument("value", this.value) + .label(Label.MODIFY_ENTITY_VALUE))))))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("linkage", this.linkage) + .then(CommandNode.literal("from") + .then(CommandNode.literal("block") + .then(CommandNode.argument("sourcePos", this.sourcePos) + .label(Label.MODIFY_STORAGE_FROM_BLOCK) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_ENTITY_FROM_BLOCK_PATH)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("sourceTarget", this.sourceTarget) + .label(Label.MODIFY_STORAGE_FROM_ENTITY) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_STORAGE_FROM_ENTITY_PATH)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("source", this.sourceTarget) + .label(Label.MODIFY_STORAGE_FROM_STORAGE) + .then(CommandNode.argument("sourcePath", this.sourcePath) + .label(Label.MODIFY_STORAGE_FROM_STORAGE_PATH))))) + .then(CommandNode.literal("value") + .then(CommandNode.argument("value", this.value) + .label(Label.MODIFY_STORAGE_VALUE)))))))) + .then(CommandNode.literal("remove") + .then(CommandNode.literal("block") + .then(CommandNode.argument("targetPos", this.targetPos) + .then(CommandNode.argument("path", this.path) + .label(Label.REMOVE_BLOCK)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .label(Label.REMOVE_ENTITY)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .label(Label.REMOVE_STORAGE))))); + + public BlockPosArgument targetPos() + { + return this.targetPos; + } + + public NbtPathArgument path() + { + return this.path; + } + + public PrimitiveArgument linkage() + { + return this.linkage; + } + + public PrimitiveArgument scale() + { + return this.scale; + } + + public TargetArgument target() + { + return this.target; + } + + public TagArgument nbt() + { + return this.nbt; + } + + public TargetArgument sourceTarget() + { + return this.sourceTarget; + } + + public BlockPosArgument sourcePos() + { + return this.sourcePos; + } + + public PrimitiveArgument sourcePath() + { + return this.sourcePath; + } + + public PrimitiveArgument value() + { + return this.value; + } + + public PrimitiveArgument index() + { + return this.index; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + GET_BLOCK, + GET_BLOCK_PATH, + GET_BLOCK_PATH_SCALE, + GET_ENTITY, + GET_ENTITY_PATH, + GET_ENTITY_PATH_SCALE, + GET_STORAGE, + GET_STORAGE_PATH, + GET_STORAGE_PATH_SCALE, + MERGE_BLOCK, + MERGE_ENTITY, + MERGE_STORAGE, + MODIFY_BLOCK_FROM_BLOCK, + MODIFY_BLOCK_FROM_BLOCK_PATH, + MODIFY_BLOCK_FROM_ENTITY, + MODIFY_BLOCK_FROM_ENTITY_PATH, + MODIFY_BLOCK_FROM_STORAGE, + MODIFY_BLOCK_FROM_STORAGE_PATH, + MODIFY_BLOCK_VALUE, + MODIFY_ENTITY_FROM_BLOCK, + MODIFY_ENTITY_FROM_BLOCK_PATH, + MODIFY_ENTITY_FROM_ENTITY, + MODIFY_ENTITY_FROM_ENTITY_PATH, + MODIFY_ENTITY_FROM_STORAGE, + MODIFY_ENTITY_FROM_STORAGE_PATH, + MODIFY_ENTITY_VALUE, + MODIFY_STORAGE_FROM_BLOCK, + MODIFY_STORAGE_FROM_BLOCK_PATH, + MODIFY_STORAGE_FROM_ENTITY, + MODIFY_STORAGE_FROM_ENTITY_PATH, + MODIFY_STORAGE_FROM_STORAGE, + MODIFY_STORAGE_FROM_STORAGE_PATH, + MODIFY_STORAGE_VALUE, + REMOVE_BLOCK, + REMOVE_ENTITY, + REMOVE_STORAGE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/DeOpCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/DeOpCommandBuilder.java new file mode 100644 index 0000000..fc36def --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/DeOpCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class DeOpCommandBuilder extends TargetCommandBuilder +{ + public DeOpCommandBuilder() + { + super("deop", Label.DEOP); + } + + public static enum Label + { + DEOP; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/impl/DifficultyCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/DifficultyCommandBuilder.java new file mode 100644 index 0000000..2de0fe7 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/DifficultyCommandBuilder.java @@ -0,0 +1,33 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import net.minecraft.world.Difficulty; + +public class DifficultyCommandBuilder extends CommandBuilder +{ + private final PrimitiveArgument difficulty = Arguments.difficulty(); + + private final CommandNodeLiteral root = CommandNode.literal("difficulty") + .then(CommandNode.argument("difficulty", this.difficulty) + .label(Label.DIFFICULTY)); + + public PrimitiveArgument difficulty() + { + return this.difficulty; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + DIFFICULTY; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/EffectCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/EffectCommandBuilder.java new file mode 100644 index 0000000..b54c03a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/EffectCommandBuilder.java @@ -0,0 +1,78 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.EffectArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class EffectCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final EffectArgument effect = Arguments.effect(); + private final PrimitiveArgument seconds = Arguments.intArg(); + private final PrimitiveArgument amplifier = Arguments.byteArg(); + private final PrimitiveArgument hideParticles = Arguments.boolArg(); + + private final CommandNodeLiteral root = CommandNode.literal("effect") + .then(CommandNode.literal("give") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("effect", this.effect) + .label(Label.GIVE) + .then(CommandNode.argument("seconds", this.seconds) + .label(Label.GIVE_SECONDS) + .then(CommandNode.argument("amplifier", this.amplifier) + .label(Label.GIVE_SECONDS_AMPLIFIER) + .then(CommandNode.argument("hideParticles", this.hideParticles) + .label(Label.GIVE_SECONDS_AMPLIFIER_HIDEPARTICLES))))))) + .then(CommandNode.literal("clear") + .label(Label.CLEAR) + .then(CommandNode.argument("targets", this.targets) + .label(Label.CLEAR_TARGETS) + .then(CommandNode.argument("effect", this.effect) + .label(Label.CLEAR_TARGETS_EFFECT)))); + + public TargetArgument targets() + { + return this.targets; + } + + public EffectArgument effect() + { + return this.effect; + } + + public PrimitiveArgument seconds() + { + return this.seconds; + } + + public PrimitiveArgument amplifier() + { + return this.amplifier; + } + + public PrimitiveArgument hideParticles() + { + return this.hideParticles; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + GIVE, + GIVE_SECONDS, + GIVE_SECONDS_AMPLIFIER, + GIVE_SECONDS_AMPLIFIER_HIDEPARTICLES, + CLEAR, + CLEAR_TARGETS, + CLEAR_TARGETS_EFFECT; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/EnchantCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/EnchantCommandBuilder.java new file mode 100644 index 0000000..054a6c4 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/EnchantCommandBuilder.java @@ -0,0 +1,50 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.EnchantmentArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class EnchantCommandBuilder extends CommandBuilder +{ + private final TargetArgument target = Arguments.target(); + private final EnchantmentArgument enchantment = Arguments.enchantment(); + private final PrimitiveArgument level = Arguments.intArg(); + + private final CommandNodeLiteral root = CommandNode.literal("enchant") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("enchantment", this.enchantment) + .label(Label.ENCHANT) + .then(CommandNode.argument("level", this.level) + .label(Label.ENCHANT_LEVEL)))); + + public TargetArgument target() + { + return this.target; + } + + public EnchantmentArgument enchantment() + { + return this.enchantment; + } + + public PrimitiveArgument level() + { + return this.level; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ENCHANT, + ENCHANT_LEVEL; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/ExecuteCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/ExecuteCommandBuilder.java new file mode 100644 index 0000000..cc6161d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/ExecuteCommandBuilder.java @@ -0,0 +1,624 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.ArgumentListArgument; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.CommandArgument; +import exopandora.worldhandler.builder.argument.DimensionArgument; +import exopandora.worldhandler.builder.argument.NbtPathArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.RangeArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; +import exopandora.worldhandler.builder.argument.ArgumentListArgument.OptionalCommandBuilder; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Type; +import net.minecraft.commands.arguments.EntityAnchorArgument.Anchor; +import net.minecraft.core.Direction.Axis; +import net.minecraft.resources.ResourceLocation; + +public class ExecuteCommandBuilder extends CommandBuilder +{ + private final CommandArgument command = new CommandArgument(); + private final ArgumentListArgument modifiers = new ArgumentListArgument(); + private final CommandNodeLiteral root = CommandNode.literal("execute") + .then(CommandNode.argument("modifiers", this.modifiers) + .then(CommandNode.literal("run") + .then(CommandNode.argument("command", this.command) + .label(Label.RUN)))); + + public ArgumentListArgument modifiers() + { + return this.modifiers; + } + + public CommandArgument command() + { + return this.command; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + RUN; + } + + public static class AlignOptionalArgument extends OptionalCommandBuilder + { + private final PrimitiveArgument axis = Arguments.axis(); + private final CommandNodeLiteral root = CommandNode.literal("align") + .then(CommandNode.argument("axis", this.axis) + .label(Label.AXIS)); + + public AlignOptionalArgument(Label label) + { + super(label); + } + + public PrimitiveArgument axis() + { + return this.axis; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + AXIS; + } + } + + public static class AnchoredOptionalArgument extends OptionalCommandBuilder + { + private final PrimitiveArgument anchor = Arguments.anchor(); + private final CommandNodeLiteral root = CommandNode.literal("anchored") + .then(CommandNode.argument("anchor", this.anchor) + .label(Label.ANCHOR)); + + public AnchoredOptionalArgument(Label label) + { + super(label); + } + + public PrimitiveArgument anchor() + { + return this.anchor; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ANCHOR; + } + } + + public static class AsOptionalArgument extends OptionalCommandBuilder + { + private final TargetArgument targets = Arguments.target(); + private final CommandNodeLiteral root = CommandNode.literal("as") + .then(CommandNode.argument("targets", this.targets) + .label(Label.AS)); + + public AsOptionalArgument(Label label) + { + super(label); + } + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + AS; + } + } + + public static class AtOptionalArgument extends OptionalCommandBuilder + { + private final TargetArgument targets = Arguments.target(); + private final CommandNodeLiteral root = CommandNode.literal("at") + .then(CommandNode.argument("targets", this.targets) + .label(Label.AT)); + + public AtOptionalArgument(Label label) + { + super(label); + } + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + AT; + } + } + + public static class FacingOptionalArgument extends OptionalCommandBuilder + { + private final PrimitiveArgument anchor = Arguments.anchor(); + private final BlockPosArgument pos = Arguments.blockPos(); + private final TargetArgument targets = Arguments.target(); + private final CommandNodeLiteral root = CommandNode.literal("facing") + .then(CommandNode.argument("pos", this.pos) + .label(Label.POS)) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("anchor", this.anchor) + .label(Label.ENTITY)))); + + public FacingOptionalArgument(Label label) + { + super(label); + } + + public PrimitiveArgument anchor() + { + return this.anchor; + } + + public BlockPosArgument pos() + { + return this.pos; + } + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + POS, + ENTITY; + } + } + + public static class InOptionalArgument extends OptionalCommandBuilder + { + private final DimensionArgument dimension = DimensionArgument.dimension(); + private final CommandNodeLiteral root = CommandNode.literal("in") + .then(CommandNode.argument("dimension", this.dimension) + .label(Label.IN)); + + public InOptionalArgument(Label label) + { + super(label); + } + + public DimensionArgument dimension() + { + return this.dimension; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + IN; + } + } + + public static class PositionedOptionalArgument extends OptionalCommandBuilder + { + private final BlockPosArgument pos = Arguments.blockPos(); + private final TargetArgument targets = Arguments.target(); + private final CommandNodeLiteral root = CommandNode.literal("positioned") + .then(CommandNode.argument("pos", this.pos) + .label(Label.POS)) + .then(CommandNode.literal("as") + .then(CommandNode.argument("targets", this.targets) + .label(Label.AS))); + + public PositionedOptionalArgument(Label label) + { + super(label); + } + + public BlockPosArgument pos() + { + return this.pos; + } + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + POS, + AS; + } + } + + public static class RotatedOptionalArgument extends OptionalCommandBuilder + { + private final TargetArgument targets = Arguments.target(); + private final CommandNodeLiteral root = CommandNode.literal("rotated") + .then(CommandNode.literal("as") + .then(CommandNode.argument("targets", this.targets) + .label(Label.ROTATED))); + + public RotatedOptionalArgument(Label label) + { + super(label); + } + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ROTATED; + } + } + + private static class ConditionOptionalArgument extends OptionalCommandBuilder + { + private final BlockPosArgument pos = Arguments.blockPos(); + private final PrimitiveArgument block = Arguments.resourceLocation(); + private final BlockPosArgument start = Arguments.blockPos(); + private final BlockPosArgument end = Arguments.blockPos(); + private final BlockPosArgument destination = Arguments.blockPos(); + private final NbtPathArgument path = Arguments.nbtPath(); + private final PrimitiveArgument predicate = Arguments.resourceLocation(); + private final TargetArgument target = Arguments.target(); + private final TargetArgument source = Arguments.target(); + private final PrimitiveArgument targetObjective = Arguments.word(); + private final PrimitiveArgument sourceObjective = Arguments.word(); + private final RangeArgument range = Arguments.intRange(); + private final CommandNodeLiteral root; + + public ConditionOptionalArgument(String condition, Label label) + { + super(label); + this.root = CommandNode.literal(condition) + .then(CommandNode.literal("block") + .then(CommandNode.argument("pos", this.pos) + .then(CommandNode.argument("block", this.block) + .label(Label.BLOCK)))) + .then(CommandNode.literal("blocks") + .then(CommandNode.argument("start", this.start) + .then(CommandNode.argument("end", this.end) + .then(CommandNode.argument("destination", this.destination) + .then(CommandNode.literal("all") + .label(Label.BLOCKS_ALL)) + .then(CommandNode.literal("masked") + .label(Label.BLOCKS_MASKED)))))) + .then(CommandNode.literal("data") + .then(CommandNode.literal("block") + .then(CommandNode.argument("sourcePos", this.pos) + .then(CommandNode.argument("sourcePath", this.path) + .label(Label.DATA_BLOCK)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("sourceTarget", this.target) + .then(CommandNode.argument("sourcePath", this.path) + .label(Label.DATA_ENTITY)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("source", this.target) + .then(CommandNode.argument("sourcePath", this.path) + .label(Label.DATA_STORAGE))))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("entites", this.target) + .label(Label.ENTITY))) + .then(CommandNode.literal("predicate") + .then(CommandNode.argument("predicate", this.predicate) + .label(Label.PREDICATE))) + .then(CommandNode.literal("score") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("targetObjective", this.targetObjective) + .then(CommandNode.literal("<") + .then(CommandNode.argument("source", this.source) + .then(CommandNode.argument("sourceObjective", this.sourceObjective) + .label(Label.SCORE_LT)))) + .then(CommandNode.literal("<=") + .then(CommandNode.argument("source", this.source) + .then(CommandNode.argument("sourceObjective", this.sourceObjective) + .label(Label.SCORE_LE)))) + .then(CommandNode.literal("=") + .then(CommandNode.argument("source", this.source) + .then(CommandNode.argument("sourceObjective", this.sourceObjective) + .label(Label.SCORE_EQ)))) + .then(CommandNode.literal(">") + .then(CommandNode.argument("source", this.source) + .then(CommandNode.argument("sourceObjective", this.sourceObjective) + .label(Label.SCORE_GT)))) + .then(CommandNode.literal(">=") + .then(CommandNode.argument("source", this.source) + .then(CommandNode.argument("sourceObjective", this.sourceObjective) + .label(Label.SCORE_GE)))) + .then(CommandNode.literal("matches") + .then(CommandNode.argument("range", this.range) + .label(Label.SCORE_MATCHES)))))); + } + + public BlockPosArgument pos() + { + return this.pos; + } + + public PrimitiveArgument block() + { + return this.block; + } + + public BlockPosArgument start() + { + return this.start; + } + + public BlockPosArgument end() + { + return this.end; + } + + public BlockPosArgument destination() + { + return this.destination; + } + + public NbtPathArgument path() + { + return this.path; + } + + public PrimitiveArgument predicate() + { + return this.predicate; + } + + public TargetArgument targets() + { + return this.target; + } + + public TargetArgument source() + { + return this.source; + } + + public PrimitiveArgument targetObjective() + { + return this.targetObjective; + } + + public PrimitiveArgument sourceObjective() + { + return this.sourceObjective; + } + + public RangeArgument range() + { + return this.range; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + BLOCK, + BLOCKS_ALL, + BLOCKS_MASKED, + DATA_BLOCK, + DATA_ENTITY, + DATA_STORAGE, + ENTITY, + PREDICATE, + SCORE_LT, + SCORE_LE, + SCORE_EQ, + SCORE_GT, + SCORE_GE, + SCORE_MATCHES; + } + } + + public static class IfOptionalArgument extends ConditionOptionalArgument + { + public IfOptionalArgument(Label label) + { + super("if", label); + } + } + + public static class UnlessOptionalArgument extends ConditionOptionalArgument + { + public UnlessOptionalArgument(Label label) + { + super("unless", label); + } + } + + public static class StoreOptionalArgument extends OptionalCommandBuilder + { + private final BlockPosArgument targetPos = Arguments.blockPos(); + private final NbtPathArgument path = Arguments.nbtPath(); + private final PrimitiveArgument type = Arguments.type(); + private final PrimitiveArgument scale = Arguments.doubleArg(); + private final PrimitiveArgument id = Arguments.resourceLocation(); + private final TargetArgument target = Arguments.target(); + private final PrimitiveArgument objective = Arguments.word(); + + private final CommandNodeLiteral root = CommandNode.literal("store") + .then(CommandNode.literal("result") + .then(CommandNode.literal("block") + .then(CommandNode.argument("targetPos", this.targetPos) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("type", this.type) + .then(CommandNode.argument("scale", this.scale) + .label(Label.RESULT_BLOCK)))))) + .then(CommandNode.literal("bossbar") + .then(CommandNode.argument("id", this.id) + .then(CommandNode.literal("max") + .label(Label.RESULT_BOSSBAR_MAX)) + .then(CommandNode.literal("value") + .label(Label.RESULT_BOSSBAR_VALUE)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("type", this.type) + .then(CommandNode.argument("scale", this.scale) + .label(Label.RESULT_ENTITY)))))) + .then(CommandNode.literal("score") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("objective", this.objective) + .label(Label.RESULT_SCORE)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("type", this.type) + .then(CommandNode.argument("scale", this.scale) + .label(Label.RESULT_STORAGE)))))) + .then(CommandNode.literal("success") + .then(CommandNode.literal("block") + .then(CommandNode.argument("targetPos", this.targetPos) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("type", this.type) + .then(CommandNode.argument("scale", this.scale) + .label(Label.SUCCESS_BLOCK)))))) + .then(CommandNode.literal("bossbar") + .then(CommandNode.argument("id", this.id) + .then(CommandNode.literal("max") + .label(Label.SUCCESS_BOSSBAR_MAX)) + .then(CommandNode.literal("value") + .label(Label.SUCCESS_BOSSBAR_VALUE)))) + .then(CommandNode.literal("entity") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("type", this.type) + .then(CommandNode.argument("scale", this.scale) + .label(Label.SUCCESS_ENTITY)))))) + .then(CommandNode.literal("score") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("objective", this.objective) + .label(Label.SUCCESS_SCORE)))) + .then(CommandNode.literal("storage") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("path", this.path) + .then(CommandNode.argument("type", this.type) + .then(CommandNode.argument("scale", this.scale) + .label(Label.SUCCESS_STORAGE)))))))); + + public StoreOptionalArgument(Label label) + { + super(label); + } + + public BlockPosArgument targetPos() + { + return this.targetPos; + } + + public NbtPathArgument path() + { + return this.path; + } + + public PrimitiveArgument type() + { + return this.type; + } + + public PrimitiveArgument scale() + { + return this.scale; + } + + public PrimitiveArgument id() + { + return this.id; + } + + public TargetArgument target() + { + return this.target; + } + + public PrimitiveArgument objective() + { + return this.objective; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + RESULT_BLOCK, + RESULT_BOSSBAR_MAX, + RESULT_BOSSBAR_VALUE, + RESULT_ENTITY, + RESULT_SCORE, + RESULT_STORAGE, + SUCCESS_BLOCK, + SUCCESS_BOSSBAR_MAX, + SUCCESS_BOSSBAR_VALUE, + SUCCESS_ENTITY, + SUCCESS_SCORE, + SUCCESS_STORAGE; + } + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/ExperienceCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/ExperienceCommandBuilder.java new file mode 100644 index 0000000..4b9eb2d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/ExperienceCommandBuilder.java @@ -0,0 +1,66 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class ExperienceCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final PrimitiveArgument amount = Arguments.intArg(); + + private final CommandNodeLiteral root = CommandNode.literal("experience") + .then(CommandNode.literal("add") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("amount", this.amount) + .label(Label.ADD) + .then(CommandNode.literal("points") + .label(Label.ADD_POINTS)) + .then(CommandNode.literal("levels") + .label(Label.ADD_LEVELS))))) + .then(CommandNode.literal("set") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("amount", this.amount) + .label(Label.SET) + .then(CommandNode.literal("points") + .label(Label.SET_POINTS)) + .then(CommandNode.literal("levels") + .label(Label.SET_LEVELS))))) + .then(CommandNode.literal("query") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.literal("points") + .label(Label.QUERY_POINTS)) + .then(CommandNode.literal("levels") + .label(Label.QUERY_LEVELS)))); + + public TargetArgument targets() + { + return this.targets; + } + + public PrimitiveArgument amount() + { + return this.amount; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ADD, + ADD_POINTS, + ADD_LEVELS, + SET, + SET_POINTS, + SET_LEVELS, + QUERY_POINTS, + QUERY_LEVELS; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/FillCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/FillCommandBuilder.java new file mode 100644 index 0000000..9fe3522 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/FillCommandBuilder.java @@ -0,0 +1,70 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.BlockPredicateArgument; +import exopandora.worldhandler.builder.argument.BlockStateArgument; + +public class FillCommandBuilder extends CommandBuilder +{ + private final BlockPosArgument from = Arguments.blockPos(); + private final BlockPosArgument to = Arguments.blockPos(); + private final BlockStateArgument block = Arguments.blockState(); + private final BlockPredicateArgument filter = Arguments.blockPredicate(); + + private final CommandNodeLiteral root = CommandNode.literal("fill") + .then(CommandNode.argument("from", this.from) + .then(CommandNode.argument("to", this.to) + .then(CommandNode.argument("block", this.block) + .label(Label.FILL) + .then(CommandNode.literal("destroy") + .label(Label.DESTROY)) + .then(CommandNode.literal("hollow") + .label(Label.HOLLOW)) + .then(CommandNode.literal("keep") + .label(Label.KEEP)) + .then(CommandNode.literal("outline") + .label(Label.OUTLINE)) + .then(CommandNode.literal("replace") + .then(CommandNode.argument("filter", this.filter) + .label(Label.REPLACE)))))); + + public BlockPosArgument from() + { + return this.from; + } + + public BlockPosArgument to() + { + return this.to; + } + + public BlockStateArgument block() + { + return this.block; + } + + public BlockPredicateArgument filter() + { + return this.filter; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public enum Label + { + FILL, + DESTROY, + HOLLOW, + KEEP, + OUTLINE, + REPLACE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/GameRuleCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/GameRuleCommandBuilder.java new file mode 100644 index 0000000..07ee696 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/GameRuleCommandBuilder.java @@ -0,0 +1,41 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; + +public class GameRuleCommandBuilder extends CommandBuilder +{ + private final PrimitiveArgument rule = Arguments.word(); + private final PrimitiveArgument value = Arguments.word(); + + private final CommandNodeLiteral root = CommandNode.literal("gamerule") + .then(CommandNode.argument("rule", this.rule) + .label(Label.GAMERULE) + .then(CommandNode.argument("value", this.value) + .label(Label.GAMERULE_VALUE))); + + public PrimitiveArgument rule() + { + return this.rule; + } + + public PrimitiveArgument value() + { + return this.value; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + GAMERULE, + GAMERULE_VALUE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/GamemodeCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/GamemodeCommandBuilder.java new file mode 100644 index 0000000..3c82e1a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/GamemodeCommandBuilder.java @@ -0,0 +1,43 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.Gamemode; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class GamemodeCommandBuilder extends CommandBuilder +{ + private final PrimitiveArgument gamemode = Arguments.gamemode(); + private final TargetArgument target = Arguments.target(); + + private final CommandNodeLiteral root = CommandNode.literal("gamemode") + .then(CommandNode.argument("gamemode", this.gamemode) + .label(Label.GAMEMODE) + .then(CommandNode.argument("target", this.target) + .label(Label.PLAYER))); + + public PrimitiveArgument gamemode() + { + return this.gamemode; + } + + public TargetArgument target() + { + return this.target; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public enum Label + { + GAMEMODE, + PLAYER; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/GiveCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/GiveCommandBuilder.java new file mode 100644 index 0000000..5bf06c2 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/GiveCommandBuilder.java @@ -0,0 +1,50 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.ItemArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class GiveCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final ItemArgument item = Arguments.item(); + private final PrimitiveArgument count = Arguments.intArg(); + + private final CommandNodeLiteral root = CommandNode.literal("give") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("item", this.item) + .label(Label.GIVE) + .then(CommandNode.argument("count", this.count) + .label(Label.GIVE_COUNT)))); + + public TargetArgument targets() + { + return this.targets; + } + + public ItemArgument item() + { + return this.item; + } + + public PrimitiveArgument count() + { + return this.count; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public enum Label + { + GIVE, + GIVE_COUNT; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/KickCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/KickCommandBuilder.java new file mode 100644 index 0000000..fa49484 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/KickCommandBuilder.java @@ -0,0 +1,15 @@ +package exopandora.worldhandler.builder.impl; + +public class KickCommandBuilder extends TargetReasonCommandBuilder +{ + public KickCommandBuilder() + { + super("kick", Label.KICK, Label.KICK_REASON); + } + + public static enum Label + { + KICK, + KICK_REASON; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/impl/KillCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/KillCommandBuilder.java new file mode 100644 index 0000000..f723231 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/KillCommandBuilder.java @@ -0,0 +1,34 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class KillCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + + private final CommandNodeLiteral root = CommandNode.literal("kill") + .label(Label.KILL) + .then(CommandNode.argument("targets", this.targets) + .label(Label.KILL_TARGETS)); + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + KILL, + KILL_TARGETS; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/impl/LiteralCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/LiteralCommandBuilder.java new file mode 100644 index 0000000..6930937 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/LiteralCommandBuilder.java @@ -0,0 +1,32 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; + +public class LiteralCommandBuilder extends CommandBuilder +{ + private final CommandNodeLiteral command; + + public LiteralCommandBuilder(String command) + { + this(command, Label.ROOT); + } + + public LiteralCommandBuilder(String command, Object label) + { + this.command = CommandNode.literal(command) + .label(label); + } + + @Override + protected CommandNodeLiteral root() + { + return this.command; + } + + public static enum Label + { + ROOT; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/OpCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/OpCommandBuilder.java new file mode 100644 index 0000000..b479216 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/OpCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class OpCommandBuilder extends TargetCommandBuilder +{ + public OpCommandBuilder() + { + super("op", Label.OP); + } + + public static enum Label + { + OP; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/impl/PardonCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/PardonCommandBuilder.java new file mode 100644 index 0000000..d59706d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/PardonCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class PardonCommandBuilder extends TargetCommandBuilder +{ + public PardonCommandBuilder() + { + super("pardon", Label.PARDON); + } + + public static enum Label + { + PARDON; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/builder/impl/RecipeCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/RecipeCommandBuilder.java new file mode 100644 index 0000000..4bfaa58 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/RecipeCommandBuilder.java @@ -0,0 +1,53 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; +import net.minecraft.resources.ResourceLocation; + +public class RecipeCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final PrimitiveArgument recipe = Arguments.resourceLocation(); + + private final CommandNodeLiteral root = CommandNode.literal("recipe") + .then(CommandNode.literal("give") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("recipe", this.recipe) + .label(Label.GIVE)) + .then(CommandNode.literal("*") + .label(Label.GIVE_ALL)))) + .then(CommandNode.literal("take") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("recipe", this.recipe) + .label(Label.TAKE)) + .then(CommandNode.literal("*") + .label(Label.TAKE_ALL)))); + + public TargetArgument targets() + { + return this.targets; + } + + public PrimitiveArgument recipe() + { + return this.recipe; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + GIVE, + GIVE_ALL, + TAKE, + TAKE_ALL; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SaveAllCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SaveAllCommandBuilder.java new file mode 100644 index 0000000..366f1d9 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SaveAllCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class SaveAllCommandBuilder extends LiteralCommandBuilder +{ + public SaveAllCommandBuilder() + { + super("save-all", Label.SAVE_ALL); + } + + public static enum Label + { + SAVE_ALL; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SaveOffCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SaveOffCommandBuilder.java new file mode 100644 index 0000000..c679d3d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SaveOffCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class SaveOffCommandBuilder extends LiteralCommandBuilder +{ + public SaveOffCommandBuilder() + { + super("save-off", Label.SAVE_OFF); + } + + public static enum Label + { + SAVE_OFF; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SaveOnCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SaveOnCommandBuilder.java new file mode 100644 index 0000000..f956442 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SaveOnCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class SaveOnCommandBuilder extends LiteralCommandBuilder +{ + public SaveOnCommandBuilder() + { + super("save-on", Label.SAVE_ON); + } + + public static enum Label + { + SAVE_ON; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/ScoreboardCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/ScoreboardCommandBuilder.java new file mode 100644 index 0000000..9e423c7 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/ScoreboardCommandBuilder.java @@ -0,0 +1,175 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.PrimitiveArgument.Operation; +import exopandora.worldhandler.builder.argument.TargetArgument; +import net.minecraft.network.chat.Component; +import net.minecraft.world.scores.criteria.ObjectiveCriteria.RenderType; + +public class ScoreboardCommandBuilder extends CommandBuilder +{ + private final PrimitiveArgument objective = Arguments.word(); + private final PrimitiveArgument criteria = Arguments.criteria(); + private final PrimitiveArgument displayName = Arguments.textComponent(); + private final PrimitiveArgument slot = Arguments.word(); + private final PrimitiveArgument renderType = Arguments.renderType(); + private final TargetArgument target = Arguments.target(); + private final TargetArgument targets = Arguments.target(); + private final PrimitiveArgument score = Arguments.intArg(); + private final PrimitiveArgument operation = Arguments.operation(); + private final PrimitiveArgument sourceObjective = Arguments.word(); + + private final CommandNodeLiteral root = CommandNode.literal("scoreboard") + .then(CommandNode.literal("objectives") + .label(Label.OBJECTIVES) + .then(CommandNode.literal("add") + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.argument("criteria", this.criteria) + .label(Label.OBJECTIVES_ADD) + .then(CommandNode.argument("displayName", this.displayName) + .label(Label.OBJECTIVES_ADD_DISPLAYNAME))))) + .then(CommandNode.literal("modify") + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.literal("displayname") + .then(CommandNode.argument("displayName", this.displayName) + .label(Label.OBJECTIVES_MODIFY_DISPLAYNAME))) + .then(CommandNode.literal("rendertype") + .then(CommandNode.argument("renderType", this.renderType) + .label(Label.OBJECTIVES_MODIFY_RENDERTYPE))))) + .then(CommandNode.literal("remove") + .then(CommandNode.argument("objective", this.objective) + .label(Label.OBJECTIVES_REMOVE))) + .then(CommandNode.literal("setdisplay") + .then(CommandNode.argument("slot", this.slot) + .label(Label.OBJECTIVES_SETDISPLAY_SLOT) + .then(CommandNode.argument("objective", this.objective) + .label(Label.OBJECTIVES_SETDISPLAY_SLOT_OBJECTIVE))))) + .then(CommandNode.literal("players") + .label(Label.PLAYERS) + .then(CommandNode.literal("list") + .label(Label.PLAYERS_LIST) + .then(CommandNode.argument("target", this.target) + .label(Label.PLAYERS_LIST_TARGET))) + .then(CommandNode.literal("set") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.argument("score", this.score) + .label(Label.PLAYERS_SET_SCORE))))) + .then(CommandNode.literal("get") + .then(CommandNode.argument("target", this.target) + .then(CommandNode.argument("objective", this.objective) + .label(Label.PLAYERS_GET_SCORE)))) + .then(CommandNode.literal("set") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.argument("score", this.score) + .label(Label.PLAYERS_SET_SCORE))))) + .then(CommandNode.literal("add") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.argument("score", this.score) + .label(Label.PLAYERS_ADD_SCORE))))) + .then(CommandNode.literal("remove") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.argument("score", this.score) + .label(Label.PLAYERS_REMOVE_SCORE))))) + .then(CommandNode.literal("reset") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.argument("objective", this.objective) + .label(Label.PLAYERS_RESET_SCORE)))) + .then(CommandNode.literal("enable") + .then(CommandNode.argument("targets", this.targets) + .label(Label.PLAYERS_ENABLE) + .then(CommandNode.argument("objective", this.objective) + .label(Label.PLAYERS_ENABLE_OBJECTIVE)))) + .then(CommandNode.literal("operation") + .then(CommandNode.argument("targetObjective", this.objective) + .then(CommandNode.argument("operation", this.operation) + .then(CommandNode.argument("source", this.targets) + .then(CommandNode.argument("sourceObjective", this.sourceObjective) + .label(Label.PLAYERS_OPERATION))))))); + + public PrimitiveArgument objective() + { + return this.objective; + } + + public PrimitiveArgument criteria() + { + return this.criteria; + } + + public PrimitiveArgument displayName() + { + return this.displayName; + } + + public PrimitiveArgument slot() + { + return this.slot; + } + + public PrimitiveArgument renderType() + { + return this.renderType; + } + + public TargetArgument target() + { + return this.target; + } + + public TargetArgument targets() + { + return this.targets; + } + + public PrimitiveArgument score() + { + return this.score; + } + + public PrimitiveArgument operation() + { + return this.operation; + } + + public PrimitiveArgument sourceObjective() + { + return this.sourceObjective; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + OBJECTIVES, + OBJECTIVES_ADD, + OBJECTIVES_ADD_DISPLAYNAME, + OBJECTIVES_MODIFY_DISPLAYNAME, + OBJECTIVES_MODIFY_RENDERTYPE, + OBJECTIVES_REMOVE, + OBJECTIVES_SETDISPLAY_SLOT, + OBJECTIVES_SETDISPLAY_SLOT_OBJECTIVE, + PLAYERS, + PLAYERS_LIST, + PLAYERS_LIST_TARGET, + PLAYERS_SET_SCORE, + PLAYERS_GET_SCORE, + PLAYERS_ADD_SCORE, + PLAYERS_REMOVE_SCORE, + PLAYERS_RESET_SCORE, + PLAYERS_ENABLE, + PLAYERS_ENABLE_OBJECTIVE, + PLAYERS_OPERATION; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SetBlockCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SetBlockCommandBuilder.java new file mode 100644 index 0000000..da2e7f3 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SetBlockCommandBuilder.java @@ -0,0 +1,49 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.BlockStateArgument; + +public class SetBlockCommandBuilder extends CommandBuilder +{ + private final BlockPosArgument pos = Arguments.blockPos(); + private final BlockStateArgument block = Arguments.blockState(); + + private final CommandNodeLiteral root = CommandNode.literal("setblock") + .then(CommandNode.argument("pos", this.pos) + .then(CommandNode.argument("block", this.block) + .label(Label.SETBLOCK) + .then(CommandNode.literal("destroy") + .label(Label.DESTROY)) + .then(CommandNode.literal("keep") + .label(Label.KEEP)) + .then(CommandNode.literal("replace") + .label(Label.REPLACE)))); + + public BlockPosArgument pos() + { + return this.pos; + } + + public BlockStateArgument block() + { + return this.block; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + SETBLOCK, + DESTROY, + KEEP, + REPLACE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SetSpawnCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SetSpawnCommandBuilder.java new file mode 100644 index 0000000..c3e8b8d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SetSpawnCommandBuilder.java @@ -0,0 +1,52 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.AngleArgument; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class SetSpawnCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final BlockPosArgument pos = Arguments.blockPos(); + private final AngleArgument angle = Arguments.angle(); + + private final CommandNodeLiteral root = CommandNode.literal("spawnpoint") + .then(CommandNode.argument("targets", this.targets) + .label(Label.SPAWNPOINT) + .then(CommandNode.argument("pos", this.pos) + .label(Label.SPAWNPOINT_POS) + .then(CommandNode.argument("angle", this.angle) + .label(Label.SPAWNPOINT_POS_ANGLE)))); + + public TargetArgument targets() + { + return this.targets; + } + + public BlockPosArgument pos() + { + return this.pos; + } + + public AngleArgument angle() + { + return this.angle; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + SPAWNPOINT, + SPAWNPOINT_POS, + SPAWNPOINT_POS_ANGLE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SetWorldSpawnCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SetWorldSpawnCommandBuilder.java new file mode 100644 index 0000000..e0fed30 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SetWorldSpawnCommandBuilder.java @@ -0,0 +1,44 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.AngleArgument; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; + +public class SetWorldSpawnCommandBuilder extends CommandBuilder +{ + private final BlockPosArgument pos = Arguments.blockPos(); + private final AngleArgument angle = Arguments.angle(); + + private final CommandNodeLiteral root = CommandNode.literal("setworldspawn") + .label(Label.SET_WORLD_SPAWN) + .then(CommandNode.argument("pos", this.pos) + .label(Label.SET_WORLD_SPAWN_POS) + .then(CommandNode.argument("angle", this.angle) + .label(Label.SET_WORLD_SPAWN_POS_ANGLE))); + + public BlockPosArgument pos() + { + return this.pos; + } + + public AngleArgument angle() + { + return this.angle; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + SET_WORLD_SPAWN, + SET_WORLD_SPAWN_POS, + SET_WORLD_SPAWN_POS_ANGLE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/StopCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/StopCommandBuilder.java new file mode 100644 index 0000000..8c05a13 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/StopCommandBuilder.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.builder.impl; + +public class StopCommandBuilder extends LiteralCommandBuilder +{ + public StopCommandBuilder() + { + super("stop", Label.STOP); + } + + public static enum Label + { + STOP; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/SummonCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/SummonCommandBuilder.java new file mode 100644 index 0000000..e975899 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/SummonCommandBuilder.java @@ -0,0 +1,52 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPosArgument; +import exopandora.worldhandler.builder.argument.EntitySummonArgument; +import exopandora.worldhandler.builder.argument.TagArgument; + +public class SummonCommandBuilder extends CommandBuilder +{ + private final EntitySummonArgument entity = Arguments.entitySummon(); + private final BlockPosArgument pos = Arguments.blockPos(); + private final TagArgument nbt = Arguments.tag(); + + private final CommandNodeLiteral root = CommandNode.literal("summon") + .then(CommandNode.argument("entity", this.entity) + .label(Label.SUMMON) + .then(CommandNode.argument("pos", this.pos) + .label(Label.SUMMON_POS) + .then(CommandNode.argument("nbt", this.nbt) + .label(Label.SUMMON_POS_NBT)))); + + public EntitySummonArgument entity() + { + return this.entity; + } + + public BlockPosArgument pos() + { + return this.pos; + } + + public TagArgument nbt() + { + return this.nbt; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + SUMMON, + SUMMON_POS, + SUMMON_POS_NBT; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/TagCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/TagCommandBuilder.java new file mode 100644 index 0000000..7a41f5a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/TagCommandBuilder.java @@ -0,0 +1,48 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class TagCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final PrimitiveArgument name = Arguments.word(); + + private final CommandNodeLiteral root = CommandNode.literal("tag") + .then(CommandNode.argument("targets", this.targets) + .then(CommandNode.literal("add") + .then(CommandNode.argument("name", this.name) + .label(Label.ADD))) + .then(CommandNode.literal("remove") + .then(CommandNode.argument("name", this.name) + .label(Label.REMOVE))) + .then(CommandNode.literal("list") + .label(Label.LIST))); + + public TargetArgument targets() + { + return this.targets; + } + + public PrimitiveArgument name() + { + return this.name; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ADD, + REMOVE, + LIST; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/TargetCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/TargetCommandBuilder.java new file mode 100644 index 0000000..d1e2f08 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/TargetCommandBuilder.java @@ -0,0 +1,31 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class TargetCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final CommandNodeLiteral root; + + public TargetCommandBuilder(String root, Object label) + { + this.root = CommandNode.literal(root) + .then(CommandNode.argument("targets", this.targets) + .label(label)); + } + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/TargetReasonCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/TargetReasonCommandBuilder.java new file mode 100644 index 0000000..113528c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/TargetReasonCommandBuilder.java @@ -0,0 +1,41 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class TargetReasonCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + private final PrimitiveArgument reason = Arguments.greedyString(); + + private final CommandNodeLiteral root; + + public TargetReasonCommandBuilder(String root, T noReason, T reason) + { + this.root = CommandNode.literal(root) + .then(CommandNode.argument("targets", this.targets) + .label(noReason) + .then(CommandNode.argument("reason", this.reason) + .label(reason))); + } + + public TargetArgument targets() + { + return this.targets; + } + + public PrimitiveArgument reason() + { + return this.reason; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/TeamCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/TeamCommandBuilder.java new file mode 100644 index 0000000..f6aa1cb --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/TeamCommandBuilder.java @@ -0,0 +1,91 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; +import exopandora.worldhandler.builder.argument.TargetArgument; +import net.minecraft.network.chat.Component; + +public class TeamCommandBuilder extends CommandBuilder +{ + private final PrimitiveArgument team = Arguments.word(); + private final PrimitiveArgument displayName = Arguments.textComponent(); + private final TargetArgument members = Arguments.target(); + private final PrimitiveArgument option = Arguments.word(); + private final PrimitiveArgument value = Arguments.string(); + + private final CommandNodeLiteral root = CommandNode.literal("team") + .then(CommandNode.literal("add") + .then(CommandNode.argument("team", this.team) + .label(Label.ADD) + .then(CommandNode.argument("displayName", this.displayName) + .label(Label.ADD_DISPLAYNAME)))) + .then(CommandNode.literal("empty") + .then(CommandNode.argument("team", this.team) + .label(Label.EMPTY))) + .then(CommandNode.literal("join") + .then(CommandNode.argument("team", this.team) + .then(CommandNode.argument("members", this.members) + .label(Label.JOIN)))) + .then(CommandNode.literal("leave") + .then(CommandNode.argument("members", this.members) + .label(Label.LEAVE))) + .then(CommandNode.literal("list") + .label(Label.LIST) + .then(CommandNode.argument("team", this.team) + .label(Label.LIST_TEAM))) + .then(CommandNode.literal("modify") + .then(CommandNode.argument("team", this.team) + .then(CommandNode.argument("option", this.option) + .then(CommandNode.argument("value", this.value) + .label(Label.MODIFY))))) + .then(CommandNode.literal("remove") + .then(CommandNode.argument("team", this.team) + .label(Label.REMOVE))); + + public PrimitiveArgument team() + { + return this.team; + } + + public PrimitiveArgument displayName() + { + return this.displayName; + } + + public TargetArgument members() + { + return this.members; + } + + public PrimitiveArgument option() + { + return this.option; + } + + public PrimitiveArgument value() + { + return this.value; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ADD, + ADD_DISPLAYNAME, + EMPTY, + JOIN, + LEAVE, + LIST, + LIST_TEAM, + MODIFY, + REMOVE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/TimeCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/TimeCommandBuilder.java new file mode 100644 index 0000000..e308194 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/TimeCommandBuilder.java @@ -0,0 +1,59 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.TimeArgument; + +public class TimeCommandBuilder extends CommandBuilder +{ + private final TimeArgument time = Arguments.time(); + + private final CommandNodeLiteral root = CommandNode.literal("time") + .then(CommandNode.literal("add") + .then(CommandNode.argument("time", this.time) + .label(Label.ADD))) + .then(CommandNode.literal("query") + .then(CommandNode.literal("day") + .label(Label.QUERY_DAY)) + .then(CommandNode.literal("daytime") + .label(Label.QUERY_DAYTIME)) + .then(CommandNode.literal("gametime") + .label(Label.QUERY_GAMETIME))) + .then(CommandNode.literal("set") + .then(CommandNode.argument("time", this.time) + .label(Label.SET)) + .then(CommandNode.literal("day") + .label(Label.SET_DAY)) + .then(CommandNode.literal("midnight") + .label(Label.SET_MIDNIGHT)) + .then(CommandNode.literal("night") + .label(Label.SET_NIGHT)) + .then(CommandNode.literal("noon") + .label(Label.SET_NOON))); + + public TimeArgument time() + { + return this.time; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ADD, + QUERY_DAY, + QUERY_DAYTIME, + QUERY_GAMETIME, + SET, + SET_DAY, + SET_MIDNIGHT, + SET_NIGHT, + SET_NOON; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/TriggerCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/TriggerCommandBuilder.java new file mode 100644 index 0000000..8b19c3d --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/TriggerCommandBuilder.java @@ -0,0 +1,44 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.PrimitiveArgument; + +public class TriggerCommandBuilder extends CommandBuilder +{ + private final PrimitiveArgument objective = Arguments.word(); + private final PrimitiveArgument value = Arguments.intArg(); + + private final CommandNodeLiteral root = CommandNode.literal("trigger") + .then(CommandNode.argument("objective", this.objective) + .then(CommandNode.literal("add") + .then(CommandNode.argument("value", this.value) + .label(Label.ADD))) + .then(CommandNode.literal("set") + .then(CommandNode.argument("value", this.value) + .label(Label.SET)))); + + public PrimitiveArgument objective() + { + return this.objective; + } + + public PrimitiveArgument value() + { + return this.value; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ADD, + SET; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/UsercontentCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/UsercontentCommandBuilder.java new file mode 100644 index 0000000..560b78a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/UsercontentCommandBuilder.java @@ -0,0 +1,94 @@ +package exopandora.worldhandler.builder.impl; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.IDeserializableArgument; +import exopandora.worldhandler.usercontent.factory.ArgumentFactory; +import exopandora.worldhandler.usercontent.model.ArgumentType; +import exopandora.worldhandler.usercontent.model.JsonArgument; + +public class UsercontentCommandBuilder extends CommandBuilder +{ + private final Map arguments = new HashMap(); + private final Set player = new HashSet(); + private final CommandNodeLiteral root; + private final String label; + + public UsercontentCommandBuilder(JsonArgument argument, String label) + { + this.root = CommandNode.literal(argument.getName()).label(argument.getLabel()); + this.label = label; + this.createChildren(this.root, argument.getChildren()); + } + + private void createChildren(CommandNode root, List children) + { + if(children != null) + { + for(JsonArgument child : children) + { + CommandNode node = this.createNode(child); + this.createChildren(node, child.getChildren()); + root.then(node); + } + } + } + + private CommandNode createNode(JsonArgument json) + { + if(json.getType() == null) + { + return CommandNode.literal(json.getName()).label(json.getLabel()); + } + + IDeserializableArgument argument = this.arguments.computeIfAbsent(json.getName(), key -> ArgumentFactory.createArgument(json)); + + if(ArgumentType.PLAYER.equals(json.getType())) + { + this.player.add(argument); + } + + return CommandNode.argument(json.getName(), argument).label(json.getLabel()); + } + + public String getLabel() + { + return label; + } + + public void setPlayerName(String username) + { + this.player.forEach(argument -> argument.deserialize(username)); + } + + @Nullable + public IDeserializableArgument getArgument(String name) + { + return this.arguments.get(name); + } + + public void setArgument(String key, String value) + { + IDeserializableArgument argument = this.arguments.get(key); + + if(argument != null) + { + argument.deserialize(value); + } + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/WHCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/WHCommandBuilder.java new file mode 100644 index 0000000..644493b --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/WHCommandBuilder.java @@ -0,0 +1,64 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.BlockPredicateArgument; +import exopandora.worldhandler.builder.argument.BlockStateArgument; + +public class WHCommandBuilder extends CommandBuilder +{ + private final BlockStateArgument block = Arguments.blockState(); + private final BlockPredicateArgument filter = Arguments.blockPredicate(); + + private final CommandNodeLiteral root = CommandNode.literal("wh") + .then(CommandNode.literal("clone") + .label(Label.CLONE) + .then(CommandNode.literal("filtered") + .then(CommandNode.argument("filter", this.filter) + .label(Label.CLONE_FILTERED))) + .then(CommandNode.literal("masked") + .label(Label.CLONE_MASKED)) + .then(CommandNode.literal("replace") + .label(Label.CLONE_REPLACE))) + .then(CommandNode.literal("fill") + .then(CommandNode.argument("block", this.block) + .label(Label.FILL))) + .then(CommandNode.literal("pos1") + .label(Label.POS1)) + .then(CommandNode.literal("pos2") + .label(Label.POS2)) + .then(CommandNode.literal("replace") + .then(CommandNode.argument("block", this.block) + .then(CommandNode.argument("filter", this.filter) + .label(Label.REPLACE)))); + + public BlockStateArgument block() + { + return this.block; + } + + public BlockPredicateArgument filter() + { + return this.filter; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + CLONE, + CLONE_FILTERED, + CLONE_MASKED, + CLONE_REPLACE, + FILL, + POS1, + POS2, + REPLACE; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/WeatherCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/WeatherCommandBuilder.java new file mode 100644 index 0000000..2af03f5 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/WeatherCommandBuilder.java @@ -0,0 +1,29 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; + +public class WeatherCommandBuilder extends CommandBuilder +{ + private final CommandNodeLiteral root = CommandNode.literal("weather") + .then(CommandNode.literal("clear") + .label(Label.CLEAR)) + .then(CommandNode.literal("rain") + .label(Label.RAIN)) + .then(CommandNode.literal("thunder") + .label(Label.THUNDER)); + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + CLEAR, + RAIN, + THUNDER; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/WhitelistCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/WhitelistCommandBuilder.java new file mode 100644 index 0000000..d64de0c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/WhitelistCommandBuilder.java @@ -0,0 +1,49 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; +import exopandora.worldhandler.builder.argument.Arguments; +import exopandora.worldhandler.builder.argument.TargetArgument; + +public class WhitelistCommandBuilder extends CommandBuilder +{ + private final TargetArgument targets = Arguments.target(); + + private final CommandNodeLiteral root = CommandNode.literal("whitelist") + .then(CommandNode.literal("add") + .then(CommandNode.argument("target", this.targets) + .label(Label.ADD))) + .then(CommandNode.literal("remove") + .then(CommandNode.argument("target", this.targets) + .label(Label.REMOVE))) + .then(CommandNode.literal("reload") + .label(Label.RELOAD)) + .then(CommandNode.literal("on") + .label(Label.ON)) + .then(CommandNode.literal("off") + .label(Label.OFF)) + .then(CommandNode.literal("list") + .label(Label.LIST)); + + public TargetArgument targets() + { + return this.targets; + } + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + ADD, + REMOVE, + RELOAD, + ON, + OFF, + LIST; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/WorldHandlerCommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/impl/WorldHandlerCommandBuilder.java new file mode 100644 index 0000000..8910d21 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/WorldHandlerCommandBuilder.java @@ -0,0 +1,29 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandNode; +import exopandora.worldhandler.builder.CommandNodeLiteral; + +public class WorldHandlerCommandBuilder extends CommandBuilder +{ + private final CommandNodeLiteral root = CommandNode.literal("worldhandler") + .then(CommandNode.literal("help") + .label(Label.HELP)) + .then(CommandNode.literal("display") + .label(Label.DISPLAY)) + .then(CommandNode.literal("version") + .label(Label.VERSION)); + + @Override + protected CommandNodeLiteral root() + { + return this.root; + } + + public static enum Label + { + HELP, + DISPLAY, + VERSION; + } +} diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java index 104af83..51f259e 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEditBlocks.java @@ -119,7 +119,7 @@ public class ContentEditBlocks extends Content this.block2Field.setResponder(text -> { this.block2 = text; - this.builderFill.filter().deserialize(this.block2); //TODO block2 = filter ??? + this.builderFill.filter().deserialize(this.block2); container.initButtons(); }); diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/ArgumentFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/ArgumentFactory.java new file mode 100644 index 0000000..e6ad51e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/ArgumentFactory.java @@ -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> FACTORY = new HashMap>(); + + 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 supplier = FACTORY.get(json.getType()); + + if(supplier == null) + { + return null; + } + + return supplier.get(); + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/ArgumentType.java b/src/main/java/exopandora/worldhandler/usercontent/model/ArgumentType.java new file mode 100644 index 0000000..7f29a26 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/ArgumentType.java @@ -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(); + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonArgument.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonArgument.java new file mode 100644 index 0000000..38143bb --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonArgument.java @@ -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 children; + + public JsonArgument(String name, String label, ArgumentType type, List 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 getChildren() + { + return this.children; + } + + public void setChildren(List children) + { + this.children = children; + } + + public void validate() + { + this.validate(this.name, new HashMap()); + } + + private void validate(String path, Map typeMap) + { + if(this.name == null) + { + throw new IllegalStateException("Argument in path \"" + path + "\" has no name"); + } + + if(this.children == null) + { + return; + } + + List types = new ArrayList(); + List names = new ArrayList(); + + 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); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/util/BlockPlacingMode.java b/src/main/java/exopandora/worldhandler/util/BlockPlacingMode.java new file mode 100644 index 0000000..8352257 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/util/BlockPlacingMode.java @@ -0,0 +1,14 @@ +package exopandora.worldhandler.util; + +public enum BlockPlacingMode +{ + KEEP, + REPLACE, + DESTROY; + + @Override + public String toString() + { + return this.name().toLowerCase(); + } +} diff --git a/src/main/java/exopandora/worldhandler/util/Util.java b/src/main/java/exopandora/worldhandler/util/Util.java new file mode 100644 index 0000000..6496c6f --- /dev/null +++ b/src/main/java/exopandora/worldhandler/util/Util.java @@ -0,0 +1,39 @@ +package exopandora.worldhandler.util; + +import javax.annotation.Nullable; + +public class Util +{ + @Nullable + public static String serializeBounds(@Nullable Number minBound, @Nullable Number maxBound) + { + boolean min = minBound != null; + boolean max = maxBound != null; + + if(min && max && minBound.equals(maxBound)) + { + return minBound.toString(); + } + + if(min || max) + { + StringBuilder builder = new StringBuilder(); + + if(min) + { + builder.append(minBound); + } + + builder.append(".."); + + if(max) + { + builder.append(maxBound); + } + + return builder.toString(); + } + + return null; + } +}