-
-
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.
Fixes bugs and implements features (#24)
* Fixes bugs and implements features * Deleting forgotten comment
- Loading branch information
1 parent
c964fb9
commit 87ece61
Showing
7 changed files
with
182 additions
and
21 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
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
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
85 changes: 85 additions & 0 deletions
85
src/main/java/world/bentobox/islandfly/listeners/FlyFlagListener.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,85 @@ | ||
package world.bentobox.islandfly.listeners; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import world.bentobox.bentobox.BentoBox; | ||
import world.bentobox.bentobox.api.events.flags.FlagProtectionChangeEvent; | ||
import world.bentobox.bentobox.api.localization.TextVariables; | ||
import world.bentobox.bentobox.api.user.User; | ||
import world.bentobox.bentobox.database.objects.Island; | ||
import world.bentobox.islandfly.IslandFlyAddon; | ||
|
||
public class FlyFlagListener implements Listener { | ||
|
||
private BentoBox plugin; | ||
private IslandFlyAddon addon; | ||
|
||
public FlyFlagListener(IslandFlyAddon addon) { | ||
this.plugin = addon.getPlugin(); | ||
this.addon = addon; | ||
} | ||
|
||
@EventHandler | ||
public void onFlagChange(FlagProtectionChangeEvent e) { | ||
|
||
if (!e.getEditedFlag().equals(IslandFlyAddon.ISLAND_FLY_PROTECTION)) | ||
return; | ||
|
||
Island island = e.getIsland(); | ||
|
||
// Stream through all of the flying and not allowed users at | ||
// the moment and warn them that their fly is about to turn off | ||
e.getIsland().getPlayersOnIsland().parallelStream() | ||
.filter(Player::isFlying) | ||
.filter(p -> !(island.isAllowed(User.getInstance(p), IslandFlyAddon.ISLAND_FLY_PROTECTION) || p.isOp())) | ||
.forEach(p -> { | ||
|
||
startDisabling(p, island); | ||
}); | ||
} | ||
|
||
public void startDisabling(Player p, Island island) { | ||
|
||
int flyTimeout = this.addon.getSettings().getFlyTimeout(); | ||
User user = User.getInstance(p); | ||
|
||
|
||
// Alert player fly will be disabled | ||
user.sendMessage("islandfly.fly-turning-off-alert", TextVariables.NUMBER, String.valueOf(flyTimeout)); | ||
|
||
// If timeout is 0 or less disable fly immediately | ||
if (flyTimeout <= 0) { | ||
|
||
p.setFlying(false); | ||
p.setAllowFlight(false); | ||
user.sendMessage("islandfly.disable-fly"); | ||
|
||
return; | ||
} | ||
|
||
// Else disable fly with a delay | ||
addon.getServer().getScheduler().runTaskLater(this.addon.getPlugin(), () -> { | ||
|
||
// Verify that player is still online | ||
if (!user.isOnline()) return; | ||
|
||
// Check if user was reallowed to fly in the meantime | ||
if (!island.isAllowed(user,IslandFlyAddon.ISLAND_FLY_PROTECTION)) { | ||
|
||
// Silent cancel fly if player changed island in the meantime | ||
// It will be the job of Enter/Exit island event to turn fly off if required | ||
if (!island.onIsland(p.getLocation())) | ||
return; | ||
|
||
p.setFlying(false); | ||
p.setAllowFlight(false); | ||
user.sendMessage("islandfly.disable-fly"); | ||
} | ||
else { | ||
user.sendMessage("islandfly.reallowed-fly"); | ||
} | ||
|
||
}, 20L* flyTimeout); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,9 +1,17 @@ | ||
islandfly: | ||
fly-outside-alert: "&cYou are outside your island so fly mode will be disabled in &e[number]&c seconds." | ||
fly-turning-off-alert: "&cYou are not permitted to fly here anymore. Turning fly off in &e[number]&c seconds." | ||
disable-fly: "&cYour fly mode has been disabled." | ||
reallowed-fly: "&aYour fly has been reallowed" | ||
enable-fly: "&aYour fly mode has been enabled." | ||
cancel-disable: "&aYou are back, huh! Fly fuel successfully refilled!" | ||
wrong-world: "&cYou are not in the right gamemode world" | ||
command: | ||
description: "allows you to fly on your island" | ||
only-on-island: "&cYou can only fly on your island." | ||
not-allowed-fly: "&cYou are not allowed to fly on this island" | ||
|
||
protection: | ||
flags: | ||
ISLAND_FLY_PROTECTION: | ||
description: "&aToggle who can fly on your island" | ||
name: "&aFly prevention" |