13
0
geforkt von Mirrors/Paper

Deprecate ChatColor (#9069)

All API that uses it is deprecated
Dieser Commit ist enthalten in:
Jake Potrebic 2023-04-02 11:53:29 -07:00
Ursprung 7d091ee970
Commit 74b88dc367
7 geänderte Dateien mit 87 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -959,6 +959,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public static String getShutdownMessage() {
return server.getShutdownMessage();
}
diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/ChatColor.java
+++ b/src/main/java/org/bukkit/ChatColor.java
@@ -0,0 +0,0 @@ import org.jetbrains.annotations.Nullable;
/**
* All supported color values for chat
*/
+@Deprecated // Paper
public enum ChatColor {
/**
* Represents black
diff --git a/src/main/java/org/bukkit/Keyed.java b/src/main/java/org/bukkit/Keyed.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/Keyed.java
@ -1724,33 +1736,46 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
*
* @param message Message to be displayed
+ * @see #sendMessage(net.kyori.adventure.text.Component)
+ * @see #sendPlainMessage(String)
+ * @see #sendRichMessage(String)
*/
+ @org.jetbrains.annotations.ApiStatus.Obsolete // Paper
public void sendMessage(@NotNull String message);
@@ -0,0 +0,0 @@ public interface CommandSender extends Permissible {
/**
* Sends this sender multiple messages
*
* @param messages An array of messages to be displayed
+ * @see #sendMessage(net.kyori.adventure.text.Component)
+ * @see #sendPlainMessage(String)
+ * @see #sendRichMessage(String)
*/
+ @org.jetbrains.annotations.ApiStatus.Obsolete // Paper
public void sendMessage(@NotNull String... messages);
/**
@@ -0,0 +0,0 @@ public interface CommandSender extends Permissible {
*
* @param message Message to be displayed
* @param sender The sender of this message
+ * @see #sendMessage(net.kyori.adventure.identity.Identified, net.kyori.adventure.text.Component)
+ * @deprecated sender UUID is ignored
*/
+ @Deprecated // Paper
public void sendMessage(@Nullable UUID sender, @NotNull String message);
/**
@@ -0,0 +0,0 @@ public interface CommandSender extends Permissible {
*
* @param messages An array of messages to be displayed
* @param sender The sender of this message
+ * @see #sendMessage(net.kyori.adventure.identity.Identified, net.kyori.adventure.text.Component)
+ * @deprecated sender UUID is ignored
*/
+ @Deprecated // Paper
public void sendMessage(@Nullable UUID sender, @NotNull String... messages);
/**
@@ -0,0 +0,0 @@ public interface CommandSender extends Permissible {
* Sends this sender a chat component.
*
@ -1874,6 +1899,27 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/conversations/Conversable.java b/src/main/java/org/bukkit/conversations/Conversable.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/conversations/Conversable.java
+++ b/src/main/java/org/bukkit/conversations/Conversable.java
@@ -0,0 +0,0 @@ public interface Conversable {
*
* @param message Message to be displayed
*/
+ @org.jetbrains.annotations.ApiStatus.Obsolete // Paper
public void sendRawMessage(@NotNull String message);
/**
@@ -0,0 +0,0 @@ public interface Conversable {
*
* @param message Message to be displayed
* @param sender The sender of this message
+ * @deprecated sender UUID is ignored
*/
+ @Deprecated // Paper
public void sendRawMessage(@Nullable UUID sender, @NotNull String message);
}
diff --git a/src/main/java/org/bukkit/enchantments/Enchantment.java b/src/main/java/org/bukkit/enchantments/Enchantment.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/enchantments/Enchantment.java

Datei anzeigen

@ -692,6 +692,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return getLegacy(player.getHandle());
+ }
+
+ @SuppressWarnings("deprecation") // Valid suppress due to supporting legacy display name formatting
+ public static String getLegacy(final ServerPlayer player) {
+ final String legacy = player.displayName;
+ if (legacy != null) {

Datei anzeigen

@ -13,9 +13,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+package com.destroystokyo.paper.network;
+
+import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
+import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
+import net.minecraft.ChatFormatting;
+import net.minecraft.server.MinecraftServer;
+import org.apache.commons.lang3.StringUtils;
+import org.bukkit.ChatColor;
+
+import java.net.InetSocketAddress;
+
@ -68,13 +69,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return event;
+ }
+
+ @SuppressWarnings("deprecation") // Valid as this is the legacy status client
+ public static String getMotd(PaperServerListPingEvent event) {
+ return getFirstLine(event.getMotd());
+ }
+
+ public static String getUnformattedMotd(PaperServerListPingEvent event) {
+ // Strip color codes and all other occurrences of the color char (because it's used as delimiter)
+ return getFirstLine(StringUtils.remove(ChatColor.stripColor(event.getMotd()), ChatColor.COLOR_CHAR));
+ return getFirstLine(StringUtils.remove(PlainTextComponentSerializer.plainText().serialize(event.motd()), ChatFormatting.PREFIX_CODE));
+ }
+
+ private static String getFirstLine(String s) {

Datei anzeigen

@ -170,6 +170,19 @@ diff --git a/src/main/java/org/spigotmc/TicksPerSecondCommand.java b/src/main/ja
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/spigotmc/TicksPerSecondCommand.java
+++ b/src/main/java/org/spigotmc/TicksPerSecondCommand.java
@@ -0,0 +0,0 @@ public class TicksPerSecondCommand extends Command
this.usageMessage = "/tps";
this.setPermission( "bukkit.command.tps" );
}
+ // Paper start
+ private static final net.kyori.adventure.text.Component WARN_MSG = net.kyori.adventure.text.Component.text()
+ .append(net.kyori.adventure.text.Component.text("Warning: ", net.kyori.adventure.text.format.NamedTextColor.RED))
+ .append(net.kyori.adventure.text.Component.text("Memory usage on modern garbage collectors is not a stable value and it is perfectly normal to see it reach max. Please do not pay it much attention.", net.kyori.adventure.text.format.NamedTextColor.GOLD))
+ .build();
+ // Paper end
@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args)
@@ -0,0 +0,0 @@ public class TicksPerSecondCommand extends Command
return true;
}
@ -186,12 +199,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ for ( int i = 0; i < tps.length; i++) {
+ tpsAvg[i] = TicksPerSecondCommand.format( tps[i] );
+ }
+ sender.sendMessage(ChatColor.GOLD + "TPS from last 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", "));
+ sender.sendMessage(net.kyori.adventure.text.Component.text("TPS from last 1m, 5m, 15m: " + org.apache.commons.lang.StringUtils.join(tpsAvg, ", "), net.kyori.adventure.text.format.NamedTextColor.GOLD));
+ if (args.length > 0 && args[0].equals("mem") && sender.hasPermission("bukkit.command.tpsmemory")) {
+ sender.sendMessage(ChatColor.GOLD + "Current Memory Usage: " + ChatColor.GREEN + ((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) + "/" + (Runtime.getRuntime().totalMemory() / (1024 * 1024)) + " mb (Max: " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " mb)");
+ if (!hasShownMemoryWarning) {
+ sender.sendMessage(ChatColor.RED + "Warning: " + ChatColor.GOLD + " Memory usage on modern garbage collectors is not a stable value and it is perfectly normal to see it reach max. Please do not pay it much attention.");
+ hasShownMemoryWarning = true;
+ sender.sendMessage(net.kyori.adventure.text.Component.text()
+ .append(net.kyori.adventure.text.Component.text("Current Memory Usage: ", net.kyori.adventure.text.format.NamedTextColor.GOLD))
+ .append(net.kyori.adventure.text.Component.text(((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (1024 * 1024)) + "/" + (Runtime.getRuntime().totalMemory() / (1024 * 1024)) + " mb (Max: " + (Runtime.getRuntime().maxMemory() / (1024 * 1024)) + " mb)", net.kyori.adventure.text.format.NamedTextColor.GREEN))
+ );
+ if (!this.hasShownMemoryWarning) {
+ sender.sendMessage(WARN_MSG);
+ this.hasShownMemoryWarning = true;
+ }
}
- sender.sendMessage( sb.substring( 0, sb.length() - 2 ) );

Datei anzeigen

@ -15,11 +15,17 @@ diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/m
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -0,0 +0,0 @@ import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.resources.ResourceKey;
@@ -0,0 +0,0 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.audience.ForwardingAudience;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
+import net.minecraft.ChatFormatting;
import net.minecraft.Optionull;
import net.minecraft.Util;
import net.minecraft.core.registries.Registries;
@@ -0,0 +0,0 @@ import net.minecraft.resources.ResourceKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
+import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
@ -30,7 +36,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
static String legacyDisplayName(final CraftPlayer player) {
+ if (((org.bukkit.craftbukkit.CraftWorld) player.getWorld()).getHandle().paperConfig().scoreboards.useVanillaWorldScoreboardNameColoring) {
+ return legacySection().serialize(player.teamDisplayName()) + ChatColor.RESET;
+ return legacySection().serialize(player.teamDisplayName()) + ChatFormatting.RESET;
+ }
return player.getDisplayName();
}

Datei anzeigen

@ -3261,6 +3261,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ });
+ }
+
+ @SuppressWarnings("deprecation") // valid use to convert legacy string to mini-message in legacy migration
+ private static String miniMessage(final String input) {
+ return MiniMessage.miniMessage().serialize(LegacyComponentSerializer.legacySection().deserialize(ChatColor.translateAlternateColorCodes('&', input)));
+ }

Datei anzeigen

@ -34,6 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
// Paper start
+ @Override
+ @Deprecated
+ public void sendActionBar(BaseComponent[] message) {
+ if (getHandle().connection == null) return;
+ net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket packet = new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket((net.minecraft.network.chat.Component) null);
@ -42,12 +43,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ }
+
+ @Override
+ @Deprecated
+ public void sendActionBar(String message) {
+ if (getHandle().connection == null || message == null || message.isEmpty()) return;
+ getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSetActionBarTextPacket(CraftChatMessage.fromStringOrNull(message)));
+ }
+
+ @Override
+ @Deprecated
+ public void sendActionBar(char alternateChar, String message) {
+ if (message == null || message.isEmpty()) return;
+ sendActionBar(org.bukkit.ChatColor.translateAlternateColorCodes(alternateChar, message));