From ef2553e6ac46e2db6d7831ab3f7f06d8fe70e3eb Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 11 Sep 2021 16:51:36 +0200 Subject: [PATCH] Fix Messagesystem for 1.8 --- .../src/de/steamwar/core/BountifulWrapper8.java | 10 ++++++++++ .../src/de/steamwar/core/BountifulWrapper9.java | 7 +++++++ .../src/de/steamwar/core/BountifulWrapper.java | 4 ++++ SpigotCore_Main/src/de/steamwar/message/Message.java | 6 ++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java b/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java index 2337739..8c08082 100644 --- a/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java +++ b/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java @@ -19,7 +19,12 @@ package de.steamwar.core; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; +import net.minecraft.server.v1_8_R3.ChatComponentText; +import net.minecraft.server.v1_8_R3.PacketPlayOutChat; import org.bukkit.Sound; +import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; import org.bukkit.entity.Player; public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { @@ -28,4 +33,9 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper { public void playPling(Player player) { player.playSound(player.getLocation(), Sound.ORB_PICKUP, 1, 1); } + + @Override + public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(new PacketPlayOutChat(new ChatComponentText(BaseComponent.toLegacyText(msg)), (byte)type.ordinal())); + } } diff --git a/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java b/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java index 632606c..d12a37d 100644 --- a/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java +++ b/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java @@ -19,6 +19,8 @@ package de.steamwar.core; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.Sound; import org.bukkit.entity.Player; @@ -28,4 +30,9 @@ public class BountifulWrapper9 implements BountifulWrapper.IBountifulWrapper { public void playPling(Player player) { player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1); } + + @Override + public void sendMessage(Player player, ChatMessageType type, BaseComponent... msg) { + player.spigot().sendMessage(type, msg); + } } diff --git a/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java b/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java index 26069de..8b22c31 100644 --- a/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java +++ b/SpigotCore_Main/src/de/steamwar/core/BountifulWrapper.java @@ -19,6 +19,8 @@ package de.steamwar.core; +import net.md_5.bungee.api.ChatMessageType; +import net.md_5.bungee.api.chat.BaseComponent; import org.bukkit.entity.Player; public class BountifulWrapper { @@ -28,5 +30,7 @@ public class BountifulWrapper { public interface IBountifulWrapper { void playPling(Player player); + + void sendMessage(Player player, ChatMessageType type, BaseComponent... msg); } } diff --git a/SpigotCore_Main/src/de/steamwar/message/Message.java b/SpigotCore_Main/src/de/steamwar/message/Message.java index e277ee1..efdf651 100644 --- a/SpigotCore_Main/src/de/steamwar/message/Message.java +++ b/SpigotCore_Main/src/de/steamwar/message/Message.java @@ -19,6 +19,7 @@ package de.steamwar.message; +import de.steamwar.core.BountifulWrapper; import de.steamwar.core.WorldOfColorWrapper; import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.chat.ClickEvent; @@ -108,10 +109,11 @@ public class Message { msg.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(onHover))); if(onClick != null) msg.setClickEvent(onClick); + if(sender instanceof Player) - ((Player)sender).spigot().sendMessage(type, msg); + BountifulWrapper.impl.sendMessage((Player)sender, type, msg); else - sender.spigot().sendMessage(msg); + sender.sendMessage(msg.toPlainText()); } /* Send message to all players */