Change implementation of String based Action Bar API

Appears colors did not work for Bungee version, as Action Bar is stricter
This commit is contained in:
Aikar 2016-12-27 15:06:14 -05:00
parent 64f6edc759
commit fc6f3510a2
2 changed files with 95 additions and 10 deletions

View File

@ -1,26 +1,22 @@
From 096901560b7ced2820b8f131d8633ccfab953a57 Mon Sep 17 00:00:00 2001 From bd017a4c0713a165504663f7b82f701eb43accda Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co> From: Aikar <aikar@aikar.co>
Date: Tue, 20 Dec 2016 15:55:55 -0500 Date: Tue, 20 Dec 2016 15:55:55 -0500
Subject: [PATCH] Add String based Action Bar API Subject: [PATCH] Add String based Action Bar API
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 083e60f..4d577a5 100644 index 083e60fa..528ed6c9 100644
--- a/src/main/java/org/bukkit/entity/Player.java --- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java
@@ -392,6 +392,12 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline @@ -392,6 +392,8 @@ public interface Player extends HumanEntity, Conversable, CommandSender, Offline
public void sendMap(MapView map); public void sendMap(MapView map);
// Paper start // Paper start
+ public default void sendActionBar(String message) { + public void sendActionBar(String message);
+ sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR, net.md_5.bungee.api.chat.TextComponent.fromLegacyText(message)); + public void sendActionBar(char alternateChar, String message);
+ }
+ public default void sendActionBar(char alternateChar, String message) {
+ sendMessage(net.md_5.bungee.api.ChatMessageType.ACTION_BAR, net.md_5.bungee.api.chat.TextComponent.fromLegacyText(org.bukkit.ChatColor.translateAlternateColorCodes(alternateChar, message)));
+ }
/** /**
* Sends the component to the player * Sends the component to the player
* *
-- --
2.9.3 2.11.0

View File

@ -0,0 +1,89 @@
From e084bdc8d74009aa017c01186ceda098027069d9 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 27 Dec 2016 15:02:42 -0500
Subject: [PATCH] String based Action Bar API
diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java
index fe7b476c0..117cfba80 100644
--- a/src/main/java/net/minecraft/server/MCUtil.java
+++ b/src/main/java/net/minecraft/server/MCUtil.java
@@ -1,10 +1,13 @@
package net.minecraft.server;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import org.apache.commons.lang.exception.ExceptionUtils;
import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.util.Waitable;
import org.spigotmc.AsyncCatcher;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
@@ -18,6 +21,24 @@ public final class MCUtil {
private MCUtil() {}
+ /**
+ * Quickly generate a stack trace for current location
+ *
+ * @return Stacktrace
+ */
+ public static String stack() {
+ return ExceptionUtils.getFullStackTrace(new Throwable());
+ }
+
+ /**
+ * Quickly generate a stack trace for current location with message
+ *
+ * @param str
+ * @return Stacktrace
+ */
+ public static String stack(String str) {
+ return ExceptionUtils.getFullStackTrace(new Throwable(str));
+ }
/**
* Builds a chat componenent from a string.
@@ -196,4 +217,13 @@ public final class MCUtil {
}
return null;
}
+
+ @Nonnull
+ public static World getNMSWorld(@Nonnull org.bukkit.World world) {
+ return ((CraftWorld) world).getHandle();
+ }
+
+ public static World getNMSWorld(@Nonnull org.bukkit.entity.Entity entity) {
+ return getNMSWorld(entity.getWorld());
+ }
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 3edeb4910..0f0056561 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -163,6 +163,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
// Paper start
@Override
+ public void sendActionBar(String message) {
+ if (getHandle().playerConnection == null || message == null || message.isEmpty()) return;
+ getHandle().playerConnection.sendPacket(new PacketPlayOutChat(net.minecraft.server.MCUtil.cmpFromMessage(message), (byte) 2));
+ }
+
+ @Override
+ public void sendActionBar(char alternateChar, String message) {
+ if (message == null || message.isEmpty()) return;
+ sendActionBar(org.bukkit.ChatColor.translateAlternateColorCodes(alternateChar, message));
+ }
+
+ @Override
public void setPlayerListHeaderFooter(BaseComponent[] header, BaseComponent[] footer) {
PacketPlayOutPlayerListHeaderFooter packet = new PacketPlayOutPlayerListHeaderFooter();
packet.header = header;
--
2.11.0