From 2f9ef32580cb64514753ec1d012de80d7764f108 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 28 Jul 2023 21:51:38 -0700 Subject: [PATCH] Handle 3rd party fly plugins Make the fly flag apply to general flying, e.g., by the Essentials /fly command https://github.com/BentoBoxWorld/BentoBox/issues/2159 --- pom.xml | 2 +- .../islandfly/listeners/FlyListener.java | 29 +++++++++++++++++++ src/main/resources/locales/en-US.yml | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 21efb80..2bc34b8 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ ${build.version}-SNAPSHOT - 1.10.0 + 1.11.0 -LOCAL diff --git a/src/main/java/world/bentobox/islandfly/listeners/FlyListener.java b/src/main/java/world/bentobox/islandfly/listeners/FlyListener.java index 7cb38fa..5c6a165 100644 --- a/src/main/java/world/bentobox/islandfly/listeners/FlyListener.java +++ b/src/main/java/world/bentobox/islandfly/listeners/FlyListener.java @@ -6,7 +6,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerToggleFlightEvent; +import world.bentobox.bentobox.api.events.island.IslandEnterEvent; import world.bentobox.bentobox.api.events.island.IslandExitEvent; import world.bentobox.bentobox.api.localization.TextVariables; import world.bentobox.bentobox.api.user.User; @@ -32,6 +34,33 @@ public FlyListener(final IslandFlyAddon addon) { this.addon = addon; } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onToggleFlight(final PlayerToggleFlightEvent event) { + final User user = User.getInstance(event.getPlayer()); + if (checkUser(user)) { + user.sendMessage("islandfly.not-allowed"); + } + } + + /** + * @param user user + * @return true if fly was blocked + */ + private boolean checkUser(User user) { + String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(user.getWorld()); + // Ignore ops + if (user.isOp() || user.getPlayer().getGameMode().equals(GameMode.CREATIVE) + || user.getPlayer().getGameMode().equals(GameMode.SPECTATOR) + || user.hasPermission(permPrefix + "island.flybypass")) return false; + return removeFly(user); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEnterIsland(final IslandEnterEvent event) { + final User user = User.getInstance(event.getPlayerUUID()); + // Wait until after arriving at the island + Bukkit.getScheduler().runTask(this.addon.getPlugin(), () -> checkUser(user)); + } /** * This method is triggered when player leaves their island. diff --git a/src/main/resources/locales/en-US.yml b/src/main/resources/locales/en-US.yml index e3333f3..a229f9e 100644 --- a/src/main/resources/locales/en-US.yml +++ b/src/main/resources/locales/en-US.yml @@ -2,6 +2,7 @@ islandfly: fly-outside-alert: "&c You are outside your island so fly mode will be disabled in &e[number] &c seconds." fly-turning-off-alert: "&c You are not permitted to fly here anymore. Turning fly off in &e[number] &c seconds." disable-fly: "&c Your fly mode has been disabled." + not-allowed: "&c Flying is not allowed here." reallowed-fly: "&a Your fly has been reallowed" enable-fly: "&a Your fly mode has been enabled." cancel-disable: "&a You are back, huh! Fly fuel successfully refilled!"