From b63f8f73cacbf9ed1daaf8b6b722c9db0a51157f Mon Sep 17 00:00:00 2001 From: Aikar 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 9f9341c98f..966309a07d 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.Queue; import java.util.concurrent.CompletableFuture; @@ -21,6 +24,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)); + } public static boolean isMainThread() { return MinecraftServer.getServer().isMainThread(); @@ -293,4 +314,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 03c262935d..2837fb87e5 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -209,6 +209,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(new net.minecraft.server.ChatComponentText(message), net.minecraft.server.ChatMessageType.GAME_INFO)); + } + + @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) { setPlayerListHeader(header == null ? null : net.md_5.bungee.chat.ComponentSerializer.toString(header)); -- 2.18.0