mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Allow anvil colors
This commit is contained in:
committed by
granny
parent
adb892fc2d
commit
42c95b8717
@@ -1,83 +0,0 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
||||||
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
|
|
||||||
Date: Tue, 4 Aug 2020 22:08:23 -0500
|
|
||||||
Subject: [PATCH] Allow anvil colors
|
|
||||||
|
|
||||||
|
|
||||||
diff --git a/net/minecraft/world/inventory/AnvilMenu.java b/net/minecraft/world/inventory/AnvilMenu.java
|
|
||||||
index f8c0a4fd95f341cbf8f6a06dfae408d505b0f018..a7c3338ed6edcd26fce869ec66fdcaa4c32c0e4f 100644
|
|
||||||
--- a/net/minecraft/world/inventory/AnvilMenu.java
|
|
||||||
+++ b/net/minecraft/world/inventory/AnvilMenu.java
|
|
||||||
@@ -285,6 +285,54 @@ public class AnvilMenu extends ItemCombinerMenu {
|
|
||||||
if (!this.itemName.equals(itemstack.getHoverName().getString())) {
|
|
||||||
b0 = 1;
|
|
||||||
i += b0;
|
|
||||||
+ // Purpur start
|
|
||||||
+ 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);
|
|
||||||
+ }
|
|
||||||
+ itemstack1.set(DataComponents.CUSTOM_NAME, io.papermc.paper.adventure.PaperAdventure.asVanilla(component));
|
|
||||||
+ }
|
|
||||||
+ else
|
|
||||||
+ // Purpur end
|
|
||||||
itemstack1.set(DataComponents.CUSTOM_NAME, Component.literal(this.itemName));
|
|
||||||
}
|
|
||||||
} else if (itemstack.has(DataComponents.CUSTOM_NAME)) {
|
|
||||||
diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
index efebca2a6dd217d853a27516c29be89421c1df68..7a7b8725f7a0b1a193b4e19510c386b46604f006 100644
|
|
||||||
--- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java
|
|
||||||
@@ -288,6 +288,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;
|
|
||||||
@@ -35,6 +35,13 @@ public final class PurpurPermissions {
|
|||||||
|
|
||||||
DefaultPermissions.registerPermission(PREFIX + "inventory_totem", "Allows the user to use totem of undying anywhere in their inventory", PermissionDefault.FALSE, purpur);
|
DefaultPermissions.registerPermission(PREFIX + "inventory_totem", "Allows the user to use totem of undying anywhere in their inventory", PermissionDefault.FALSE, purpur);
|
||||||
|
|
||||||
|
Permission anvil = DefaultPermissions.registerPermission(PREFIX + "anvil", "Allows the user to use all anvil color and format abilities", PermissionDefault.FALSE, purpur);
|
||||||
|
DefaultPermissions.registerPermission(PREFIX + "anvil.color", "Allows the user to use color codes in an anvil", PermissionDefault.FALSE, anvil);
|
||||||
|
DefaultPermissions.registerPermission(PREFIX + "anvil.minimessage", "Allows the user to use minimessage tags in an anvil", PermissionDefault.FALSE, anvil);
|
||||||
|
DefaultPermissions.registerPermission(PREFIX + "anvil.remove_italics", "Allows the user to remove italics in an anvil", PermissionDefault.FALSE, anvil);
|
||||||
|
DefaultPermissions.registerPermission(PREFIX + "anvil.format", "Allows the user to use format codes in an anvil", PermissionDefault.FALSE, anvil);
|
||||||
|
anvil.recalculatePermissibles();
|
||||||
|
|
||||||
Permission book = DefaultPermissions.registerPermission(PREFIX + "book", "Allows the user to use color codes on books", PermissionDefault.FALSE, purpur);
|
Permission book = DefaultPermissions.registerPermission(PREFIX + "book", "Allows the user to use color codes on books", PermissionDefault.FALSE, purpur);
|
||||||
DefaultPermissions.registerPermission(PREFIX + "book.color.edit", "Allows the user to use color codes on books when editing", PermissionDefault.FALSE, book);
|
DefaultPermissions.registerPermission(PREFIX + "book.color.edit", "Allows the user to use color codes on books when editing", PermissionDefault.FALSE, book);
|
||||||
DefaultPermissions.registerPermission(PREFIX + "book.color.sign", "Allows the user to use color codes on books when signing", PermissionDefault.FALSE, book);
|
DefaultPermissions.registerPermission(PREFIX + "book.color.sign", "Allows the user to use color codes on books when signing", PermissionDefault.FALSE, book);
|
||||||
|
|||||||
@@ -73,6 +73,61 @@
|
|||||||
i++;
|
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 @@
|
@@ -260,6 +_,12 @@
|
||||||
this.onlyRenaming = true;
|
this.onlyRenaming = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 boolean bedExplode = true;
|
||||||
public double bedExplosionPower = 5.0D;
|
public double bedExplosionPower = 5.0D;
|
||||||
public boolean bedExplosionFire = true;
|
public boolean bedExplosionFire = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user