Fixed potential NPEs and added @Nonnull and @Nullable annotations

This commit is contained in:
Marcel Konrad
2020-10-18 17:19:37 +02:00
parent 9f18302706
commit e23d73726b
40 changed files with 248 additions and 114 deletions

View File

@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.WorldHandler;
@@ -191,11 +192,13 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
return this.get(index, ArgumentType.LONG);
}
@Nonnull
protected CoordinateInt getNodeAsCoordinateInt(int index)
{
return this.get(index, ArgumentType.COORDINATE_INT);
}
@Nonnull
protected CoordinateDouble getNodeAsCoordinateDouble(int index)
{
return this.get(index, ArgumentType.COORDINATE_DOUBLE);
@@ -207,6 +210,7 @@ public abstract class CommandBuilder implements ICommandBuilderSyntax
return this.get(index, ArgumentType.RESOURCE_LOCATION);
}
@Nonnull
protected TargetSelector getNodeAsTargetSelector(int index)
{
return this.get(index, ArgumentType.TARGET_SELECTOR);

View File

@@ -3,6 +3,8 @@ package exopandora.worldhandler.builder;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.IBuilderComponent;
import exopandora.worldhandler.util.NBTHelper;
import net.minecraft.nbt.CompoundNBT;
@@ -46,6 +48,7 @@ public abstract class CommandBuilderNBT extends CommandBuilder implements IComma
return super.toActualCommand();
}
@Nullable
protected CompoundNBT buildNBT()
{
CompoundNBT nbt = new CompoundNBT();

View File

@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.IBuilderComponent;

View File

@@ -77,7 +77,7 @@ public class BuilderAdvancement extends CommandBuilder
public BuilderAdvancement getBuilder(EnumActionType action, EnumMode mode)
{
return new BuilderAdvancement(action, this.getPlayer(), mode, (mode != null && !mode.equals(EnumMode.EVERYTHING)) ? this.getAdvancement() : null);
return new BuilderAdvancement(action, this.getPlayer(), mode, !EnumMode.EVERYTHING.equals(mode) ? this.getAdvancement() : null);
}
@Override

View File

@@ -1,5 +1,6 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
@@ -59,16 +60,19 @@ public class BuilderClone extends BuilderDoubleBlockPos
this.setNode(8, z);
}
@Nonnull
public CoordinateInt getXCoordiante()
{
return this.getNodeAsCoordinateInt(6);
}
@Nonnull
public CoordinateInt getYCoordiante()
{
return this.getNodeAsCoordinateInt(7);
}
@Nonnull
public CoordinateInt getZCoordiante()
{
return this.getNodeAsCoordinateInt(8);
@@ -99,6 +103,7 @@ public class BuilderClone extends BuilderDoubleBlockPos
this.setNode(9, mask != null ? mask.toString() : null);
}
@Nullable
public EnumMask getMask()
{
return EnumHelper.valueOf(this.getNodeAsString(9), EnumMask.class);

View File

@@ -4,10 +4,10 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.builder.types.TargetSelector;
import exopandora.worldhandler.util.EnumHelper;
import exopandora.worldhandler.builder.types.ArgumentType;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
@@ -57,6 +57,7 @@ public class BuilderData extends BuilderBlockPos
}
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(0), EnumMode.class);
@@ -79,6 +80,7 @@ public class BuilderData extends BuilderBlockPos
}
}
@Nullable
public EnumTarget getTarget()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumTarget.class);
@@ -254,6 +256,7 @@ public class BuilderData extends BuilderBlockPos
}
@Override
@Nonnull
public CoordinateInt getXCoordinate()
{
this.ensureTarget(EnumTarget.BLOCK);
@@ -261,6 +264,7 @@ public class BuilderData extends BuilderBlockPos
}
@Override
@Nonnull
public CoordinateInt getYCoordinate()
{
this.ensureTarget(EnumTarget.BLOCK);
@@ -268,6 +272,7 @@ public class BuilderData extends BuilderBlockPos
}
@Override
@Nonnull
public CoordinateInt getZCoordinate()
{
this.ensureTarget(EnumTarget.BLOCK);
@@ -275,6 +280,7 @@ public class BuilderData extends BuilderBlockPos
}
@Override
@Nonnull
public BlockPos getBlockPos()
{
this.ensureTarget(EnumTarget.BLOCK);

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nonnull;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.types.CoordinateInt;
import exopandora.worldhandler.util.BlockHelper;
@@ -53,16 +55,19 @@ public abstract class BuilderDoubleBlockPos extends CommandBuilder
this.setNode(2, z);
}
@Nonnull
public CoordinateInt getX1Coordiante()
{
return this.getNodeAsCoordinateInt(0);
}
@Nonnull
public CoordinateInt getY1Coordiante()
{
return this.getNodeAsCoordinateInt(1);
}
@Nonnull
public CoordinateInt getZ1Coordiante()
{
return this.getNodeAsCoordinateInt(2);
@@ -125,16 +130,19 @@ public abstract class BuilderDoubleBlockPos extends CommandBuilder
this.setNode(5, z);
}
@Nonnull
public CoordinateInt getX2Coordiante()
{
return this.getNodeAsCoordinateInt(3);
}
@Nonnull
public CoordinateInt getY2Coordiante()
{
return this.getNodeAsCoordinateInt(4);
}
@Nonnull
public CoordinateInt getZ2Coordiante()
{
return this.getNodeAsCoordinateInt(5);

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
@@ -11,9 +13,10 @@ import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class BuilderEnchantment extends CommandBuilder
{
public void getPlayer(String player)
@Nullable
public String getPlayer()
{
this.getNodeAsString(0);
return this.getNodeAsString(0);
}
public void setPlayer(String player)
@@ -21,6 +24,7 @@ public class BuilderEnchantment extends CommandBuilder
this.setNode(0, player);
}
@Nullable
public ResourceLocation getEnchantment()
{
return this.getNodeAsResourceLocation(1);

View File

@@ -28,6 +28,7 @@ public class BuilderExecute extends CommandBuilder
this.setNode(1, target);
}
@Nullable
public String getTarget()
{
return this.getNodeAsString(1);
@@ -56,6 +57,7 @@ public class BuilderExecute extends CommandBuilder
}
}
@Nullable
public String getCommand()
{
return this.getNodeAsString(3);

View File

@@ -41,6 +41,7 @@ public class BuilderExperience extends CommandBuilder
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
@@ -51,6 +52,7 @@ public class BuilderExperience extends CommandBuilder
this.setNode(2, level);
}
@Nullable
public int getLevel()
{
return this.getNodeAsInt(2);

View File

@@ -11,7 +11,7 @@ public class BuilderGamemode extends CommandBuilder
{
public BuilderGamemode()
{
super();
}
public BuilderGamemode(EnumGamemode mode)

View File

@@ -35,6 +35,7 @@ public class BuilderGive extends CommandBuilderNBT
this.setNode(0, username);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
@@ -74,9 +75,17 @@ public class BuilderGive extends CommandBuilderNBT
this.setNode(1, this.itemResourceLocation);
}
@Nullable
public CompoundNBT getNBT()
{
return this.getNodeAsItemResourceLocation(1).getNBT();
ItemResourceLocation item = this.getItem();
if(item != null)
{
return item.getNBT();
}
return null;
}
@Override

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
@@ -21,6 +23,7 @@ public class BuilderPlayer extends CommandBuilder
this.setNode(0, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
@@ -21,6 +23,7 @@ public class BuilderPlayerReason extends CommandBuilder
this.setNode(0, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
@@ -31,6 +34,7 @@ public class BuilderPlayerReason extends CommandBuilder
this.setNode(1, reason);
}
@Nullable
public String getReason()
{
return this.getNodeAsString(1);

View File

@@ -52,6 +52,7 @@ public class BuilderPotionEffect extends CommandBuilder
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);
@@ -80,6 +81,7 @@ public class BuilderPotionEffect extends CommandBuilder
return null;
}
@Nullable
public ResourceLocation getEffect()
{
return this.getNodeAsResourceLocation(2);

View File

@@ -37,6 +37,7 @@ public class BuilderScoreboardObjectives extends BuilderScoreboard
this.init();
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class);

View File

@@ -1,7 +1,12 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import org.apache.commons.lang3.RegExUtils;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
import exopandora.worldhandler.util.EnumHelper;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -18,9 +23,10 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
this.setNode(0, "players");
}
public String getMode()
@Nullable
public EnumMode getMode()
{
return this.getNodeAsString(1);
return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class);
}
public void setMode(String mode)
@@ -47,6 +53,7 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
this.setNode(2, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(2);
@@ -54,20 +61,16 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
public void setObjective(String name)
{
String mode = this.getMode();
String objective = name != null ? name.replaceAll(" ", "_") : null;
if(mode != null)
if(this.getMode() != null)
{
this.setNode(3, objective);
this.setNode(3, RegExUtils.replaceAll(name, " ", "_"));
}
}
@Nullable
public String getObjective()
{
String mode = this.getMode();
if(mode != null)
if(this.getMode() != null)
{
return this.getNodeAsString(3);
}
@@ -82,7 +85,7 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
public int getPoints()
{
if(this.getMode() != null && !this.getMode().equals("enable"))
if(!EnumMode.ENABLE.equals(this.getMode()))
{
return this.getNodeAsInt(4);
}
@@ -111,7 +114,6 @@ public class BuilderScoreboardPlayers extends BuilderScoreboard
syntax.addRequired("score", ArgumentType.INT, 0);
return syntax;
}
public BuilderScoreboardPlayers getBuilderForPoints(EnumMode mode)

View File

@@ -472,6 +472,11 @@ public class BuilderSummon extends CommandBuilderNBT
{
String name = ResourceHelper.stripToResourceLocation(entityName);
if(name == null || name.isEmpty())
{
return null;
}
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{
if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey())))
@@ -482,116 +487,111 @@ public class BuilderSummon extends CommandBuilderNBT
String entity = name.replaceAll("_", "");
if(entity.equalsIgnoreCase("RedCow"))
if("RedCow".equalsIgnoreCase(entity))
{
return EntityType.MOOSHROOM.getRegistryName();
}
else if(entity.equalsIgnoreCase("ChickenJockey"))
else if("ChickenJockey".equalsIgnoreCase(entity))
{
return EntityType.CHICKEN.getRegistryName();
}
else if(entity.equalsIgnoreCase("Pigman") || entity.equalsIgnoreCase("ZombiePig") || entity.equalsIgnoreCase("ZombiePigman"))
else if("Pigman".equalsIgnoreCase(entity) || "ZombiePig".equalsIgnoreCase(entity) || "ZombiePigman".equalsIgnoreCase(entity))
{
return EntityType.PIGLIN.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wither"))
else if("Wither".equalsIgnoreCase(entity))
{
return EntityType.WITHER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Dog"))
else if("Dog".equalsIgnoreCase(entity))
{
return EntityType.WOLF.getRegistryName();
}
else if(entity.equalsIgnoreCase("Dragon"))
else if("Dragon".equalsIgnoreCase(entity))
{
return EntityType.ENDER_DRAGON.getRegistryName();
}
else if(entity.equalsIgnoreCase("SnowMan"))
else if("SnowMan".equalsIgnoreCase(entity))
{
return EntityType.SNOW_GOLEM.getRegistryName();
}
else if(entity.equalsIgnoreCase("Horse") || entity.equalsIgnoreCase("ZombieHorse") || entity.equalsIgnoreCase("SkeletonHorse"))
else if("Horse".equalsIgnoreCase(entity) || "ZombieHorse".equalsIgnoreCase(entity) || "SkeletonHorse".equalsIgnoreCase(entity))
{
return EntityType.HORSE.getRegistryName();
}
else if(entity.equalsIgnoreCase("LavaCube")|| entity.equalsIgnoreCase("MagmaSlime") || entity.equalsIgnoreCase("MagmaCube"))
else if("LavaCube".equalsIgnoreCase(entity)|| "MagmaSlime".equalsIgnoreCase(entity) || "MagmaCube".equalsIgnoreCase(entity))
{
return EntityType.MAGMA_CUBE.getRegistryName();
}
else if(entity.equalsIgnoreCase("SpiderJockey"))
else if("SpiderJockey".equalsIgnoreCase(entity))
{
return EntityType.SPIDER.getRegistryName();
}
else if(entity.equalsIgnoreCase("IronGolem"))
else if("IronGolem".equalsIgnoreCase(entity))
{
return EntityType.IRON_GOLEM.getRegistryName();
}
else if(entity.equalsIgnoreCase("Ozelot") || entity.equals("Ocelot"))
else if("Ozelot".equalsIgnoreCase(entity) || entity.equals("Ocelot"))
{
return EntityType.OCELOT.getRegistryName();
}
else if(entity.equalsIgnoreCase("Kitty") || entity.equalsIgnoreCase("Kitten"))
else if("Kitty".equalsIgnoreCase(entity) || "Kitten".equalsIgnoreCase(entity))
{
return EntityType.CAT.getRegistryName();
}
else if(entity.equalsIgnoreCase("TESTIFICATE") || entity.equalsIgnoreCase("Blacksmith") || entity.equalsIgnoreCase("Farmer") || entity.equalsIgnoreCase("Fisherman") || entity.equalsIgnoreCase("Shepherd") || entity.equalsIgnoreCase("Fletcher") || entity.equalsIgnoreCase("Librarian") || entity.equalsIgnoreCase("Cleric") || entity.equalsIgnoreCase("Priest") || entity.equalsIgnoreCase("Armorer") || entity.equalsIgnoreCase("WeaponSmith") || entity.equalsIgnoreCase("ToolSmith") || entity.equalsIgnoreCase("Butcher") || entity.equalsIgnoreCase("Leatherworker") || entity.equalsIgnoreCase("Carthographer") || entity.equalsIgnoreCase("Nitwit"))
else if("TESTIFICATE".equalsIgnoreCase(entity) || "Blacksmith".equalsIgnoreCase(entity) || "Farmer".equalsIgnoreCase(entity) || "Fisherman".equalsIgnoreCase(entity) || "Shepherd".equalsIgnoreCase(entity) || "Fletcher".equalsIgnoreCase(entity) || "Librarian".equalsIgnoreCase(entity) || "Cleric".equalsIgnoreCase(entity) || "Priest".equalsIgnoreCase(entity) || "Armorer".equalsIgnoreCase(entity) || "WeaponSmith".equalsIgnoreCase(entity) || "ToolSmith".equalsIgnoreCase(entity) || "Butcher".equalsIgnoreCase(entity) || "Leatherworker".equalsIgnoreCase(entity) || "Carthographer".equalsIgnoreCase(entity) || "Nitwit".equalsIgnoreCase(entity))
{
return EntityType.VILLAGER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Octopus") || entity.equalsIgnoreCase("Kraken"))
else if("Octopus".equalsIgnoreCase(entity) || "Kraken".equalsIgnoreCase(entity))
{
return EntityType.SQUID.getRegistryName();
}
else if(entity.equalsIgnoreCase("Exwife"))
else if("Exwife".equalsIgnoreCase(entity))
{
return EntityType.GHAST.getRegistryName();
}
else if(entity.equalsIgnoreCase("TNTMinecart"))
else if("TNTMinecart".equalsIgnoreCase(entity))
{
return EntityType.TNT_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("Minecart"))
else if("Minecart".equalsIgnoreCase(entity))
{
return EntityType.MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("HopperMinecart"))
else if("HopperMinecart".equalsIgnoreCase(entity))
{
return EntityType.HOPPER_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("ChestMinecart"))
else if("ChestMinecart".equalsIgnoreCase(entity))
{
return EntityType.CHEST_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("SpawnerMinecart"))
else if("SpawnerMinecart".equalsIgnoreCase(entity))
{
return EntityType.SPAWNER_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("FurnaceMinecart"))
else if("FurnaceMinecart".equalsIgnoreCase(entity))
{
return EntityType.FURNACE_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("CommandBlockMinecart") || entity.equalsIgnoreCase("MinecartCommand") || entity.equalsIgnoreCase("CommandMinecart"))
else if("CommandBlockMinecart".equalsIgnoreCase(entity) || "MinecartCommand".equalsIgnoreCase(entity) || "CommandMinecart".equalsIgnoreCase(entity))
{
return EntityType.COMMAND_BLOCK_MINECART.getRegistryName();
}
else if(entity.equalsIgnoreCase("Wizard"))
else if("Wizard".equalsIgnoreCase(entity))
{
return EntityType.EVOKER.getRegistryName();
}
else if(entity.equalsIgnoreCase("Johnny"))
else if("Johnny".equalsIgnoreCase(entity))
{
return EntityType.VINDICATOR.getRegistryName();
}
else if(entity.equalsIgnoreCase("BabyZombie"))
else if("BabyZombie".equalsIgnoreCase(entity))
{
return EntityType.ZOMBIE.getRegistryName();
}
if(entity == null || entity.isEmpty())
{
return null;
}
return ResourceHelper.stringToResourceLocation(name);
}
}

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
@@ -11,7 +13,7 @@ public class BuilderTag extends CommandBuilder
{
public BuilderTag()
{
super();
}
public BuilderTag(String player, EnumMode mode, String name)
@@ -26,6 +28,7 @@ public class BuilderTag extends CommandBuilder
this.setNode(0, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(0);
@@ -44,6 +47,7 @@ public class BuilderTag extends CommandBuilder
this.setNode(2, name);
}
@Nullable
public String getName()
{
return this.getNodeAsString(2);

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.types.ArgumentType;
@@ -27,6 +29,7 @@ public class BuilderTrigger extends CommandBuilder
this.setNode(0, name != null ? name.replaceAll(" ", "_") : null);
}
@Nullable
public String getObjective()
{
return this.getNodeAsString(0);
@@ -40,6 +43,7 @@ public class BuilderTrigger extends CommandBuilder
}
}
@Nullable
public EnumMode getMode()
{
return EnumHelper.valueOf(this.getNodeAsString(1), EnumMode.class);

View File

@@ -1,5 +1,7 @@
package exopandora.worldhandler.builder.impl;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.CommandBuilder;
import exopandora.worldhandler.builder.CommandSyntax;
import exopandora.worldhandler.builder.CommandSyntax.Argument;
@@ -91,6 +93,7 @@ public class BuilderUsercontent extends CommandBuilder
}
}
@Nullable
public String get(int index)
{
if(index < this.syntax.getArguments().size() && index >= 0)

View File

@@ -11,7 +11,7 @@ public class BuilderWeather extends CommandBuilder
{
public BuilderWeather()
{
super();
}
public BuilderWeather(EnumWeather weather)

View File

@@ -13,7 +13,7 @@ public class BuilderWhitelist extends CommandBuilder
{
public BuilderWhitelist()
{
super();
}
public BuilderWhitelist(EnumMode mode)
@@ -37,6 +37,7 @@ public class BuilderWhitelist extends CommandBuilder
this.setNode(1, player);
}
@Nullable
public String getPlayer()
{
return this.getNodeAsString(1);

View File

@@ -48,7 +48,6 @@ public enum ArgumentType
return (T) this.parser.apply(object);
}
@Nonnull
public <T> T parseOfDefault(String object, T def)
{
try

View File

@@ -2,8 +2,6 @@ package exopandora.worldhandler.builder.types;
import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -50,7 +48,6 @@ public abstract class Coordinate<T extends Number> implements ICoordinate<T>
return this.type.format(this.value, this.zero());
}
@Nullable
public static <S extends Number, U extends Coordinate<S>> U parse(U coordiante, String input, Function<String, S> parser)
{
for(EnumType type : EnumType.values())

View File

@@ -88,7 +88,7 @@ public class ClientEventHandler
@SubscribeEvent
public static void clientChatEvent(ClientChatEvent event)
{
if(!Minecraft.getInstance().isSingleplayer())
if(!Minecraft.getInstance().isSingleplayer() && Minecraft.getInstance().player != null)
{
CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<CommandSource>();
CommandHelper.registerCommands(dispatcher);

View File

@@ -17,6 +17,7 @@ import exopandora.worldhandler.gui.widget.IContainerWidget.EnumLayer;
import exopandora.worldhandler.gui.widget.WidgetCommandSyntax;
import exopandora.worldhandler.gui.widget.WidgetNameField;
import exopandora.worldhandler.gui.widget.WidgetShortcuts;
import exopandora.worldhandler.gui.widget.WidgetTabRenderer;
import exopandora.worldhandler.gui.widget.WidgetWatch;
import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip;
import exopandora.worldhandler.util.ActionHelper;

View File

@@ -23,9 +23,11 @@ import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries;
@@ -115,18 +117,24 @@ public class ContentButcher extends Content
slaughter.active = enabled;
}
public static void slaughter(String player, Collection<EntityType<?>> entities, int radius)
public static void slaughter(String username, Collection<EntityType<?>> entities, int radius)
{
AxisAlignedBB aabb = new AxisAlignedBB(Minecraft.getInstance().player.getPosition()).grow(radius);
PlayerEntity player = Minecraft.getInstance().player;
World world = Minecraft.getInstance().world;
for(EntityType<?> entity : entities)
if(player != null && world != null)
{
List<? extends Entity> targets = Minecraft.getInstance().world.getEntitiesWithinAABB(entity, aabb, Predicates.alwaysTrue());
targets.removeIf(target -> Minecraft.getInstance().player.equals(target));
AxisAlignedBB aabb = new AxisAlignedBB(player.getPosition()).grow(radius);
if(!targets.isEmpty())
for(EntityType<?> entity : entities)
{
CommandHelper.sendCommand(player, new BuilderButcher(entity.getRegistryName(), radius));
List<? extends Entity> targets = world.getEntitiesWithinAABB(entity, aabb, Predicates.alwaysTrue());
targets.removeIf(target -> player.equals(target));
if(!targets.isEmpty())
{
CommandHelper.sendCommand(username, new BuilderButcher(entity.getRegistryName(), radius));
}
}
}
}

View File

@@ -75,8 +75,11 @@ public class ContentChangeWorld extends ContentChild
return new IntegratedConnection(folder, worldSettings, dimensionGeneratorSettings);
}
Minecraft.getInstance().world.sendQuittingDisconnectingPacket();
Minecraft.getInstance().unloadWorld();
if(Minecraft.getInstance().world != null)
{
Minecraft.getInstance().world.sendQuittingDisconnectingPacket();
Minecraft.getInstance().unloadWorld();
}
if(isRealms)
{

View File

@@ -5,6 +5,8 @@ import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import javax.annotation.Nullable;
import com.google.common.base.Predicates;
import com.mojang.blaze3d.matrix.MatrixStack;
@@ -240,7 +242,12 @@ public class ContentCommandStack extends ContentChild
private void setCommand(int index, String command)
{
this.builderCommandStack.getPassenger(index + HEAD_LENGTH).setCommand(command);
EntityNBT entity = this.builderCommandStack.getPassenger(index + HEAD_LENGTH);
if(entity != null)
{
entity.setCommand(command);
}
}
private void addCommand(int index)
@@ -253,9 +260,17 @@ public class ContentCommandStack extends ContentChild
this.builderCommandStack.removePassenger(index + HEAD_LENGTH);
}
@Nullable
private String getCommand(int index)
{
return this.builderCommandStack.getPassenger(index + HEAD_LENGTH).getCommand();
EntityNBT entity = this.builderCommandStack.getPassenger(index + HEAD_LENGTH);
if(entity != null)
{
return entity.getCommand();
}
return null;
}
private int getCommandCount()

View File

@@ -31,6 +31,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -211,7 +212,14 @@ public class ContentNoteEditor extends Content
private SoundEvent getSoundEvent(BlockPos blockPos)
{
return NoteBlockInstrument.byState(Minecraft.getInstance().world.getBlockState(blockPos)).getSound();
World world = Minecraft.getInstance().world;
if(world != null)
{
return NoteBlockInstrument.byState(world.getBlockState(blockPos)).getSound();
}
return null;
}
@Override

View File

@@ -22,7 +22,8 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.inventory.InventoryScreen;
import net.minecraft.client.resources.I18n;
import net.minecraft.util.math.MathHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
@@ -119,11 +120,13 @@ public class ContentPlayer extends Content
container.add(new GuiButtonBase(x + 118, y + 72, 114, 20, new TranslationTextComponent("gui.worldhandler.entities.player.position.copy_position"), () ->
{
int posX = MathHelper.floor(Minecraft.getInstance().player.getPosX());
int posY = MathHelper.floor(Minecraft.getInstance().player.getPosY());
int posZ = MathHelper.floor(Minecraft.getInstance().player.getPosZ());
PlayerEntity player = Minecraft.getInstance().player;
Minecraft.getInstance().keyboardListener.setClipboardString(posX + " " + posY + " " + posZ);
if(player != null)
{
BlockPos position = player.getPosition();
Minecraft.getInstance().keyboardListener.setClipboardString(position.getX() + " " + position.getY() + " " + position.getZ());
}
}));
}
else if(Page.MISC.equals(this.page))
@@ -152,18 +155,25 @@ public class ContentPlayer extends Content
@Override
public void tick(Container container)
{
this.posXField.setText("X: " + MathHelper.floor(Minecraft.getInstance().player.getPosX()));
this.posYField.setText("Y: " + MathHelper.floor(Minecraft.getInstance().player.getPosY()));
this.posZField.setText("Z: " + MathHelper.floor(Minecraft.getInstance().player.getPosZ()));
this.scoreField.setText(I18n.format("gui.worldhandler.entities.player.score") + ": " + Minecraft.getInstance().player.getScore());
this.coinsField.setText(I18n.format("gui.worldhandler.entities.player.score.experience") + ": " + Minecraft.getInstance().player.experienceLevel + "L");
this.xpField.setText(I18n.format("gui.worldhandler.entities.player.score.experience_coins") + ": " + Minecraft.getInstance().player.experienceTotal);
PlayerEntity player = Minecraft.getInstance().player;
if(player != null)
{
BlockPos position = player.getPosition();
this.posXField.setText("X: " + position.getX());
this.posYField.setText("Y: " + position.getY());
this.posZField.setText("Z: " + position.getZ());
this.scoreField.setText(I18n.format("gui.worldhandler.entities.player.score") + ": " + player.getScore());
this.coinsField.setText(I18n.format("gui.worldhandler.entities.player.score.experience") + ": " + player.experienceLevel + "L");
this.xpField.setText(I18n.format("gui.worldhandler.entities.player.score.experience_coins") + ": " + player.experienceTotal);
}
}
@Override
public void drawScreen(MatrixStack matrix, Container container, int x, int y, int mouseX, int mouseY, float partialTicks)
{
if(Page.START.equals(this.page))
if(Page.START.equals(this.page) && Minecraft.getInstance().player != null)
{
int xPos = x + 175;
int yPos = y + 82;

View File

@@ -147,12 +147,22 @@ public class ContentWorldInfo extends Content
private void updateCurrentTime()
{
this.currentTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.world_time") + ": " + TextUtils.formatWorldTime(Minecraft.getInstance().world.getWorldInfo().getDayTime()));
World world = Minecraft.getInstance().world;
if(world != null)
{
this.currentTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.world_time") + ": " + TextUtils.formatWorldTime(world.getWorldInfo().getDayTime()));
}
}
private void updateTotalTime()
{
this.totalTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.played") + ": " + TextUtils.formatTotalTime(Minecraft.getInstance().world.getWorldInfo().getGameTime()));
World world = Minecraft.getInstance().world;
if(world != null)
{
this.totalTimeField.setText(I18n.format("gui.worldhandler.world_info.statistics.played") + ": " + TextUtils.formatTotalTime(world.getWorldInfo().getGameTime()));
}
}
private static <T> String format(T object, Function<T, Object> function)

View File

@@ -106,7 +106,10 @@ public class GuiButtonPiano extends GuiButtonBase
@Override
public void playDownSound(SoundHandler soundHandler)
{
soundHandler.play(SimpleSound.master(this.sound, this.pitch));
if(this.sound != null)
{
soundHandler.play(SimpleSound.master(this.sound, this.pitch));
}
}
private boolean isHoveringBlack(double mouseX, double mouseY)

View File

@@ -7,6 +7,7 @@ import java.util.function.Supplier;
import javax.annotation.Nullable;
import exopandora.worldhandler.builder.impl.BuilderGeneric;
import exopandora.worldhandler.builder.impl.BuilderUsercontent;
import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.usercontent.ScriptEngineAdapter;
@@ -16,7 +17,6 @@ import exopandora.worldhandler.usercontent.model.Action;
import exopandora.worldhandler.util.ActionHandler;
import exopandora.worldhandler.util.ActionHelper;
import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@@ -81,7 +81,14 @@ public class ActionHandlerFactory
}
else if(!action.getAttributes().getValue().isEmpty())
{
Minecraft.getInstance().player.sendChatMessage(action.getAttributes().getValue());
String command = action.getAttributes().getValue();
if(command.startsWith("/"))
{
command = command.substring(1);
}
CommandHelper.sendCommand(player.get(), new BuilderGeneric(command));
}
};
}

View File

@@ -63,7 +63,12 @@ public class BooleanExpression
}
else if(this.type == Type.JS)
{
return (boolean) engine.invokeFunction(this.function);
Object result = engine.invokeFunction(this.function);
if(result != null && result instanceof Boolean)
{
return (boolean) result;
}
}
return true;

View File

@@ -71,77 +71,77 @@ public class ActionHelper
public static void timeDawn()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getDawn()));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderTime(EnumMode.SET, Config.getSettings().getDawn()));
}
public static void timeNoon()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getNoon()));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderTime(EnumMode.SET, Config.getSettings().getNoon()));
}
public static void timeSunset()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getSunset()));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderTime(EnumMode.SET, Config.getSettings().getSunset()));
}
public static void timeMidnight()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderTime(EnumMode.SET, Config.getSettings().getMidnight()));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderTime(EnumMode.SET, Config.getSettings().getMidnight()));
}
public static void weatherClear()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderWeather(EnumWeather.CLEAR));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderWeather(EnumWeather.CLEAR));
}
public static void weatherRain()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderWeather(EnumWeather.RAIN));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderWeather(EnumWeather.RAIN));
}
public static void weatherThunder()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderWeather(EnumWeather.THUNDER));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderWeather(EnumWeather.THUNDER));
}
public static void difficultyPeaceful()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderDifficulty(Difficulty.PEACEFUL));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderDifficulty(Difficulty.PEACEFUL));
}
public static void difficultyEasy()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderDifficulty(Difficulty.EASY));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderDifficulty(Difficulty.EASY));
}
public static void difficultyNormal()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderDifficulty(Difficulty.NORMAL));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderDifficulty(Difficulty.NORMAL));
}
public static void difficultyHard()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderDifficulty(Difficulty.HARD));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderDifficulty(Difficulty.HARD));
}
public static void gamemodeSurvival()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderGamemode(EnumGamemode.SURVIVAL));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderGamemode(EnumGamemode.SURVIVAL));
}
public static void gamemodeCreative()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderGamemode(EnumGamemode.CREATIVE));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderGamemode(EnumGamemode.CREATIVE));
}
public static void gamemodeAdventure()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderGamemode(EnumGamemode.ADVENTURE));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderGamemode(EnumGamemode.ADVENTURE));
}
public static void gamemodeSpectator()
{
CommandHelper.sendCommand(Minecraft.getInstance().player.getGameProfile().getName(), new BuilderGamemode(EnumGamemode.SPECTATOR));
CommandHelper.sendCommand(Minecraft.getInstance().getSession().getUsername(), new BuilderGamemode(EnumGamemode.SPECTATOR));
}
public static void tryRun(ActionHandler action)

View File

@@ -22,7 +22,12 @@ public class CommandHelper
public static boolean canPlayerIssueCommand()
{
return Minecraft.getInstance().player.hasPermissionLevel(1);
if(Minecraft.getInstance().player != null)
{
return Minecraft.getInstance().player.hasPermissionLevel(1);
}
return false;
}
public static void registerCommands(CommandDispatcher<CommandSource> dispatcher)
@@ -59,7 +64,7 @@ public class CommandHelper
{
BlockHelper.setCommandBlockNearPlayer(player, command);
}
else
else if(Minecraft.getInstance().player != null)
{
Minecraft.getInstance().player.sendChatMessage(command);
}

View File

@@ -54,7 +54,7 @@ public class NBTHelper
public static INBT serialize(ResourceLocation[] itemArray)
{
if(Arrays.stream(itemArray).allMatch(resource -> Items.AIR.getRegistryName().equals(resource)))
if(Arrays.stream(itemArray).allMatch(resource -> resource != null && resource.equals(Items.AIR.getRegistryName())))
{
return null;
}

View File

@@ -1,7 +1,5 @@
package exopandora.worldhandler.util;
import javax.annotation.Nonnull;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.IFormattableTextComponent;
@@ -58,21 +56,21 @@ public class TextUtils
if(seconds > 60)
{
int min = MathHelper.floor(seconds / 60);
int min = seconds / 60;
seconds = seconds % 60;
minutes = min;
}
if(minutes > 60)
{
int hrs = MathHelper.floor(minutes / 60);
int hrs = minutes / 60;
minutes = minutes % 60;
hours = hrs;
}
if(hours > 24)
{
int day = MathHelper.floor(hours / 24);
int day = hours / 24;
hours = hours % 24;
days = day;
}
@@ -82,9 +80,7 @@ public class TextUtils
public static int toHour(long tick)
{
int hour = MathHelper.floor((tick + 6000) / 1000F) % 24;
return hour;
return MathHelper.floor((tick + 6000) / 1000F) % 24;
}
public static int toMinute(long tick)
@@ -103,7 +99,6 @@ public class TextUtils
return String.format("%02d:%02d", hour, minute);
}
@Nonnull
public static IFormattableTextComponent formatNonnull(String text, Object... parameters)
{
if(text == null)