Allow anvil colors

This commit is contained in:
William Blake Galbreath
2025-01-07 18:21:41 -08:00
committed by granny
parent adb892fc2d
commit 42c95b8717
4 changed files with 69 additions and 83 deletions

View File

@@ -73,6 +73,61 @@
i++;
}
}
@@ -236,6 +_,54 @@
if (!this.itemName.equals(item.getHoverName().getString())) {
i1 = 1;
i += i1;
+ // Purpur start - Allow anvil colors
+ 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")) {
+ if (name.startsWith("&r")) {
+ name = name.substring(2);
+ removeItalics = true;
+ } else if (name.startsWith("<r>")) {
+ name = name.substring(3);
+ removeItalics = true;
+ } else if (name.startsWith("<reset>")) {
+ name = name.substring(7);
+ removeItalics = true;
+ }
+ }
+ if (this.player.level().purpurConfig.anvilAllowColors) {
+ if (player.hasPermission("purpur.anvil.color")) {
+ java.util.regex.Matcher matcher = java.util.regex.Pattern.compile("(?i)&([0-9a-fr])").matcher(name);
+ while (matcher.find()) {
+ String match = matcher.group(1);
+ name = name.replace("&" + match, "\u00a7" + match.toLowerCase(java.util.Locale.ROOT));
+ }
+ //name = name.replaceAll("(?i)&([0-9a-fr])", "\u00a7$1");
+ }
+ if (player.hasPermission("purpur.anvil.format")) {
+ java.util.regex.Matcher matcher = java.util.regex.Pattern.compile("(?i)&([k-or])").matcher(name);
+ while (matcher.find()) {
+ String match = matcher.group(1);
+ name = name.replace("&" + match, "\u00a7" + match.toLowerCase(java.util.Locale.ROOT));
+ }
+ //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(org.bukkit.ChatColor.stripColor(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);
+ }
+ itemStack.set(DataComponents.CUSTOM_NAME, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
+ }
+ else
+ // Purpur end - Allow anvil colors
itemStack.set(DataComponents.CUSTOM_NAME, Component.literal(this.itemName));
}
} else if (item.has(DataComponents.CUSTOM_NAME)) {
@@ -260,6 +_,12 @@
this.onlyRenaming = true;
}

View File

@@ -277,6 +277,13 @@ public class PurpurWorldConfig {
});
}
public boolean anvilAllowColors = false;
public boolean anvilColorsUseMiniMessage;
private void anvilSettings() {
anvilAllowColors = getBoolean("blocks.anvil.allow-colors", anvilAllowColors);
anvilColorsUseMiniMessage = getBoolean("blocks.anvil.use-mini-message", anvilColorsUseMiniMessage);
}
public boolean bedExplode = true;
public double bedExplosionPower = 5.0D;
public boolean bedExplosionFire = true;