Skip to content

Commit

Permalink
Fix flight not being taken from player who quit being residents of a
Browse files Browse the repository at this point in the history
town.

Closes #77.
  • Loading branch information
LlmDl committed Apr 19, 2024
1 parent cd9f212 commit 3f8d7de
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.llmdlio</groupId>
<artifactId>TownyFlight</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
<name>TownyFlight</name>
<description>A flight plugin for Towny servers.</description>
<properties>
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/gmail/llmdlio/townyflight/TownyFlight.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.gmail.llmdlio.townyflight.listeners.PlayerLogOutListener;
import com.gmail.llmdlio.townyflight.listeners.PlayerPVPListener;
import com.gmail.llmdlio.townyflight.listeners.PlayerTeleportListener;
import com.gmail.llmdlio.townyflight.listeners.TownRemoveResidentListener;
import com.gmail.llmdlio.townyflight.listeners.TownStatusScreenListener;
import com.gmail.llmdlio.townyflight.listeners.TownUnclaimListener;
import com.gmail.llmdlio.townyflight.tasks.TaskHandler;
Expand Down Expand Up @@ -118,6 +119,7 @@ protected void registerEvents() {
pm.registerEvents(new PlayerJoinListener(this), this);
pm.registerEvents(new PlayerLogOutListener(), this);
pm.registerEvents(new PlayerLeaveTownListener(this), this);
pm.registerEvents(new TownRemoveResidentListener(this), this);
pm.registerEvents(new TownUnclaimListener(this), this);
pm.registerEvents(new PlayerFallListener(), this);
pm.registerEvents(new PlayerTeleportListener(), this);
Expand Down
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, "");
}
}
}

0 comments on commit 3f8d7de

Please sign in to comment.