Skip to content

Commit

Permalink
Fixed banned players not teleported to spawn when they join the serve…
Browse files Browse the repository at this point in the history
…r inside an island they are banned from
  • Loading branch information
OmerBenGera committed Oct 13, 2022
1 parent ca72adf commit 9b856ff
Showing 1 changed file with 10 additions and 15 deletions.
Expand Up @@ -10,6 +10,7 @@
import com.bgsoftware.superiorskyblock.api.island.IslandChest;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.core.Materials;
import com.bgsoftware.superiorskyblock.core.Mutable;
import com.bgsoftware.superiorskyblock.core.Singleton;
import com.bgsoftware.superiorskyblock.core.collections.AutoRemovalCollection;
import com.bgsoftware.superiorskyblock.core.events.EventResult;
Expand Down Expand Up @@ -109,10 +110,12 @@ private void onPlayerJoin(PlayerJoinEvent e) {
if (superiorPlayer.isShownAsOnline())
notifyPlayerJoin(superiorPlayer);

Mutable<Boolean> teleportToSpawn = new Mutable<>(false);

Island island = plugin.getGrid().getIslandAt(e.getPlayer().getLocation());
if (island != null) {
onPlayerEnterIsland(superiorPlayer, null, null, e.getPlayer().getLocation(), island,
IslandEnterEvent.EnterCause.PLAYER_JOIN);
if (island != null && preventPlayerEnterIsland(superiorPlayer, null, null,
e.getPlayer().getLocation(), island, IslandEnterEvent.EnterCause.PLAYER_JOIN)) {
teleportToSpawn.setValue(true);
}

BukkitExecutor.sync(() -> {
Expand All @@ -126,9 +129,11 @@ private void onPlayerJoin(PlayerJoinEvent e) {
if (!superiorPlayer.hasBypassModeEnabled()) {
Island delayedIsland = plugin.getGrid().getIslandAt(e.getPlayer().getLocation());
// Checking if the player is in the islands world, not inside an island.
if (plugin.getGrid().isIslandsWorld(superiorPlayer.getWorld()) && delayedIsland == null) {
if ((delayedIsland == island && teleportToSpawn.getValue()) ||
(plugin.getGrid().isIslandsWorld(superiorPlayer.getWorld()) && delayedIsland == null)) {
superiorPlayer.teleport(plugin.getGrid().getSpawnIsland());
Message.ISLAND_GOT_DELETED_WHILE_INSIDE.send(superiorPlayer);
if (!teleportToSpawn.getValue())
Message.ISLAND_GOT_DELETED_WHILE_INSIDE.send(superiorPlayer);
}
}

Expand Down Expand Up @@ -388,16 +393,6 @@ public boolean preventPlayerLeaveIsland(SuperiorPlayer superiorPlayer,
return false;
}

public void onPlayerEnterIsland(SuperiorPlayer superiorPlayer,
@Nullable Location fromLocation,
@Nullable Island fromIsland,
@NotNull Location toLocation,
@NotNull Island toIsland,
IslandEnterEvent.EnterCause enterCause) {
/* Alias for preventPlayerEnterIsland */
this.preventPlayerEnterIsland(superiorPlayer, fromLocation, fromIsland, toLocation, toIsland, enterCause);
}

public boolean preventPlayerEnterIsland(SuperiorPlayer superiorPlayer,
@Nullable Location fromLocation,
@Nullable Island fromIsland,
Expand Down

0 comments on commit 9b856ff

Please sign in to comment.