Skip to content

Commit

Permalink
Fixed potential null issues
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jan 28, 2022
1 parent 3b7ee61 commit ba0c31b
Showing 1 changed file with 13 additions and 14 deletions.
Expand Up @@ -97,16 +97,16 @@ public static boolean handlePlayerLeaveIsland(SuperiorPlayer superiorPlayer, Loc
fromIsland.setPlayerInside(superiorPlayer, false);

Player player = superiorPlayer.asPlayer();
assert player != null;

player.resetPlayerTime();
player.resetPlayerWeather();
fromIsland.removeEffects(superiorPlayer);

if (superiorPlayer.hasIslandFlyEnabled() && (toIsland == null || toIsland.isSpawn()) && !superiorPlayer.hasFlyGamemode()) {
player.setAllowFlight(false);
player.setFlying(false);
Message.ISLAND_FLY_DISABLED.send(player);
if (player != null) {
player.resetPlayerTime();
player.resetPlayerWeather();
fromIsland.removeEffects(superiorPlayer);

if (superiorPlayer.hasIslandFlyEnabled() && (toIsland == null || toIsland.isSpawn()) && !superiorPlayer.hasFlyGamemode()) {
player.setAllowFlight(false);
player.setFlying(false);
Message.ISLAND_FLY_DISABLED.send(player);
}
}

if (toIsland == null)
Expand Down Expand Up @@ -152,8 +152,6 @@ public static void handlePlayerEnterIsland(SuperiorPlayer superiorPlayer, Locati
boolean toInsideRange = toIsland.isInsideRange(toLocation);
boolean fromInsideRange = fromLocation != null && fromIsland != null && fromIsland.isInsideRange(fromLocation);
boolean equalWorlds = fromLocation != null && toLocation.getWorld().equals(fromLocation.getWorld());
Player player = superiorPlayer.asPlayer();
assert player != null;

if (toInsideRange && (!equalIslands || !fromInsideRange)) {
if (!EventsCaller.callIslandEnterProtectedEvent(superiorPlayer, toIsland, enterCause)) {
Expand Down Expand Up @@ -193,7 +191,8 @@ public static void handlePlayerEnterIsland(SuperiorPlayer superiorPlayer, Locati
superiorPlayer.setImmunedToPortals(true);
Executor.sync(() -> superiorPlayer.setImmunedToPortals(false), 100L);

if (plugin.getSettings().getSpawn().isProtected() || !toIsland.isSpawn()) {
Player player = superiorPlayer.asPlayer();
if (player != null && (plugin.getSettings().getSpawn().isProtected() || !toIsland.isSpawn())) {
if (toIsland.hasSettingsEnabled(IslandFlags.ALWAYS_DAY)) {
player.setPlayerTime(0, false);
} else if (toIsland.hasSettingsEnabled(IslandFlags.ALWAYS_MIDDLE_DAY)) {
Expand All @@ -215,7 +214,7 @@ public static void handlePlayerEnterIsland(SuperiorPlayer superiorPlayer, Locati

if (superiorPlayer.hasIslandFlyEnabled() && !superiorPlayer.hasFlyGamemode()) {
Executor.sync(() -> {
if (player.isOnline())
if (player != null)
toIsland.updateIslandFly(superiorPlayer);
}, 5L);
}
Expand Down

0 comments on commit ba0c31b

Please sign in to comment.