From 0416f4bfd2f3202d43387909e7d965da64edc14a Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Wed, 4 May 2022 11:00:06 -0400 Subject: [PATCH] no pvp damage event fix --- .../net/tylermurphy/hideAndSeek/game/Board.java | 7 ++++--- .../hideAndSeek/game/EventListener.java | 15 ++++++++++++--- src/main/resources/lang/localization_de-DE.yml | 1 + src/main/resources/lang/localization_en-US.yml | 1 + 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java index d569a7f..c08b779 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/Board.java @@ -20,6 +20,7 @@ package net.tylermurphy.hideAndSeek.game; import static net.tylermurphy.hideAndSeek.configuration.Config.*; +import static net.tylermurphy.hideAndSeek.configuration.Localization.message; import java.util.*; import java.util.stream.Collectors; @@ -271,9 +272,9 @@ public class Board { } private static String getTeam(Player player) { - if(isHider(player)) return ChatColor.GOLD + "HIDER"; - else if(isSeeker(player)) return ChatColor.RED + "SEEKER"; - else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR"; + if(isHider(player)) return message("HIDER_TEAM_NAME").toString(); + else if(isSeeker(player)) return message("SEEKER_TEAM_NAME").toString(); + else if(isSpectator(player)) return message("SPECTATOR_TEAM_NAME").toString(); else return ChatColor.WHITE + "UNKNOWN"; } diff --git a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java index 0c750fa..db97967 100644 --- a/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java +++ b/src/main/java/net/tylermurphy/hideAndSeek/game/EventListener.java @@ -189,9 +189,18 @@ public class EventListener implements Listener { } if(event.isCancelled()) return; if (player.getHealth() - event.getFinalDamage() < 0.5 || !pvpEnabled) { - if(!pvpEnabled && !Board.isSeeker(player)){ - event.setCancelled(true); - return; + if (event instanceof EntityDamageByEntityEvent && !pvpEnabled) { + Entity damager = ((EntityDamageByEntityEvent) event).getDamager(); + if (damager instanceof Player) { + Player atacker = (Player) damager; + if(!Board.isSeeker(atacker)){ + event.setCancelled(true); + return; + } + } else { + event.setCancelled(true); + return; + } } if (spawnPosition == null) return; event.setCancelled(true); diff --git a/src/main/resources/lang/localization_de-DE.yml b/src/main/resources/lang/localization_de-DE.yml index 26841d5..d560d24 100644 --- a/src/main/resources/lang/localization_de-DE.yml +++ b/src/main/resources/lang/localization_de-DE.yml @@ -58,6 +58,7 @@ Localization: STOP: "Das Spiel wurde gestoppt." HIDER_TEAM_NAME: "&6&lHIDER" SEEKER_TEAM_NAME: "&c&lSEEKER" + SPECTATOR_TEAM_NAME: "&8&lSPECTATOR" HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!" SEEKERS_SUBTITLE: "Finde alle Hider!" SPECTATOR_SUBTITLE: "Du bist mitten im spiel beigetreten." diff --git a/src/main/resources/lang/localization_en-US.yml b/src/main/resources/lang/localization_en-US.yml index 72719f2..1757877 100644 --- a/src/main/resources/lang/localization_en-US.yml +++ b/src/main/resources/lang/localization_en-US.yml @@ -59,6 +59,7 @@ Localization: STOP: "Game has been force stopped." HIDER_TEAM_NAME: "&6&lHIDER" SEEKER_TEAM_NAME: "&c&lSEEKER" + SPECTATOR_TEAM_NAME: "&8&lSPECTATOR" HIDERS_SUBTITLE: "Hide away from the seekers" SEEKERS_SUBTITLE: "Eliminate all hiders" SPECTATOR_SUBTITLE: "You joined mid-game."