From 00d84825a9031aa307ce692a47774b400216eec6 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Thu, 21 Nov 2019 11:03:55 +0100 Subject: [PATCH] Using Chat-ChatMessageType for chat messages --- .../fightsystem/listener/BasicListener_12.java | 4 ++++ .../fightsystem/listener/BasicListener_8.java | 4 ++++ .../fightsystem/listener/BasicListener.java | 10 ++++++++++ .../fightsystem/listener/PlayerChatListener.java | 15 +++++++++++---- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/FightSystem_12/src/de/steamwar/fightsystem/listener/BasicListener_12.java b/FightSystem_12/src/de/steamwar/fightsystem/listener/BasicListener_12.java index 0137e62..9dc603b 100644 --- a/FightSystem_12/src/de/steamwar/fightsystem/listener/BasicListener_12.java +++ b/FightSystem_12/src/de/steamwar/fightsystem/listener/BasicListener_12.java @@ -13,6 +13,10 @@ class BasicListener_12 { player.spigot().sendMessage(ChatMessageType.ACTION_BAR, components); } + static void toChat(Player player, BaseComponent... components){ + player.spigot().sendMessage(ChatMessageType.CHAT, components); + } + static void setAttackSpeed(Player player){ AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); attribute.setBaseValue(16); diff --git a/FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java b/FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java index 2f42665..521f1a6 100644 --- a/FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java +++ b/FightSystem_8/src/de/steamwar/fightsystem/listener/BasicListener_8.java @@ -9,4 +9,8 @@ class BasicListener_8 { static void toActionbar(Player player, BaseComponent... components){ player.spigot().sendMessage(components); } + + static void toChat(Player player, BaseComponent... components){ + player.spigot().sendMessage(components); + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java index 67e6660..99867a4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/BasicListener.java @@ -63,4 +63,14 @@ public abstract class BasicListener implements Listener { BasicListener_12.setAttackSpeed(player); } } + + public static void toChat(Player player, BaseComponent... components){ + switch(Core.getVersion()){ + case 8: + BasicListener_8.toChat(player, components); + break; + default: + BasicListener_12.toChat(player, components); + } + } } diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java index 8b6957a..d6b5fab 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/listener/PlayerChatListener.java @@ -1,9 +1,11 @@ package de.steamwar.fightsystem.listener; +import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.Config; +import net.md_5.bungee.api.chat.BaseComponent; +import net.md_5.bungee.api.chat.TextComponent; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -23,15 +25,20 @@ public class PlayerChatListener extends BasicListener { if(message.startsWith(Config.TeamChatDetection)) { fightTeam.broadcast(teamName + " " + player.getName() + "» " + message.substring(1)); } else { - Bukkit.broadcastMessage(teamName + " " + player.getName() + "§8» §7" + message); + broadcastChat(teamName + " " + player.getName() + "§8» §7" + message); } }else if(player == FightSystem.getEventLeiter()){ - Bukkit.broadcastMessage("§e" + player.getName() + "§8» §e" + message); + broadcastChat("§e" + player.getName() + "§8» §e" + message); }else{ - Bukkit.broadcastMessage("§7" + player.getName() + "§8» §7" + message); + broadcastChat("§7" + player.getName() + "§8» §7" + message); } event.setCancelled(true); } + private void broadcastChat(String message){ + BaseComponent[] msg = TextComponent.fromLegacyText(message); + for(Player p : Bukkit.getOnlinePlayers()) + toChat(p, msg); + } } -- 2.39.5