Split allowUnsafeEnchants setting (#1047)

Co-authored-by: BillyGalbreath <blake.galbreath@gmail.com>
This commit is contained in:
Krakenied
2022-07-09 04:37:43 +02:00
committed by GitHub
parent 6061e12e23
commit 023416e380
11 changed files with 65 additions and 47 deletions

View File

@@ -27,37 +27,40 @@ index 7c012f1e37b0085c0939797b0dae8996b4953ab8..155b0a1aa58b891e98a55e10f112f611
++i;
} else if (targets.size() == 1) {
diff --git a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
index 800df3b7c04ce7ed52f265d681e7752f63ae4ec7..c01faa0d2900230a323c7e1f41093c691fb394aa 100644
index 800df3b7c04ce7ed52f265d681e7752f63ae4ec7..33c33a953cdd47c30720225b10a5378f16daf225 100644
--- a/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
+++ b/src/main/java/net/minecraft/world/inventory/AnvilMenu.java
@@ -209,7 +209,7 @@ public class AnvilMenu extends ItemCombinerMenu {
@@ -209,7 +209,8 @@ public class AnvilMenu extends ItemCombinerMenu {
int i2 = (Integer) map1.get(enchantment);
i2 = l1 == i2 ? i2 + 1 : Math.max(i2, l1);
- boolean flag3 = canDoUnsafeEnchants || enchantment.canEnchant(itemstack); // Purpur
+ boolean flag3 = canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowUnsafeEnchants || enchantment.canEnchant(itemstack); // Purpur
+ boolean flag3 = canDoUnsafeEnchants || (org.purpurmc.purpur.PurpurConfig.allowUnsafeEnchants && org.purpurmc.purpur.PurpurConfig.allowInapplicableEnchants) || enchantment.canEnchant(itemstack); // Purpur
+ boolean flag4 = true; // Purpur
if (this.player.getAbilities().instabuild || itemstack.is(Items.ENCHANTED_BOOK)) {
flag3 = true;
@@ -221,7 +221,7 @@ public class AnvilMenu extends ItemCombinerMenu {
@@ -221,16 +222,16 @@ public class AnvilMenu extends ItemCombinerMenu {
Enchantment enchantment1 = (Enchantment) iterator1.next();
if (enchantment1 != enchantment && !enchantment.isCompatibleWith(enchantment1)) {
- flag3 = canDoUnsafeEnchants; // Purpur
+ flag3 = canDoUnsafeEnchants || org.purpurmc.purpur.PurpurConfig.allowUnsafeEnchants; // Purpur
+ flag4 = canDoUnsafeEnchants || (org.purpurmc.purpur.PurpurConfig.allowUnsafeEnchants && org.purpurmc.purpur.PurpurConfig.allowIncompatibleEnchants); // Purpur flag3 -> flag4
++i;
}
}
@@ -230,7 +230,7 @@ public class AnvilMenu extends ItemCombinerMenu {
- if (!flag3) {
+ if (!flag3 || !flag4) { // Purpur
flag2 = true;
} else {
flag1 = true;
- if (i2 > enchantment.getMaxLevel()) {
+ if (!org.purpurmc.purpur.PurpurConfig.allowUnsafeEnchants && i2 > enchantment.getMaxLevel()) { // Purpur
+ if ((!org.purpurmc.purpur.PurpurConfig.allowUnsafeEnchants || !org.purpurmc.purpur.PurpurConfig.allowHigherEnchantsLevels) && i2 > enchantment.getMaxLevel()) { // Purpur
i2 = enchantment.getMaxLevel();
}
@@ -333,7 +333,7 @@ public class AnvilMenu extends ItemCombinerMenu {
@@ -333,7 +334,7 @@ public class AnvilMenu extends ItemCombinerMenu {
sendAllDataToRemote(); // CraftBukkit - SPIGOT-6686: Always send completed inventory to stay in sync with client
this.broadcastChanges();
// Purpur start
@@ -84,23 +87,38 @@ index 5b79adf2e036b4e9c2abd7cea53f1ef064252d7a..520c76a7a2baa3091224c96580a861a6
this.getOrCreateTag().put(key, element);
}
diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
index 111bea3e08b998003ee4c8d81f61ab43247ca793..bd8c2caaf717621eda0427e4cdea240245180f1a 100644
index d4f66066dce1c6e4571ebefb68a4ef537718921c..79929c701983c1ac316c2623e3375175859cf068 100644
--- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java
+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java
@@ -278,6 +278,8 @@ public class PurpurConfig {
@@ -278,14 +278,32 @@ public class PurpurConfig {
public static boolean allowInfinityMending = false;
public static boolean allowCrossbowInfinity = false;
+ public static boolean allowUnsafeEnchants = false;
+ public static boolean allowInapplicableEnchants = true;
+ public static boolean allowIncompatibleEnchants = true;
+ public static boolean allowHigherEnchantsLevels = true;
+ public static boolean allowUnsafeEnchantCommand = false;
private static void enchantmentSettings() {
if (version < 5) {
boolean oldValue = getBoolean("settings.enchantment.allow-infinite-and-mending-together", false);
@@ -286,6 +288,8 @@ public class PurpurConfig {
set("settings.enchantment.allow-infinity-and-mending-together", oldValue);
set("settings.enchantment.allow-infinite-and-mending-together", null);
}
+ if (version < 30) {
+ boolean oldValue = getBoolean("settings.enchantment.allow-unsafe-enchants", false);
+ set("settings.enchantment.anvil.allow-unsafe-enchants", oldValue);
+ set("settings.enchantment.anvil.allow-inapplicable-enchants", true);
+ set("settings.enchantment.anvil.allow-incompatible-enchants", true);
+ set("settings.enchantment.anvil.allow-higher-enchants-levels", true);
+ set("settings.enchantment.allow-unsafe-enchants", null);
+ }
allowInfinityMending = getBoolean("settings.enchantment.allow-infinity-and-mending-together", allowInfinityMending);
allowCrossbowInfinity = getBoolean("settings.enchantment.allow-infinity-on-crossbow", allowCrossbowInfinity);
+ allowUnsafeEnchants = getBoolean("settings.enchantment.allow-unsafe-enchants", allowUnsafeEnchants);
+ allowUnsafeEnchants = getBoolean("settings.enchantment.anvil.allow-unsafe-enchants", allowUnsafeEnchants);
+ allowInapplicableEnchants = getBoolean("settings.enchantment.anvil.allow-inapplicable-enchants", allowInapplicableEnchants);
+ allowIncompatibleEnchants = getBoolean("settings.enchantment.anvil.allow-incompatible-enchants", allowIncompatibleEnchants);
+ allowHigherEnchantsLevels = getBoolean("settings.enchantment.anvil.allow-higher-enchants-levels", allowHigherEnchantsLevels);
+ allowUnsafeEnchantCommand = getBoolean("settings.enchantment.allow-unsafe-enchant-command", allowUnsafeEnchants); // allowUnsafeEnchants as default for backwards compatability
}