From 53901654a9d4d6d298279c7a8067c695256e1f7f Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 25 Feb 2022 11:50:32 +0100 Subject: [PATCH] Fix double death error by rearranging death event sequence Signed-off-by: Lixfel --- .../fightsystem/utils/BountifulWrapper9.java | 2 +- .../fightsystem/listener/IngameDeath.java | 52 +++++++++---------- .../fightsystem/listener/Permanent.java | 8 ++- .../fightsystem/listener/Recording.java | 31 +++++------ .../fightsystem/listener/Shutdown.java | 3 +- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java index 8e86735..20c7aa4 100644 --- a/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java +++ b/FightSystem_9/src/de/steamwar/fightsystem/utils/BountifulWrapper9.java @@ -100,7 +100,7 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { @Override public Listener newHandSwapRecorder() { return new Listener() { - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onItemSwap(PlayerSwapHandItemsEvent e){ if(Recording.isNotSent(e.getPlayer())) return; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java index 822380e..75d80cf 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/IngameDeath.java @@ -20,15 +20,12 @@ package de.steamwar.fightsystem.listener; import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightPlayer; -import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import de.steamwar.fightsystem.utils.FightUI; import de.steamwar.fightsystem.utils.SWSound; -import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -36,41 +33,42 @@ import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; +import java.util.function.Consumer; + public class IngameDeath implements Listener { public IngameDeath() { new StateDependentListener(ArenaMode.AntiReplay, FightState.Ingame, this); } - @EventHandler(priority = EventPriority.HIGH) - public void handlePlayerDeath(PlayerDeathEvent event) { - event.setDeathMessage(null); - - Player player = event.getEntity(); - FightTeam team = Fight.getPlayerTeam(player); - - if(team == null) - return; - - FightUI.addSubtitle("UI_PLAYER_DEATH", team.getPrefix(), player.getName()); - Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> team.getFightPlayer(player).setOut()); + @EventHandler + public void broadcastDeath(PlayerDeathEvent event) { + onPlayerEnd(event.getEntity(), fightPlayer -> { + FightUI.addSubtitle("UI_PLAYER_DEATH", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName()); + Fight.playSound(SWSound.ENTITY_WITHER_DEATH.getSound(), 100.0F, 1.0F); + }); } - @EventHandler(priority = EventPriority.HIGH) + @EventHandler + public void broadcastQuit(PlayerQuitEvent event) { + onPlayerEnd(event.getPlayer(), fightPlayer -> FightUI.addSubtitle("UI_PLAYER_LEAVE", fightPlayer.getTeam().getPrefix(), fightPlayer.getPlayer().getName())); + } + + @EventHandler(priority = EventPriority.MONITOR) + public void handlePlayerDeath(PlayerDeathEvent event) { + onPlayerEnd(event.getEntity(), FightPlayer::setOut); + } + + @EventHandler(priority = EventPriority.MONITOR) public void handlePlayerQuit(PlayerQuitEvent event) { - event.setQuitMessage(null); + onPlayerEnd(event.getPlayer(), FightPlayer::setOut); + } - Player player = event.getPlayer(); - FightTeam team = Fight.getPlayerTeam(player); - if(team == null) + private void onPlayerEnd(Player player, Consumer withLivingPlayer) { + FightPlayer fightPlayer = Fight.getFightPlayer(player); + if(fightPlayer == null || !fightPlayer.isLiving()) return; - FightPlayer fightPlayer = team.getFightPlayer(player); - if(!fightPlayer.isLiving()) - return; - - FightUI.addSubtitle("UI_PLAYER_LEAVE", team.getPrefix(), player.getName()); - Bukkit.getScheduler().runTask(FightSystem.getPlugin(), () -> team.getFightPlayer(player).setOut()); + withLivingPlayer.accept(fightPlayer); } } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java index 1b242a0..c411722 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Permanent.java @@ -34,6 +34,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.SpawnerSpawnEvent; import org.bukkit.event.inventory.CraftItemEvent; import org.bukkit.event.inventory.FurnaceSmeltEvent; @@ -81,7 +82,12 @@ public class Permanent implements Listener { REntity.playerJoins(player); } - @EventHandler + @EventHandler(priority = EventPriority.MONITOR) + public void handlePlayerDeath(PlayerDeathEvent event) { + event.setDeathMessage(null); + } + + @EventHandler(priority = EventPriority.MONITOR) public void handlePlayerLeave(PlayerQuitEvent event) { event.setQuitMessage(null); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java index 0b158b6..6d961a4 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Recording.java @@ -133,7 +133,7 @@ public class Recording implements Listener { return packet; } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerMove(PlayerMoveEvent e){ if(isNotSent(e.getPlayer())) return; @@ -141,15 +141,12 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entityMoves(e.getPlayer()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerDeath(PlayerDeathEvent e){ - if(isNotSent(e.getEntity())) - return; - + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { GlobalRecorder.getInstance().entityDespawns(e.getEntity()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler public void onPlayerQuit(PlayerQuitEvent e){ if(isNotSent(e.getPlayer())) return; @@ -157,13 +154,13 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entityDespawns(e.getPlayer()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockPhysics(BlockPhysicsEvent e){ if(FlatteningWrapper.impl.doRecord(e)) GlobalRecorder.getInstance().blockChange(e.getBlock()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onSneak(PlayerToggleSneakEvent e){ if(isNotSent(e.getPlayer())) return; @@ -171,7 +168,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().playerSneak(e.getPlayer(), e.isSneaking()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onAnimation(PlayerAnimationEvent e){ if(isNotSent(e.getPlayer())) return; @@ -180,7 +177,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().entityAnimation(e.getPlayer(), AIR); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityDamage(EntityDamageEvent e) { if(e.getEntityType() != EntityType.PLAYER) return; @@ -195,7 +192,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().setOnFire(p, false); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onEntityCombust(EntityCombustEvent e) { if(e.getEntityType() != EntityType.PLAYER) return; @@ -207,7 +204,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().setOnFire(p, false); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onTNTSpawn(EntitySpawnEvent e){ if(e.getEntityType() != EntityType.PRIMED_TNT) return; @@ -215,7 +212,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().tntSpawn(e.getEntity()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onExplosion(EntityExplodeEvent e){ if(e.getEntityType() != EntityType.PRIMED_TNT) return; @@ -226,7 +223,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().sound(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), SWSound.ENTITY_GENERIC_EXPLODE, "BLOCKS", 4.0F, (1.0F + (random.nextFloat() - random.nextFloat()) * 0.2F) * 0.7F); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onItem(PlayerItemHeldEvent e){ if(isNotSent(e.getPlayer())) return; @@ -234,7 +231,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().item(e.getPlayer(), disarmNull(e.getPlayer().getInventory().getItem(e.getNewSlot())), "MAINHAND"); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onProjectileSpawn(ProjectileLaunchEvent e){ if(e.getEntityType() == EntityType.FIREBALL) GlobalRecorder.getInstance().fireballSpawn(e.getEntity()); @@ -242,7 +239,7 @@ public class Recording implements Listener { GlobalRecorder.getInstance().arrowSpawn(e.getEntity()); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent e){ Player player = (Player) e.getWhoClicked(); if(isNotSent(player)) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java index e088314..714cfdf 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/listener/Shutdown.java @@ -25,7 +25,6 @@ import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.StateDependentListener; import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerQuitEvent; @@ -35,7 +34,7 @@ public class Shutdown implements Listener { new StateDependentListener(ArenaMode.AntiEvent, FightState.All, this); } - @EventHandler(priority = EventPriority.HIGH) + @EventHandler public void handlePlayerQuit(PlayerQuitEvent event) { if(Config.replayserver()) return;