-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix flight not being taken from player who quit being residents of a
town. Closes #77.
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/gmail/llmdlio/townyflight/listeners/TownRemoveResidentListener.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,43 @@ | ||
package com.gmail.llmdlio.townyflight.listeners; | ||
|
||
import com.gmail.llmdlio.townyflight.TownyFlight; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
|
||
import com.gmail.llmdlio.townyflight.TownyFlightAPI; | ||
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent; | ||
import com.palmergames.bukkit.towny.object.Resident; | ||
|
||
public class TownRemoveResidentListener implements Listener { | ||
private final TownyFlight plugin; | ||
|
||
public TownRemoveResidentListener(TownyFlight plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
/* | ||
* Listener for a player who stops being a resident of a town. | ||
*/ | ||
@EventHandler(priority = EventPriority.LOWEST) | ||
private void playerLeftTownEvent(TownRemoveResidentEvent event) { | ||
Resident resident = event.getResident(); | ||
if (!resident.isOnline()) | ||
return; | ||
Player player = resident.getPlayer(); | ||
if (!player.getAllowFlight() || player.hasPermission("townyflight.bypass")) | ||
return; | ||
|
||
plugin.getScheduler().runLater(player, () -> testPlayer(player), 1); | ||
} | ||
|
||
/* | ||
* Check if the player is allowed to fly at their location. | ||
*/ | ||
private void testPlayer(Player player) { | ||
if (!TownyFlightAPI.getInstance().canFly(player, true)) { | ||
TownyFlightAPI.getInstance().removeFlight(player, false, true, ""); | ||
} | ||
} | ||
} |