Fix possible NPE and the forge-server instance never being initialized

This commit is contained in:
Blue (Lukas Rieger) 2020-08-30 20:52:30 +02:00
parent 0559df9730
commit cd24f57031
10 changed files with 12 additions and 1 deletions

View File

@ -100,6 +100,7 @@ public HttpResponse handlePlayersRequest(HttpRequest request) {
json.beginObject(); json.beginObject();
json.name("players").beginArray(); json.name("players").beginArray();
for (Player player : server.getOnlinePlayers()) { for (Player player : server.getOnlinePlayers()) {
if (!player.isOnline()) continue;
if (config.isHideInvisible() && player.isInvisible()) continue; if (config.isHideInvisible() && player.isInvisible()) continue;
if (config.isHideSneaking() && player.isSneaking()) continue; if (config.isHideSneaking() && player.isSneaking()) continue;
@ -116,6 +117,7 @@ public HttpResponse handlePlayersRequest(HttpRequest request) {
json.endObject(); json.endObject();
json.endObject(); json.endObject();
} }
json.endArray(); json.endArray();
json.endObject(); json.endObject();

View File

@ -129,6 +129,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode()); this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY); StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0; this.invisible = invis != null && invis.getDuration() > 0;

View File

@ -129,6 +129,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode()); this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY); StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0; this.invisible = invis != null && invis.getDuration() > 0;

View File

@ -129,6 +129,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode()); this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameMode());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY); StatusEffectInstance invis = player.getStatusEffect(StatusEffects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0; this.invisible = invis != null && invis.getDuration() > 0;

View File

@ -129,6 +129,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType()); this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY); EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0; this.invisible = invis != null && invis.getDuration() > 0;

View File

@ -129,6 +129,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType()); this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY); EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0; this.invisible = invis != null && invis.getDuration() > 0;

View File

@ -98,12 +98,13 @@ public ForgeMod() {
@SubscribeEvent @SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) { public void onServerStarting(FMLServerStartingEvent event) {
this.worldUUIDs.clear(); this.worldUUIDs.clear();
this.serverInstance = event.getServer();
//register commands //register commands
new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource)); new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new ForgeCommandSource(this, pluginInstance, forgeSource));
//save worlds to generate level.dat files //save worlds to generate level.dat files
event.getServer().save(false, true, true); serverInstance.save(false, true, true);
new Thread(() -> { new Thread(() -> {
Logger.global.logInfo("Loading..."); Logger.global.logInfo("Loading...");

View File

@ -128,6 +128,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType()); this.gamemode = GAMEMODE_MAP.get(player.interactionManager.getGameType());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY); EffectInstance invis = player.getActivePotionEffect(Effects.INVISIBILITY);
this.invisible = invis != null && invis.getDuration() > 0; this.invisible = invis != null && invis.getDuration() > 0;

View File

@ -114,6 +114,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.getGameMode()); this.gamemode = GAMEMODE_MAP.get(player.getGameMode());
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
this.invisible = player.hasPotionEffect(PotionEffectType.INVISIBILITY); this.invisible = player.hasPotionEffect(PotionEffectType.INVISIBILITY);

View File

@ -119,6 +119,7 @@ public void update() {
} }
this.gamemode = GAMEMODE_MAP.get(player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET)); this.gamemode = GAMEMODE_MAP.get(player.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET));
if (this.gamemode == null) this.gamemode = Gamemode.SURVIVAL;
boolean invis = player.get(Keys.VANISH).orElse(false); boolean invis = player.get(Keys.VANISH).orElse(false);
if (!invis && player.get(Keys.INVISIBLE).orElse(false)) invis = true; if (!invis && player.get(Keys.INVISIBLE).orElse(false)) invis = true;