-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turns on island fly automatically on login if player is in air
Requires player to have the islandfly permission, to be on an island where they are allowed to fly and be in the air. Fixes #33
- Loading branch information
1 parent
744e821
commit 5ea1723
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/world/bentobox/islandfly/listeners/FlyLoginListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package world.bentobox.islandfly.listeners; | ||
|
||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerJoinEvent; | ||
|
||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.islandfly.IslandFlyAddon; | ||
|
||
/** | ||
* This class disables fly mode if player quits server. | ||
*/ | ||
public class FlyLoginListener implements Listener { | ||
|
||
/** | ||
* IslandFlyAddon instance. | ||
*/ | ||
private final IslandFlyAddon addon; | ||
|
||
|
||
/** | ||
* Default constructor. | ||
* @param addon instance of IslandFlyAddon | ||
*/ | ||
public FlyLoginListener(IslandFlyAddon addon) | ||
{ | ||
this.addon = addon; | ||
} | ||
|
||
|
||
/** | ||
* Disable player fly mode on logout | ||
* @param event Instance of PlayerQuitEvent | ||
*/ | ||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) | ||
public void onLogin(final PlayerJoinEvent event) { | ||
final Player player = event.getPlayer(); | ||
final User user = User.getInstance(player); | ||
final String permPrefix = addon.getPlugin().getIWM().getPermissionPrefix(player.getWorld()); | ||
if (player.hasPermission(permPrefix + "island.fly") | ||
&& !this.addon.getSettings().isFlyDisableOnLogout() && isInAir(player) | ||
&& addon.getIslands().userIsOnIsland(user.getWorld(), user)) | ||
{ | ||
if (!addon.getIslands().getIslandAt(user.getLocation()).map(i -> { | ||
if (i.isAllowed(user, IslandFlyAddon.ISLAND_FLY_PROTECTION)) { | ||
// Enable fly | ||
player.setFallDistance(0); | ||
player.setAllowFlight(true); | ||
player.setFlying(true); | ||
user.sendMessage("islandfly.enable-fly"); | ||
return true; | ||
} | ||
return false; | ||
}).orElse(false)) { | ||
user.sendMessage("islandfly.command.not-allowed-fly"); | ||
} | ||
} | ||
} | ||
|
||
|
||
private boolean isInAir(Player player) { | ||
Block b = player.getLocation().getBlock(); | ||
return player.getLocation().getBlockY() > 1 && b.getRelative(BlockFace.DOWN).isEmpty() && b.getRelative(BlockFace.DOWN, 2).isEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters