From b937903ee19c7c0effe82567c87e3dcf299f0e7c Mon Sep 17 00:00:00 2001 From: jojo Date: Tue, 26 Jan 2021 11:14:46 +0100 Subject: [PATCH] Add TeamChat with '+' --- src/de/steamwar/misslewars/MWTeam.java | 2 +- .../misslewars/listener/ChatListener.java | 20 +++++++++++++++++-- .../listener/ConnectionListener.java | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index 760a393..e2042b1 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -128,6 +128,7 @@ public class MWTeam { if (!players.contains(p)) return; players.remove(p); + p.setDisplayName("§7" + p.getName()); sbteam.removePlayer(p); if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING) MissileWars.end(WinReasons.NO_ENEMY, enemy()); @@ -135,7 +136,6 @@ public class MWTeam { public void invitePlayer(Player p) { if (enemy().openInvitations.contains(p)) return; - openInvitations.add(p); } diff --git a/src/de/steamwar/misslewars/listener/ChatListener.java b/src/de/steamwar/misslewars/listener/ChatListener.java index 86f8d81..8df3095 100644 --- a/src/de/steamwar/misslewars/listener/ChatListener.java +++ b/src/de/steamwar/misslewars/listener/ChatListener.java @@ -20,7 +20,10 @@ package de.steamwar.misslewars.listener; import de.steamwar.misslewars.FightState; +import de.steamwar.misslewars.MWTeam; +import de.steamwar.misslewars.MissileWars; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.AsyncPlayerChatEvent; @@ -33,8 +36,21 @@ public class ChatListener extends BasicListener { } @EventHandler - public void onChat(AsyncPlayerChatEvent e){ - Bukkit.broadcastMessage(e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage()); + public void onChat(AsyncPlayerChatEvent e) { e.setCancelled(true); + + Player p = e.getPlayer(); + MWTeam team = MissileWars.getTeam(p); + String message = e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage(); + if (team == null) { + Bukkit.broadcastMessage(message); + } else { + if (e.getMessage().startsWith("+")) { + String teamMessage = "§8[" + team.getColorCode() + "TEAM§8] " + message; + team.getPlayers().forEach(player -> player.sendMessage(teamMessage)); + } else { + Bukkit.broadcastMessage(message); + } + } } } diff --git a/src/de/steamwar/misslewars/listener/ConnectionListener.java b/src/de/steamwar/misslewars/listener/ConnectionListener.java index 549393f..7e42772 100644 --- a/src/de/steamwar/misslewars/listener/ConnectionListener.java +++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java @@ -38,6 +38,7 @@ public class ConnectionListener extends BasicListener{ @EventHandler(priority = EventPriority.HIGH) public void onJoin(PlayerJoinEvent e) { + e.getPlayer().setDisplayName("§7" + e.getPlayer().getName()); e.getPlayer().setGameMode(GameMode.SPECTATOR); }