Paper/Spigot-API-Patches/0020-Add-BaseComponent-sendMessage-methods-to-CommandSend.patch
Aikar a8c28e1920
Initial Paper-API for Bukkit 1.13 Preview 4 - THIS IS NOT SERVER
This branch/commit is only useful to those who purely use a clean Bukkit/Spigot/Paper API
and does not use NMS/OBC references.

This will let you start updating your plugin to the latest 1.13 builds of Bukkit Preview (4 as of now)

Note that this release is not final!!! API breakages may occur!

It is up to you if you find use out of this work.
2018-07-14 21:53:22 -04:00

65 lines
2.3 KiB
Diff

From 59307ee0a977ee3d99fd9e44acb1bd3e5b040fc4 Mon Sep 17 00:00:00 2001
From: kashike <kashike@vq.lc>
Date: Tue, 8 Mar 2016 13:05:59 -0800
Subject: [PATCH] Add BaseComponent sendMessage methods to CommandSender
diff --git a/src/main/java/org/bukkit/command/CommandSender.java b/src/main/java/org/bukkit/command/CommandSender.java
index abf68a2c..fcb03b83 100644
--- a/src/main/java/org/bukkit/command/CommandSender.java
+++ b/src/main/java/org/bukkit/command/CommandSender.java
@@ -58,4 +58,30 @@ public interface CommandSender extends Permissible {
Spigot spigot();
// Spigot end
+
+ // Paper start
+ /**
+ * Sends the component to the sender
+ *
+ * <p>If this sender does not support sending full components then
+ * the component will be sent as legacy text.</p>
+ *
+ * @param component the component to send
+ */
+ default void sendMessage(net.md_5.bungee.api.chat.BaseComponent component) {
+ this.sendMessage(component.toLegacyText());
+ }
+
+ /**
+ * Sends an array of components as a single message to the sender
+ *
+ * <p>If this sender does not support sending full components then
+ * the components will be sent as legacy text.</p>
+ *
+ * @param components the components to send
+ */
+ default void sendMessage(net.md_5.bungee.api.chat.BaseComponent... components) {
+ this.sendMessage(new net.md_5.bungee.api.chat.TextComponent(components).toLegacyText());
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 5dbec412..5955b20c 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -399,6 +399,7 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
*
* @param component the components to send
*/
+ @Override
public default void sendMessage(net.md_5.bungee.api.chat.BaseComponent component) {
spigot().sendMessage(component);
}
@@ -408,6 +409,7 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
*
* @param components the components to send
*/
+ @Override
public default void sendMessage(net.md_5.bungee.api.chat.BaseComponent... components) {
spigot().sendMessage(components);
}
--
2.18.0