From 50e0f1d91a4e521cb65637a2f3c8106001607579 Mon Sep 17 00:00:00 2001 From: MATRIX-feather Date: Mon, 21 Oct 2024 19:32:07 +0800 Subject: [PATCH] misc: Handle more towny events --- .../misc/integrations/towny/TownyAdapter.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/nifeather/morph/misc/integrations/towny/TownyAdapter.java b/src/main/java/xyz/nifeather/morph/misc/integrations/towny/TownyAdapter.java index 11fdb1a1..b081e64c 100644 --- a/src/main/java/xyz/nifeather/morph/misc/integrations/towny/TownyAdapter.java +++ b/src/main/java/xyz/nifeather/morph/misc/integrations/towny/TownyAdapter.java @@ -2,8 +2,7 @@ import com.destroystokyo.paper.event.entity.EntityAddToWorldEvent; import com.palmergames.bukkit.towny.TownyAPI; -import com.palmergames.bukkit.towny.event.TownClaimEvent; -import com.palmergames.bukkit.towny.event.TownSpawnEvent; +import com.palmergames.bukkit.towny.event.*; import com.palmergames.bukkit.towny.event.player.PlayerEntersIntoTownBorderEvent; import com.palmergames.bukkit.towny.event.player.PlayerExitsFromTownBorderEvent; import com.palmergames.bukkit.towny.event.town.TownUnclaimEvent; @@ -33,6 +32,7 @@ import xyz.nifeather.morph.config.MorphConfigManager; import xyz.nifeather.morph.events.api.gameplay.PlayerMorphEvent; import xyz.nifeather.morph.events.api.gameplay.PlayerUnMorphEvent; +import xyz.nifeather.morph.misc.NmsRecord; import java.util.Arrays; import java.util.List; @@ -183,6 +183,18 @@ public void onTownClaim(TownClaimEvent e) .forEach(chunkTask -> chunkTask.thenAccept(chunk -> this.updatePlayersInChunk(chunk, currentTown))); } + @EventHandler + public void onTownRemoveResident(TownRemoveResidentEvent e) + { + updatePlayer(e.getResident().getPlayer(), e.getTown()); + } + + @EventHandler + public void onTownAddResident(TownAddResidentEvent e) + { + updatePlayer(e.getResident().getPlayer(), e.getTown()); + } + @EventHandler public void onPlayerMorph(PlayerMorphEvent e) { @@ -219,11 +231,11 @@ public void onPlayerExit(PlayerQuitEvent e) this.unblockPlayer(e.getPlayer()); } - @EventHandler + @EventHandler(ignoreCancelled = true) public void onPlayerTeleport(PlayerTeleportEvent e) { if (e.getFrom().getWorld().equals(e.getTo().getWorld())) - this.updatePlayer(e.getPlayer(), null); + this.updatePlayer(e.getPlayer(), townyAPI.getTown(e.getTo())); } public void updatePlayer(Player player, @Nullable Town town)