From 6ccc15d51d849f6da6f81939d642bf810db078d4 Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 23 Nov 2021 14:28:42 +0100 Subject: [PATCH] more optimized? --- .../tilly/bedwars/listeners/PartyChatListener.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/rip/tilly/bedwars/listeners/PartyChatListener.java b/src/main/java/rip/tilly/bedwars/listeners/PartyChatListener.java index 4cbe5b0..7c5e371 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/PartyChatListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/PartyChatListener.java @@ -7,6 +7,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent; import rip.tilly.bedwars.BedWars; import rip.tilly.bedwars.managers.party.Party; import rip.tilly.bedwars.playerdata.PlayerData; +import rip.tilly.bedwars.playerdata.PlayerSettings; import rip.tilly.bedwars.utils.CC; public class PartyChatListener implements Listener { @@ -18,17 +19,23 @@ public class PartyChatListener implements Listener { Player player = event.getPlayer(); Party party = this.plugin.getPartyManager().getParty(player.getUniqueId()); PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()); + PlayerSettings settings = playerData.getPlayerSettings(); + + if (party == null && !settings.isPartyChatEnabled()) { + return; + } + String chatMessage = event.getMessage(); if (party != null) { - if (playerData.getPlayerSettings().isPartyChatEnabled()) { + if (settings.isPartyChatEnabled()) { event.setCancelled(true); String message = CC.translate("&9Party > &d" + player.getDisplayName() + "&f: " + chatMessage); party.broadcast(message); } - } else if (playerData.getPlayerSettings().isPartyChatEnabled()) { + } else if (settings.isPartyChatEnabled()) { event.setCancelled(true); player.sendMessage(CC.translate("&cSince you are not in a party we toggled your party chat to false!")); - playerData.getPlayerSettings().setPartyChatEnabled(!playerData.getPlayerSettings().isPartyChatEnabled()); + settings.setPartyChatEnabled(!settings.isPartyChatEnabled()); } } }