Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/BentoBoxWorld/Parkour.git
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
tastybento committed Nov 12, 2023
2 parents ad55237 + ec63231 commit 9d301c5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.Optional;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.EntityEffect;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -20,6 +22,7 @@
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.util.Vector;
Expand Down Expand Up @@ -84,33 +87,54 @@ public void onVisitorArrive(IslandEnterEvent e) {
// since exit would trigger first
// cross (unmanaged) world teleportation is handled in onPlayerChangeWorld

if (island.getFlag(addon.PARKOUR_CREATIVE) <= island.getRank(user)) {
user.setGameMode(GameMode.CREATIVE);
} else {
user.setGameMode(GameMode.SURVIVAL);
}
updateGamemode(island, user);
}
}

@EventHandler
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
User user = User.getInstance(event.getPlayer());
Location currentLocation = user.getLocation();
boolean fromParkour = addon.inWorld(event.getFrom());
boolean toParkour = addon.inWorld(currentLocation);
World newWorld = user.getWorld();
boolean toParkour = addon.inWorld(newWorld);

if (toParkour && !fromParkour) {
// switching from non-parkour world to parkour world
addon.getIslandsManager().getIslandAt(currentLocation).ifPresent(island -> {
if (island.getFlag(addon.PARKOUR_CREATIVE) <= island.getRank(user)) {
user.setGameMode(GameMode.CREATIVE);
} else {
user.setGameMode(GameMode.SURVIVAL);
Bukkit.getServer().getScheduler().runTaskLater(addon.getPlugin(), () -> {
Location currentLocation = user.getLocation();

// world has changed in the 2 ticks delay, dont set gamemode
if (currentLocation.getWorld() != newWorld) {
return;
}
});

addon.getIslandsManager().getIslandAt(currentLocation).ifPresent(island -> updateGamemode(island, user));
}, 2); // 2 ticks since multiverse overrides gamemode after 1 tick
}
}


@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
User user = User.getInstance(event.getPlayer());
World world = user.getWorld();
if (!addon.inWorld(world)) {
return;
}

Bukkit.getServer().getScheduler().runTaskLater(addon.getPlugin(), () -> {
Location currentLocation = user.getLocation();

// world has changed in the 2 ticks delay, dont set gamemode
if (currentLocation.getWorld() != world) {
return;
}

addon.getIslandsManager().getIslandAt(currentLocation).ifPresent(island -> updateGamemode(island, user));
}, 2);
}


@EventHandler(priority = EventPriority.NORMAL)
public void onVisitorLeave(IslandExitEvent e) {
// If the user leaves any island, end and clear the session.
Expand Down Expand Up @@ -154,14 +178,14 @@ public void onVisitorFall(EntityDamageEvent e) {
checkpointLocation = checkpointLocation.clone().add(0.5, 0, 0.5);
parkourRunManager.currentlyTeleporting().add(player.getUniqueId());
Util.teleportAsync(player, checkpointLocation, PlayerTeleportEvent.TeleportCause.PLUGIN)
.thenAccept(b -> parkourRunManager.currentlyTeleporting().remove(player.getUniqueId()));
.thenAccept(b -> parkourRunManager.currentlyTeleporting().remove(player.getUniqueId()));
}

@EventHandler
public void onTeleport(PlayerTeleportEvent e) {
boolean shouldStopRun = switch (e.getCause()) {
case ENDER_PEARL, CHORUS_FRUIT, DISMOUNT, EXIT_BED, NETHER_PORTAL, END_PORTAL -> false;
case COMMAND, PLUGIN, SPECTATE, END_GATEWAY, UNKNOWN -> true;
case ENDER_PEARL, CHORUS_FRUIT, DISMOUNT, EXIT_BED, NETHER_PORTAL, END_PORTAL -> false;
case COMMAND, PLUGIN, SPECTATE, END_GATEWAY, UNKNOWN -> true;
};
UUID playerUUID = e.getPlayer().getUniqueId();
if (!parkourRunManager.currentlyTeleporting().contains(playerUUID) && shouldStopRun && parkourRunManager.timers().containsKey(playerUUID)) {
Expand All @@ -182,20 +206,26 @@ public void onTeleport(PlayerTeleportEvent e) {
Optional<Island> toIsland = addon.getIslands().getIslandAt(e.getTo());

boolean shouldAlterGamemode = switch (e.getCause()) {
case COMMAND, PLUGIN, UNKNOWN -> true;
default -> false;
case COMMAND, PLUGIN, UNKNOWN -> true;
default -> false;
};
if (shouldAlterGamemode && 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.PARKOUR_CREATIVE) <= island.getRank(user)) {
user.setGameMode(GameMode.CREATIVE);
} else {
user.setGameMode(GameMode.SURVIVAL);
}
updateGamemode(fromIsland.get(), user);
}
}

private void updateGamemode(Island island, User user) {
if (user.hasPermission("parkour.mod.bypassgamemodechange")) {
return;
}

if (island.getFlag(addon.PARKOUR_CREATIVE) <= island.getRank(user)) {
user.setGameMode(GameMode.CREATIVE);
} else {
user.setGameMode(GameMode.SURVIVAL);
}
}


Expand Down
21 changes: 3 additions & 18 deletions src/main/resources/addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ permissions:
parkour.mod.bypasslock:
description: Bypasses an course lock
default: op
parkour.mod.bypassgamemodechange:
description: Bypasses the changing of your gamemode when entering your island.
default: false
parkour.mod.bypassban:
description: Bypasses course ban
default: op
Expand Down Expand Up @@ -89,18 +92,6 @@ permissions:
parkour.mod.team.setowner:
description: Allow use of '/pkadmin team setowner' command - transfers course ownership to the player
default: op
parkour.mod.team.add:
description: Allow use of '/pkadmin add' command - add player to owner's team
default: op
parkour.mod.team.kick:
description: Allow use of '/pkadmin kick' command - kick a player from a team
default: op
parkour.mod.team.disband:
description: Allow use of '/pkadmin disband' command - disband owner's team
default: op
parkour.mod.team.setowner:
description: Allow use of '/pkadmin setowner' command - transfers course ownership to the player
default: op
parkour.admin.blueprint:
description: Allow use of '/pkadmin blueprint' command - manipulate blueprints
default: op
Expand Down Expand Up @@ -170,9 +161,6 @@ permissions:
parkour.admin.resets.add:
description: Allow use of '/pkadmin resets add' command - adds this player's course reset count
default: op
parkour.admin.resets.remove:
description: Allow use of '/pkadmin resets remove' command - reduces the player's course reset count
default: op
parkour.admin.delete:
description: Allow use of '/pkadmin delete' command - deletes a player and regenerates their course
default: op
Expand Down Expand Up @@ -296,9 +284,6 @@ permissions:
parkour.island.team.coop:
description: Allow use of '/parkour team coop' command - make a player coop rank on your course
default: true
parkour.island.team.coop:
description: Allow use of '/parkour team uncoop' command - remove a coop rank from player
default: true
parkour.island.team.trust:
description: Allow use of '/parkour team trust', '/parkour team untrust' command - remove trusted player rank from player
default: true
Expand Down

0 comments on commit 9d301c5

Please sign in to comment.