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

View File

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

View File

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

View File

@@ -77,7 +77,7 @@ public class BuilderAdvancement extends CommandBuilder
public BuilderAdvancement getBuilder(EnumActionType action, EnumMode mode) 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 @Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -472,6 +472,11 @@ public class BuilderSummon extends CommandBuilderNBT
{ {
String name = ResourceHelper.stripToResourceLocation(entityName); String name = ResourceHelper.stripToResourceLocation(entityName);
if(name == null || name.isEmpty())
{
return null;
}
for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues()) for(EntityType<?> type : ForgeRegistries.ENTITIES.getValues())
{ {
if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey()))) if(type.isSummonable() && entityName.equalsIgnoreCase(I18n.format(type.getTranslationKey())))
@@ -482,116 +487,111 @@ public class BuilderSummon extends CommandBuilderNBT
String entity = name.replaceAll("_", ""); String entity = name.replaceAll("_", "");
if(entity.equalsIgnoreCase("RedCow")) if("RedCow".equalsIgnoreCase(entity))
{ {
return EntityType.MOOSHROOM.getRegistryName(); return EntityType.MOOSHROOM.getRegistryName();
} }
else if(entity.equalsIgnoreCase("ChickenJockey")) else if("ChickenJockey".equalsIgnoreCase(entity))
{ {
return EntityType.CHICKEN.getRegistryName(); 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(); return EntityType.PIGLIN.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Wither")) else if("Wither".equalsIgnoreCase(entity))
{ {
return EntityType.WITHER.getRegistryName(); return EntityType.WITHER.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Dog")) else if("Dog".equalsIgnoreCase(entity))
{ {
return EntityType.WOLF.getRegistryName(); return EntityType.WOLF.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Dragon")) else if("Dragon".equalsIgnoreCase(entity))
{ {
return EntityType.ENDER_DRAGON.getRegistryName(); return EntityType.ENDER_DRAGON.getRegistryName();
} }
else if(entity.equalsIgnoreCase("SnowMan")) else if("SnowMan".equalsIgnoreCase(entity))
{ {
return EntityType.SNOW_GOLEM.getRegistryName(); 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(); 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(); return EntityType.MAGMA_CUBE.getRegistryName();
} }
else if(entity.equalsIgnoreCase("SpiderJockey")) else if("SpiderJockey".equalsIgnoreCase(entity))
{ {
return EntityType.SPIDER.getRegistryName(); return EntityType.SPIDER.getRegistryName();
} }
else if(entity.equalsIgnoreCase("IronGolem")) else if("IronGolem".equalsIgnoreCase(entity))
{ {
return EntityType.IRON_GOLEM.getRegistryName(); 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(); return EntityType.OCELOT.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Kitty") || entity.equalsIgnoreCase("Kitten")) else if("Kitty".equalsIgnoreCase(entity) || "Kitten".equalsIgnoreCase(entity))
{ {
return EntityType.CAT.getRegistryName(); 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(); return EntityType.VILLAGER.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Octopus") || entity.equalsIgnoreCase("Kraken")) else if("Octopus".equalsIgnoreCase(entity) || "Kraken".equalsIgnoreCase(entity))
{ {
return EntityType.SQUID.getRegistryName(); return EntityType.SQUID.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Exwife")) else if("Exwife".equalsIgnoreCase(entity))
{ {
return EntityType.GHAST.getRegistryName(); return EntityType.GHAST.getRegistryName();
} }
else if(entity.equalsIgnoreCase("TNTMinecart")) else if("TNTMinecart".equalsIgnoreCase(entity))
{ {
return EntityType.TNT_MINECART.getRegistryName(); return EntityType.TNT_MINECART.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Minecart")) else if("Minecart".equalsIgnoreCase(entity))
{ {
return EntityType.MINECART.getRegistryName(); return EntityType.MINECART.getRegistryName();
} }
else if(entity.equalsIgnoreCase("HopperMinecart")) else if("HopperMinecart".equalsIgnoreCase(entity))
{ {
return EntityType.HOPPER_MINECART.getRegistryName(); return EntityType.HOPPER_MINECART.getRegistryName();
} }
else if(entity.equalsIgnoreCase("ChestMinecart")) else if("ChestMinecart".equalsIgnoreCase(entity))
{ {
return EntityType.CHEST_MINECART.getRegistryName(); return EntityType.CHEST_MINECART.getRegistryName();
} }
else if(entity.equalsIgnoreCase("SpawnerMinecart")) else if("SpawnerMinecart".equalsIgnoreCase(entity))
{ {
return EntityType.SPAWNER_MINECART.getRegistryName(); return EntityType.SPAWNER_MINECART.getRegistryName();
} }
else if(entity.equalsIgnoreCase("FurnaceMinecart")) else if("FurnaceMinecart".equalsIgnoreCase(entity))
{ {
return EntityType.FURNACE_MINECART.getRegistryName(); 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(); return EntityType.COMMAND_BLOCK_MINECART.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Wizard")) else if("Wizard".equalsIgnoreCase(entity))
{ {
return EntityType.EVOKER.getRegistryName(); return EntityType.EVOKER.getRegistryName();
} }
else if(entity.equalsIgnoreCase("Johnny")) else if("Johnny".equalsIgnoreCase(entity))
{ {
return EntityType.VINDICATOR.getRegistryName(); return EntityType.VINDICATOR.getRegistryName();
} }
else if(entity.equalsIgnoreCase("BabyZombie")) else if("BabyZombie".equalsIgnoreCase(entity))
{ {
return EntityType.ZOMBIE.getRegistryName(); return EntityType.ZOMBIE.getRegistryName();
} }
if(entity == null || entity.isEmpty())
{
return null;
}
return ResourceHelper.stringToResourceLocation(name); return ResourceHelper.stringToResourceLocation(name);
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,6 @@ package exopandora.worldhandler.builder.types;
import java.util.function.Function; import java.util.function.Function;
import javax.annotation.Nullable;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; 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()); 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) public static <S extends Number, U extends Coordinate<S>> U parse(U coordiante, String input, Function<String, S> parser)
{ {
for(EnumType type : EnumType.values()) for(EnumType type : EnumType.values())

View File

@@ -88,7 +88,7 @@ public class ClientEventHandler
@SubscribeEvent @SubscribeEvent
public static void clientChatEvent(ClientChatEvent event) public static void clientChatEvent(ClientChatEvent event)
{ {
if(!Minecraft.getInstance().isSingleplayer()) if(!Minecraft.getInstance().isSingleplayer() && Minecraft.getInstance().player != null)
{ {
CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<CommandSource>(); CommandDispatcher<CommandSource> dispatcher = new CommandDispatcher<CommandSource>();
CommandHelper.registerCommands(dispatcher); 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.WidgetCommandSyntax;
import exopandora.worldhandler.gui.widget.WidgetNameField; import exopandora.worldhandler.gui.widget.WidgetNameField;
import exopandora.worldhandler.gui.widget.WidgetShortcuts; import exopandora.worldhandler.gui.widget.WidgetShortcuts;
import exopandora.worldhandler.gui.widget.WidgetTabRenderer;
import exopandora.worldhandler.gui.widget.WidgetWatch; import exopandora.worldhandler.gui.widget.WidgetWatch;
import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip; import exopandora.worldhandler.gui.widget.button.GuiButtonTooltip;
import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.ActionHelper;

View File

@@ -23,9 +23,11 @@ import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.text.IFormattableTextComponent; import net.minecraft.util.text.IFormattableTextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
@@ -115,18 +117,24 @@ public class ContentButcher extends Content
slaughter.active = enabled; 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()); AxisAlignedBB aabb = new AxisAlignedBB(player.getPosition()).grow(radius);
targets.removeIf(target -> Minecraft.getInstance().player.equals(target));
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); return new IntegratedConnection(folder, worldSettings, dimensionGeneratorSettings);
} }
Minecraft.getInstance().world.sendQuittingDisconnectingPacket(); if(Minecraft.getInstance().world != null)
Minecraft.getInstance().unloadWorld(); {
Minecraft.getInstance().world.sendQuittingDisconnectingPacket();
Minecraft.getInstance().unloadWorld();
}
if(isRealms) if(isRealms)
{ {

View File

@@ -5,6 +5,8 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.function.Consumer; import java.util.function.Consumer;
import javax.annotation.Nullable;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
@@ -240,7 +242,12 @@ public class ContentCommandStack extends ContentChild
private void setCommand(int index, String command) 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) private void addCommand(int index)
@@ -253,9 +260,17 @@ public class ContentCommandStack extends ContentChild
this.builderCommandStack.removePassenger(index + HEAD_LENGTH); this.builderCommandStack.removePassenger(index + HEAD_LENGTH);
} }
@Nullable
private String getCommand(int index) 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() 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.IFormattableTextComponent;
import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@@ -211,7 +212,14 @@ public class ContentNoteEditor extends Content
private SoundEvent getSoundEvent(BlockPos blockPos) 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 @Override

View File

@@ -22,7 +22,8 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.AbstractGui; import net.minecraft.client.gui.AbstractGui;
import net.minecraft.client.gui.screen.inventory.InventoryScreen; import net.minecraft.client.gui.screen.inventory.InventoryScreen;
import net.minecraft.client.resources.I18n; 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.IFormattableTextComponent;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent; 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"), () -> 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()); PlayerEntity player = Minecraft.getInstance().player;
int posY = MathHelper.floor(Minecraft.getInstance().player.getPosY());
int posZ = MathHelper.floor(Minecraft.getInstance().player.getPosZ());
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)) else if(Page.MISC.equals(this.page))
@@ -152,18 +155,25 @@ public class ContentPlayer extends Content
@Override @Override
public void tick(Container container) public void tick(Container container)
{ {
this.posXField.setText("X: " + MathHelper.floor(Minecraft.getInstance().player.getPosX())); PlayerEntity player = Minecraft.getInstance().player;
this.posYField.setText("Y: " + MathHelper.floor(Minecraft.getInstance().player.getPosY()));
this.posZField.setText("Z: " + MathHelper.floor(Minecraft.getInstance().player.getPosZ())); if(player != null)
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"); BlockPos position = player.getPosition();
this.xpField.setText(I18n.format("gui.worldhandler.entities.player.score.experience_coins") + ": " + Minecraft.getInstance().player.experienceTotal);
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 @Override
public void drawScreen(MatrixStack matrix, Container container, int x, int y, int mouseX, int mouseY, float partialTicks) 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 xPos = x + 175;
int yPos = y + 82; int yPos = y + 82;

View File

@@ -147,12 +147,22 @@ public class ContentWorldInfo extends Content
private void updateCurrentTime() 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() 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) private static <T> String format(T object, Function<T, Object> function)

View File

@@ -106,7 +106,10 @@ public class GuiButtonPiano extends GuiButtonBase
@Override @Override
public void playDownSound(SoundHandler soundHandler) 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) private boolean isHoveringBlack(double mouseX, double mouseY)

View File

@@ -7,6 +7,7 @@ import java.util.function.Supplier;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import exopandora.worldhandler.builder.impl.BuilderGeneric;
import exopandora.worldhandler.builder.impl.BuilderUsercontent; import exopandora.worldhandler.builder.impl.BuilderUsercontent;
import exopandora.worldhandler.gui.content.Content; import exopandora.worldhandler.gui.content.Content;
import exopandora.worldhandler.usercontent.ScriptEngineAdapter; import exopandora.worldhandler.usercontent.ScriptEngineAdapter;
@@ -16,7 +17,6 @@ import exopandora.worldhandler.usercontent.model.Action;
import exopandora.worldhandler.util.ActionHandler; import exopandora.worldhandler.util.ActionHandler;
import exopandora.worldhandler.util.ActionHelper; import exopandora.worldhandler.util.ActionHelper;
import exopandora.worldhandler.util.CommandHelper; import exopandora.worldhandler.util.CommandHelper;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@@ -81,7 +81,14 @@ public class ActionHandlerFactory
} }
else if(!action.getAttributes().getValue().isEmpty()) 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) 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; return true;

View File

@@ -71,77 +71,77 @@ public class ActionHelper
public static void timeDawn() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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() 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) public static void tryRun(ActionHandler action)

View File

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

View File

@@ -54,7 +54,7 @@ public class NBTHelper
public static INBT serialize(ResourceLocation[] itemArray) 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; return null;
} }

View File

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