From b643889355612362387f740b943fed47be8a07dd Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 17 Oct 2020 17:43:03 +1100 Subject: [PATCH] #759: Allow sending messages from specific UUIDs By: Mariell Hoversholm --- .../command/CraftConsoleCommandSender.java | 6 +++++ .../command/ProxiedNativeCommandSender.java | 11 +++++++++ .../command/ServerCommandSender.java | 11 +++++++++ .../craftbukkit/entity/CraftEntity.java | 10 ++++++++ .../craftbukkit/entity/CraftPlayer.java | 23 +++++++++++++++++++ 5 files changed, 61 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java b/paper-server/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java index bfd21a0728..089fe4a345 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/command/CraftConsoleCommandSender.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.command; +import java.util.UUID; import org.bukkit.ChatColor; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.conversations.Conversation; @@ -28,6 +29,11 @@ public class CraftConsoleCommandSender extends ServerCommandSender implements Co System.out.println(ChatColor.stripColor(message)); } + @Override + public void sendRawMessage(UUID sender, String message) { + this.sendRawMessage(message); // Console doesn't know of senders + } + @Override public void sendMessage(String[] messages) { for (String message : messages) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java b/paper-server/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java index 477e920968..bafdde8a48 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/command/ProxiedNativeCommandSender.java @@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.command; import java.util.Set; +import java.util.UUID; import net.minecraft.server.CommandListenerWrapper; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -47,6 +48,16 @@ public class ProxiedNativeCommandSender implements ProxiedCommandSender { getCaller().sendMessage(messages); } + @Override + public void sendMessage(UUID sender, String message) { + getCaller().sendMessage(sender, message); + } + + @Override + public void sendMessage(UUID sender, String[] messages) { + getCaller().sendMessage(sender, messages); + } + @Override public Server getServer() { return getCallee().getServer(); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java b/paper-server/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java index 993b57b8dc..d977160273 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/command/ServerCommandSender.java @@ -1,6 +1,7 @@ package org.bukkit.craftbukkit.command; import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.command.CommandSender; @@ -79,4 +80,14 @@ public abstract class ServerCommandSender implements CommandSender { public Server getServer() { return Bukkit.getServer(); } + + @Override + public void sendMessage(UUID uuid, String message) { + this.sendMessage(message); // ServerCommandSenders have no use for senders + } + + @Override + public void sendMessage(UUID uuid, String[] messages) { + this.sendMessage(messages); // ServerCommandSenders have no use for senders + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 096011a2a2..1da70bfe8a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -793,6 +793,16 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { } + @Override + public void sendMessage(UUID sender, String message) { + this.sendMessage(message); // Most entities don't know about senders + } + + @Override + public void sendMessage(UUID sender, String[] messages) { + this.sendMessage(messages); // Most entities don't know about senders + } + @Override public String getName() { return CraftChatMessage.fromComponent(getHandle().getDisplayName()); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index c5f943d5a0..c50e2ae007 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -199,6 +199,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } + @Override + public void sendRawMessage(UUID sender, String message) { + if (getHandle().playerConnection == null) return; + + for (IChatBaseComponent component : CraftChatMessage.fromString(message)) { + getHandle().playerConnection.sendPacket(new PacketPlayOutChat(component, ChatMessageType.CHAT, (sender == null) ? SystemUtils.b : sender)); + } + } + @Override public void sendMessage(String message) { if (!conversationTracker.isConversingModaly()) { @@ -213,6 +222,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player { } } + @Override + public void sendMessage(UUID sender, String message) { + if (!conversationTracker.isConversingModaly()) { + this.sendRawMessage(sender, message); + } + } + + @Override + public void sendMessage(UUID sender, String[] messages) { + for (String message : messages) { + sendMessage(sender, message); + } + } + @Override public String getDisplayName() { return getHandle().displayName;