Files
ParchmentMC/patches/api/0006-Expanded-Adventure-support.patch
Blast-MC da7ff326fe 1.21
2024-06-23 20:12:32 -04:00

152 lines
5.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Mon, 5 Jul 2021 01:45:49 -0400
Subject: [PATCH] Expanded Adventure support
Adds support for Adventure in a few places where it was previously missing.
diff --git a/src/main/java/org/bukkit/ChatColor.java b/src/main/java/org/bukkit/ChatColor.java
index 918a045165cdcde264bc24082b7afebb407271de..3f912d3fbf5fdef3b95f81585d2fcf76719d2d04 100644
--- a/src/main/java/org/bukkit/ChatColor.java
+++ b/src/main/java/org/bukkit/ChatColor.java
@@ -13,7 +13,7 @@ import org.jetbrains.annotations.Nullable;
* @deprecated ChatColor has been deprecated in favor of <a href="https://docs.advntr.dev/text.html">Adventure</a> API. See {@link net.kyori.adventure.text.format.NamedTextColor} for the adventure equivalent of pre-defined text colors
*/
@Deprecated // Paper
-public enum ChatColor {
+public enum ChatColor implements net.kyori.adventure.text.format.StyleBuilderApplicable, net.kyori.adventure.text.format.TextFormat { // Parchment
/**
* Represents black
*/
@@ -183,6 +183,13 @@ public enum ChatColor {
public net.md_5.bungee.api.ChatColor asBungee() {
return net.md_5.bungee.api.ChatColor.MAGIC;
}
+
+ // Parchment start
+ @Override
+ public void styleApply(net.kyori.adventure.text.format.Style.@NotNull Builder style) {
+ style.apply(net.kyori.adventure.text.format.TextDecoration.OBFUSCATED);
+ }
+ // Parchment end
},
/**
* Makes the text bold.
@@ -213,6 +220,13 @@ public enum ChatColor {
public net.md_5.bungee.api.ChatColor asBungee() {
return net.md_5.bungee.api.ChatColor.UNDERLINE;
}
+
+ // Parchment start
+ @Override
+ public void styleApply(net.kyori.adventure.text.format.Style.@NotNull Builder style) {
+ style.apply(net.kyori.adventure.text.format.TextDecoration.UNDERLINED);
+ }
+ // Parchment end
},
/**
* Makes the text italic.
@@ -233,6 +247,16 @@ public enum ChatColor {
public net.md_5.bungee.api.ChatColor asBungee() {
return net.md_5.bungee.api.ChatColor.RESET;
}
+
+ // Parchment start
+ @Override
+ public void styleApply(net.kyori.adventure.text.format.Style.@NotNull Builder style) {
+ style.color(null);
+ for (net.kyori.adventure.text.format.TextDecoration decoration : net.kyori.adventure.text.format.TextDecoration.values()) {
+ style.decoration(decoration, net.kyori.adventure.text.format.TextDecoration.State.NOT_SET);
+ }
+ }
+ // Parchment end
};
/**
@@ -265,6 +289,16 @@ public enum ChatColor {
return net.md_5.bungee.api.ChatColor.RESET;
};
+ // Parchment start
+ @Override
+ public void styleApply(net.kyori.adventure.text.format.Style.@NotNull Builder style) {
+ if (isColor())
+ style.color(net.kyori.adventure.text.format.TextColor.color(asBungee().getColor().getRGB()));
+ else
+ style.decorate(net.kyori.adventure.text.format.TextDecoration.valueOf(name()));
+ }
+ // Parchment end
+
/**
* Gets the char value associated with this color
*
diff --git a/src/main/java/org/bukkit/Color.java b/src/main/java/org/bukkit/Color.java
index f8edb964c4af597b03a2de06c464cc06a96b791c..3957d290c606a50b59c7c421ea7c163f4625449c 100644
--- a/src/main/java/org/bukkit/Color.java
+++ b/src/main/java/org/bukkit/Color.java
@@ -17,7 +17,7 @@ import org.jetbrains.annotations.Nullable;
* but subject to change.
*/
@SerializableAs("Color")
-public final class Color implements ConfigurationSerializable {
+public final class Color implements ConfigurationSerializable, net.kyori.adventure.text.format.TextColor { // Parchment
private static final int BIT_MASK = 0xff;
private static final int DEFAULT_ALPHA = 255;
@@ -310,6 +310,13 @@ public final class Color implements ConfigurationSerializable {
return getAlpha() << 24 | getRed() << 16 | getGreen() << 8 | getBlue();
}
+ // Parchment start
+ @Override
+ public int value() {
+ return asRGB();
+ }
+ // Parchment end
+
/**
* Gets the color as an BGR integer.
*
diff --git a/src/main/java/org/bukkit/DyeColor.java b/src/main/java/org/bukkit/DyeColor.java
index 47df858e095c4423c20e49e029d72f0f50d2c924..c7504e017bc57df6903a2d76ce98e9fd4c35a7cc 100644
--- a/src/main/java/org/bukkit/DyeColor.java
+++ b/src/main/java/org/bukkit/DyeColor.java
@@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
/**
* All supported color values for dyes and cloth
*/
-public enum DyeColor {
+public enum DyeColor implements net.kyori.adventure.util.RGBLike, net.kyori.adventure.text.format.StyleBuilderApplicable { // Parchment
/**
* Represents white dye.
@@ -135,6 +135,28 @@ public enum DyeColor {
return firework;
}
+ // Parchment start
+ @Override
+ public @org.jetbrains.annotations.Range(from = 0L, to = 255L) int red() {
+ return color.getRed();
+ }
+
+ @Override
+ public @org.jetbrains.annotations.Range(from = 0L, to = 255L) int green() {
+ return color.getGreen();
+ }
+
+ @Override
+ public @org.jetbrains.annotations.Range(from = 0L, to = 255L) int blue() {
+ return color.getBlue();
+ }
+
+ @Override
+ public void styleApply(net.kyori.adventure.text.format.Style.@org.jetbrains.annotations.NotNull Builder style) {
+ style.color(net.kyori.adventure.text.format.TextColor.color(color));
+ }
+ // Parchment end
+
/**
* Gets the DyeColor with the given wool data value.
*