diff --git a/.gitignore b/.gitignore index 65f324f..50d1962 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ !/src/ !/gradle/ +!/run/config/worldhandler/usercontent/ +!/usercontent/ !build.gradle !curseforge.html !gradlew diff --git a/README.md b/README.md index bcd149e..2fb2714 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ It lets you create powerful and complex sub-commands alongside NBT-structures wi # Features # * GUI for commands -* World and player information -* /wh for a simplified /fill and /clone * Client Commands: advancement, blockdata, clear, clone, difficulty, effect, enchant, fill, gamemode, gamerule, give, kill, recipe, scoreboard, setworldspawn, spawnpoint, summon, tag, team, time, trigger, weather, xp * Server Commands: ban, deop, kick, op, pardon, save-all, save-off, save-on, whitelist +* World and player information +* /wh for a simplified /fill and /clone +* Expandable GUI with json files and child mods * Client-side only # Download # @@ -55,6 +56,11 @@ Download World Handler or build from source 2. Copy all files of the `World_Handler_GUI_[VERSION].zip` into the `1.6.2ML.jar` 3. Run Minecraft +# Expansion # + +The World Handler GUI can also be expanded with custom tabs configured with json and javascript files or as a separate child mod in java. +A description on how to implement a custom json and javascript file can be found [here](https://github.com/Exopandora/WorldHandler/blob/master/README.md) and an example child mod can be found [here](https://github.com/Exopandora/WorldHandlerPlugin). + # FAQ # **Q:** Is this client-side only ? diff --git a/curseforge.html b/curseforge.html index f4e82b5..98eecc3 100644 --- a/curseforge.html +++ b/curseforge.html @@ -9,6 +9,12 @@
  • GUI for commands
  • +
  • + Client Commands: advancement, blockdata, clear, clone, difficulty, effect, enchant, fill, gamemode, gamerule, give, kill, recipe, scoreboard, setworldspawn, spawnpoint, summon, tag, team, time, trigger, weather, xp +
  • +
  • + Server Commands: ban, deop, kick, op, pardon, save-all, save-off, save-on, whitelist +
  • World and player information
  • @@ -16,10 +22,7 @@ /wh for a simplified /fill and /clone
  • - Client Commands: advancement, blockdata, clear, clone, difficulty, effect, enchant, fill, gamemode, gamerule, give, kill, recipe, scoreboard, setworldspawn, spawnpoint, summon, tag, team, time, trigger, weather, xp -
  • -
  • - Server Commands: ban, deop, kick, op, pardon, save-all, save-off, save-on, whitelist + Expandable GUI with json files and child mods
  • Client-side only @@ -103,6 +106,11 @@ 3. Run Minecraft
  • +

    Expansion

    +

    + The World Handler GUI can also be expanded with custom tabs configured with json and javascript files or as a separate child mod written in java. + A description on how to implement a custom json and javascript file can be found here and an example child mod can be found here. +

    FAQ

    1. diff --git a/src/main/java/exopandora/worldhandler/WorldHandler.java b/src/main/java/exopandora/worldhandler/WorldHandler.java index 0d00076..c24e212 100644 --- a/src/main/java/exopandora/worldhandler/WorldHandler.java +++ b/src/main/java/exopandora/worldhandler/WorldHandler.java @@ -1,5 +1,7 @@ package exopandora.worldhandler; +import java.nio.file.Path; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -10,6 +12,7 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.helper.AdvancementHelper; import exopandora.worldhandler.helper.CommandHelper; +import exopandora.worldhandler.usercontent.UsercontentLoader; import net.minecraft.client.Minecraft; import net.minecraft.resources.SimpleReloadableResourceManager; import net.minecraftforge.api.distmarker.Dist; @@ -24,11 +27,13 @@ import net.minecraftforge.fml.config.ModConfig.Type; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.fml.loading.FMLPaths; @Mod(Main.MODID) public class WorldHandler { public static final Logger LOGGER = LogManager.getLogger(); + public static final Path USERCONTENT_PATH = FMLPaths.CONFIGDIR.get().resolve(Main.MODID).resolve("usercontent"); public WorldHandler() { @@ -39,7 +44,9 @@ public class WorldHandler { SimpleReloadableResourceManager manager = (SimpleReloadableResourceManager) Minecraft.getInstance().getResourceManager(); manager.addReloadListener(AdvancementHelper.getInstance()); - ModLoadingContext.get().registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + ".toml"); + Config.setupDirectories(WorldHandler.USERCONTENT_PATH); + ModLoadingContext.get().registerConfig(Type.CLIENT, Config.CLIENT_SPEC, Main.MODID + "/" + Main.MODID + ".toml"); + UsercontentLoader.load(WorldHandler.USERCONTENT_PATH); modEventBus.register(Config.class); modEventBus.addListener(Content::createRegistry); modEventBus.addListener(Category::createRegistry); diff --git a/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java b/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java index 0592bdf..ebaaf69 100644 --- a/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java +++ b/src/main/java/exopandora/worldhandler/builder/CommandBuilder.java @@ -8,14 +8,14 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; import exopandora.worldhandler.WorldHandler; -import exopandora.worldhandler.builder.Syntax.SyntaxEntry; +import exopandora.worldhandler.builder.CommandSyntax.Argument; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.builder.types.BlockResourceLocation; import exopandora.worldhandler.builder.types.CoordinateDouble; import exopandora.worldhandler.builder.types.CoordinateInt; import exopandora.worldhandler.builder.types.GreedyString; import exopandora.worldhandler.builder.types.ItemResourceLocation; import exopandora.worldhandler.builder.types.TargetSelector; -import exopandora.worldhandler.builder.types.Type; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -24,7 +24,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public abstract class CommandBuilder implements ICommandBuilderSyntax { - private List> command; + private List> command; public CommandBuilder() { @@ -33,93 +33,98 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax protected void setNode(int index, String node) { - this.set(index, node != null ? (node.isEmpty() ? null : node) : null, Type.STRING); + this.set(index, node != null ? (node.isEmpty() ? null : node) : null, ArgumentType.STRING); } protected void setNode(int index, GreedyString node) { - this.set(index, node != null ? (node.isEmpty() ? null : node) : null, Type.GREEDY_STRING); + this.set(index, node != null ? (node.isEmpty() ? null : node) : null, ArgumentType.GREEDY_STRING); } protected void setNode(int index, boolean node) { - this.set(index, node, Type.BOOLEAN); + this.set(index, node, ArgumentType.BOOLEAN); } protected void setNode(int index, short node) { - this.set(index, node, Type.SHORT); + this.set(index, node, ArgumentType.SHORT); } protected void setNode(int index, byte node) { - this.set(index, node, Type.BYTE); + this.set(index, node, ArgumentType.BYTE); } protected void setNode(int index, int node) { - this.set(index, node, Type.INT); + this.set(index, node, ArgumentType.INT); } protected void setNode(int index, float node) { - this.set(index, node, Type.FLOAT); + this.set(index, node, ArgumentType.FLOAT); } protected void setNode(int index, double node) { - this.set(index, node, Type.DOUBLE); + this.set(index, node, ArgumentType.DOUBLE); } protected void setNode(int index, long node) { - this.set(index, node, Type.LONG); + this.set(index, node, ArgumentType.LONG); } protected void setNode(int index, ResourceLocation node) { - this.set(index, node, Type.RESOURCE_LOCATION); + this.set(index, node, ArgumentType.RESOURCE_LOCATION); } protected void setNode(int index, CoordinateInt coordinate) { - this.set(index, coordinate, Type.COORDINATE_INT); + this.set(index, coordinate, ArgumentType.COORDINATE_INT); } protected void setNode(int index, CoordinateDouble coordinate) { - this.set(index, coordinate, Type.COORDINATE_DOUBLE); + this.set(index, coordinate, ArgumentType.COORDINATE_DOUBLE); } protected void setNode(int index, TargetSelector target) { - this.set(index, target, Type.TARGET_SELECTOR); + this.set(index, target, ArgumentType.TARGET_SELECTOR); } protected void setNode(int index, ItemResourceLocation resource) { - this.set(index, resource != null ? resource.get() : null, Type.ITEM_RESOURCE_LOCATION); + this.set(index, resource != null ? resource.get() : null, ArgumentType.ITEM_RESOURCE_LOCATION); } protected void setNode(int index, BlockResourceLocation resource) { - this.set(index, resource != null ? resource.get() : null, Type.BLOCK_RESOURCE_LOCATION); + this.set(index, resource != null ? resource.get() : null, ArgumentType.BLOCK_RESOURCE_LOCATION); } protected void setNode(int index, CompoundNBT nbt) { - this.set(index, nbt, Type.NBT); + this.set(index, nbt, ArgumentType.NBT); } - private void set(int index, Object value, Type type) + protected void setPlayerName(int index, String username) + { + this.set(index, username, ArgumentType.PLAYER); + } + + private void set(int index, Object value, ArgumentType type) { if(index < this.command.size()) { - SyntaxEntry entry = this.command.get(index).getKey(); - Type expected = entry.getType(); - boolean flag = expected.equals(type); + Argument entry = this.command.get(index).getKey(); + ArgumentType expectedType = entry.getType(); + boolean typeMatch = expectedType.equals(type); - if(value != null && flag) + if(value != null && typeMatch) { this.command.get(index).setValue(value.toString()); } @@ -127,9 +132,9 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax { this.command.get(index).setValue(entry.toString()); - if(!flag) + if(!typeMatch) { - this.warn("set", expected, type, index); + this.warn("set", expectedType, type, index); } } } @@ -142,96 +147,96 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax @Nullable protected String getNodeAsString(int index) { - return this.get(index, Type.STRING); + return this.get(index, ArgumentType.STRING); } @Nullable protected String getNodeAsGreedyString(int index) { - return this.get(index, Type.GREEDY_STRING); + return this.get(index, ArgumentType.GREEDY_STRING); } protected boolean getNodeAsBoolean(int index) { - return this.get(index, Type.BOOLEAN); + return this.get(index, ArgumentType.BOOLEAN); } protected short getNodeAsShort(int index) { - return this.get(index, Type.SHORT); + return this.get(index, ArgumentType.SHORT); } protected byte getNodeAsByte(int index) { - return this.get(index, Type.BYTE); + return this.get(index, ArgumentType.BYTE); } protected int getNodeAsInt(int index) { - return this.get(index, Type.INT); + return this.get(index, ArgumentType.INT); } protected float getNodeAsFloat(int index) { - return this.get(index, Type.FLOAT); + return this.get(index, ArgumentType.FLOAT); } protected double getNodeAsDouble(int index) { - return this.get(index, Type.DOUBLE); + return this.get(index, ArgumentType.DOUBLE); } protected long getNodeAsLong(int index) { - return this.get(index, Type.LONG); + return this.get(index, ArgumentType.LONG); } protected CoordinateInt getNodeAsCoordinateInt(int index) { - return this.get(index, Type.COORDINATE_INT); + return this.get(index, ArgumentType.COORDINATE_INT); } protected CoordinateDouble getNodeAsCoordinateDouble(int index) { - return this.get(index, Type.COORDINATE_DOUBLE); + return this.get(index, ArgumentType.COORDINATE_DOUBLE); } @Nullable protected ResourceLocation getNodeAsResourceLocation(int index) { - return this.get(index, Type.RESOURCE_LOCATION); + return this.get(index, ArgumentType.RESOURCE_LOCATION); } protected TargetSelector getNodeAsTargetSelector(int index) { - return this.get(index, Type.TARGET_SELECTOR); + return this.get(index, ArgumentType.TARGET_SELECTOR); } @Nullable protected ItemResourceLocation getNodeAsItemResourceLocation(int index) { - return this.get(index, Type.ITEM_RESOURCE_LOCATION); + return this.get(index, ArgumentType.ITEM_RESOURCE_LOCATION); } @Nullable protected BlockResourceLocation getNodeAsBlockResourceLocation(int index) { - return this.get(index, Type.BLOCK_RESOURCE_LOCATION); + return this.get(index, ArgumentType.BLOCK_RESOURCE_LOCATION); } @Nullable protected CompoundNBT getNodeAsNBT(int index) { - return this.get(index, Type.NBT); + return this.get(index, ArgumentType.NBT); } @Nullable - private T get(int index, Type type) + private T get(int index, ArgumentType type) { if(index < this.command.size()) { - Entry entry = this.command.get(index); - Type expected = entry.getKey().getType(); + Entry entry = this.command.get(index); + ArgumentType expected = entry.getKey().getType(); String value = entry.getValue(); if(expected.equals(type)) @@ -252,21 +257,21 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax return null; } - private void warn(String function, Type expected, Type type, int index) + private void warn(String function, ArgumentType expected, ArgumentType type, int index) { WorldHandler.LOGGER.warn("[" + function.toUpperCase() + "] Expected \"" + expected + "\" instead of \"" + type + "\" at index \"" + index + "\" for command \"" + this.getCommandName() + "\""); } - private boolean isDefaultEntry(Entry entry) + private boolean isDefaultEntry(Entry entry) { return entry.getKey().getDefault() != null ? entry.getValue().equals(entry.getKey().getDefault().toString()) : false; } - protected void updateSyntax(Syntax syntax) + protected void updateSyntax(CommandSyntax syntax) { if(syntax != null) { - this.command = syntax.getSyntaxEntries().stream().map(entry -> new SimpleEntry(entry, entry.toString())).collect(Collectors.toList()); + this.command = syntax.getArguments().stream().map(entry -> new SimpleEntry(entry, entry.toString())).collect(Collectors.toList()); } } @@ -275,7 +280,7 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax { CommandString command = new CommandString(this.getCommandName()); - for(Entry entry : this.command) + for(Entry entry : this.command) { if(this.isDefaultEntry(entry)) { @@ -295,14 +300,21 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax { CommandString command = new CommandString(this.getCommandName()); - for(Entry entry : this.command) + for(Entry entry : this.command) { if(!entry.getKey().isRequired() && (entry.getKey().toString().equals(entry.getValue()) || this.isDefaultEntry(entry))) { break; } - command.append(entry.getValue()); + if(entry.getKey().isRequired() && entry.getKey().toString().equals(entry.getValue()) && entry.getKey().getDefault() != null) + { + command.append(entry.getKey().getDefault().toString()); + } + else + { + command.append(entry.getValue()); + } } return command.toString(); diff --git a/src/main/java/exopandora/worldhandler/builder/CommandSyntax.java b/src/main/java/exopandora/worldhandler/builder/CommandSyntax.java new file mode 100644 index 0000000..24ffa8f --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/CommandSyntax.java @@ -0,0 +1,112 @@ +package exopandora.worldhandler.builder; + +import java.util.ArrayList; +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +import exopandora.worldhandler.builder.types.ArgumentType; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class CommandSyntax +{ + private List syntax = new ArrayList(); + + public CommandSyntax() + { + + } + + public CommandSyntax(List syntax) + { + this.syntax = syntax; + } + + public CommandSyntax addRequired(String key, ArgumentType type) + { + this.syntax.add(new Argument(key, type, true, null)); + return this; + } + + public CommandSyntax addRequired(String key, ArgumentType type, Object def) + { + this.syntax.add(new Argument(key, type, true, def)); + return this; + } + + public CommandSyntax addOptional(String key, ArgumentType type) + { + this.syntax.add(new Argument(key, type, false, null)); + return this; + } + + public CommandSyntax addOptional(String key, ArgumentType type, Object def) + { + this.syntax.add(new Argument(key, type, false, def)); + return this; + } + + public List getArguments() + { + return this.syntax; + } + + @OnlyIn(Dist.CLIENT) + public static class Argument + { + @SerializedName("name") + private final String key; + + @SerializedName("type") + private final ArgumentType type; + + @SerializedName("required") + private final boolean required; + + @SerializedName("default") + private final Object def; + + public Argument(String key, ArgumentType type, boolean required, Object def) + { + this.key = key; + this.type = type; + this.required = required; + this.def = def; + } + + public String getKey() + { + return this.key; + } + + public ArgumentType getType() + { + return this.type; + } + + public boolean isRequired() + { + return this.required; + } + + public Object getDefault() + { + return this.def; + } + + @Override + public String toString() + { + if(this.required) + { + return "<" + this.key + ">"; + } + else + { + return "[" + this.key + "]"; + } + } + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java b/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java index 9a8743a..b9fb81b 100644 --- a/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java +++ b/src/main/java/exopandora/worldhandler/builder/ICommandBuilderSyntax.java @@ -4,7 +4,7 @@ public interface ICommandBuilderSyntax extends ICommandBuilder { String getCommandName(); String toActualCommand(); - Syntax getSyntax(); + CommandSyntax getSyntax(); @Override default boolean needsCommandBlock() diff --git a/src/main/java/exopandora/worldhandler/builder/Syntax.java b/src/main/java/exopandora/worldhandler/builder/Syntax.java deleted file mode 100644 index a60d104..0000000 --- a/src/main/java/exopandora/worldhandler/builder/Syntax.java +++ /dev/null @@ -1,93 +0,0 @@ -package exopandora.worldhandler.builder; - -import java.util.ArrayList; -import java.util.List; - -import exopandora.worldhandler.builder.types.Type; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -@OnlyIn(Dist.CLIENT) -public class Syntax -{ - private List syntax = new ArrayList(); - - public Syntax addRequired(String key, Type type) - { - this.syntax.add(new SyntaxEntry(key, type, true, null)); - return this; - } - - public Syntax addRequired(String key, Type type, Object def) - { - this.syntax.add(new SyntaxEntry(key, type, true, def)); - return this; - } - - public Syntax addOptional(String key, Type type) - { - this.syntax.add(new SyntaxEntry(key, type, false, null)); - return this; - } - - public Syntax addOptional(String key, Type type, Object def) - { - this.syntax.add(new SyntaxEntry(key, type, false, def)); - return this; - } - - public List getSyntaxEntries() - { - return this.syntax; - } - - @OnlyIn(Dist.CLIENT) - public static class SyntaxEntry - { - private final String key; - private final Type type; - private final boolean required; - private final Object def; - - public SyntaxEntry(String key, Type type, boolean required, Object def) - { - this.key = key; - this.type = type; - this.required = required; - this.def = def; - } - - public String getKey() - { - return this.key; - } - - public Type getType() - { - return this.type; - } - - public boolean isRequired() - { - return this.required; - } - - public Object getDefault() - { - return this.def; - } - - @Override - public String toString() - { - if(this.required) - { - return "<" + this.key + ">"; - } - else - { - return "[" + this.key + "]"; - } - } - } -} diff --git a/src/main/java/exopandora/worldhandler/builder/component/abstr/ComponentAttribute.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttribute.java similarity index 89% rename from src/main/java/exopandora/worldhandler/builder/component/abstr/ComponentAttribute.java rename to src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttribute.java index 6704da6..8f81dc0 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/abstr/ComponentAttribute.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttribute.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.component.abstr; +package exopandora.worldhandler.builder.component.impl; import java.util.HashMap; import java.util.Map; @@ -6,7 +6,7 @@ import java.util.Set; import java.util.function.Function; import exopandora.worldhandler.builder.component.IBuilderComponent; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; +import exopandora.worldhandler.builder.impl.EnumAttributes; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java index 0abb712..46a61ed 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeItem.java @@ -6,8 +6,7 @@ import java.util.function.Function; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.component.abstr.ComponentAttribute; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; +import exopandora.worldhandler.builder.impl.EnumAttributes; import net.minecraft.nbt.INBT; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.ListNBT; diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java index ca6f2c2..8b6e554 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentAttributeMob.java @@ -5,8 +5,7 @@ import java.util.function.Function; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.component.abstr.ComponentAttribute; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; +import exopandora.worldhandler.builder.impl.EnumAttributes; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java index df204b9..067ad3f 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentDisplay.java @@ -1,7 +1,7 @@ package exopandora.worldhandler.builder.component.impl; import exopandora.worldhandler.builder.component.IBuilderComponent; -import exopandora.worldhandler.text.MutableStringTextComponent; +import exopandora.worldhandler.util.MutableStringTextComponent; import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.INBT; import net.minecraft.nbt.ListNBT; diff --git a/src/main/java/exopandora/worldhandler/builder/component/abstr/ComponentPotion.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotion.java similarity index 98% rename from src/main/java/exopandora/worldhandler/builder/component/abstr/ComponentPotion.java rename to src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotion.java index 89f0b84..cf6dbfd 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/abstr/ComponentPotion.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotion.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.component.abstr; +package exopandora.worldhandler.builder.component.impl; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java index a95bd6e..e1bc0b5 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionItem.java @@ -1,6 +1,5 @@ package exopandora.worldhandler.builder.component.impl; -import exopandora.worldhandler.builder.component.abstr.ComponentPotion; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java index bfa6992..7aa5a25 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/ComponentPotionMob.java @@ -1,6 +1,5 @@ package exopandora.worldhandler.builder.component.impl; -import exopandora.worldhandler.builder.component.abstr.ComponentPotion; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/builder/component/abstr/EffectData.java b/src/main/java/exopandora/worldhandler/builder/component/impl/EffectData.java similarity index 97% rename from src/main/java/exopandora/worldhandler/builder/component/abstr/EffectData.java rename to src/main/java/exopandora/worldhandler/builder/component/impl/EffectData.java index 9c2b570..f2e98e2 100644 --- a/src/main/java/exopandora/worldhandler/builder/component/abstr/EffectData.java +++ b/src/main/java/exopandora/worldhandler/builder/component/impl/EffectData.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.component.abstr; +package exopandora.worldhandler.builder.component.impl; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java index 036566c..1830b69 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderAdvancement.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -87,14 +87,14 @@ public class BuilderAdvancement extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("grant|revoke|test", Type.STRING); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("only|until|from|through|everything", Type.STRING); - syntax.addOptional("advancement", Type.RESOURCE_LOCATION); + syntax.addRequired("grant|revoke|test", ArgumentType.STRING); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("only|until|from|through|everything", ArgumentType.STRING); + syntax.addOptional("advancement", ArgumentType.RESOURCE_LOCATION); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderBlockPos.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderBlockPos.java similarity index 96% rename from src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderBlockPos.java rename to src/main/java/exopandora/worldhandler/builder/impl/BuilderBlockPos.java index 0e85e05..598d437 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderBlockPos.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderBlockPos.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.impl.abstr; +package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilderNBT; import exopandora.worldhandler.builder.types.CoordinateInt; diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java index e6eb211..ec38655 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderButcher.java @@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nonnull; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.TargetSelector; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -70,11 +70,11 @@ public class BuilderButcher extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("entity_name", Type.TARGET_SELECTOR); + syntax.addRequired("entity_name", ArgumentType.TARGET_SELECTOR); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java index 8c62f9e..ee4cde8 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderClone.java @@ -2,11 +2,10 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.Coordinate.CoordinateType; import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraft.util.math.BlockPos; import net.minecraftforge.api.distmarker.Dist; @@ -133,21 +132,21 @@ public class BuilderClone extends BuilderDoubleBlockPos } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("x1", Type.COORDINATE_INT); - syntax.addRequired("y1", Type.COORDINATE_INT); - syntax.addRequired("z1", Type.COORDINATE_INT); - syntax.addRequired("x2", Type.COORDINATE_INT); - syntax.addRequired("y2", Type.COORDINATE_INT); - syntax.addRequired("z2", Type.COORDINATE_INT); - syntax.addRequired("x", Type.COORDINATE_INT); - syntax.addRequired("y", Type.COORDINATE_INT); - syntax.addRequired("z", Type.COORDINATE_INT); - syntax.addOptional("mask", Type.STRING); - syntax.addOptional("filter", Type.STRING); + syntax.addRequired("x1", ArgumentType.COORDINATE_INT); + syntax.addRequired("y1", ArgumentType.COORDINATE_INT); + syntax.addRequired("z1", ArgumentType.COORDINATE_INT); + syntax.addRequired("x2", ArgumentType.COORDINATE_INT); + syntax.addRequired("y2", ArgumentType.COORDINATE_INT); + syntax.addRequired("z2", ArgumentType.COORDINATE_INT); + syntax.addRequired("x", ArgumentType.COORDINATE_INT); + syntax.addRequired("y", ArgumentType.COORDINATE_INT); + syntax.addRequired("z", ArgumentType.COORDINATE_INT); + syntax.addOptional("mask", ArgumentType.STRING); + syntax.addOptional("filter", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java index 465d4a2..f28d8a0 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderCustomItem.java @@ -5,9 +5,8 @@ import java.util.Set; import exopandora.worldhandler.builder.component.impl.ComponentAttributeItem; import exopandora.worldhandler.builder.component.impl.ComponentDisplay; import exopandora.worldhandler.builder.component.impl.ComponentEnchantment; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable; -import exopandora.worldhandler.text.MutableStringTextComponent; +import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable; +import exopandora.worldhandler.util.MutableStringTextComponent; import net.minecraft.enchantment.Enchantment; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java index 4a3e994..64b12ae 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderData.java @@ -3,11 +3,10 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.impl.abstr.BuilderBlockPos; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.CoordinateInt; import exopandora.worldhandler.builder.types.TargetSelector; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ResourceLocation; @@ -180,24 +179,24 @@ public class BuilderData extends BuilderBlockPos } @Nullable - private final Syntax getSyntax(EnumMode mode, EnumTarget target) + private final CommandSyntax getSyntax(EnumMode mode, EnumTarget target) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired(mode != null ? mode.toString() : "mode", Type.STRING); - syntax.addRequired(target != null ? target.toString() : "target", Type.STRING); + syntax.addRequired(mode != null ? mode.toString() : "mode", ArgumentType.STRING); + syntax.addRequired(target != null ? target.toString() : "target", ArgumentType.STRING); if(target != null) { switch(target) { case BLOCK: - syntax.addRequired("x", Type.COORDINATE_INT); - syntax.addRequired("y", Type.COORDINATE_INT); - syntax.addRequired("z", Type.COORDINATE_INT); + syntax.addRequired("x", ArgumentType.COORDINATE_INT); + syntax.addRequired("y", ArgumentType.COORDINATE_INT); + syntax.addRequired("z", ArgumentType.COORDINATE_INT); break; case ENTITY: - syntax.addRequired("entity", Type.TARGET_SELECTOR); + syntax.addRequired("entity", ArgumentType.TARGET_SELECTOR); break; default: break; @@ -208,10 +207,10 @@ public class BuilderData extends BuilderBlockPos case GET: break; case MERGE: - syntax.addRequired("nbt", Type.NBT); + syntax.addRequired("nbt", ArgumentType.NBT); break; case REMOVE: - syntax.addRequired("path", Type.STRING); + syntax.addRequired("path", ArgumentType.STRING); break; default: break; @@ -219,7 +218,7 @@ public class BuilderData extends BuilderBlockPos } else { - syntax.addOptional("...", Type.STRING); + syntax.addOptional("...", ArgumentType.STRING); } return syntax; @@ -283,13 +282,13 @@ public class BuilderData extends BuilderBlockPos } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("get|merge|remove", Type.STRING); - syntax.addRequired("block|entity", Type.STRING); - syntax.addOptional("...", Type.STRING); + syntax.addRequired("get|merge|remove", ArgumentType.STRING); + syntax.addRequired("block|entity", ArgumentType.STRING); + syntax.addOptional("...", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java index 160b471..a1e9604 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDifficulty.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraft.world.Difficulty; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -35,11 +35,11 @@ public class BuilderDifficulty extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("peaceful|easy|normal|hard", Type.STRING); + syntax.addRequired("peaceful|easy|normal|hard", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderDoubleBlockPos.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDoubleBlockPos.java similarity index 98% rename from src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderDoubleBlockPos.java rename to src/main/java/exopandora/worldhandler/builder/impl/BuilderDoubleBlockPos.java index 1f73b0f..3ee296b 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderDoubleBlockPos.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderDoubleBlockPos.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.impl.abstr; +package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; import exopandora.worldhandler.builder.types.CoordinateInt; diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java index 4a83c0c..2b658bc 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderEnchantment.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraft.enchantment.Enchantment; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -53,13 +53,13 @@ public class BuilderEnchantment extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("enchantment", Type.RESOURCE_LOCATION); - syntax.addOptional("level", Type.INT, 1); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("enchantment", ArgumentType.RESOURCE_LOCATION); + syntax.addOptional("level", ArgumentType.INT, 1); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java index c503a08..f479aab 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderExperience.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -74,14 +74,14 @@ public class BuilderExperience extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("add|set|query", Type.STRING); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("amount", Type.INT); - syntax.addOptional("levels|points", Type.STRING); + syntax.addRequired("add|set|query", ArgumentType.STRING); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("amount", ArgumentType.INT); + syntax.addOptional("levels|points", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java index 153f93d..4fe089c 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderFill.java @@ -2,11 +2,10 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.impl.abstr.BuilderDoubleBlockPos; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.BlockResourceLocation; import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.BlockHelper; import exopandora.worldhandler.helper.EnumHelper; import net.minecraft.util.math.BlockPos; @@ -106,19 +105,19 @@ public class BuilderFill extends BuilderDoubleBlockPos } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("x1", Type.COORDINATE_INT); - syntax.addRequired("y1", Type.COORDINATE_INT); - syntax.addRequired("z1", Type.COORDINATE_INT); - syntax.addRequired("x2", Type.COORDINATE_INT); - syntax.addRequired("y2", Type.COORDINATE_INT); - syntax.addRequired("z2", Type.COORDINATE_INT); - syntax.addRequired("block", Type.BLOCK_RESOURCE_LOCATION); - syntax.addOptional("filter", Type.STRING); - syntax.addOptional("block", Type.BLOCK_RESOURCE_LOCATION, "block"); + syntax.addRequired("x1", ArgumentType.COORDINATE_INT); + syntax.addRequired("y1", ArgumentType.COORDINATE_INT); + syntax.addRequired("z1", ArgumentType.COORDINATE_INT); + syntax.addRequired("x2", ArgumentType.COORDINATE_INT); + syntax.addRequired("y2", ArgumentType.COORDINATE_INT); + syntax.addRequired("z2", ArgumentType.COORDINATE_INT); + syntax.addRequired("block", ArgumentType.BLOCK_RESOURCE_LOCATION); + syntax.addOptional("filter", ArgumentType.STRING); + syntax.addOptional("block", ArgumentType.BLOCK_RESOURCE_LOCATION, "block"); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java index dae7ebe..ca27c28 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamemode.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -42,12 +42,12 @@ public class BuilderGamemode extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("mode", Type.STRING); - syntax.addOptional("player", Type.STRING); + syntax.addRequired("mode", ArgumentType.STRING); + syntax.addOptional("player", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java index eb7caea..0a68c42 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGamerule.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -52,12 +52,12 @@ public class BuilderGamerule extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addOptional("rule", Type.STRING); - syntax.addOptional("true|false|value", Type.STRING); + syntax.addOptional("rule", ArgumentType.STRING); + syntax.addOptional("true|false|value", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java index c3066c7..cd7e50b 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderGive.java @@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilderNBT; -import exopandora.worldhandler.builder.Syntax; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.ItemResourceLocation; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.ResourceHelper; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ResourceLocation; @@ -86,13 +86,13 @@ public class BuilderGive extends CommandBuilderNBT } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("item", Type.ITEM_RESOURCE_LOCATION); - syntax.addRequired("count", Type.INT); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("item", ArgumentType.ITEM_RESOURCE_LOCATION); + syntax.addRequired("count", ArgumentType.INT); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java index 1b9222a..19ba225 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderMultiCommand.java @@ -11,9 +11,9 @@ public class BuilderMultiCommand implements ICommandBuilder { private final ICommandBuilder[] builders; - public BuilderMultiCommand(ICommandBuilder... builder) + public BuilderMultiCommand(ICommandBuilder... builders) { - this.builders = builder; + this.builders = builders; } @Override diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java index 45fad76..b833415 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayer.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -33,11 +33,11 @@ public class BuilderPlayer extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("player", Type.STRING); + syntax.addRequired("player", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java index f6bf215..35d7c5a 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPlayerReason.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -43,12 +43,12 @@ public class BuilderPlayerReason extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("player", Type.STRING); - syntax.addOptional("reason", Type.STRING); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addOptional("reason", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java index 18921ba..7b117c7 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderPotionEffect.java @@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.component.abstr.EffectData; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.component.impl.EffectData; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraft.potion.Effect; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; @@ -170,16 +170,16 @@ public class BuilderPotionEffect extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("give|clear", Type.STRING); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("effect", Type.RESOURCE_LOCATION); - syntax.addOptional("seconds", Type.INT, 0); - syntax.addOptional("amplifier", Type.BYTE, (byte) -1); - syntax.addOptional("hideParticles", Type.BOOLEAN, false); + syntax.addRequired("give|clear", ArgumentType.STRING); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("effect", ArgumentType.RESOURCE_LOCATION); + syntax.addOptional("seconds", ArgumentType.INT, 0); + syntax.addOptional("amplifier", ArgumentType.BYTE, (byte) -1); + syntax.addOptional("hideParticles", ArgumentType.BOOLEAN, false); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java index 564e510..c64ee93 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderRecipe.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.ResourceLocation; @@ -76,13 +76,13 @@ public class BuilderRecipe extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("give|take", Type.STRING); - syntax.addOptional("player", Type.STRING); - syntax.addOptional("recipe", Type.RESOURCE_LOCATION); + syntax.addRequired("give|take", ArgumentType.STRING); + syntax.addOptional("player", ArgumentType.STRING); + syntax.addOptional("recipe", ArgumentType.RESOURCE_LOCATION); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderScoreboard.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboard.java similarity index 85% rename from src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderScoreboard.java rename to src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboard.java index 6ab306a..4c52b9f 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/abstr/BuilderScoreboard.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboard.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.impl.abstr; +package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java index ffa07c0..d5d3174 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardObjectives.java @@ -2,10 +2,9 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.impl.abstr.BuilderScoreboard; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.GreedyString; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -120,29 +119,29 @@ public class BuilderScoreboardObjectives extends BuilderScoreboard } @Nullable - private Syntax getSyntax(EnumMode mode) + private CommandSyntax getSyntax(EnumMode mode) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); switch(mode) { case ADD: - syntax.addRequired("objectives", Type.STRING); - syntax.addRequired("add", Type.STRING); - syntax.addRequired("name", Type.STRING); - syntax.addRequired("criteria_type", Type.STRING); - syntax.addOptional("display_name...", Type.GREEDY_STRING); + syntax.addRequired("objectives", ArgumentType.STRING); + syntax.addRequired("add", ArgumentType.STRING); + syntax.addRequired("name", ArgumentType.STRING); + syntax.addRequired("criteria_type", ArgumentType.STRING); + syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING); return syntax; case REMOVE: - syntax.addRequired("objectives", Type.STRING); - syntax.addRequired("remove", Type.STRING); - syntax.addRequired("name", Type.STRING); + syntax.addRequired("objectives", ArgumentType.STRING); + syntax.addRequired("remove", ArgumentType.STRING); + syntax.addRequired("name", ArgumentType.STRING); return syntax; case SETDISPLAY: - syntax.addRequired("objectives", Type.STRING); - syntax.addRequired("setdisplay", Type.STRING); - syntax.addRequired("slot", Type.STRING); - syntax.addOptional("objective", Type.STRING); + syntax.addRequired("objectives", ArgumentType.STRING); + syntax.addRequired("setdisplay", ArgumentType.STRING); + syntax.addRequired("slot", ArgumentType.STRING); + syntax.addOptional("objective", ArgumentType.STRING); return syntax; default: return null; @@ -150,13 +149,13 @@ public class BuilderScoreboardObjectives extends BuilderScoreboard } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("objectives", Type.STRING); - syntax.addRequired("list|add|remove|setdisplay", Type.STRING); - syntax.addOptional("...", Type.STRING); + syntax.addRequired("objectives", ArgumentType.STRING); + syntax.addRequired("list|add|remove|setdisplay", ArgumentType.STRING); + syntax.addOptional("...", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java index 768aec9..ae16c0e 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderScoreboardPlayers.java @@ -1,8 +1,7 @@ package exopandora.worldhandler.builder.impl; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.impl.abstr.BuilderScoreboard; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -91,25 +90,25 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard return 0; } - private Syntax getSyntax(String mode) + private CommandSyntax getSyntax(String mode) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); if(mode.equals("enable")) { - syntax.addRequired("players", Type.STRING); - syntax.addRequired("enable", Type.STRING); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("objective", Type.STRING); + syntax.addRequired("players", ArgumentType.STRING); + syntax.addRequired("enable", ArgumentType.STRING); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("objective", ArgumentType.STRING); return syntax; } - syntax.addRequired("players", Type.STRING); - syntax.addRequired("add|set|remove", Type.STRING, "add|set|remove"); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("objective", Type.STRING); - syntax.addRequired("score", Type.INT, 0); + syntax.addRequired("players", ArgumentType.STRING); + syntax.addRequired("add|set|remove", ArgumentType.STRING, "add|set|remove"); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("objective", ArgumentType.STRING); + syntax.addRequired("score", ArgumentType.INT, 0); return syntax; @@ -144,13 +143,13 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("players", Type.STRING); - syntax.addRequired("add|enable|get|list|operation|remove|reset|set", Type.STRING); - syntax.addOptional("...", Type.STRING); + syntax.addRequired("players", ArgumentType.STRING); + syntax.addRequired("add|enable|get|list|operation|remove|reset|set", ArgumentType.STRING); + syntax.addOptional("...", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java index e060e9e..6f4a90b 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSetBlock.java @@ -1,10 +1,9 @@ package exopandora.worldhandler.builder.impl; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.impl.abstr.BuilderBlockPos; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.BlockResourceLocation; import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.IProperty; import net.minecraft.util.ResourceLocation; @@ -71,15 +70,15 @@ public class BuilderSetBlock extends BuilderBlockPos } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("x", Type.COORDINATE_INT); - syntax.addRequired("y", Type.COORDINATE_INT); - syntax.addRequired("z", Type.COORDINATE_INT); - syntax.addRequired("block", Type.BLOCK_RESOURCE_LOCATION); - syntax.addOptional("mode", Type.STRING); + syntax.addRequired("x", ArgumentType.COORDINATE_INT); + syntax.addRequired("y", ArgumentType.COORDINATE_INT); + syntax.addRequired("z", ArgumentType.COORDINATE_INT); + syntax.addRequired("block", ArgumentType.BLOCK_RESOURCE_LOCATION); + syntax.addOptional("mode", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java index 771702d..1b8cbe6 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSignEditor.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.component.impl.ComponentTag; -import exopandora.worldhandler.text.MutableStringTextComponent; -import exopandora.worldhandler.text.SignText; +import exopandora.worldhandler.util.MutableStringTextComponent; +import exopandora.worldhandler.util.SignText; import net.minecraft.nbt.StringNBT; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java index a874dc7..80971c5 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSpawnpoint.java @@ -1,10 +1,10 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.Coordinate.CoordinateType; import exopandora.worldhandler.builder.types.CoordinateInt; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -45,14 +45,14 @@ public class BuilderSpawnpoint extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("x", Type.COORDINATE_INT); - syntax.addRequired("y", Type.COORDINATE_INT); - syntax.addRequired("z", Type.COORDINATE_INT); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("x", ArgumentType.COORDINATE_INT); + syntax.addRequired("y", ArgumentType.COORDINATE_INT); + syntax.addRequired("z", ArgumentType.COORDINATE_INT); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java index 49d2d51..6ed3d66 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderSummon.java @@ -7,17 +7,16 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilderNBT; -import exopandora.worldhandler.builder.Syntax; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.component.impl.ComponentAttributeMob; import exopandora.worldhandler.builder.component.impl.ComponentPotionMob; import exopandora.worldhandler.builder.component.impl.ComponentSummon; import exopandora.worldhandler.builder.component.impl.ComponentTag; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable; +import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable; import exopandora.worldhandler.builder.types.Coordinate.CoordinateType; -import exopandora.worldhandler.text.MutableStringTextComponent; +import exopandora.worldhandler.util.MutableStringTextComponent; import exopandora.worldhandler.builder.types.CoordinateDouble; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraft.block.Block; import net.minecraft.block.Blocks; import net.minecraft.item.Item; @@ -369,15 +368,15 @@ public class BuilderSummon extends CommandBuilderNBT } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("entity_name", Type.RESOURCE_LOCATION); - syntax.addOptional("x", Type.COORDINATE_DOUBLE); - syntax.addOptional("y", Type.COORDINATE_DOUBLE); - syntax.addOptional("z", Type.COORDINATE_DOUBLE); - syntax.addOptional("nbt", Type.NBT); + syntax.addRequired("entity_name", ArgumentType.RESOURCE_LOCATION); + syntax.addOptional("x", ArgumentType.COORDINATE_DOUBLE); + syntax.addOptional("y", ArgumentType.COORDINATE_DOUBLE); + syntax.addOptional("z", ArgumentType.COORDINATE_DOUBLE); + syntax.addOptional("nbt", ArgumentType.NBT); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java index 759e1f5..71d8027 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTag.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -56,13 +56,13 @@ public class BuilderTag extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("player", Type.STRING); - syntax.addRequired("add|list|remove", Type.STRING); - syntax.addRequired("name", Type.STRING); + syntax.addRequired("player", ArgumentType.STRING); + syntax.addRequired("add|list|remove", ArgumentType.STRING); + syntax.addRequired("name", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java index 75a0815..84a78d3 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTeams.java @@ -3,9 +3,9 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; +import exopandora.worldhandler.builder.CommandSyntax; import exopandora.worldhandler.builder.types.GreedyString; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -131,45 +131,45 @@ public class BuilderTeams extends CommandBuilder } @Nullable - private Syntax getSyntax(String mode) + private CommandSyntax getSyntax(String mode) { if(mode.equals("add")) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("add", Type.STRING); - syntax.addRequired("name", Type.STRING); - syntax.addOptional("display_name...", Type.GREEDY_STRING); + syntax.addRequired("add", ArgumentType.STRING); + syntax.addRequired("name", ArgumentType.STRING); + syntax.addOptional("display_name...", ArgumentType.GREEDY_STRING); return syntax; } else if(mode.equals("remove|empty")) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("remove|empty", Type.STRING, "remove|empty"); - syntax.addRequired("name", Type.STRING); + syntax.addRequired("remove|empty", ArgumentType.STRING, "remove|empty"); + syntax.addRequired("name", ArgumentType.STRING); return syntax; } else if(mode.equals("join|leave")) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("join|leave", Type.STRING, "join|leave"); - syntax.addRequired("name", Type.STRING); - syntax.addOptional("player", Type.STRING); + syntax.addRequired("join|leave", ArgumentType.STRING, "join|leave"); + syntax.addRequired("name", ArgumentType.STRING); + syntax.addOptional("player", ArgumentType.STRING); return syntax; } else if(mode.equals("modify")) { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("modify", Type.STRING); - syntax.addRequired("team", Type.STRING); - syntax.addRequired("friendlyfire|color|seeFriendlyInvisibles|nametagVisibility|deathMessageVisibility|collisionRule", Type.STRING); - syntax.addRequired("value", Type.STRING); + syntax.addRequired("modify", ArgumentType.STRING); + syntax.addRequired("team", ArgumentType.STRING); + syntax.addRequired("friendlyfire|color|seeFriendlyInvisibles|nametagVisibility|deathMessageVisibility|collisionRule", ArgumentType.STRING); + syntax.addRequired("value", ArgumentType.STRING); return syntax; } @@ -212,12 +212,12 @@ public class BuilderTeams extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("list|add|remove|empty|join|leave|modify", Type.STRING); - syntax.addOptional("...", Type.STRING); + syntax.addRequired("list|add|remove|empty|join|leave|modify", ArgumentType.STRING); + syntax.addOptional("...", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java index 75d8465..267908e 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTime.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -42,12 +42,12 @@ public class BuilderTime extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("set|add|query", Type.STRING); - syntax.addOptional("value", Type.INT); + syntax.addRequired("set|add|query", ArgumentType.STRING); + syntax.addOptional("value", ArgumentType.INT); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java index 4e1ea6f..b4aaa62 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderTrigger.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import exopandora.worldhandler.helper.EnumHelper; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -62,13 +62,13 @@ public class BuilderTrigger extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("objective", Type.STRING); - syntax.addRequired("add|set", Type.STRING); - syntax.addRequired("value", Type.INT); + syntax.addRequired("objective", ArgumentType.STRING); + syntax.addRequired("add|set", ArgumentType.STRING); + syntax.addRequired("value", ArgumentType.INT); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderUsercontent.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderUsercontent.java new file mode 100644 index 0000000..8f68e92 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderUsercontent.java @@ -0,0 +1,164 @@ +package exopandora.worldhandler.builder.impl; + +import exopandora.worldhandler.builder.CommandBuilder; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.CommandSyntax.Argument; +import exopandora.worldhandler.builder.types.ArgumentType; +import exopandora.worldhandler.builder.types.BlockResourceLocation; +import exopandora.worldhandler.builder.types.CoordinateDouble; +import exopandora.worldhandler.builder.types.CoordinateInt; +import exopandora.worldhandler.builder.types.GreedyString; +import exopandora.worldhandler.builder.types.ItemResourceLocation; +import exopandora.worldhandler.builder.types.TargetSelector; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class BuilderUsercontent extends CommandBuilder +{ + private final String name; + private final CommandSyntax syntax; + + public BuilderUsercontent(String name, CommandSyntax syntax) + { + this.name = name; + this.syntax = syntax; + this.updateSyntax(this.syntax); + } + + public void set(int index, String object) + { + if(index < this.syntax.getArguments().size() && index >= 0) + { + Argument argument = this.syntax.getArguments().get(index); + ArgumentType type = argument.getType(); + + switch(type) + { + case STRING: + this.setNode(index, type.parseOfDefault(object, (String) argument.getDefault())); + break; + case BLOCK_RESOURCE_LOCATION: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case BOOLEAN: + this.setNode(index, type.parseOfDefault(object, (Boolean) argument.getDefault())); + break; + case BYTE: + this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).byteValue())); + break; + case COORDINATE_DOUBLE: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case COORDINATE_INT: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case DOUBLE: + this.setNode(index, type.parseOfDefault(object, (Double) argument.getDefault())); + break; + case FLOAT: + this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).floatValue())); + break; + case GREEDY_STRING: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case INT: + this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).intValue())); + break; + case ITEM_RESOURCE_LOCATION: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case LONG: + this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).longValue())); + break; + case NBT: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case RESOURCE_LOCATION: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + case SHORT: + this.setNode(index, type.parseOfDefault(object, ((Double) argument.getDefault()).shortValue())); + break; + case TARGET_SELECTOR: + this.setNode(index, type.parseOfDefault(object, type.parse((String) argument.getDefault()))); + break; + default: + break; + } + } + } + + public String get(int index) + { + if(index < this.syntax.getArguments().size() && index >= 0) + { + Argument argument = this.syntax.getArguments().get(index); + + switch(argument.getType()) + { + case BLOCK_RESOURCE_LOCATION: + return this.getNodeAsBlockResourceLocation(index).toString(); + case BOOLEAN: + return String.valueOf(this.getNodeAsBoolean(index)); + case BYTE: + return String.valueOf(this.getNodeAsByte(index)); + case COORDINATE_DOUBLE: + return this.getNodeAsCoordinateDouble(index).toString(); + case COORDINATE_INT: + return this.getNodeAsCoordinateInt(index).toString(); + case DOUBLE: + return String.valueOf(this.getNodeAsDouble(index)); + case FLOAT: + return String.valueOf(this.getNodeAsFloat(index)); + case GREEDY_STRING: + return this.getNodeAsGreedyString(index); + case INT: + return String.valueOf(this.getNodeAsInt(index)); + case ITEM_RESOURCE_LOCATION: + return this.getNodeAsItemResourceLocation(index).toString(); + case LONG: + return String.valueOf(this.getNodeAsLong(index)); + case NBT: + return this.getNodeAsNBT(index).toString(); + case RESOURCE_LOCATION: + return this.getNodeAsResourceLocation(index).toString(); + case SHORT: + return String.valueOf(this.getNodeAsShort(index)); + case STRING: + return this.getNodeAsString(index); + case TARGET_SELECTOR: + return this.getNodeAsTargetSelector(index).toString(); + default: + break; + } + } + + return null; + } + + public void setPlayerName(String username) + { + for(int x = 0; x < this.syntax.getArguments().size(); x++) + { + if(ArgumentType.PLAYER.equals(this.syntax.getArguments().get(x).getType())) + { + this.setPlayerName(x, username); + } + } + } + + @Override + public String getCommandName() + { + return this.name; + } + + @Override + public CommandSyntax getSyntax() + { + return this.syntax; + } +} diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java index 1d80cba..b388c48 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWH.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -16,11 +16,11 @@ public class BuilderWH extends CommandBuilder } @Override - public Syntax getSyntax() + public CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("pos1|pos2|fill|replace", Type.STRING); + syntax.addRequired("pos1|pos2|fill|replace", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java index 8a946b1..5a7944f 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWeather.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -42,12 +42,12 @@ public class BuilderWeather extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("clear|rain|thunde", Type.STRING); - syntax.addOptional("duration", Type.INT); + syntax.addRequired("clear|rain|thunde", ArgumentType.STRING); + syntax.addOptional("duration", ArgumentType.INT); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java index ee5ee36..4556535 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWhitelist.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.builder.impl; import javax.annotation.Nullable; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -66,12 +66,12 @@ public class BuilderWhitelist extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("add|remove|reload|on|off", Type.STRING); - syntax.addOptional("player", Type.STRING); + syntax.addRequired("add|remove|reload|on|off", ArgumentType.STRING); + syntax.addOptional("player", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java index 4a96fc2..70f8ea5 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/BuilderWorldHandler.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.builder.impl; import exopandora.worldhandler.builder.CommandBuilder; -import exopandora.worldhandler.builder.Syntax; -import exopandora.worldhandler.builder.types.Type; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.types.ArgumentType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -16,11 +16,11 @@ public class BuilderWorldHandler extends CommandBuilder } @Override - public final Syntax getSyntax() + public final CommandSyntax getSyntax() { - Syntax syntax = new Syntax(); + CommandSyntax syntax = new CommandSyntax(); - syntax.addRequired("help|display|version", Type.STRING); + syntax.addRequired("help|display|version", ArgumentType.STRING); return syntax; } diff --git a/src/main/java/exopandora/worldhandler/builder/impl/abstr/EnumAttributes.java b/src/main/java/exopandora/worldhandler/builder/impl/EnumAttributes.java similarity index 98% rename from src/main/java/exopandora/worldhandler/builder/impl/abstr/EnumAttributes.java rename to src/main/java/exopandora/worldhandler/builder/impl/EnumAttributes.java index d442cf7..95ae826 100644 --- a/src/main/java/exopandora/worldhandler/builder/impl/abstr/EnumAttributes.java +++ b/src/main/java/exopandora/worldhandler/builder/impl/EnumAttributes.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.builder.impl.abstr; +package exopandora.worldhandler.builder.impl; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/exopandora/worldhandler/builder/types/Type.java b/src/main/java/exopandora/worldhandler/builder/types/ArgumentType.java similarity index 73% rename from src/main/java/exopandora/worldhandler/builder/types/Type.java rename to src/main/java/exopandora/worldhandler/builder/types/ArgumentType.java index a1643ae..b361b00 100644 --- a/src/main/java/exopandora/worldhandler/builder/types/Type.java +++ b/src/main/java/exopandora/worldhandler/builder/types/ArgumentType.java @@ -2,6 +2,7 @@ package exopandora.worldhandler.builder.types; import java.util.function.Function; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import com.mojang.brigadier.exceptions.CommandSyntaxException; @@ -13,7 +14,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) -public enum Type +public enum ArgumentType { SHORT(Short::valueOf), BYTE(Byte::valueOf), @@ -24,17 +25,18 @@ public enum Type BOOLEAN(Boolean::valueOf), STRING(String::valueOf), GREEDY_STRING(GreedyString::valueOf), - RESOURCE_LOCATION(Type::parseResourceLocation), + RESOURCE_LOCATION(ArgumentType::parseResourceLocation), ITEM_RESOURCE_LOCATION(ItemResourceLocation::valueOf), BLOCK_RESOURCE_LOCATION(BlockResourceLocation::valueOf), - NBT(Type::parseCompoundNBT), + NBT(ArgumentType::parseCompoundNBT), COORDINATE_INT(CoordinateInt::valueOf), COORDINATE_DOUBLE(CoordinateDouble::valueOf), - TARGET_SELECTOR(TargetSelector::valueOf); + TARGET_SELECTOR(TargetSelector::valueOf), + PLAYER(String::valueOf); private final Function parser; - private Type(Function parser) + private ArgumentType(Function parser) { this.parser = parser; } @@ -46,10 +48,23 @@ public enum Type return (T) this.parser.apply(object); } + @Nonnull + public T parseOfDefault(String object, T def) + { + try + { + return this.parse(object); + } + catch(Exception e) + { + return def; + } + } + @Nullable public static ResourceLocation parseResourceLocation(String value) { - return value != null ? new ResourceLocation(value) : null; + return value != null && !value.isEmpty() ? new ResourceLocation(value) : null; } @Nullable diff --git a/src/main/java/exopandora/worldhandler/config/Config.java b/src/main/java/exopandora/worldhandler/config/Config.java index 6a4d074..396c084 100644 --- a/src/main/java/exopandora/worldhandler/config/Config.java +++ b/src/main/java/exopandora/worldhandler/config/Config.java @@ -1,5 +1,8 @@ package exopandora.worldhandler.config; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import org.apache.commons.lang3.tuple.Pair; @@ -124,4 +127,19 @@ public class Config KeyHandler.updatePosKeys(); } } + + public static void setupDirectories(Path path) + { + try + { + if(!Files.exists(path)) + { + Files.createDirectories(path); + } + } + catch(IOException e) + { + e.printStackTrace(); + } + } } diff --git a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonIcon.java b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonIcon.java index f2f0317..7e7d14e 100644 --- a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonIcon.java +++ b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonIcon.java @@ -11,7 +11,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class GuiButtonIcon extends GuiButtonTooltip { - private EnumIcon icon; + private final EnumIcon icon; public GuiButtonIcon(int x, int y, int widthIn, int heightIn, EnumIcon icon, String tooltip, ActionHandler actionHandler) { diff --git a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java index 9d87742..3ef43b2 100644 --- a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java +++ b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonList.java @@ -24,6 +24,12 @@ public class GuiButtonList extends GuiButtonTooltip this.items = items; this.logic = logic; this.persistence = container.getContent().getPersistence(this.logic.getId(), Persistence::new); + this.init(); + } + + private void init() + { + this.logic.onInit(this.items.get(this.persistence.getIndex())); this.updateMessage(); } @@ -43,7 +49,7 @@ public class GuiButtonList extends GuiButtonTooltip int maxWidth = Math.max(0, this.width - fontRenderer.getStringWidth("< >")); int spaceWidth = fontRenderer.getStringWidth(" "); - String display = exopandora.worldhandler.text.TextFormatting.shortenString(this.getMessage(), maxWidth, fontRenderer); + String display = exopandora.worldhandler.util.TextFormatting.shortenString(this.getMessage(), maxWidth, fontRenderer); int yPos = this.y + (this.height - 8) / 2; this.drawCenteredString(fontRenderer, display, this.x + this.width / 2, yPos, this.getFGColor()); @@ -71,7 +77,7 @@ public class GuiButtonList extends GuiButtonTooltip { if(index < 10) { - this.persistence.setIndex(max - (9 - index)); + this.persistence.setIndex((index - 9 + max) % max); } else { @@ -96,7 +102,7 @@ public class GuiButtonList extends GuiButtonTooltip { if(index > max - 10) { - this.persistence.setIndex(9 - (max - index)); + this.persistence.setIndex((index + 9 - max) % max); } else { diff --git a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonTooltip.java b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonTooltip.java index 85ed7cd..8084b12 100644 --- a/src/main/java/exopandora/worldhandler/gui/button/GuiButtonTooltip.java +++ b/src/main/java/exopandora/worldhandler/gui/button/GuiButtonTooltip.java @@ -22,7 +22,7 @@ public class GuiButtonTooltip extends GuiButtonBase public void renderTooltip(int mouseX, int mouseY) { - if(this.isHovered() && this.tooltip != null) + if(this.isHovered() && this.tooltip != null && !this.tooltip.isEmpty()) { List list = Arrays.asList(this.tooltip.split("\n")); diff --git a/src/main/java/exopandora/worldhandler/gui/button/GuiSlider.java b/src/main/java/exopandora/worldhandler/gui/button/GuiSlider.java index 9262f5e..4259101 100644 --- a/src/main/java/exopandora/worldhandler/gui/button/GuiSlider.java +++ b/src/main/java/exopandora/worldhandler/gui/button/GuiSlider.java @@ -7,7 +7,7 @@ import com.mojang.blaze3d.platform.GlStateManager; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.logic.ILogic; -import exopandora.worldhandler.text.TextFormatting; +import exopandora.worldhandler.util.TextFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/exopandora/worldhandler/gui/category/Categories.java b/src/main/java/exopandora/worldhandler/gui/category/Categories.java index 9207fdd..802e9de 100644 --- a/src/main/java/exopandora/worldhandler/gui/category/Categories.java +++ b/src/main/java/exopandora/worldhandler/gui/category/Categories.java @@ -27,15 +27,20 @@ public class Categories SCOREBOARD = Categories.getRegisteredCategory("scoreboard"); } - private static Category getRegisteredCategory(String name) + public static Category getRegisteredCategory(String name) { Category category = Category.REGISTRY.getValue(new ResourceLocation(Main.MODID, name)); if(category == null) { - throw new IllegalStateException("Invalid Category requested: " + name); + throw new IllegalStateException("Requested missing category: " + name); } return category; } + + public static boolean isRegistered(String name) + { + return Category.REGISTRY.containsKey(new ResourceLocation(Main.MODID, name)); + } } diff --git a/src/main/java/exopandora/worldhandler/gui/category/Category.java b/src/main/java/exopandora/worldhandler/gui/category/Category.java index a2bd7c5..9bd62ca 100644 --- a/src/main/java/exopandora/worldhandler/gui/category/Category.java +++ b/src/main/java/exopandora/worldhandler/gui/category/Category.java @@ -11,6 +11,9 @@ import com.google.common.collect.Lists; import exopandora.worldhandler.Main; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.helper.RegistryHelper; +import exopandora.worldhandler.usercontent.UsercontentConfig; +import exopandora.worldhandler.usercontent.UsercontentLoader; +import exopandora.worldhandler.usercontent.model.JsonTab; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -48,15 +51,15 @@ public class Category extends ForgeRegistryEntry this(Arrays.stream(keys).map(key -> new ResourceLocation(Main.MODID, key)).collect(Collectors.toList())); } - public Category add(ResourceLocation content) + public Category add(int index, ResourceLocation content) { - this.contents.add(content); + this.contents.add(Math.min(index, this.getSize()), content); return this; } - public Category add(String key) + public Category add(int index, String key) { - return this.add(new ResourceLocation(Main.MODID, key)); + return this.add(index, new ResourceLocation(Main.MODID, key)); } public List getContents() @@ -96,5 +99,28 @@ public class Category extends ForgeRegistryEntry RegistryHelper.register(event.getRegistry(), "world", new Category("world", "gamerules")); RegistryHelper.register(event.getRegistry(), "player", new Category("player", "experience", "advancements")); RegistryHelper.register(event.getRegistry(), "scoreboard", new Category("scoreboard_objectives", "scoreboard_teams", "scoreboard_players")); + + for(UsercontentConfig config : UsercontentLoader.CONFIGS) + { + if(config.getContent().getGui() != null && config.getContent().getGui().getTab() != null) + { + Category.registerCategory(event.getRegistry(), config.getId(), config.getContent().getGui().getTab()); + } + } + } + + private static void registerCategory(IForgeRegistry registry, String id, JsonTab tab) + { + if(tab.getCategory() != null && !tab.getCategory().isEmpty()) + { + if(!Categories.isRegistered(tab.getCategory())) + { + RegistryHelper.register(registry, tab.getCategory(), new Category(id)); + } + else + { + Categories.getRegisteredCategory(tab.getCategory()).add(tab.getCategoryIndex(), id); + } + } } } diff --git a/src/main/java/exopandora/worldhandler/gui/container/Container.java b/src/main/java/exopandora/worldhandler/gui/container/Container.java index ff5cc76..86cd6e7 100644 --- a/src/main/java/exopandora/worldhandler/gui/container/Container.java +++ b/src/main/java/exopandora/worldhandler/gui/container/Container.java @@ -3,8 +3,8 @@ package exopandora.worldhandler.gui.container; import java.util.ArrayList; import java.util.List; -import exopandora.worldhandler.gui.content.element.Element; -import exopandora.worldhandler.gui.content.element.IElement; +import exopandora.worldhandler.gui.element.Element; +import exopandora.worldhandler.gui.element.IElement; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.gui.widget.Widget; diff --git a/src/main/java/exopandora/worldhandler/gui/container/IContainer.java b/src/main/java/exopandora/worldhandler/gui/container/IContainer.java index c6bf0cd..a524adf 100644 --- a/src/main/java/exopandora/worldhandler/gui/container/IContainer.java +++ b/src/main/java/exopandora/worldhandler/gui/container/IContainer.java @@ -1,7 +1,7 @@ package exopandora.worldhandler.gui.container; import exopandora.worldhandler.gui.content.Content; -import exopandora.worldhandler.gui.content.element.Element; +import exopandora.worldhandler.gui.element.Element; import net.minecraft.client.gui.widget.Widget; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java b/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java index 26b2d2c..bdc4b0f 100644 --- a/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java +++ b/src/main/java/exopandora/worldhandler/gui/container/impl/GuiWorldHandler.java @@ -23,10 +23,10 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.IContent; -import exopandora.worldhandler.gui.content.element.IElement; +import exopandora.worldhandler.gui.element.IElement; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.ResourceHelper; -import exopandora.worldhandler.text.TextFormatting; +import exopandora.worldhandler.util.TextFormatting; import exopandora.worldhandler.util.UtilRender; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.widget.Widget; @@ -139,32 +139,33 @@ public class GuiWorldHandler extends Container }); this.updateNameField(); - final int backgroundX = this.getBackgroundX(); - final int backgroundY = this.getBackgroundY(); - - this.forEachTab((index, xOffset) -> - { - IContent tab = this.content.getCategory().getContent(index); - - if(!this.content.getActiveContent().equals(tab)) - { - this.finalButtons.add(new GuiButtonTab((int) (backgroundX + xOffset), backgroundY - 20, (int) this.tabWidth + (int) Math.ceil(this.tabEpsilon / this.tabSize), 21, tab.getTabTitle()) - { - @Override - public void onPress() - { - ActionHelper.changeTab(GuiWorldHandler.this.content, index); - } - }); - } - }); - //BUTTONS + this.forEachTab(this::addTabButtons); this.initButtons(); }); } + private void addTabButtons(int index, double xOffset) + { + final int backgroundX = this.getBackgroundX(); + final int backgroundY = this.getBackgroundY(); + + IContent tab = this.content.getCategory().getContent(index); + + if(!tab.equals(this.content.getActiveContent())) + { + this.finalButtons.add(new GuiButtonTab((int) (backgroundX + xOffset), backgroundY - 20, (int) this.tabWidth + (int) Math.ceil(this.tabEpsilon / this.tabSize), 21, tab.getTabTitle()) + { + @Override + public void onPress() + { + ActionHelper.changeTab(GuiWorldHandler.this.content, index); + } + }); + } + } + public void initButtons() { this.buttons.clear(); @@ -374,118 +375,7 @@ public class GuiWorldHandler extends Container //TABS - this.forEachTab((index, xOffset) -> - { - IContent tab = this.content.getCategory().getContent(index); - int yOffset; - int fHeight; - int color; - - if(this.content.getActiveContent().equals(tab)) - { - yOffset = -22; - fHeight = 25; - color = 0xFFFFFF; - this.defaultColor(); - } - else - { - yOffset = -20; - fHeight = 20; - color = 0xE0E0E0; - this.darkColor(); - } - - this.bindBackground(); - this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset), 0, 0, (int) Math.ceil(this.tabHalf), fHeight); - this.blit((int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY + yOffset), this.bgTextureWidth - (int) Math.ceil(this.tabHalf), 0, (int) Math.ceil(this.tabHalf), fHeight); - - if(!Config.getSkin().sharpEdges()) - { - if(this.content.getActiveContent().equals(tab)) - { - //RIGHT TAB CURVATURE - - if(index < this.tabSize - 1 || this.tabSize == 1) - { - int factor = 2; - - for(int x = 0; x < factor; x++) - { - this.blit((int) (backgroundX + this.tabWidth + xOffset - x - 1), (int) (backgroundY + x + 1), (int) (this.tabWidth - x - 1), x + 1, x + 1, 1); - } - } - - //LEFT TAB CURVATURE - - if(index > 0) - { - int factor = 2; - - for(int x = 0; x < factor; x++) - { - this.blit((int) (backgroundX + xOffset), (int) (backgroundY + x + 1), xOffset.intValue(), x + 1, x + 1, 1); - } - } - - int width = (int)(this.tabWidth - 3); - int interval = 5; - - //LEFT GRADIENT - - if(index == 0) - { - for(int x = 0; x < width; x += interval) - { - this.defaultColor(1.0F - (x / (width + 5.0F * interval))); - this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset + fHeight + x / interval), 0, fHeight, width - x, 1); - } - } - - //RIGHT GRADIENT - - if(index == this.tabSize - 1 && this.tabSize > 1) - { - int offset = 3; - - for(int x = 0; x < width; x += interval) - { - this.defaultColor(1.0F - (x / (width + 5.0F * interval))); - this.blit((int) (backgroundX + Math.ceil(xOffset) + x + offset), (int) (backgroundY + yOffset + fHeight + x / interval), this.bgTextureWidth - width + x, fHeight, width - x, 1); - } - } - } - else - { - //LEFT CORNER FILLER - - if(index == 0) - { - int factor = 2; - - for(int x = 0; x < factor; x++) - { - this.blit(backgroundX, backgroundY + x, 0, fHeight, factor - x, 1); - } - } - - //RIGHT CORNER FILLER - - if(index == this.tabSize - 1) - { - int factor = 3; - - for(int x = 0; x < factor + 1; x++) - { - this.blit(backgroundX + this.bgTextureWidth - x, backgroundY + factor - x, this.bgTextureWidth - x, fHeight, x, 1); - } - } - } - } - - this.drawCenteredString(this.font, net.minecraft.util.text.TextFormatting.UNDERLINE + tab.getTabTitle(), (int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY - 13), color); - }); - + this.forEachTab(this::drawTab); this.defaultColor(); //VERSION LABEL @@ -608,6 +498,122 @@ public class GuiWorldHandler extends Container }); } + private void drawTab(int index, Double xOffset) + { + final IContent tab = this.content.getCategory().getContent(index); + + final int backgroundX = this.getBackgroundX(); + final int backgroundY = this.getBackgroundY(); + + int yOffset; + int fHeight; + int color; + + if(this.content.getActiveContent().equals(tab)) + { + yOffset = -22; + fHeight = 25; + color = 0xFFFFFF; + this.defaultColor(); + } + else + { + yOffset = -20; + fHeight = 20; + color = 0xE0E0E0; + this.darkColor(); + } + + this.bindBackground(); + this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset), 0, 0, (int) Math.ceil(this.tabHalf), fHeight); + this.blit((int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY + yOffset), this.bgTextureWidth - (int) Math.floor(this.tabHalf + 1), 0, (int) Math.floor(this.tabHalf + 1), fHeight); + + if(!Config.getSkin().sharpEdges()) + { + if(this.content.getActiveContent().equals(tab)) + { + //RIGHT TAB CURVATURE + + if(index < this.tabSize - 1 || this.tabSize == 1) + { + int factor = 2; + + for(int x = 0; x < factor; x++) + { + this.blit((int) (backgroundX + xOffset - x - 1 + Math.floor(this.tabHalf + 1) + this.tabHalf), (int) (backgroundY + x + 1), (int) (this.tabWidth - x - 1), x + 1, x + 1, 1); + } + } + + //LEFT TAB CURVATURE + + if(index > 0) + { + int factor = 2; + + for(int x = 0; x < factor; x++) + { + this.blit((int) (backgroundX + xOffset), (int) (backgroundY + x + 1), xOffset.intValue(), x + 1, x + 1, 1); + } + } + + int width = (int)(this.tabWidth - 3); + int interval = 5; + + //LEFT GRADIENT + + if(index == 0) + { + for(int x = 0; x < width; x += interval) + { + this.defaultColor(1.0F - (x / (width + 5.0F * interval))); + this.blit((int) (backgroundX + xOffset), (int) (backgroundY + yOffset + fHeight + x / interval), 0, fHeight, width - x, 1); + } + } + + //RIGHT GRADIENT + + if(index == this.tabSize - 1 && this.tabSize > 1) + { + int offset = 3; + + for(int x = 0; x < width; x += interval) + { + this.defaultColor(1.0F - (x / (width + 5.0F * interval))); + this.blit((int) (backgroundX + Math.ceil(xOffset) + x + offset), (int) (backgroundY + yOffset + fHeight + x / interval), this.bgTextureWidth - width + x, fHeight, width - x, 1); + } + } + } + else + { + //LEFT CORNER FILLER + + if(index == 0) + { + int factor = 2; + + for(int x = 0; x < factor; x++) + { + this.blit(backgroundX, backgroundY + x, 0, fHeight, factor - x, 1); + } + } + + //RIGHT CORNER FILLER + + if(index == this.tabSize - 1) + { + int factor = 3; + + for(int x = 0; x < factor + 1; x++) + { + this.blit(backgroundX + this.bgTextureWidth - x, backgroundY + factor - x, this.bgTextureWidth - x, fHeight, x, 1); + } + } + } + } + + this.drawCenteredString(this.font, TextFormatting.shortenString(net.minecraft.util.text.TextFormatting.UNDERLINE + tab.getTabTitle(), (int) this.tabWidth, this.font), (int) (backgroundX + this.tabHalf + xOffset), (int) (backgroundY - 13), color); + } + @Override public boolean charTyped(char charTyped, int keyCode) { diff --git a/src/main/java/exopandora/worldhandler/gui/content/Content.java b/src/main/java/exopandora/worldhandler/gui/content/Content.java index 8ffa326..e13a929 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/Content.java +++ b/src/main/java/exopandora/worldhandler/gui/content/Content.java @@ -28,8 +28,11 @@ import exopandora.worldhandler.gui.content.impl.ContentScoreboardTeams; import exopandora.worldhandler.gui.content.impl.ContentSettings; import exopandora.worldhandler.gui.content.impl.ContentSignEditor; import exopandora.worldhandler.gui.content.impl.ContentSummon; +import exopandora.worldhandler.gui.content.impl.ContentUsercontent; import exopandora.worldhandler.gui.content.impl.ContentWorldInfo; import exopandora.worldhandler.helper.RegistryHelper; +import exopandora.worldhandler.usercontent.UsercontentConfig; +import exopandora.worldhandler.usercontent.UsercontentLoader; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -100,6 +103,21 @@ public abstract class Content extends ForgeRegistryEntry implements ICo RegistryHelper.register(event.getRegistry(), "butcher", new ContentButcher()); RegistryHelper.register(event.getRegistry(), "butcher_settings", new ContentButcherSettings()); RegistryHelper.register(event.getRegistry(), "settings", new ContentSettings()); + + //USERCONTENT + UsercontentLoader.CONFIGS.forEach(config -> Content.registerContent(event.getRegistry(), config)); + } + + private static void registerContent(IForgeRegistry registry, UsercontentConfig config) + { + try + { + RegistryHelper.register(registry, config.getId(), new ContentUsercontent(config)); + } + catch(Exception e) + { + throw new RuntimeException("Error loading js for usercontent: " + config.getId(), e); + } } private Map persistence; diff --git a/src/main/java/exopandora/worldhandler/gui/content/Contents.java b/src/main/java/exopandora/worldhandler/gui/content/Contents.java index 2157da6..1431b6d 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/Contents.java +++ b/src/main/java/exopandora/worldhandler/gui/content/Contents.java @@ -1,8 +1,8 @@ package exopandora.worldhandler.gui.content; import exopandora.worldhandler.Main; +import exopandora.worldhandler.gui.content.impl.ContentChild; import exopandora.worldhandler.gui.content.impl.ContentContinue; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; import net.minecraft.util.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -79,15 +79,20 @@ public class Contents SETTINGS = (ContentChild) Contents.getRegisteredContent("settings"); } - private static Content getRegisteredContent(String name) + public static Content getRegisteredContent(String name) { Content content = Content.REGISTRY.getValue(new ResourceLocation(Main.MODID, name)); if(content == null) { - throw new IllegalStateException("Invalid Content requested: " + name); + throw new IllegalStateException("Requested missing content: " + name); } return content; } + + public static boolean isRegistered(String name) + { + return Content.REGISTRY.containsKey(new ResourceLocation(Main.MODID, name)); + } } \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java index fdcef4c..1a106f1 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentAdvancements.java @@ -17,7 +17,7 @@ import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicMapped; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.helper.ActionHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java index 85f315b..598f817 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcher.java @@ -8,7 +8,6 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; import net.minecraft.client.Minecraft; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java index 5f436e9..e46a9c6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentButcherSettings.java @@ -7,8 +7,7 @@ import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiButtonTooltip; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.util.ActionHandler; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentChangeWorld.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentChangeWorld.java index 8800c2a..300c1d6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentChangeWorld.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentChangeWorld.java @@ -2,7 +2,6 @@ package exopandora.worldhandler.gui.content.impl; import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; import exopandora.worldhandler.helper.ActionHelper; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.ConnectingScreen; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/abstr/ContentChild.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentChild.java similarity index 94% rename from src/main/java/exopandora/worldhandler/gui/content/impl/abstr/ContentChild.java rename to src/main/java/exopandora/worldhandler/gui/content/impl/ContentChild.java index e7077f6..32ee684 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/abstr/ContentChild.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentChild.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.impl.abstr; +package exopandora.worldhandler.gui.content.impl; import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.content.Content; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java index 260958c..2997f84 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentContinue.java @@ -6,7 +6,6 @@ import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; import net.minecraft.client.Minecraft; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java index 1afb082..17980e8 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentCustomItem.java @@ -9,8 +9,8 @@ import com.google.common.base.Predicates; import exopandora.worldhandler.builder.ICommandBuilder; import exopandora.worldhandler.builder.impl.BuilderCustomItem; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable; +import exopandora.worldhandler.builder.impl.EnumAttributes; +import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiSlider; @@ -20,8 +20,8 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementColorMenu; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; +import exopandora.worldhandler.gui.element.impl.ElementColorMenu; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.gui.logic.LogicSliderAttribute; import exopandora.worldhandler.gui.logic.LogicSliderSimple; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java index 6d618f0..429868c 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentEnchantment.java @@ -12,7 +12,7 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.gui.logic.LogicSliderSimple; import exopandora.worldhandler.helper.ActionHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java index 42b2d6f..b012c95 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentGamerules.java @@ -18,7 +18,7 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java index 40504c9..e1de982 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentPotions.java @@ -11,8 +11,7 @@ import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiButtonTooltip; import exopandora.worldhandler.gui.button.GuiSlider; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.gui.logic.LogicSliderSimple; import exopandora.worldhandler.helper.ActionHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java index cc0bd1d..af3fe9a 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentRecipes.java @@ -13,7 +13,7 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/abstr/ContentScoreboard.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java similarity index 95% rename from src/main/java/exopandora/worldhandler/gui/content/impl/abstr/ContentScoreboard.java rename to src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java index 3c54962..a20a0d6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/abstr/ContentScoreboard.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboard.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.impl.abstr; +package exopandora.worldhandler.gui.content.impl; import exopandora.worldhandler.gui.category.Categories; import exopandora.worldhandler.gui.category.Category; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java index 0216540..cb87217 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardObjectives.java @@ -15,8 +15,7 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementMultiButtonList; -import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard; +import exopandora.worldhandler.gui.element.impl.ElementMultiButtonList; import exopandora.worldhandler.gui.logic.ILogicClickList; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java index f32e4fc..e745ccc 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardPlayers.java @@ -16,7 +16,6 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard; import exopandora.worldhandler.gui.logic.LogicSliderSimple; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java index ceeb7cf..069cfa8 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentScoreboardTeams.java @@ -13,8 +13,7 @@ import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementMultiButtonList; -import exopandora.worldhandler.gui.content.impl.abstr.ContentScoreboard; +import exopandora.worldhandler.gui.element.impl.ElementMultiButtonList; import exopandora.worldhandler.gui.logic.ILogicClickList; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.CommandHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java index 90f57a6..d823f52 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSettings.java @@ -10,10 +10,9 @@ import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiButtonTooltip; import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.BooleanSetting; import exopandora.worldhandler.gui.content.impl.ContentSettings.Setting.IntegerSetting; -import exopandora.worldhandler.gui.content.impl.abstr.ContentChild; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.util.ActionHandler; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java index b5914b0..2ca5445 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSignEditor.java @@ -15,7 +15,7 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementColorMenu; +import exopandora.worldhandler.gui.element.impl.ElementColorMenu; import exopandora.worldhandler.gui.logic.ILogicColorMenu; import exopandora.worldhandler.helper.ActionHelper; import exopandora.worldhandler.helper.BlockHelper; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java index 3dda62a..e3aeefd 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentSummon.java @@ -11,8 +11,8 @@ import com.google.common.base.Predicates; import exopandora.worldhandler.builder.ICommandBuilder; import exopandora.worldhandler.builder.impl.BuilderSummon; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes.Applyable; +import exopandora.worldhandler.builder.impl.EnumAttributes; +import exopandora.worldhandler.builder.impl.EnumAttributes.Applyable; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiButtonItem; @@ -23,7 +23,7 @@ import exopandora.worldhandler.gui.category.Category; import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; -import exopandora.worldhandler.gui.content.element.impl.ElementPageList; +import exopandora.worldhandler.gui.element.impl.ElementPageList; import exopandora.worldhandler.gui.logic.ILogicPageList; import exopandora.worldhandler.gui.logic.LogicSliderAttribute; import exopandora.worldhandler.gui.logic.LogicSliderSimple; diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java new file mode 100644 index 0000000..d94ecd0 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentUsercontent.java @@ -0,0 +1,261 @@ +package exopandora.worldhandler.gui.content.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import exopandora.worldhandler.Main; +import exopandora.worldhandler.builder.CommandSyntax; +import exopandora.worldhandler.builder.ICommandBuilder; +import exopandora.worldhandler.builder.impl.BuilderMultiCommand; +import exopandora.worldhandler.builder.impl.BuilderUsercontent; +import exopandora.worldhandler.gui.category.Categories; +import exopandora.worldhandler.gui.category.Category; +import exopandora.worldhandler.gui.container.Container; +import exopandora.worldhandler.gui.content.Content; +import exopandora.worldhandler.gui.content.Contents; +import exopandora.worldhandler.usercontent.ScriptEngineAdapter; +import exopandora.worldhandler.usercontent.UsercontentAPI; +import exopandora.worldhandler.usercontent.UsercontentConfig; +import exopandora.worldhandler.usercontent.VisibleActiveObject; +import exopandora.worldhandler.usercontent.VisibleObject; +import exopandora.worldhandler.usercontent.factory.ActionHandlerFactory; +import exopandora.worldhandler.usercontent.factory.ButtonFactory; +import exopandora.worldhandler.usercontent.factory.ElementFactory; +import exopandora.worldhandler.usercontent.model.JsonButton; +import exopandora.worldhandler.usercontent.model.JsonCommand; +import exopandora.worldhandler.usercontent.model.JsonElement; +import exopandora.worldhandler.usercontent.model.JsonModel; +import exopandora.worldhandler.usercontent.model.JsonText; +import exopandora.worldhandler.usercontent.model.JsonUsercontent; +import exopandora.worldhandler.usercontent.model.JsonWidget; +import exopandora.worldhandler.util.TextFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.widget.TextFieldWidget; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.util.text.ChatType; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class ContentUsercontent extends Content +{ + private final String id; + private final JsonUsercontent content; + private final ScriptEngineAdapter engineAdapter; + private final List> builders; + private final Map> textfields = new HashMap>(); + private final List> buttons = new ArrayList>(); + private UsercontentAPI api; + private ButtonFactory buttonFactory; + private ElementFactory elementFactory; + + public ContentUsercontent(UsercontentConfig config) throws Exception + { + this.id = config.getId(); + this.content = config.getContent(); + this.engineAdapter = new ScriptEngineAdapter(config.getScriptEngine()); + this.builders = this.createBuilders(this.content.getModel()); + this.api = new UsercontentAPI(this.builders.stream().map(VisibleObject::getObject).collect(Collectors.toList())); + ActionHandlerFactory actionHandlerFactory = new ActionHandlerFactory(this.api,this. builders, this.engineAdapter); + this.buttonFactory = new ButtonFactory(this.api, actionHandlerFactory); + this.elementFactory = new ElementFactory(this.api, actionHandlerFactory); + this.engineAdapter.addObject("api", this.api); + this.engineAdapter.eval(config.getJs()); + } + + @Override + public ICommandBuilder getCommandBuilder() + { + ICommandBuilder[] builders = this.builders.stream() + .filter(builder -> builder.isVisible(this.engineAdapter)) + .map(VisibleObject::getObject) + .toArray(ICommandBuilder[]::new); + + return builders.length > 0 ? new BuilderMultiCommand(builders) : null; + } + + @Override + public void initGui(Container container, int x, int y) + { + this.textfields.clear(); + this.buttons.clear(); + + for(JsonButton button : this.getWidgets(this.content.getGui().getButtons(), JsonWidget.Type.BUTTON)) + { + Widget widget = this.buttonFactory.createButton(button, this, container, x, y); + + if(JsonButton.Type.TEXTFIELD.equals(button.getType())) + { + VisibleActiveObject visObj = new VisibleActiveObject(button, (TextFieldWidget) widget); + this.textfields.put(button.getAttributes().getId(), visObj); + } + else + { + this.buttons.add(new VisibleActiveObject(button, widget)); + } + } + + for(JsonElement element : this.getWidgets(this.content.getGui().getElements(), JsonWidget.Type.ELEMENT)) + { + container.add(this.elementFactory.createElement(element, this, container, x, y)); + } + + this.updateTextfields(); + this.updateButtons(); + } + + @Override + public void initButtons(Container container, int x, int y) + { + this.textfields.values().stream().map(VisibleObject::getObject).forEach(container::add); + this.buttons.stream().map(VisibleObject::getObject).forEach(container::add); + } + + @Override + public void tick(Container container) + { + for(VisibleObject textfield : this.textfields.values()) + { + if(textfield.isVisible(this.engineAdapter)) + { + textfield.getObject().tick(); + } + } + + this.updateButtons(); + this.updateTextfields(); + } + + @Override + public void drawScreen(Container container, int x, int y, int mouseX, int mouseY, float partialTicks) + { + for(VisibleObject textfield : this.textfields.values()) + { + if(textfield.getObject().visible) + { + textfield.getObject().renderButton(mouseX, mouseY, partialTicks); + } + } + + if(this.content.getGui() != null && this.content.getGui().getTexts() != null) + { + for(JsonText text : this.content.getGui().getTexts()) + { + container.getMinecraft().fontRenderer.drawString(TextFormatting.formatNullable(text.getText()), text.getX() + x, text.getY() + y, text.getColor()); + } + } + } + + @Override + public Category getCategory() + { + return Categories.getRegisteredCategory(this.content.getGui().getTab().getCategory()); + } + + @Override + public String getTitle() + { + return TextFormatting.formatNullable(this.content.getGui().getTitle()); + } + + @Override + public String getTabTitle() + { + return TextFormatting.formatNullable(this.content.getGui().getTab().getTitle()); + } + + @Override + public Content getActiveContent() + { + if(this.content.getGui().getTab().getActiveContent() == null) + { + return this; + } + + return Contents.getRegisteredContent(this.content.getGui().getTab().getActiveContent()); + } + + @Override + public void onPlayerNameChanged(String username) + { + for(VisibleObject visObj : this.builders) + { + visObj.getObject().setPlayerName(username); + } + } + + private List> createBuilders(JsonModel model) + { + List> builders = new ArrayList>(); + + if(model != null && model.getCommands() != null) + { + for(JsonCommand command : model.getCommands()) + { + if(command.getName() != null && command.getSyntax() != null) + { + BuilderUsercontent builder = new BuilderUsercontent(command.getName(), new CommandSyntax(command.getSyntax())); + builders.add(new VisibleObject(command.getVisible(), builder)); + } + } + } + + return builders; + } + + private > List getWidgets(List list, JsonWidget.Type type) + { + List result = new ArrayList(); + + if(list == null) + { + return result; + } + + for(int x = 0; x < list.size(); x++) + { + T widget = list.get(x); + + try + { + widget.validate(); + result.add(widget); + } + catch(Exception e) + { + this.printError(type.toString().toLowerCase(), x, e); + } + } + + return result; + } + + private void printError(String type, int index, Throwable e) + { + ITextComponent message = new StringTextComponent(net.minecraft.util.text.TextFormatting.RED + "<" + Main.NAME + ":" + this.id + ":" + type + ":" + index + "> " + e.getMessage()); + Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.CHAT, message); + } + + private void updateTextfields() + { + for(VisibleActiveObject visObj : this.textfields.values()) + { + visObj.getObject().setEnabled(visObj.isEnabled(this.engineAdapter)); + visObj.getObject().visible = visObj.isVisible(this.engineAdapter); + } + } + + private void updateButtons() + { + for(VisibleActiveObject visObj : this.buttons) + { + visObj.getObject().active = visObj.isEnabled(this.engineAdapter); + visObj.getObject().visible = visObj.isVisible(this.engineAdapter); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentWorldInfo.java b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentWorldInfo.java index dd96291..813cafb 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/impl/ContentWorldInfo.java +++ b/src/main/java/exopandora/worldhandler/gui/content/impl/ContentWorldInfo.java @@ -10,7 +10,7 @@ import exopandora.worldhandler.gui.container.Container; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; import exopandora.worldhandler.helper.ActionHelper; -import exopandora.worldhandler.text.TextFormatting; +import exopandora.worldhandler.util.TextFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import net.minecraft.world.World; diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/Element.java b/src/main/java/exopandora/worldhandler/gui/element/Element.java similarity index 83% rename from src/main/java/exopandora/worldhandler/gui/content/element/Element.java rename to src/main/java/exopandora/worldhandler/gui/element/Element.java index 2d21ed3..b02d7ef 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/Element.java +++ b/src/main/java/exopandora/worldhandler/gui/element/Element.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.element; +package exopandora.worldhandler.gui.element; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/IElement.java b/src/main/java/exopandora/worldhandler/gui/element/IElement.java similarity index 86% rename from src/main/java/exopandora/worldhandler/gui/content/element/IElement.java rename to src/main/java/exopandora/worldhandler/gui/element/IElement.java index d08ae8e..31263d4 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/IElement.java +++ b/src/main/java/exopandora/worldhandler/gui/element/IElement.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.element; +package exopandora.worldhandler.gui.element; import exopandora.worldhandler.gui.container.Container; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementColorMenu.java b/src/main/java/exopandora/worldhandler/gui/element/impl/ElementColorMenu.java similarity index 96% rename from src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementColorMenu.java rename to src/main/java/exopandora/worldhandler/gui/element/impl/ElementColorMenu.java index ac387ba..db594d2 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementColorMenu.java +++ b/src/main/java/exopandora/worldhandler/gui/element/impl/ElementColorMenu.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.element.impl; +package exopandora.worldhandler.gui.element.impl; import java.util.ArrayList; import java.util.List; @@ -7,10 +7,10 @@ import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiButtonList; import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.element.Element; +import exopandora.worldhandler.gui.element.Element; import exopandora.worldhandler.gui.logic.ILogicColorMenu; import exopandora.worldhandler.gui.logic.ILogicMapped; -import exopandora.worldhandler.text.MutableStringTextComponent; +import exopandora.worldhandler.util.MutableStringTextComponent; import net.minecraft.client.resources.I18n; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementMultiButtonList.java b/src/main/java/exopandora/worldhandler/gui/element/impl/ElementMultiButtonList.java similarity index 96% rename from src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementMultiButtonList.java rename to src/main/java/exopandora/worldhandler/gui/element/impl/ElementMultiButtonList.java index a7ce0b0..8976b54 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementMultiButtonList.java +++ b/src/main/java/exopandora/worldhandler/gui/element/impl/ElementMultiButtonList.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.element.impl; +package exopandora.worldhandler.gui.element.impl; import java.util.ArrayList; import java.util.Collections; @@ -11,7 +11,7 @@ import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.button.GuiButtonList; import exopandora.worldhandler.gui.button.GuiButtonList.Persistence; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.element.Element; +import exopandora.worldhandler.gui.element.Element; import exopandora.worldhandler.gui.logic.ILogicClickList; import exopandora.worldhandler.gui.logic.ILogicMapped; import exopandora.worldhandler.helper.Node; @@ -75,7 +75,7 @@ public class ElementMultiButtonList extends Element public void onClick(Node item) { ElementMultiButtonList.this.getPersistence(container, 1).setIndex(0); - container.initButtons(); + container.init(); } @Override diff --git a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java b/src/main/java/exopandora/worldhandler/gui/element/impl/ElementPageList.java similarity index 91% rename from src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java rename to src/main/java/exopandora/worldhandler/gui/element/impl/ElementPageList.java index a11c7c7..12d32a6 100644 --- a/src/main/java/exopandora/worldhandler/gui/content/element/impl/ElementPageList.java +++ b/src/main/java/exopandora/worldhandler/gui/element/impl/ElementPageList.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.gui.content.element.impl; +package exopandora.worldhandler.gui.element.impl; import java.util.List; import java.util.Objects; @@ -6,9 +6,9 @@ import java.util.Objects; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.button.GuiButtonBase; import exopandora.worldhandler.gui.container.Container; -import exopandora.worldhandler.gui.content.element.Element; +import exopandora.worldhandler.gui.element.Element; import exopandora.worldhandler.gui.logic.ILogicPageList; -import exopandora.worldhandler.text.TextFormatting; +import exopandora.worldhandler.util.TextFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraftforge.api.distmarker.Dist; @@ -143,7 +143,7 @@ public class ElementPageList extends Element private int getTotalPages() { - return (int) Math.ceil((float) this.items.size() / this.length); + return Math.max((int) Math.ceil((float) this.items.size() / this.length), 1); } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/exopandora/worldhandler/gui/logic/ILogicMapped.java b/src/main/java/exopandora/worldhandler/gui/logic/ILogicMapped.java index 9312c40..78e06ec 100644 --- a/src/main/java/exopandora/worldhandler/gui/logic/ILogicMapped.java +++ b/src/main/java/exopandora/worldhandler/gui/logic/ILogicMapped.java @@ -22,4 +22,9 @@ public interface ILogicMapped extends ILogic } void onClick(T item); + + default void onInit(T item) + { + + } } diff --git a/src/main/java/exopandora/worldhandler/gui/logic/LogicSliderAttribute.java b/src/main/java/exopandora/worldhandler/gui/logic/LogicSliderAttribute.java index 1d7ab1f..b4f936e 100644 --- a/src/main/java/exopandora/worldhandler/gui/logic/LogicSliderAttribute.java +++ b/src/main/java/exopandora/worldhandler/gui/logic/LogicSliderAttribute.java @@ -2,7 +2,7 @@ package exopandora.worldhandler.gui.logic; import java.util.function.Consumer; -import exopandora.worldhandler.builder.impl.abstr.EnumAttributes; +import exopandora.worldhandler.builder.impl.EnumAttributes; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; diff --git a/src/main/java/exopandora/worldhandler/helper/ActionHelper.java b/src/main/java/exopandora/worldhandler/helper/ActionHelper.java index 61d244e..9ec9db4 100644 --- a/src/main/java/exopandora/worldhandler/helper/ActionHelper.java +++ b/src/main/java/exopandora/worldhandler/helper/ActionHelper.java @@ -13,18 +13,19 @@ import exopandora.worldhandler.config.Config; import exopandora.worldhandler.gui.container.impl.GuiWorldHandler; import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Contents; +import exopandora.worldhandler.gui.content.impl.ContentChild; +import exopandora.worldhandler.gui.content.impl.ContentContinue; import exopandora.worldhandler.util.ActionHandler; import net.minecraft.block.AbstractSignBlock; import net.minecraft.block.NoteBlock; import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; import net.minecraft.util.text.ChatType; +import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.Style; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.util.text.event.ClickEvent; -import net.minecraft.util.text.event.ClickEvent.Action; import net.minecraft.world.Difficulty; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -38,17 +39,45 @@ public class ActionHelper Minecraft.getInstance().mouseHelper.grabMouse(); } + public static void back(String id) throws Exception + { + ActionHelper.back(Contents.getRegisteredContent(id)); + } + public static void back(Content content) throws Exception { if(content.getBackContent() != null) { - Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getBackContent())); + ActionHelper.open(content.getBackContent()); } } public static void changeTab(Content content, int index) { - ActionHelper.tryRun(() -> Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content.getCategory().getContent(index)))); + ActionHelper.tryRun(() -> ActionHelper.open(content.getCategory().getContent(index))); + } + + public static void open(String id) throws Exception + { + if(id != null) + { + ActionHelper.open(Contents.getRegisteredContent(id)); + } + } + + public static void open(Content content) throws Exception + { + if(content != null && !(content instanceof ContentContinue)) + { + if(content instanceof ContentChild && Minecraft.getInstance().currentScreen != null && Minecraft.getInstance().currentScreen instanceof GuiWorldHandler) + { + Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(((ContentChild) content).withParent(((GuiWorldHandler) Minecraft.getInstance().currentScreen).getContent()))); + } + else + { + Minecraft.getInstance().displayGuiScreen(new GuiWorldHandler(content)); + } + } } public static void timeDawn() @@ -140,13 +169,14 @@ public class ActionHelper Minecraft.getInstance().displayGuiScreen(null); Minecraft.getInstance().mouseHelper.grabMouse(); - StringTextComponent name = new StringTextComponent(Main.NAME); - name.setStyle(new Style().setUnderlined(true).setClickEvent(new ClickEvent(Action.OPEN_URL, Main.URL))); + Style redColor = new Style().setColor(TextFormatting.RED); - TranslationTextComponent message = new TranslationTextComponent("worldhandler.error.gui", name); - message.setStyle(new Style().setColor(net.minecraft.util.text.TextFormatting.RED)); + ITextComponent message = new TranslationTextComponent("<" + Main.NAME + "> %s", new TranslationTextComponent("worldhandler.error.gui")).setStyle(redColor); + ITextComponent cause = new StringTextComponent(" " + e.getClass().getCanonicalName() + ": " + e.getMessage()).setStyle(redColor); Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, message); + Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.SYSTEM, cause); + WorldHandler.LOGGER.throwing(e); } } diff --git a/src/main/java/exopandora/worldhandler/usercontent/ScriptEngineAdapter.java b/src/main/java/exopandora/worldhandler/usercontent/ScriptEngineAdapter.java new file mode 100644 index 0000000..6cd954b --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/ScriptEngineAdapter.java @@ -0,0 +1,69 @@ +package exopandora.worldhandler.usercontent; + +import javax.annotation.Nullable; +import javax.script.Invocable; +import javax.script.ScriptEngine; +import javax.script.ScriptException; + +import exopandora.worldhandler.WorldHandler; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class ScriptEngineAdapter +{ + private final ScriptEngine engine; + + public ScriptEngineAdapter(ScriptEngine engine) + { + this.engine = engine; + } + + @Nullable + public Object invokeFunction(String function) + { + return this.invokeFunction(function, null); + } + + @Nullable + public Object invokeFunction(String function, Object value) + { + if(function != null && !function.isEmpty()) + { + try + { + if(value != null) + { + return ((Invocable) this.engine).invokeFunction(function, value); + } + else + { + return ((Invocable) this.engine).invokeFunction(function); + } + } + catch(Exception e) + { + e.printStackTrace(); + } + } + else + { + WorldHandler.LOGGER.warn("No function specified"); + } + + return null; + } + + public void addObject(String key, Object instance) + { + this.engine.put(key, instance); + } + + public void eval(String js) throws ScriptException + { + if(js != null) + { + this.engine.eval(js); + } + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java b/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java new file mode 100644 index 0000000..cd582be --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/UsercontentAPI.java @@ -0,0 +1,64 @@ +package exopandora.worldhandler.usercontent; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.impl.BuilderUsercontent; +import net.minecraft.client.Minecraft; +import net.minecraft.util.text.ChatType; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class UsercontentAPI +{ + private final Map values = new HashMap(); + private final List builders; + + public UsercontentAPI(List builders) + { + this.builders = builders; + } + + @Nullable + public String getValue(String id) + { + return this.values.get(id); + } + + public void updateValue(String id, String value) + { + this.values.put(id, value); + } + + public void addChatMessage(Object object) + { + if(object != null) + { + Minecraft.getInstance().ingameGUI.addChatMessage(ChatType.CHAT, new StringTextComponent(object.toString())); + } + } + + public void setCommandArgument(int command, int index, String object) + { + if(command < this.builders.size() && command >= 0) + { + this.builders.get(command).set(index, object); + } + } + + @Nullable + public String getCommandArgument(int command, int index) + { + if(command < this.builders.size() && command >= 0) + { + return this.builders.get(command).get(index); + } + + return null; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/UsercontentConfig.java b/src/main/java/exopandora/worldhandler/usercontent/UsercontentConfig.java new file mode 100644 index 0000000..9df280c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/UsercontentConfig.java @@ -0,0 +1,84 @@ +package exopandora.worldhandler.usercontent; + +import java.nio.file.Path; + +import javax.script.ScriptEngine; + +import exopandora.worldhandler.usercontent.model.JsonUsercontent; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class UsercontentConfig +{ + private final String id; + private final JsonUsercontent content; + private final String js; + private final ScriptEngine engine; + + private UsercontentConfig(Builder builder) + { + this.id = builder.id; + this.content = builder.content; + this.js = builder.js; + this.engine = builder.engine; + } + + public String getId() + { + return this.id; + } + + public JsonUsercontent getContent() + { + return this.content; + } + + public String getJs() + { + return this.js; + } + + public ScriptEngine getScriptEngine() + { + return this.engine; + } + + @OnlyIn(Dist.CLIENT) + public static class Builder + { + private final String id; + private JsonUsercontent content; + private String js; + private ScriptEngine engine; + + public Builder(Path path) + { + String fileName = path.getFileName().toString(); + this.id = fileName.substring(0, fileName.length() - 3); + } + + public Builder setContent(JsonUsercontent content) + { + this.content = content; + return this; + } + + public Builder setJs(String js) + { + this.js = js; + return this; + } + + public Builder setScriptEngine(ScriptEngine engine) + { + this.engine = engine; + return this; + } + + public UsercontentConfig build() + { + return new UsercontentConfig(this); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java b/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java new file mode 100644 index 0000000..defbf8e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/UsercontentLoader.java @@ -0,0 +1,189 @@ +package exopandora.worldhandler.usercontent; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +import javax.script.ScriptContext; +import javax.script.ScriptEngine; + +import org.apache.commons.io.IOUtils; + +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonSyntaxException; +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; + +import exopandora.worldhandler.WorldHandler; +import exopandora.worldhandler.builder.types.ArgumentType; +import exopandora.worldhandler.gui.button.EnumIcon; +import exopandora.worldhandler.usercontent.model.Action; +import exopandora.worldhandler.usercontent.model.BooleanExpression; +import exopandora.worldhandler.usercontent.model.JsonButton; +import exopandora.worldhandler.usercontent.model.JsonElement; +import exopandora.worldhandler.usercontent.model.JsonUsercontent; +import jdk.nashorn.api.scripting.NashornScriptEngineFactory; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class UsercontentLoader +{ + public static final List CONFIGS = new ArrayList(); + + public static void load(Path path) + { + try + { + UsercontentLoader.load0(path); + } + catch(IOException e) + { + e.printStackTrace(); + } + } + + public static void load0(Path path) throws IOException + { + if(Files.notExists(path) || !Files.isReadable(path)) + { + throw new IOException("Path is not accessible"); + } + + final Gson gson = new GsonBuilder() + .registerTypeAdapter(ArgumentType.class, new EnumTypeAdapter(ArgumentType.class)) + .registerTypeAdapter(EnumIcon.class, new EnumTypeAdapter(EnumIcon.class)) + .registerTypeAdapter(BooleanExpression.Type.class, new EnumTypeAdapter(BooleanExpression.Type.class)) + .registerTypeAdapter(JsonButton.Type.class, new EnumTypeAdapter(JsonButton.Type.class)) + .registerTypeAdapter(Action.Type.class, new EnumTypeAdapter(Action.Type.class)) + .registerTypeAdapter(JsonElement.Type.class, new EnumTypeAdapter(JsonElement.Type.class)) + .create(); + final List folders = Files.list(path) + .filter(Files::isDirectory) + .filter(Files::isReadable) + .filter(UsercontentLoader::isValidPathName) + .collect(Collectors.toList()); + + for(Path folder : folders) + { + Optional json = UsercontentLoader.locateFile(folder, "json"); + Optional js = UsercontentLoader.locateFile(folder, "js"); + + if(json.isPresent()) + { + UsercontentConfig.Builder builder = new UsercontentConfig.Builder(js.get()); + String usercontent = UsercontentLoader.readFile(json.get()); + + try + { + JsonUsercontent content = gson.fromJson(usercontent, JsonUsercontent.class); + content.validate(); + builder.setContent(content); + + if(js.isPresent()) + { + builder.setScriptEngine(UsercontentLoader.buildScriptEngine()); + builder.setJs(UsercontentLoader.readFile(js.get())); + } + + UsercontentLoader.CONFIGS.add(builder.build()); + } + catch(JsonSyntaxException | IllegalStateException e) + { + WorldHandler.LOGGER.error("Error loading usercontent " + json.get().toAbsolutePath()); + WorldHandler.LOGGER.throwing(e); + } + } + } + } + + private static final List ALLOWED_CLASSES = Arrays.asList + ( + "exopandora.worldhandler.helper.ActionHelper" + ); + + private static ScriptEngine buildScriptEngine() + { + final NashornScriptEngineFactory factory = new NashornScriptEngineFactory(); + final ScriptEngine engine = factory.getScriptEngine(s -> ALLOWED_CLASSES.stream().anyMatch(s::equals)); + final ScriptContext context = engine.getContext(); + + context.removeAttribute("load", context.getAttributesScope("load")); + context.removeAttribute("quit", context.getAttributesScope("quit")); + context.removeAttribute("loadWithNewGlobal", context.getAttributesScope("loadWithNewGlobal")); + context.removeAttribute("exit", context.getAttributesScope("exit")); + + return engine; + } + + private static Optional locateFile(Path path, String fileExtension) + { + Path json = path.resolve(path.getFileName().toString() + "." + fileExtension); + + if(Files.exists(json) && Files.isRegularFile(json) && Files.isReadable(json)) + { + return Optional.of(json); + } + + return Optional.empty(); + } + + private static String readFile(Path path) + { + try + { + return IOUtils.toString(path.toUri(), Charset.defaultCharset()); + } + catch(IOException e) + { + e.printStackTrace(); + } + + return null; + } + + private static boolean isValidPathName(Path path) + { + String name = path.getFileName().toString(); + boolean valid = ResourceLocation.isResouceNameValid(name); + + if(!valid) + { + WorldHandler.LOGGER.error("Invalid usercontent folder name: " + name); + } + + return valid; + } + + @OnlyIn(Dist.CLIENT) + public static class EnumTypeAdapter> extends TypeAdapter + { + private final Class klass; + + public EnumTypeAdapter(Class klass) + { + this.klass = klass; + } + + @Override + public void write(JsonWriter writer, T value) throws IOException + { + writer.value(value.name().toLowerCase()); + } + + @Override + public T read(JsonReader reader) throws IOException + { + return Enum.valueOf(this.klass, reader.nextString().toUpperCase()); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/VisibleActiveObject.java b/src/main/java/exopandora/worldhandler/usercontent/VisibleActiveObject.java new file mode 100644 index 0000000..c62afeb --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/VisibleActiveObject.java @@ -0,0 +1,33 @@ +package exopandora.worldhandler.usercontent; + +import exopandora.worldhandler.usercontent.model.BooleanExpression; +import exopandora.worldhandler.usercontent.model.JsonButton; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class VisibleActiveObject extends VisibleObject +{ + private final BooleanExpression active; + + public VisibleActiveObject(BooleanExpression visible, BooleanExpression active, T object) + { + super(visible, object); + this.active = active; + } + + public VisibleActiveObject(JsonButton button, T object) + { + this(button.getAttributes() != null ? button.getAttributes().getVisible() : null, button.getAttributes() != null ? button.getAttributes().getEnabled() : null, object); + } + + public boolean isEnabled(ScriptEngineAdapter engine) + { + if(this.active != null) + { + return this.active.eval(engine); + } + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java b/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java new file mode 100644 index 0000000..f7d92ed --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/VisibleObject.java @@ -0,0 +1,33 @@ +package exopandora.worldhandler.usercontent; + +import exopandora.worldhandler.usercontent.model.BooleanExpression; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class VisibleObject +{ + private final BooleanExpression visible; + private final T object; + + public VisibleObject(BooleanExpression visible, T object) + { + this.visible = visible; + this.object = object; + } + + public boolean isVisible(ScriptEngineAdapter engine) + { + if(this.visible != null) + { + return this.visible.eval(engine); + } + + return true; + } + + public T getObject() + { + return this.object; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java new file mode 100644 index 0000000..4261b6c --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/ActionHandlerFactory.java @@ -0,0 +1,136 @@ +package exopandora.worldhandler.usercontent.factory; + +import java.util.List; +import java.util.function.Consumer; +import java.util.function.Function; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.builder.impl.BuilderUsercontent; +import exopandora.worldhandler.gui.content.Content; +import exopandora.worldhandler.helper.ActionHelper; +import exopandora.worldhandler.helper.CommandHelper; +import exopandora.worldhandler.usercontent.ScriptEngineAdapter; +import exopandora.worldhandler.usercontent.UsercontentAPI; +import exopandora.worldhandler.usercontent.VisibleObject; +import exopandora.worldhandler.usercontent.model.Action; +import exopandora.worldhandler.util.ActionHandler; +import net.minecraft.client.Minecraft; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class ActionHandlerFactory +{ + private final UsercontentAPI api; + private final List> builders; + private final ScriptEngineAdapter engine; + + public ActionHandlerFactory(UsercontentAPI api, List> builders, ScriptEngineAdapter engine) + { + this.api = api; + this.builders = builders; + this.engine = engine; + } + + @Nullable + public ActionHandler createActionHandler(Content content, Action action) + { + return this.createActionHandler(content, action, null); + } + + @Nullable + public ActionHandler createActionHandler(Content content, Action action, String value) + { + if(action == null) + { + return null; + } + else if(Action.Type.OPEN.equals(action.getType())) + { + if(action.getAttributes() != null && action.getAttributes().getValue() != null) + { + return () -> ActionHelper.open(action.getAttributes().getValue()); + } + } + else if(Action.Type.SET.equals(action.getType())) + { + if(action.getAttributes() != null && (action.getAttributes().getValue() != null || value != null)) + { + return () -> + { + VisibleObject visObj = this.builders.get(action.getAttributes().getCommand()); + + if(visObj != null && visObj.getObject() != null) + { + visObj.getObject().set(action.getAttributes().getIndex(), value != null ? value : action.getAttributes().getValue()); + } + }; + } + } + else if(Action.Type.RUN.equals(action.getType())) + { + if(action.getAttributes() != null) + { + return () -> + { + if(action.getAttributes().getValue() == null) + { + CommandHelper.sendCommand(this.builders.get(action.getAttributes().getCommand()).getObject()); + } + else if(!action.getAttributes().getValue().isEmpty()) + { + Minecraft.getInstance().player.sendChatMessage(action.getAttributes().getValue()); + } + }; + } + } + else if(Action.Type.BACK.equals(action.getType())) + { + return () -> ActionHelper.back(content); + } + else if(Action.Type.BACK_TO_GAME.equals(action.getType())) + { + return ActionHelper::backToGame; + } + else if(Action.Type.JS.equals(action.getType())) + { + if(action.getAttributes() != null && action.getAttributes().getFunction() != null && !action.getAttributes().getFunction().isEmpty()) + { + return () -> this.engine.invokeFunction(action.getAttributes().getFunction(), value != null ? value : action.getAttributes().getValue()); + } + } + + return null; + } + + public Consumer createResponder(Function toStringMapper, String id, Action action) + { + if(Action.Type.SET.equals(action.getType())) + { + if(action.getAttributes() != null) + { + return string -> + { + String value = toStringMapper.apply(string); + this.api.updateValue(id, value); + this.builders.get(action.getAttributes().getCommand()).getObject().set(action.getAttributes().getIndex(), value); + }; + } + } + else if(Action.Type.JS.equals(action.getType())) + { + if(action.getAttributes() != null && action.getAttributes().getFunction() != null) + { + return string -> + { + String value = toStringMapper.apply(string); + this.api.updateValue(id, value); + this.engine.invokeFunction(action.getAttributes().getFunction(), value); + }; + } + } + + return string -> this.api.updateValue(id, toStringMapper.apply(string)); + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/ButtonFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/ButtonFactory.java new file mode 100644 index 0000000..cb4039a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/ButtonFactory.java @@ -0,0 +1,125 @@ +package exopandora.worldhandler.usercontent.factory; + +import java.util.function.Consumer; + +import javax.annotation.Nullable; + +import com.google.common.base.Predicates; + +import exopandora.worldhandler.gui.button.GuiButtonIcon; +import exopandora.worldhandler.gui.button.GuiButtonItem; +import exopandora.worldhandler.gui.button.GuiButtonList; +import exopandora.worldhandler.gui.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.button.GuiSlider; +import exopandora.worldhandler.gui.button.GuiTextFieldTooltip; +import exopandora.worldhandler.gui.container.Container; +import exopandora.worldhandler.gui.content.Content; +import exopandora.worldhandler.gui.logic.LogicSliderSimple; +import exopandora.worldhandler.usercontent.UsercontentAPI; +import exopandora.worldhandler.usercontent.model.JsonItem; +import exopandora.worldhandler.util.TextFormatting; +import exopandora.worldhandler.usercontent.model.JsonButton; +import net.minecraft.client.gui.widget.Widget; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; +import net.minecraftforge.registries.ForgeRegistries; + +@OnlyIn(Dist.CLIENT) +public class ButtonFactory extends WidgetFactory +{ + public ButtonFactory(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory) + { + super(api, actionHandlerFactory); + } + + @Nullable + public Widget createButton(JsonButton button, Content content, Container container, int x, int y) + { + if(JsonButton.Type.BUTTON.equals(button.getType())) + { + return new GuiButtonTooltip + ( + button.getDimensions().getX() + x, + button.getDimensions().getY() + y, + button.getDimensions().getWidth(), + button.getDimensions().getHeight(), + TextFormatting.formatNonnull(button.getText()), + TextFormatting.formatNullable(button.getAttributes() != null ? button.getAttributes().getTooltip() : null), + this.getActionHandlerFactory().createActionHandler(content, button.getAction()) + ); + } + else if(JsonButton.Type.ITEM_BUTTON.equals(button.getType())) + { + return new GuiButtonItem + ( + button.getDimensions().getX() + x, + button.getDimensions().getY() + y, + button.getDimensions().getWidth(), + button.getDimensions().getHeight(), + ForgeRegistries.ITEMS.getValue(new ResourceLocation(button.getAttributes().getItem())), + this.getActionHandlerFactory().createActionHandler(content, button.getAction()) + ); + } + else if(JsonButton.Type.ICON_BUTTON.equals(button.getType())) + { + return new GuiButtonIcon + ( + button.getDimensions().getX() + x, + button.getDimensions().getY() + y, + button.getDimensions().getWidth(), + button.getDimensions().getHeight(), + button.getAttributes().getIcon(), + TextFormatting.formatNonnull(button.getAttributes().getTooltip()), + this.getActionHandlerFactory().createActionHandler(content, button.getAction()) + ); + } + else if(JsonButton.Type.LIST_BUTTON.equals(button.getType())) + { + return new GuiButtonList + ( + button.getDimensions().getX() + x, + button.getDimensions().getY() + y, + button.getAttributes().getItems(), + button.getDimensions().getWidth(), + button.getDimensions().getHeight(), + container, + new UsercontentLogicMapped(this.getApi(), this.getActionHandlerFactory(), content, button) + ); + } + else if(JsonButton.Type.SLIDER.equals(button.getType())) + { + Consumer responder = this.getActionHandlerFactory().createResponder(integer -> integer.toString(), button.getAttributes().getId(), button.getAction()); + return new GuiSlider + ( + button.getDimensions().getX() + x, + button.getDimensions().getY() + y, + button.getDimensions().getWidth(), + button.getDimensions().getHeight(), + button.getAttributes().getMin(), + button.getAttributes().getMax(), + button.getAttributes().getStart(), + container, + new LogicSliderSimple(button.getAttributes().getId(), TextFormatting.formatNullable(button.getText()), responder) + ); + } + else if(JsonButton.Type.TEXTFIELD.equals(button.getType())) + { + GuiTextFieldTooltip textfield = new GuiTextFieldTooltip + ( + button.getDimensions().getX() + x, + button.getDimensions().getY() + y, + button.getDimensions().getWidth(), + button.getDimensions().getHeight(), + TextFormatting.formatNullable(button.getText()) + ); + textfield.setValidator(Predicates.notNull()); + textfield.setText(this.getApi().getValue(button.getAttributes().getId())); + textfield.setResponder(this.getActionHandlerFactory().createResponder(string -> textfield.getText(), button.getAttributes().getId(), button.getAction())); + + return textfield; + } + + return null; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/ElementFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/ElementFactory.java new file mode 100644 index 0000000..ace212f --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/ElementFactory.java @@ -0,0 +1,79 @@ +package exopandora.worldhandler.usercontent.factory; + +import javax.annotation.Nullable; + +import exopandora.worldhandler.gui.button.GuiButtonBase; +import exopandora.worldhandler.gui.button.GuiButtonTooltip; +import exopandora.worldhandler.gui.container.Container; +import exopandora.worldhandler.gui.content.Content; +import exopandora.worldhandler.gui.element.Element; +import exopandora.worldhandler.gui.element.impl.ElementPageList; +import exopandora.worldhandler.gui.logic.ILogicPageList; +import exopandora.worldhandler.usercontent.UsercontentAPI; +import exopandora.worldhandler.usercontent.model.JsonElement; +import exopandora.worldhandler.usercontent.model.JsonItem; +import exopandora.worldhandler.usercontent.model.JsonWidget; +import exopandora.worldhandler.util.ActionHandler; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class ElementFactory extends WidgetFactory +{ + public ElementFactory(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory) + { + super(api, actionHandlerFactory); + } + + @Nullable + public Element createElement(JsonElement element, Content content, Container container, int x, int y) + { + if(JsonElement.Type.PAGE_LIST.equals(element.getType())) + { + return new ElementPageList + ( + element.getDimensions().getX() + x, + element.getDimensions().getY() + y, + element.getAttributes().getItems(), + element.getDimensions().getWidth(), + element.getDimensions().getHeight(), + element.getAttributes().getLength(), + container, + new UsercontentLogicPageList(this.getApi(), this.getActionHandlerFactory(), content, container, element) + ); + } + + return null; + } + + @OnlyIn(Dist.CLIENT) + public static class UsercontentLogicPageList> extends UsercontentLogicMapped implements ILogicPageList + { + private final Container container; + + public UsercontentLogicPageList(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory, Content content, Container container, JsonWidget widget) + { + super(api, actionHandlerFactory, content, widget); + this.container = container; + } + + @Override + public void onClick(JsonItem item) + { + super.onClick(item); + this.container.initButtons(); + } + + @Override + public GuiButtonBase onRegister(int x, int y, int width, int height, String text, JsonItem item, ActionHandler actionHandler) + { + return new GuiButtonTooltip(x, y, width, height, text, this.toTooltip(item), actionHandler); + } + + @Override + public void onInit(JsonItem item) + { + + } + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/factory/WidgetFactory.java b/src/main/java/exopandora/worldhandler/usercontent/factory/WidgetFactory.java new file mode 100644 index 0000000..49a7b7a --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/factory/WidgetFactory.java @@ -0,0 +1,96 @@ +package exopandora.worldhandler.usercontent.factory; + +import exopandora.worldhandler.WorldHandler; +import exopandora.worldhandler.gui.content.Content; +import exopandora.worldhandler.gui.logic.ILogicMapped; +import exopandora.worldhandler.usercontent.UsercontentAPI; +import exopandora.worldhandler.usercontent.model.JsonItem; +import exopandora.worldhandler.usercontent.model.JsonWidget; +import exopandora.worldhandler.util.ActionHandler; +import exopandora.worldhandler.util.TextFormatting; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public abstract class WidgetFactory +{ + private final ActionHandlerFactory actionHandlerFactory; + private final UsercontentAPI api; + + public WidgetFactory(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory) + { + this.api = api; + this.actionHandlerFactory = actionHandlerFactory; + } + + public ActionHandlerFactory getActionHandlerFactory() + { + return this.actionHandlerFactory; + } + + public UsercontentAPI getApi() + { + return this.api; + } + + @OnlyIn(Dist.CLIENT) + public static class UsercontentLogicMapped> implements ILogicMapped + { + private final ActionHandlerFactory actionHandlerFactory; + private final UsercontentAPI api; + private final Content content; + private final JsonWidget widget; + + public UsercontentLogicMapped(UsercontentAPI api, ActionHandlerFactory actionHandlerFactory, Content content, JsonWidget widget) + { + this.api = api; + this.actionHandlerFactory = actionHandlerFactory; + this.content = content; + this.widget = widget; + } + + @Override + public String translate(JsonItem item) + { + String translation = TextFormatting.formatNullable(item.getTranslation()); + return translation == null ? item.getId() : translation; + } + + @Override + public String toTooltip(JsonItem item) + { + return item.getId(); + } + + @Override + public void onClick(JsonItem item) + { + try + { + this.api.updateValue(this.widget.getAttributes().getId(), item.getId()); + ActionHandler action = this.actionHandlerFactory.createActionHandler(this.content, this.widget.getAction(), item.getId()); + + if(action != null) + { + action.run(); + } + } + catch(Exception e) + { + WorldHandler.LOGGER.error("Error executing action for widget"); + } + } + + @Override + public String getId() + { + return this.widget.getAttributes().getId(); + } + + @Override + public void onInit(JsonItem item) + { + this.onClick(item); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/Action.java b/src/main/java/exopandora/worldhandler/usercontent/model/Action.java new file mode 100644 index 0000000..1e472da --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/Action.java @@ -0,0 +1,98 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class Action +{ + @SerializedName("type") + private Type type; + + @SerializedName("attributes") + private ActionAttributes attributes; + + public Action(Type type, ActionAttributes attributes) + { + this.type = type; + this.attributes = attributes; + } + + public Type getType() + { + return this.type; + } + + public void setType(Type type) + { + this.type = type; + } + + public ActionAttributes getAttributes() + { + return this.attributes; + } + + public void setAttributes(ActionAttributes attributes) + { + this.attributes = attributes; + } + + public void validate() throws IllegalStateException + { + if(this.type == null) + { + throw new IllegalStateException("action.type type is null"); + } + + if(this.type == Type.OPEN) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("action.attributes is null"); + } + else if(this.getAttributes().getValue() == null) + { + throw new IllegalStateException("action.attributes.value is null"); + } + } + else if(this.type == Type.SET) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("action.attributes is null"); + } + } + else if(this.type == Type.RUN) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("action.attributes is null"); + } + } + else if(this.type == Type.JS) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("action.attributes is null"); + } + else if(this.getAttributes().getFunction() == null) + { + throw new IllegalStateException("action.attributes.function is null"); + } + } + } + + @OnlyIn(Dist.CLIENT) + public static enum Type + { + OPEN, + SET, + RUN, + BACK, + BACK_TO_GAME, + JS; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java b/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java new file mode 100644 index 0000000..8648993 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/ActionAttributes.java @@ -0,0 +1,70 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class ActionAttributes +{ + @SerializedName("function") + private String function; + + @SerializedName("command") + private int command; + + @SerializedName("index") + private int index; + + @SerializedName("value") + private String value; + + public ActionAttributes(String function, int command, int index, String value) + { + this.function = function; + this.command = command; + this.index = index; + this.value = value; + } + + public String getFunction() + { + return this.function; + } + + public void setFunction(String function) + { + this.function = function; + } + + public int getCommand() + { + return this.command; + } + + public void setCommand(int command) + { + this.command = command; + } + + public int getIndex() + { + return this.index; + } + + public void setIndex(int index) + { + this.index = index; + } + + public String getValue() + { + return this.value; + } + + public void setValue(String value) + { + this.value = value; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/Attributes.java b/src/main/java/exopandora/worldhandler/usercontent/model/Attributes.java new file mode 100644 index 0000000..e167765 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/Attributes.java @@ -0,0 +1,171 @@ +package exopandora.worldhandler.usercontent.model; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +import exopandora.worldhandler.gui.button.EnumIcon; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class Attributes +{ + @SerializedName("id") + private String id; + + @SerializedName("visible") + private BooleanExpression visible; + + @SerializedName("enabled") + private BooleanExpression enabled; + + @SerializedName("tooltip") + private String tooltip; + + @SerializedName("item") + private String item; + + @SerializedName("icon") + private EnumIcon icon; + + @SerializedName("items") + private List items = null; + + @SerializedName("length") + private int length; + + @SerializedName("min") + private double min; + + @SerializedName("max") + private double max; + + @SerializedName("start") + private double start; + + public Attributes(String id, BooleanExpression visible, BooleanExpression enabled, String tooltip, String item, EnumIcon icon, List items, int length, double min, double max, double start) + { + this.id = id; + this.visible = visible; + this.enabled = enabled; + this.tooltip = tooltip; + this.item = item; + this.icon = icon; + this.items = items; + this.length = length; + this.min = min; + this.max = max; + this.start = start; + } + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public BooleanExpression getVisible() + { + return this.visible; + } + + public void setVisible(BooleanExpression visible) + { + this.visible = visible; + } + + public BooleanExpression getEnabled() + { + return this.enabled; + } + + public void setEnabled(BooleanExpression enabled) + { + this.enabled = enabled; + } + + public String getTooltip() + { + return this.tooltip; + } + + public void setTooltip(String tooltip) + { + this.tooltip = tooltip; + } + + public String getItem() + { + return this.item; + } + + public void setItem(String item) + { + this.item = item; + } + + public EnumIcon getIcon() + { + return this.icon; + } + + public void setIcon(EnumIcon icon) + { + this.icon = icon; + } + + public List getItems() + { + return this.items; + } + + public void setItems(List items) + { + this.items = items; + } + + public int getLength() + { + return this.length; + } + + public void setLength(int length) + { + this.length = length; + } + + public double getMin() + { + return this.min; + } + + public void setMin(double min) + { + this.min = min; + } + + public double getMax() + { + return this.max; + } + + public void setMax(double max) + { + this.max = max; + } + + public double getStart() + { + return this.start; + } + + public void setStart(double start) + { + this.start = start; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/BooleanExpression.java b/src/main/java/exopandora/worldhandler/usercontent/model/BooleanExpression.java new file mode 100644 index 0000000..efa4265 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/BooleanExpression.java @@ -0,0 +1,78 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import exopandora.worldhandler.usercontent.ScriptEngineAdapter; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class BooleanExpression +{ + @SerializedName("type") + private Type type; + + @SerializedName("bool") + private boolean bool; + + @SerializedName("function") + private String function; + + public BooleanExpression(Type type, boolean bool, String function) + { + this.type = type; + this.bool = bool; + this.function = function; + } + + public Type getType() + { + return this.type; + } + + public void setType(Type type) + { + this.type = type; + } + + public boolean isBool() + { + return this.bool; + } + + public void setBool(boolean bool) + { + this.bool = bool; + } + + public String getFunction() + { + return this.function; + } + + public void setFunction(String function) + { + this.function = function; + } + + public boolean eval(ScriptEngineAdapter engine) + { + if(this.type == Type.BOOL) + { + return this.bool; + } + else if(this.type == Type.JS) + { + return (boolean) engine.invokeFunction(this.function); + } + + return true; + } + + @OnlyIn(Dist.CLIENT) + public static enum Type + { + BOOL, + JS; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonButton.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonButton.java new file mode 100644 index 0000000..ab3e1d2 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonButton.java @@ -0,0 +1,134 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import exopandora.worldhandler.usercontent.model.JsonButton.Type; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonButton extends JsonWidget +{ + @SerializedName("text") + private String text; + + @SerializedName("type") + private Type type; + + public JsonButton(String text, Type type, Action action, JsonDimensions dimensions, Attributes attributes) + { + super(action, dimensions, attributes); + this.text = text; + this.type = type; + } + + public String getText() + { + return this.text; + } + + public void setText(String text) + { + this.text = text; + } + + public Type getType() + { + return this.type; + } + + public void setType(Type type) + { + this.type = type; + } + + @Override + public void validate() throws IllegalStateException + { + if(this.type == null) + { + throw new IllegalStateException("button.type is null"); + } + + if(this.type == Type.TEXTFIELD) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("button.attributes is null"); + } + else if(this.getAttributes().getId() == null) + { + throw new IllegalStateException("button.attributes.id is null"); + } + else if(this.getAttributes().getId().isEmpty()) + { + throw new IllegalStateException("button.attributes.id is empty"); + } + + this.validateAction(Action.Type.SET, Action.Type.JS); + } + else if(this.type == Type.ITEM_BUTTON) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("button.attributes is null"); + } + else if(this.getAttributes().getItem() == null) + { + throw new IllegalStateException("button.attributes.item is null"); + } + + this.validateAction(Action.Type.OPEN, Action.Type.SET, Action.Type.RUN, Action.Type.BACK, Action.Type.BACK_TO_GAME, Action.Type.JS); + } + else if(this.type == Type.ICON_BUTTON) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("button.attributes is null"); + } + else if(this.getAttributes().getIcon() == null) + { + throw new IllegalStateException("button.attributes.icon is null"); + } + + this.validateAction(Action.Type.OPEN, Action.Type.SET, Action.Type.RUN, Action.Type.BACK, Action.Type.BACK_TO_GAME, Action.Type.JS); + } + else if(this.type == Type.LIST_BUTTON) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("button.attributes is null"); + } + else if(this.getAttributes().getItems() == null) + { + throw new IllegalStateException("button.attributes.items is null"); + } + else if(this.getAttributes().getItems().isEmpty()) + { + throw new IllegalStateException("button.attributes.items is empty"); + } + + this.validateAction(Action.Type.SET, Action.Type.JS); + } + else if(this.type == Type.SLIDER) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("button.attributes is null"); + } + + this.validateAction(Action.Type.SET, Action.Type.JS); + } + } + + @OnlyIn(Dist.CLIENT) + public static enum Type + { + BUTTON, + TEXTFIELD, + ITEM_BUTTON, + ICON_BUTTON, + LIST_BUTTON, + SLIDER; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java new file mode 100644 index 0000000..d6dcd56 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonCommand.java @@ -0,0 +1,59 @@ +package exopandora.worldhandler.usercontent.model; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +import exopandora.worldhandler.builder.CommandSyntax.Argument; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonCommand +{ + @SerializedName("name") + private String name; + + @SerializedName("syntax") + private List syntax = null; + + @SerializedName("visible") + private BooleanExpression visible; + + public JsonCommand(String name, List syntax, BooleanExpression visible) + { + this.name = name; + this.syntax = syntax; + this.visible = visible; + } + + public String getName() + { + return this.name; + } + + public void setName(String name) + { + this.name = name; + } + + public List getSyntax() + { + return this.syntax; + } + + public void setSyntax(List syntax) + { + this.syntax = syntax; + } + + public BooleanExpression getVisible() + { + return this.visible; + } + + public void setVisible(BooleanExpression visible) + { + this.visible = visible; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonDimensions.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonDimensions.java new file mode 100644 index 0000000..edc4bde --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonDimensions.java @@ -0,0 +1,70 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonDimensions +{ + @SerializedName("x") + private int x; + + @SerializedName("y") + private int y; + + @SerializedName("width") + private int width; + + @SerializedName("height") + private int height; + + public JsonDimensions(int x, int y, int width, int height) + { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + } + + public int getX() + { + return this.x; + } + + public void setX(int x) + { + this.x = x; + } + + public int getY() + { + return this.y; + } + + public void setY(int y) + { + this.y = y; + } + + public int getWidth() + { + return this.width; + } + + public void setWidth(int width) + { + this.width = width; + } + + public int getHeight() + { + return this.height; + } + + public void setHeight(int height) + { + this.height = height; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonElement.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonElement.java new file mode 100644 index 0000000..094dfa3 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonElement.java @@ -0,0 +1,71 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import exopandora.worldhandler.usercontent.model.JsonElement.Type; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonElement extends JsonWidget +{ + @SerializedName("type") + private Type type; + + public JsonElement(Type type, Action action, JsonDimensions dimensions, Attributes attributes) + { + super(action, dimensions, attributes); + this.type = type; + } + + public Type getType() + { + return this.type; + } + + public void setType(Type type) + { + this.type = type; + } + + @OnlyIn(Dist.CLIENT) + public static enum Type + { + PAGE_LIST; + } + + @Override + public void validate() throws IllegalStateException + { + if(this.type == null) + { + throw new IllegalStateException("element.type is null"); + } + + if(this.type == Type.PAGE_LIST) + { + if(this.getAttributes() == null) + { + throw new IllegalStateException("element.attributes is null"); + } + else if(this.getAttributes().getId() == null) + { + throw new IllegalStateException("element.attributes.id is null"); + } + else if(this.getAttributes().getId().isEmpty()) + { + throw new IllegalStateException("element.attributes.id is empty"); + } + else if(this.getAttributes().getItems() == null) + { + throw new IllegalStateException("element.attributes.items is null"); + } + else if(this.getAttributes().getItems().isEmpty()) + { + throw new IllegalStateException("element.attributes.items is empty"); + } + + this.validateAction(Action.Type.SET, Action.Type.JS); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonGui.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonGui.java new file mode 100644 index 0000000..5412d3e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonGui.java @@ -0,0 +1,96 @@ +package exopandora.worldhandler.usercontent.model; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonGui +{ + @SerializedName("title") + private String title; + + @SerializedName("tab") + private JsonTab tab; + + @SerializedName("buttons") + private List buttons = null; + + @SerializedName("elements") + private List elements = null; + + @SerializedName("texts") + private List texts = null; + + public JsonGui(String title, JsonTab tab, List buttons, List elements, List texts) + { + this.title = title; + this.tab = tab; + this.buttons = buttons; + this.elements = elements; + this.texts = texts; + } + + public String getTitle() + { + return this.title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public JsonTab getTab() + { + return this.tab; + } + + public void setTitle(JsonTab tab) + { + this.tab = tab; + } + + public List getButtons() + { + return this.buttons; + } + + public void setButtons(List buttons) + { + this.buttons = buttons; + } + + public List getElements() + { + return this.elements; + } + + public void setElements(List elements) + { + this.elements = elements; + } + + public List getTexts() + { + return this.texts; + } + + public void setTexts(List texts) + { + this.texts = texts; + } + + public void validate() throws IllegalStateException + { + if(this.tab == null) + { + throw new IllegalStateException("gui.tab is null"); + } + + this.tab.validate(); + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonItem.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonItem.java new file mode 100644 index 0000000..3f04c99 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonItem.java @@ -0,0 +1,42 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonItem +{ + @SerializedName("id") + private String id; + + @SerializedName("translation") + private String translation; + + public JsonItem(String id, String translation) + { + this.id = id; + this.translation = translation; + } + + public String getId() + { + return this.id; + } + + public void setId(String id) + { + this.id = id; + } + + public String getTranslation() + { + return this.translation; + } + + public void setTranslation(String translation) + { + this.translation = translation; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonModel.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonModel.java new file mode 100644 index 0000000..0b71789 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonModel.java @@ -0,0 +1,30 @@ +package exopandora.worldhandler.usercontent.model; + +import java.util.List; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonModel +{ + @SerializedName("commands") + private List commands = null; + + public JsonModel(List commands) + { + this.commands = commands; + } + + public List getCommands() + { + return this.commands; + } + + public void setCommands(List commands) + { + this.commands = commands; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonTab.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonTab.java new file mode 100644 index 0000000..a2f809e --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonTab.java @@ -0,0 +1,78 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonTab +{ + @SerializedName("title") + private String title; + + @SerializedName("category") + private String category; + + @SerializedName("category_index") + private int categoryIndex; + + @SerializedName("active_content") + private String activeContent; + + public JsonTab(String title, String category, int categoryIndex, String activeContent) + { + this.title = title; + this.category = category; + this.categoryIndex = categoryIndex; + this.activeContent = activeContent; + } + + public String getTitle() + { + return this.title; + } + + public void setTitle(String title) + { + this.title = title; + } + + public String getCategory() + { + return this.category; + } + + public void setCategory(String category) + { + this.category = category; + } + + public int getCategoryIndex() + { + return this.categoryIndex; + } + + public void setCategoryIndex(int categoryIndex) + { + this.categoryIndex = categoryIndex; + } + + public String getActiveContent() + { + return this.activeContent; + } + + public void setActiveContent(String activeContent) + { + this.activeContent = activeContent; + } + + public void validate() throws IllegalStateException + { + if(this.category == null) + { + throw new IllegalStateException("tab.category is null"); + } + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonText.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonText.java new file mode 100644 index 0000000..4601552 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonText.java @@ -0,0 +1,70 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonText +{ + @SerializedName("text") + private String text; + + @SerializedName("x") + private int x; + + @SerializedName("y") + private int y; + + @SerializedName("color") + private int color; + + public JsonText(String text, int x, int y, int color) + { + this.text = text; + this.x = x; + this.y = y; + this.color = color; + } + + public String getText() + { + return this.text; + } + + public void setText(String text) + { + this.text = text; + } + + public int getX() + { + return this.x; + } + + public void setX(int x) + { + this.x = x; + } + + public int getY() + { + return this.y; + } + + public void setY(int y) + { + this.y = y; + } + + public int getColor() + { + return this.color; + } + + public void setColor(int color) + { + this.color = color; + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java new file mode 100644 index 0000000..49134c5 --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonUsercontent.java @@ -0,0 +1,52 @@ +package exopandora.worldhandler.usercontent.model; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public class JsonUsercontent +{ + @SerializedName("model") + private JsonModel model; + + @SerializedName("gui") + private JsonGui gui; + + public JsonUsercontent(JsonModel model, JsonGui gui) + { + this.model = model; + this.gui = gui; + } + + public JsonModel getModel() + { + return this.model; + } + + public void setModel(JsonModel model) + { + this.model = model; + } + + public JsonGui getGui() + { + return this.gui; + } + + public void setGui(JsonGui gui) + { + this.gui = gui; + } + + public void validate() throws IllegalStateException + { + if(this.gui == null) + { + throw new IllegalStateException("gui is null"); + } + + this.gui.validate(); + } +} diff --git a/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java b/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java new file mode 100644 index 0000000..4befbed --- /dev/null +++ b/src/main/java/exopandora/worldhandler/usercontent/model/JsonWidget.java @@ -0,0 +1,82 @@ +package exopandora.worldhandler.usercontent.model; + +import java.util.Arrays; + +import com.google.gson.annotations.SerializedName; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +public abstract class JsonWidget> +{ + @SerializedName("action") + private Action action; + + @SerializedName("dimensions") + private JsonDimensions dimensions; + + @SerializedName("attributes") + private Attributes attributes; + + public JsonWidget(Action action, JsonDimensions dimensions, Attributes attributes) + { + this.action = action; + this.dimensions = dimensions; + this.attributes = attributes; + } + + public Action getAction() + { + return this.action; + } + + public void setAction(Action action) + { + this.action = action; + } + + public JsonDimensions getDimensions() + { + return this.dimensions; + } + + public void setDimensions(JsonDimensions dimensions) + { + this.dimensions = dimensions; + } + + public Attributes getAttributes() + { + return this.attributes; + } + + public void setAttributes(Attributes attributes) + { + this.attributes = attributes; + } + + public abstract T getType(); + public abstract void setType(T type); + public abstract void validate() throws IllegalStateException; + + protected void validateAction(Action.Type... allowedTypes) throws IllegalStateException + { + if(this.getAction() != null) + { + this.getAction().validate(); + + if(Arrays.stream(allowedTypes).noneMatch(type -> type.equals(this.getAction().getType()))) + { + throw new IllegalStateException("Illegal action for type " + this.getType().toString().toLowerCase()); + } + } + } + + @OnlyIn(Dist.CLIENT) + public static enum Type + { + BUTTON, + ELEMENT + } +} diff --git a/src/main/java/exopandora/worldhandler/text/MutableStringTextComponent.java b/src/main/java/exopandora/worldhandler/util/MutableStringTextComponent.java similarity index 98% rename from src/main/java/exopandora/worldhandler/text/MutableStringTextComponent.java rename to src/main/java/exopandora/worldhandler/util/MutableStringTextComponent.java index b4857df..e3c14f1 100644 --- a/src/main/java/exopandora/worldhandler/text/MutableStringTextComponent.java +++ b/src/main/java/exopandora/worldhandler/util/MutableStringTextComponent.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.text; +package exopandora.worldhandler.util; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; diff --git a/src/main/java/exopandora/worldhandler/text/SignText.java b/src/main/java/exopandora/worldhandler/util/SignText.java similarity index 97% rename from src/main/java/exopandora/worldhandler/text/SignText.java rename to src/main/java/exopandora/worldhandler/util/SignText.java index eeb380f..0cec8c6 100644 --- a/src/main/java/exopandora/worldhandler/text/SignText.java +++ b/src/main/java/exopandora/worldhandler/util/SignText.java @@ -1,4 +1,4 @@ -package exopandora.worldhandler.text; +package exopandora.worldhandler.util; import javax.annotation.Nullable; diff --git a/src/main/java/exopandora/worldhandler/text/TextFormatting.java b/src/main/java/exopandora/worldhandler/util/TextFormatting.java similarity index 79% rename from src/main/java/exopandora/worldhandler/text/TextFormatting.java rename to src/main/java/exopandora/worldhandler/util/TextFormatting.java index d0eb58f..1170b48 100644 --- a/src/main/java/exopandora/worldhandler/text/TextFormatting.java +++ b/src/main/java/exopandora/worldhandler/util/TextFormatting.java @@ -1,6 +1,10 @@ -package exopandora.worldhandler.text; +package exopandora.worldhandler.util; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.resources.I18n; import net.minecraft.util.math.MathHelper; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -90,4 +94,26 @@ public class TextFormatting return String.format("%02d:%02d", hour, minute); } + + @Nullable + public static String formatNullable(String text, Object... parameters) + { + if(text == null) + { + return null; + } + + return I18n.format(text, parameters); + } + + @Nonnull + public static String formatNonnull(String text, Object... parameters) + { + if(text == null) + { + return ""; + } + + return I18n.format(text, parameters); + } } diff --git a/src/main/java/exopandora/worldhandler/util/UtilRender.java b/src/main/java/exopandora/worldhandler/util/UtilRender.java index 07bc3b6..b9cbf56 100644 --- a/src/main/java/exopandora/worldhandler/util/UtilRender.java +++ b/src/main/java/exopandora/worldhandler/util/UtilRender.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.platform.GlStateManager; import exopandora.worldhandler.config.Config; import exopandora.worldhandler.helper.ResourceHelper; -import exopandora.worldhandler.text.TextFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraftforge.api.distmarker.Dist; diff --git a/src/main/resources/assets/worldhandler/lang/de_de.json b/src/main/resources/assets/worldhandler/lang/de_de.json index 8d607e8..cc3b8ca 100644 --- a/src/main/resources/assets/worldhandler/lang/de_de.json +++ b/src/main/resources/assets/worldhandler/lang/de_de.json @@ -418,5 +418,5 @@ "worldhandler.permission.refused": "Du hast nicht die benötigte Berechtigung, um den World Handler zu benutzen", "worldhandler.permission.refused.change": "Ändere \"%s\" um diese Nachricht zu umgehen", - "worldhandler.error.gui": "Ein unerwarteter Fehler ist aufgetreten. Bitte sende einen Unfallbericht mit deinen Protokolldateien an das %s Forum" + "worldhandler.error.gui": "Ein unerwarteter Fehler ist aufgetreten." } \ No newline at end of file diff --git a/src/main/resources/assets/worldhandler/lang/en_us.json b/src/main/resources/assets/worldhandler/lang/en_us.json index ddfa44e..f512c51 100644 --- a/src/main/resources/assets/worldhandler/lang/en_us.json +++ b/src/main/resources/assets/worldhandler/lang/en_us.json @@ -417,5 +417,5 @@ "worldhandler.permission.refused": "You do not have permission to use the World Handler", "worldhandler.permission.refused.change": "Change \"%s\" to disable this message", - "worldhandler.error.gui": "An unexpected error occured. Please send a crash report with your log files to the %s forum" + "worldhandler.error.gui": "An unexpected error occured." } \ No newline at end of file diff --git a/src/main/resources/assets/worldhandler/lang/zh_cn.json b/src/main/resources/assets/worldhandler/lang/zh_cn.json index 6bc75e0..6ef8495 100644 --- a/src/main/resources/assets/worldhandler/lang/zh_cn.json +++ b/src/main/resources/assets/worldhandler/lang/zh_cn.json @@ -418,5 +418,5 @@ "worldhandler.permission.refused": "您没有权限使用 World Handler", "worldhandler.permission.refused.change": "更改 \"%s\" 来停止显示这条信息", - "worldhandler.error.gui": "An unexpected error occured. Please send a crash report with your log files to the %s forum" + "worldhandler.error.gui": "An unexpected error occured." } \ No newline at end of file diff --git a/usercontent/Usercontent.md b/usercontent/Usercontent.md new file mode 100644 index 0000000..5639cd3 --- /dev/null +++ b/usercontent/Usercontent.md @@ -0,0 +1,282 @@ +# Usercontent Reference # + +The World Handler provides the ability to be extended with custom tabs configured with json files. + +# Setup # + +The World Handler only loads usercontent files from `../.minecraft/config/worldhandler/usercontent/`. +To add a custom GUI a new folder is required with a json file inside it named exactly the same as the folder. +That name indicates the id of the usercontent and may only consist of the characters `0-9` `a-z` `-_:`. +Additionally a javascript file can be created inside the folder with exactly the same name as the folder. + +Example setup for a custom GUI with id `example`: + +`../.minecraft/config/worldhandler/usercontent/example/example.json` +`../.minecraft/config/worldhandler/usercontent/example/example.js` + +An example GUI can be found [here](../../run/config/worldhandler/usercontent/) + +# Index # + +Content: A single GUI of the World Handler i.e. the main page +Category: A collection of contents that are grouped together and are displayed in tabs next to each other +Elements: A structure of buttons simplifying the creation of larger menus + +## General Structure ## + +``` +{ + "model": { + "commands": [ + #See commands + ] + }, + "gui": { + "title": "", #The title of the gui + "tab": { + "title": "", #The title of the tab + "category": "", #The category where the tab should be clickable in (See reference/category-ids) + "category_index": 0, #The index of the tab (left: 0, right: last tab index) + "active_content": "" #The id of the active content (See reference/content-ids) + }, + "buttons": [ + #See buttons + ], + "elements": [ + #See elements + ], + "texts": [ + #See texts + ] + } +} +``` + +## Commands ## + +All commands that should be modifiable, executable or visible by the command syntax need to be modeled + +``` +{ + "name": "", #The root of the command + "syntax": [ + { + "name": "", #Placeholder text for the argument + "type": "", #Type of the argument (See table below for available types) + "required": true #Whethter or not this argument is required in order to complete the command + } + ], + "visible": { + #See widget-states + } +} +``` + +Argument types | Comment +----------------------- | ----------------------------------------------------------------------------------------------------------- +byte | Default java byte +short | Default java short +int | Default java integer +float | Default java float +double | Default java double +long | Default java long +boolean | Default java boolean +string | Default java string +greedy_string | String that can be read across whitespaces. (usually in quotes) +resource_location | Minecraft resource location. Example:` namespace:resource` +item_resource_location | Resource location with attached nbt. Example: `namespace:resource{"nbt":"example"}` +block_resource_location | Item resource location with attached block tag. Example: `namespace:resource[state=example]` +nbt | Minecraft data structure. Example: `{"nbt":"example"}` +coordinate_int | An integer that can either be absolute or relative in a global (prefix: `~`) or local (prefix: `^`) context +coordinate_double | A double that can either be absolute or relative in a global (prefix: `~`) or local (prefix: `^`) context +target_selector | Filter for entities. This implementation only supports `@e` with arguments. Example: `@e[type=player]` +player | Username of the player that will be automatically set by the system + +## Buttons ## + +``` +{ + "text": "", #Optional + "type": "", #See table below for available types + "dimensions": { + "x": 0, + "y": 0, + "width": 114, + "height": 20 + }, + "action": { + #See action + }, + "attributes": { + "id": "", + "item": "", #Resource location + "icon": "", #See reference/icon-ids for available ids + "visible": { + #See widget-states + }, + "enabled": { + #See widget-states + } + } +} +``` + +Button type | Description | Actions | Required attributes | Optional Attributes +------------|---------------------------------------------- | -------------------------------------- | ------------------- | ------------------- +button | Simple button | open, set, run, back, back_to_game, js | - | tooltip +textfield | Simple textfield | set, js | id | - +item_button | Button with an item instead of text | open, set, run, back, back_to_game, js | item | - +icon_button | Button with an icon instead of text | open, set, run, back, back_to_game, js | icon | tooltip +list_button | Button with the option to cycle through items | set, js | items | - +slider | Simple slider | set, js | id, min, max | start + +## Elements ## + +``` +"type": "", #See table below for available types +"dimensions": { + "x": 0, + "y": 0, + "width": 114, + "height": 20 +}, +"attributes": { + "id": "", + "length": 1, + "items": [ + { + "id": "", + "translation": "" #Translation key or string value + } + ] +} +``` + +Element type | Description | Required attributes | Optional Attributes +------------ | ------------------------------------------------------------------------------------------------------------ | ------------------- | ------------------- +page_list | Creates column of buttons with `length` options to choose from and two buttons for navigating left and right | id, length, items | - + +## Text ## + +``` +{ + "text": "", + "x": 0, + "y": 0, + "color": 2039583 #Color of the text (red << 16 + green << 8 + blue) +} +``` + +## Action ## + +``` +"action": { + "type": "", #See table below for available types + "attributes": { + "function": "", #Name of the js function + "command": 0, #Index of the command inside the json file + "index": 0, #Argument index + "value": "" + } +} +``` + +Action type | Description | Required attributes | Optional Attributes +------------ | ------------------------------------------------------------------------------------------------------ | ------------------- | ------------------- +open | Opens the content associated with `value` | value | - +set | Sets the argument `index` of command `command` to `value` or the value provided by the system | index, command | value +run | Runs the command from `value` | value | - +back | Goes back to the previous content | - | - +back_to_game | Closes the GUI | - | - +js | Invokes the javascript function `function` (with argument `value`) | function | value + +## Widget states ## + +There are two widget states: `visible` and `enabled` +This structure is optional. + +``` +"visible": { + "type": "", + "bool": true + "function": "" #Name of the js function +} +``` + +State type | Description | Required attributes | Optional Attributes +---------- | ----------------------------------------------------------------- | ------------------- | ------------------- +bool | The state will be determined by the value of the `bool` attribute | bool | - +js | Invokes the javascript function `function` and uses the result | function | - + +## JavaScript API ## + +The JavaScript interpreter comes with an instance of `UsercontentAPI` available for reference with `api` + +Example: `api.addChatMessage("Hello World")` + +Function | Description +---------------------------------------------------------------- | ------------------------------------------------------------------- +String getValue(String id) | returns the value stored by a button or element with id `id` +String getCommandArgument(int command, int index) | returns the argument at index `index` of command `command` +void setCommandArgument(int command, int index, String object) | sets the argument at index `index` of command `command` to `object` +void addChatMessage(Object object) | prints the object to the ingame chat + +### ActionHelper ### + +Example: +``` +var ActionHelper = Java.type('exopandora.worldhandler.helper.ActionHelper'); +ActionHelper.displayGui(); +``` + +Function | Description +------------------------- | ---------------------------------------------------------------------------- +void backToGame() | Closes the GUI +void back(String id) | Tries to open the back content of content with id `id` +void open(String id) | Tries to open the content with id `id` +void timeDawn() | Sets the time to dawn +void timeNoon() | Sets the time to noon +void timeSunset() | Sets the time to sunset +void timeMidnight() | Sets the time to midnight +void weatherClear() | Sets the weather to clear +void weatherRain() | Sets the weather to rain +void weatherThunder() | Sets the weather to thunder +void difficultyPeaceful() | Sets the difficulty to peaceful +void difficultyEasy() | Sets the difficulty to easy +void difficultyNormal() | Sets the difficulty to normal +void difficultyHard() | Sets the difficulty to hard +void gamemodeSurvival() | Sets the gamemode to survival +void gamemodeCreative() | Sets the gamemode to creative +void gamemodeAdventure() | Sets the gamemode to adventure +void gamemodeSpectator() | Sets the gamemode to spectator +void displayGui() | Tries to open the World Handler GUI (same as pressing the activation button) + +## Reference ## + +Content ids | Category ids | Icon ids +--------------------- | ------------ | ------------------- +main | main | weather_sun +containers | entities | weather_rain +multiplayer | items | weather_storm +summon | blocks | difficulty_peaceful +custom_item | world | difficulty_easy +enchantment | player | difficulty_normal +edit_blocks | scoreboard | difficulty_hard +sign_editor | | time_dawn +note_editor | | time_noon +world | | time_sunset +gamerules | | time_midnight +recipes | | gamemode_survival +player | | gamemode_creative +experience | | gamemode_adventure +advancements | | gamemode_spectator +scoreboard_objectives | | butcher +scoreboard_teams | | potion +scoreboard_players | | achievements +change_world | | home +continue | | settings +potions | | reload +butcher | | +butcher_settings | | +settings | | +