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

@@ -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)