Skip to content

Commit

Permalink
Handle 3rd party fly plugins
Browse files Browse the repository at this point in the history
Make the fly flag apply to general flying, e.g., by the Essentials /fly
command

BentoBoxWorld/BentoBox#2159
  • Loading branch information
tastybento committed Jul 29, 2023
1 parent de0d406 commit 2f9ef32
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- This allows to change between versions and snapshots. -->
<build.version>1.10.0</build.version>
<build.version>1.11.0</build.version>
<build.number>-LOCAL</build.number>
</properties>

Expand Down
29 changes: 29 additions & 0 deletions src/main/java/world/bentobox/islandfly/listeners/FlyListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down

0 comments on commit 2f9ef32

Please sign in to comment.