Fixed bugs with NPEs in non-island worlds.

This commit is contained in:
tastybento 2018-06-10 22:34:01 -07:00
parent 10d5c262ca
commit aa7fbabf82
4 changed files with 9 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.api.configuration.WorldSettings;
import us.tastybento.bskyblock.api.localization.TextVariables; import us.tastybento.bskyblock.api.localization.TextVariables;
import us.tastybento.bskyblock.api.panels.PanelItem; import us.tastybento.bskyblock.api.panels.PanelItem;
import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder; import us.tastybento.bskyblock.api.panels.builders.PanelItemBuilder;
@ -61,10 +62,12 @@ public class Flag implements Comparable<Flag> {
/** /**
* Check if a setting is set in this world * Check if a setting is set in this world
* @param world - world * @param world - world
* @return world setting, or default flag setting if a specific world setting is not set * @return world setting or default flag setting if a specific world setting is not set.
* If world is not a game world, then the result will always be false!
*/ */
public boolean isSetForWorld(World world) { public boolean isSetForWorld(World world) {
return BSkyBlock.getInstance().getIWM().getWorldSettings(world).getWorldFlags().getOrDefault(getID(), setting); WorldSettings ws = BSkyBlock.getInstance().getIWM().getWorldSettings(world);
return ws != null ? ws.getWorldFlags().getOrDefault(getID(), setting) : false;
} }
/** /**

View File

@ -52,7 +52,7 @@ public class JoinLeaveListener implements Listener {
} else { } else {
plugin.logWarning("Player that just logged in has no name! " + playerUUID.toString()); plugin.logWarning("Player that just logged in has no name! " + playerUUID.toString());
} }
if (Flags.REMOVE_MOBS.isSetForWorld(user.getWorld())) { if (plugin.getIWM().inWorld(user.getLocation()) && Flags.REMOVE_MOBS.isSetForWorld(user.getWorld())) {
RemoveMobsListener.clearArea(user.getLocation()); RemoveMobsListener.clearArea(user.getLocation());
} }
} }

View File

@ -26,9 +26,9 @@ public class EnterExitListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onMove(PlayerMoveEvent e) { public void onMove(PlayerMoveEvent e) {
// Only process if Enter Exit flags are active, we are in the right world and there is a change in X or Z coords // Only process if Enter Exit flags are active, we are in the right world and there is a change in X or Z coords
if (!Flags.ENTER_EXIT_MESSAGES.isSetForWorld(e.getFrom().getWorld()) if (!getIslandWorldManager().inWorld(e.getFrom())
|| e.getFrom().toVector().multiply(XZ).equals(e.getTo().toVector().multiply(XZ)) || e.getFrom().toVector().multiply(XZ).equals(e.getTo().toVector().multiply(XZ))
|| !getIslandWorldManager().inWorld(e.getFrom())) { || !Flags.ENTER_EXIT_MESSAGES.isSetForWorld(e.getFrom().getWorld())) {
return; return;
} }
Optional<Island> from = this.getIslands().getProtectedIslandAt(e.getFrom()); Optional<Island> from = this.getIslands().getProtectedIslandAt(e.getFrom());

View File

@ -35,7 +35,7 @@ public class RemoveMobsListener extends AbstractFlagListener {
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onUserTeleport(PlayerTeleportEvent e) { public void onUserTeleport(PlayerTeleportEvent e) {
// Only process if flag is active // Only process if flag is active
if (Flags.REMOVE_MOBS.isSetForWorld(e.getTo().getWorld()) && getIslands().locationIsOnIsland(e.getPlayer(), e.getTo())) { if (getIslands().locationIsOnIsland(e.getPlayer(), e.getTo()) && Flags.REMOVE_MOBS.isSetForWorld(e.getTo().getWorld())) {
clearArea(e.getTo()); clearArea(e.getTo());
} }
} }