mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-20 18:07:43 +01:00
fix weirdness with the anvil colors patch
This commit is contained in:
@@ -5,32 +5,42 @@ Subject: [PATCH] Allow anvil colors
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
||||
index 0363d2263b2d6bd6166fa21d7849297e95eddd77..3dbef489a0bf27fbef95de599970141f4aa783f3 100644
|
||||
index 0363d2263b2d6bd6166fa21d7849297e95eddd77..92efc8caf43661b24e95653f7a43bc4cfa0f4110 100644
|
||||
--- a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
||||
+++ b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
|
||||
@@ -280,6 +280,26 @@ public class AnvilMenu extends ItemCombinerMenu {
|
||||
@@ -280,6 +280,36 @@ public class AnvilMenu extends ItemCombinerMenu {
|
||||
} else if (!this.itemName.equals(itemstack.getHoverName().getString())) {
|
||||
b1 = 1;
|
||||
i += b1;
|
||||
+ // Purpur start
|
||||
+ if (player != null && player.level.purpurConfig.anvilAllowColors) {
|
||||
+ org.bukkit.craftbukkit.entity.CraftHumanEntity bukkitPlayer = player.getBukkitEntity();
|
||||
+ final net.kyori.adventure.text.Component renameTextComponent;
|
||||
+ if (player.level.purpurConfig.anvilColorsUseMiniMessage && bukkitPlayer.hasPermission("purpur.anvil.minimessage")) {
|
||||
+ renameTextComponent = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(itemName);
|
||||
+ itemstack1.setHoverName(io.papermc.paper.adventure.PaperAdventure.asVanilla(renameTextComponent));
|
||||
+ } else if (itemName.startsWith("&r") && player.getBukkitEntity().hasPermission("purpur.anvil.remove_italics")) {
|
||||
+ renameTextComponent = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacyAmpersand().deserialize(itemName.substring(2)).decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, false);
|
||||
+ itemstack1.setHoverName(io.papermc.paper.adventure.PaperAdventure.asVanilla(renameTextComponent));
|
||||
+ } else if (bukkitPlayer.hasPermission("purpur.anvil.color")) {
|
||||
+ renameTextComponent = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacyAmpersand().deserialize(itemName);
|
||||
+ itemstack1.setHoverName(io.papermc.paper.adventure.PaperAdventure.asVanilla(renameTextComponent));
|
||||
+ } else if (player.getBukkitEntity().hasPermission("purpur.anvil.format")){
|
||||
+ itemName = itemName.replaceAll("(?i)&([l-or])", "\u00a7$1");
|
||||
+ renameTextComponent = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(itemName);
|
||||
+ itemstack1.setHoverName(io.papermc.paper.adventure.PaperAdventure.asVanilla(renameTextComponent));
|
||||
+ if (this.player != null) {
|
||||
+ org.bukkit.craftbukkit.entity.CraftHumanEntity player = this.player.getBukkitEntity();
|
||||
+ String name = this.itemName;
|
||||
+ boolean removeItalics = false;
|
||||
+ if (player.hasPermission("purpur.anvil.remove_italics") && (name.startsWith("&r") || name.startsWith("<r>") || name.startsWith("<reset>"))) {
|
||||
+ name = name.substring(2);
|
||||
+ removeItalics = true;
|
||||
+ }
|
||||
+ } else
|
||||
+ if (this.player.level.purpurConfig.anvilAllowColors) {
|
||||
+ if (player.hasPermission("purpur.anvil.color")) {
|
||||
+ name = name.replaceAll("(?i)&([0-9a-fr])", "\u00a7$1");
|
||||
+ }
|
||||
+ if (player.hasPermission("purpur.anvil.format")) {
|
||||
+ name = name.replaceAll("(?i)&([l-or])", "\u00a7$1");
|
||||
+ }
|
||||
+ }
|
||||
+ net.kyori.adventure.text.Component component;
|
||||
+ if (this.player.level.purpurConfig.anvilColorsUseMiniMessage && player.hasPermission("purpur.anvil.minimessage")) {
|
||||
+ component = net.kyori.adventure.text.minimessage.MiniMessage.miniMessage().deserialize(name);
|
||||
+ } else {
|
||||
+ component = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(name);
|
||||
+ }
|
||||
+ if (removeItalics) {
|
||||
+ component = component.decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, false);
|
||||
+ }
|
||||
+ itemstack1.setHoverName(io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
|
||||
+ }
|
||||
+ else
|
||||
+ // Purpur end
|
||||
itemstack1.setHoverName(Component.literal(this.itemName));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user