Skip to content

Commit

Permalink
stop run on certain teleport causes and set gamemode on same-island t…
Browse files Browse the repository at this point in the history
…eleport

COMMAND, PLUGIN, NETHER_PORTAL, END_PORTAL, SPECTATE, END_GATEWAY, UNKNOWN
  • Loading branch information
456dev committed Aug 1, 2023
1 parent 48575b1 commit bba15e4
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.util.Vector;

import world.bentobox.bentobox.api.commands.CompositeCommand;
Expand Down Expand Up @@ -112,6 +113,38 @@ public void onVisitorFall(EntityDamageEvent e) {

}

@EventHandler
public void onTeleport(PlayerTeleportEvent e) {
boolean shouldStopRun = switch (e.getCause()) {
case ENDER_PEARL, CHORUS_FRUIT, DISMOUNT, EXIT_BED -> false;
case COMMAND, PLUGIN, NETHER_PORTAL, END_PORTAL, SPECTATE, END_GATEWAY, UNKNOWN -> true;
};
if (shouldStopRun) {
User user = User.getInstance(e.getPlayer().getUniqueId());
if (parkourRunManager.getCheckpoints().containsKey(e.getPlayer().getUniqueId()) && user.isOnline()) {
user.notify("parkour.session-ended");
}
parkourRunManager.clear(e.getPlayer().getUniqueId());
}

if (e.getTo() != null) {
Optional<Island> fromIsland = addon.getIslands().getIslandAt(e.getFrom());
Optional<Island> toIsland = addon.getIslands().getIslandAt(e.getTo());

if (fromIsland.isPresent() && toIsland.isPresent() && fromIsland.get().equals(toIsland.get())) {
// same island teleport
Island island = fromIsland.get();
User user = User.getInstance(e.getPlayer());
if (island.getFlag(addon.CREATIVE_FLAG) <= island.getRank(user)) {
user.setGameMode(GameMode.CREATIVE);
} else {
user.setGameMode(GameMode.SURVIVAL);
}
}
}
}


/**
* Prevent players from issuing commands during a run
*
Expand Down

0 comments on commit bba15e4

Please sign in to comment.