Refactoring and fixes
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package exopandora.worldhandler.builder;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -232,20 +231,34 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
{
|
||||
if(syntax != null)
|
||||
{
|
||||
this.command = syntax.getSyntaxEntries().stream().map(entry -> new AbstractMap.SimpleEntry<SyntaxEntry, String>(entry, entry.toString())).collect(Collectors.toList());
|
||||
this.command = syntax.getSyntaxEntries().stream().map(entry -> new SimpleEntry<SyntaxEntry, String>(entry, entry.toString())).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toCommand()
|
||||
{
|
||||
return "/" + this.getCommandName() + " " + String.join(" ", this.command.stream().map(entry -> this.isDefaultEntry(entry) ? entry.getKey().toString() : entry.getValue()).collect(Collectors.toList()));
|
||||
CommandString command = new CommandString(this.getCommandName());
|
||||
|
||||
for(Entry<SyntaxEntry, String> entry : this.command)
|
||||
{
|
||||
if(this.isDefaultEntry(entry))
|
||||
{
|
||||
command.append(entry.getKey().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
command.append(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return command.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toActualCommand()
|
||||
{
|
||||
List<String> command = new ArrayList<String>();
|
||||
CommandString command = new CommandString(this.getCommandName());
|
||||
|
||||
for(Entry<SyntaxEntry, String> entry : this.command)
|
||||
{
|
||||
@@ -254,9 +267,9 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
|
||||
break;
|
||||
}
|
||||
|
||||
command.add(entry.getValue());
|
||||
command.append(entry.getValue());
|
||||
}
|
||||
|
||||
return "/" + this.getCommandName() + " " + String.join(" ", command);
|
||||
return command.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package exopandora.worldhandler.builder;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class CommandString
|
||||
{
|
||||
private final StringBuilder command = new StringBuilder("/");
|
||||
|
||||
public CommandString(String name)
|
||||
{
|
||||
this.command.append(name);
|
||||
}
|
||||
|
||||
public CommandString(String name, String... arguments)
|
||||
{
|
||||
this(name);
|
||||
this.append(arguments);
|
||||
}
|
||||
|
||||
public void append(String argument)
|
||||
{
|
||||
if(argument != null && !argument.isEmpty())
|
||||
{
|
||||
this.command.append(" " + argument);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.command.append(" " + ChatFormatting.RED + "[error]" + ChatFormatting.RESET);
|
||||
}
|
||||
}
|
||||
|
||||
public void append(String... arguments)
|
||||
{
|
||||
if(arguments != null)
|
||||
{
|
||||
for(String argument : arguments)
|
||||
{
|
||||
this.append(argument);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return this.command.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
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;
|
||||
@@ -28,7 +30,8 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
{
|
||||
this.setNode(0, action != null ? action.toString() : null);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public EnumActionType getActionType()
|
||||
{
|
||||
return EnumHelper.valueOf(EnumActionType.class, this.getNodeAsString(1));
|
||||
@@ -38,7 +41,8 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
{
|
||||
this.setNode(1, player);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public String getPlayer()
|
||||
{
|
||||
return this.getNodeAsString(1);
|
||||
@@ -48,7 +52,8 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
{
|
||||
this.setNode(2, mode != null ? mode.toString() : null);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public EnumMode getMode()
|
||||
{
|
||||
return EnumHelper.valueOf(EnumMode.class, this.getNodeAsString(2));
|
||||
@@ -58,7 +63,8 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
{
|
||||
this.setNode(3, advancement);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public ResourceLocation getAdvancement()
|
||||
{
|
||||
return this.getNodeAsResourceLocation(3);
|
||||
@@ -92,7 +98,8 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
|
||||
return syntax;
|
||||
}
|
||||
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumActionType
|
||||
{
|
||||
GRANT,
|
||||
@@ -105,6 +112,7 @@ public class BuilderAdvancement extends CommandBuilder
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumMode
|
||||
{
|
||||
ONLY,
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.TargetSelector;
|
||||
@@ -30,7 +33,8 @@ public class BuilderButcher extends CommandBuilder
|
||||
this.targetSelector.set("r", radius);
|
||||
this.setNode(0, this.targetSelector);
|
||||
}
|
||||
|
||||
|
||||
@Nonnull
|
||||
public int getRadius()
|
||||
{
|
||||
return this.targetSelector.<Integer>get("r");
|
||||
@@ -42,6 +46,7 @@ public class BuilderButcher extends CommandBuilder
|
||||
this.setNode(0, this.targetSelector);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ResourceLocation getEntity()
|
||||
{
|
||||
return this.targetSelector.<ResourceLocation>get("type");
|
||||
|
||||
@@ -129,6 +129,7 @@ public class BuilderClone extends BuilderDoubleBlockPos
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumMask
|
||||
{
|
||||
REPLACE,
|
||||
|
||||
@@ -25,12 +25,9 @@ public class BuilderCustomItem extends BuilderGive
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public BuilderCustomItem(String username, ResourceLocation item)
|
||||
public BuilderCustomItem(String player, ResourceLocation item)
|
||||
{
|
||||
this.setPlayer(username);
|
||||
this.setItem(item);
|
||||
this.setAmount(1);
|
||||
this.setMetadata(0);
|
||||
super(player, item);
|
||||
this.attribute = this.registerNBTComponent(new ComponentAttributeItem(attribute -> attribute.getApplyable().equals(Applyable.BOTH) || attribute.getApplyable().equals(Applyable.PLAYER)));
|
||||
this.display = this.registerNBTComponent(new ComponentDisplay());
|
||||
this.enchantment = this.registerNBTComponent(new ComponentEnchantment());
|
||||
|
||||
@@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BuilderDifficulty extends CommandBuilder
|
||||
{
|
||||
@@ -37,6 +39,7 @@ public class BuilderDifficulty extends CommandBuilder
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumDifficulty
|
||||
{
|
||||
PEACEFUL,
|
||||
|
||||
@@ -148,6 +148,7 @@ public class BuilderFill extends BuilderDoubleBlockPos
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumBlockHandling
|
||||
{
|
||||
REPLACE,
|
||||
|
||||
@@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BuilderGamemode extends CommandBuilder
|
||||
{
|
||||
@@ -49,6 +51,7 @@ public class BuilderGamemode extends CommandBuilder
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumGamemode
|
||||
{
|
||||
SURVIVAL,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package exopandora.worldhandler.builder.impl;
|
||||
|
||||
import exopandora.worldhandler.builder.CommandString;
|
||||
import exopandora.worldhandler.builder.ICommandBuilder;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -19,7 +20,7 @@ public class BuilderGeneric implements ICommandBuilder
|
||||
@Override
|
||||
public String toCommand()
|
||||
{
|
||||
return "/" + this.command + " " + String.join(" ", this.arguments);
|
||||
return new CommandString(this.command, this.arguments).toString();
|
||||
}
|
||||
|
||||
public String toActualCommand()
|
||||
|
||||
@@ -16,6 +16,7 @@ public class BuilderGive extends CommandBuilderNBT
|
||||
{
|
||||
this.setPlayer(player);
|
||||
this.setItem(item);
|
||||
this.setAmount(1);
|
||||
this.setMetadata(0);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,7 @@ public class BuilderPotionItem extends BuilderGive
|
||||
|
||||
public BuilderPotionItem(ResourceLocation item, String player, ComponentPotionItem potion)
|
||||
{
|
||||
this.setItem(item);
|
||||
this.setPlayer(player);
|
||||
this.setAmount(1);
|
||||
super(player, item);
|
||||
this.potion = this.registerNBTComponent(potion);
|
||||
}
|
||||
|
||||
|
||||
@@ -204,6 +204,7 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumTag
|
||||
{
|
||||
ADD,
|
||||
@@ -216,6 +217,7 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumPoints
|
||||
{
|
||||
ADD,
|
||||
|
||||
@@ -238,6 +238,7 @@ public class BuilderScoreboardTeams extends BuilderScoreboard
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumMode
|
||||
{
|
||||
JOIN,
|
||||
|
||||
@@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BuilderTime extends CommandBuilder
|
||||
{
|
||||
@@ -49,6 +51,7 @@ public class BuilderTime extends CommandBuilder
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumMode
|
||||
{
|
||||
ADD,
|
||||
|
||||
@@ -3,6 +3,8 @@ package exopandora.worldhandler.builder.impl;
|
||||
import exopandora.worldhandler.builder.CommandBuilder;
|
||||
import exopandora.worldhandler.builder.Syntax;
|
||||
import exopandora.worldhandler.builder.types.Type;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class BuilderWeather extends CommandBuilder
|
||||
{
|
||||
@@ -49,6 +51,7 @@ public class BuilderWeather extends CommandBuilder
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumWeather
|
||||
{
|
||||
CLEAR,
|
||||
|
||||
@@ -76,6 +76,7 @@ public class BuilderWhitelist extends CommandBuilder
|
||||
return syntax;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static enum EnumMode
|
||||
{
|
||||
ADD,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package exopandora.worldhandler.builder.types;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -28,6 +30,7 @@ public class Level
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Level valueOf(String value)
|
||||
{
|
||||
if(value != null)
|
||||
|
||||
@@ -4,6 +4,9 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -17,7 +20,8 @@ public class TargetSelector
|
||||
{
|
||||
this.values.put(id.toLowerCase(), value);
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public <T> T get(String id)
|
||||
{
|
||||
return (T) this.values.get(id);
|
||||
@@ -28,6 +32,7 @@ public class TargetSelector
|
||||
return this.values.remove(id.toLowerCase());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public static TargetSelector valueOf(String input)
|
||||
{
|
||||
if(input.matches(REGEX));
|
||||
|
||||
Reference in New Issue
Block a user