From 51d47b7879ed0ed95eb0435c976620093e803213 Mon Sep 17 00:00:00 2001 From: PuppyTransGirl <74014559+PuppyTransGirl@users.noreply.github.com> Date: Fri, 25 Sep 2026 16:00:59 +0200 Subject: [PATCH 1/4] feat(nms): add Minecraft 26.3 compatibility --- .../dev/lone/vanillacustomizer/nms/NMS.java | 10 ++- VanillaCustomizer-jar/pom.xml | 5 ++ VanillaCustomizer-nms-v26_3/pom.xml | 68 +++++++++++++++++++ .../nms/items/impl/v26_3.java | 48 +++++++++++++ pom.xml | 1 + 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 VanillaCustomizer-nms-v26_3/pom.xml create mode 100644 VanillaCustomizer-nms-v26_3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_3.java diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/NMS.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/NMS.java index 1605805..3d82115 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/NMS.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/NMS.java @@ -1,18 +1,21 @@ package dev.lone.vanillacustomizer.nms; -import beer.devs.fastnbt.nms.Version; import dev.lone.vanillacustomizer.Main; import dev.lone.vanillacustomizer.utils.Msg; import org.bukkit.Bukkit; import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Utility to initialize NMS wrappers and avoid Maven circular dependency problems. */ public class NMS { + private static final Pattern MINECRAFT_VERSION_PATTERN = Pattern.compile("\\(MC:\\s*([0-9]+(?:\\.[0-9]+)+)\\)"); + /** * Gets a suitable implementaion for the current Minecraft server version. * @@ -26,7 +29,10 @@ public class NMS @SuppressWarnings("unchecked") public static T findImplementation(@SuppressWarnings("unused") Class implClazz, Object nmsHolder, boolean ignoreError) { - String nmsVersion = Version.get().name(); + Matcher versionMatcher = MINECRAFT_VERSION_PATTERN.matcher(Bukkit.getServer().getVersion()); + String nmsVersion = versionMatcher.find() + ? "v" + versionMatcher.group(1).replace('.', '_') + : "UNKNOWN"; try { diff --git a/VanillaCustomizer-jar/pom.xml b/VanillaCustomizer-jar/pom.xml index 26b2ae2..0b950a2 100644 --- a/VanillaCustomizer-jar/pom.xml +++ b/VanillaCustomizer-jar/pom.xml @@ -128,6 +128,11 @@ VanillaCustomizer-nms-v1_21_11 1.0 + + dev.lone + VanillaCustomizer-nms-v26_3 + 1.0 + \ No newline at end of file diff --git a/VanillaCustomizer-nms-v26_3/pom.xml b/VanillaCustomizer-nms-v26_3/pom.xml new file mode 100644 index 0000000..2363e5f --- /dev/null +++ b/VanillaCustomizer-nms-v26_3/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + dev.lone + VanillaCustomizer + 1.0 + + + VanillaCustomizer-nms-v26_3 + + + 25 + 25 + [25,) + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 3.2.0 + + + + select-jdk-toolchain + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 25 + 25 + 25 + false + + + + ca.bkaw + paper-nms-maven-plugin + 1.5 + + + + + + + ca.bkaw + paper-nms + [26.3.build.1,26.3.build.9999) + provided + + + dev.lone + VanillaCustomizer-core + 1.0 + provided + + + diff --git a/VanillaCustomizer-nms-v26_3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_3.java b/VanillaCustomizer-nms-v26_3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_3.java new file mode 100644 index 0000000..9b21a33 --- /dev/null +++ b/VanillaCustomizer-nms-v26_3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_3.java @@ -0,0 +1,48 @@ +package dev.lone.vanillacustomizer.nms.items.impl; + +import dev.lone.vanillacustomizer.nms.items.IItemsNms; +import dev.lone.vanillacustomizer.nms.items.Rarity; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.level.block.Block; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.inventory.ItemStack; + +@SuppressWarnings("unused") +public class v26_3 implements IItemsNms +{ + @Override + public Rarity getRarity(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(bukkitItem); + return Rarity.values()[item.getRarity().ordinal()]; + } + + @Override + public float getDestroySpeed(ItemStack bukkitItem) + { + Block block = CraftMagicNumbers.getBlock(bukkitItem.getType()); + return block.defaultBlockState().getDestroySpeed(null, null); + } + + @Override + public int getNutrition(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.nutrition(); + return 0; + } + + @Override + public float getSaturation(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.saturation(); + return 0; + } +} diff --git a/pom.xml b/pom.xml index a0a8ade..8868b19 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,7 @@ VanillaCustomizer-nms-v1_21_8 VanillaCustomizer-nms-v1_21_10 VanillaCustomizer-nms-v1_21_11 + VanillaCustomizer-nms-v26_3 From 6503e30c1603bacd95771c12dea2d1c58ad7d47b Mon Sep 17 00:00:00 2001 From: PuppyTransGirl <74014559+PuppyTransGirl@users.noreply.github.com> Date: Fri, 25 Sep 2026 16:04:26 +0200 Subject: [PATCH 2/4] feat(nms): add Minecraft 26.1 and 26.2 compatibility --- VanillaCustomizer-jar/pom.xml | 17 ++++- VanillaCustomizer-nms-v26_1_1/pom.xml | 68 +++++++++++++++++++ .../nms/items/impl/v26_1_1.java | 48 +++++++++++++ VanillaCustomizer-nms-v26_1_2/pom.xml | 68 +++++++++++++++++++ .../nms/items/impl/v26_1_2.java | 48 +++++++++++++ VanillaCustomizer-nms-v26_2/pom.xml | 68 +++++++++++++++++++ .../nms/items/impl/v26_2.java | 48 +++++++++++++ pom.xml | 3 + 8 files changed, 367 insertions(+), 1 deletion(-) create mode 100644 VanillaCustomizer-nms-v26_1_1/pom.xml create mode 100644 VanillaCustomizer-nms-v26_1_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_1.java create mode 100644 VanillaCustomizer-nms-v26_1_2/pom.xml create mode 100644 VanillaCustomizer-nms-v26_1_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_2.java create mode 100644 VanillaCustomizer-nms-v26_2/pom.xml create mode 100644 VanillaCustomizer-nms-v26_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_2.java diff --git a/VanillaCustomizer-jar/pom.xml b/VanillaCustomizer-jar/pom.xml index 0b950a2..870a3a0 100644 --- a/VanillaCustomizer-jar/pom.xml +++ b/VanillaCustomizer-jar/pom.xml @@ -128,6 +128,21 @@ VanillaCustomizer-nms-v1_21_11 1.0 + + dev.lone + VanillaCustomizer-nms-v26_1_1 + 1.0 + + + dev.lone + VanillaCustomizer-nms-v26_1_2 + 1.0 + + + dev.lone + VanillaCustomizer-nms-v26_2 + 1.0 + dev.lone VanillaCustomizer-nms-v26_3 @@ -135,4 +150,4 @@ - \ No newline at end of file + diff --git a/VanillaCustomizer-nms-v26_1_1/pom.xml b/VanillaCustomizer-nms-v26_1_1/pom.xml new file mode 100644 index 0000000..a23ac0d --- /dev/null +++ b/VanillaCustomizer-nms-v26_1_1/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + dev.lone + VanillaCustomizer + 1.0 + + + VanillaCustomizer-nms-v26_1_1 + + + 25 + 25 + [25,) + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 3.2.0 + + + + select-jdk-toolchain + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 25 + 25 + 25 + false + + + + ca.bkaw + paper-nms-maven-plugin + 1.5 + + + + + + + ca.bkaw + paper-nms + [26.1.1.build.1,26.1.1.build.9999) + provided + + + dev.lone + VanillaCustomizer-core + 1.0 + provided + + + diff --git a/VanillaCustomizer-nms-v26_1_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_1.java b/VanillaCustomizer-nms-v26_1_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_1.java new file mode 100644 index 0000000..ce74ded --- /dev/null +++ b/VanillaCustomizer-nms-v26_1_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_1.java @@ -0,0 +1,48 @@ +package dev.lone.vanillacustomizer.nms.items.impl; + +import dev.lone.vanillacustomizer.nms.items.IItemsNms; +import dev.lone.vanillacustomizer.nms.items.Rarity; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.level.block.Block; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.inventory.ItemStack; + +@SuppressWarnings("unused") +public class v26_1_1 implements IItemsNms +{ + @Override + public Rarity getRarity(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(bukkitItem); + return Rarity.values()[item.getRarity().ordinal()]; + } + + @Override + public float getDestroySpeed(ItemStack bukkitItem) + { + Block block = CraftMagicNumbers.getBlock(bukkitItem.getType()); + return block.defaultBlockState().getDestroySpeed(null, null); + } + + @Override + public int getNutrition(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.nutrition(); + return 0; + } + + @Override + public float getSaturation(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.saturation(); + return 0; + } +} diff --git a/VanillaCustomizer-nms-v26_1_2/pom.xml b/VanillaCustomizer-nms-v26_1_2/pom.xml new file mode 100644 index 0000000..40c2ebc --- /dev/null +++ b/VanillaCustomizer-nms-v26_1_2/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + dev.lone + VanillaCustomizer + 1.0 + + + VanillaCustomizer-nms-v26_1_2 + + + 25 + 25 + [25,) + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 3.2.0 + + + + select-jdk-toolchain + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 25 + 25 + 25 + false + + + + ca.bkaw + paper-nms-maven-plugin + 1.5 + + + + + + + ca.bkaw + paper-nms + [26.1.2.build.1,26.1.2.build.9999) + provided + + + dev.lone + VanillaCustomizer-core + 1.0 + provided + + + diff --git a/VanillaCustomizer-nms-v26_1_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_2.java b/VanillaCustomizer-nms-v26_1_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_2.java new file mode 100644 index 0000000..999bbd3 --- /dev/null +++ b/VanillaCustomizer-nms-v26_1_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_1_2.java @@ -0,0 +1,48 @@ +package dev.lone.vanillacustomizer.nms.items.impl; + +import dev.lone.vanillacustomizer.nms.items.IItemsNms; +import dev.lone.vanillacustomizer.nms.items.Rarity; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.level.block.Block; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.inventory.ItemStack; + +@SuppressWarnings("unused") +public class v26_1_2 implements IItemsNms +{ + @Override + public Rarity getRarity(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(bukkitItem); + return Rarity.values()[item.getRarity().ordinal()]; + } + + @Override + public float getDestroySpeed(ItemStack bukkitItem) + { + Block block = CraftMagicNumbers.getBlock(bukkitItem.getType()); + return block.defaultBlockState().getDestroySpeed(null, null); + } + + @Override + public int getNutrition(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.nutrition(); + return 0; + } + + @Override + public float getSaturation(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.saturation(); + return 0; + } +} diff --git a/VanillaCustomizer-nms-v26_2/pom.xml b/VanillaCustomizer-nms-v26_2/pom.xml new file mode 100644 index 0000000..7da082e --- /dev/null +++ b/VanillaCustomizer-nms-v26_2/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + + dev.lone + VanillaCustomizer + 1.0 + + + VanillaCustomizer-nms-v26_2 + + + 25 + 25 + [25,) + + + + + + org.apache.maven.plugins + maven-toolchains-plugin + 3.2.0 + + + + select-jdk-toolchain + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.15.0 + + 25 + 25 + 25 + false + + + + ca.bkaw + paper-nms-maven-plugin + 1.5 + + + + + + + ca.bkaw + paper-nms + [26.2.build.1,26.2.build.9999) + provided + + + dev.lone + VanillaCustomizer-core + 1.0 + provided + + + diff --git a/VanillaCustomizer-nms-v26_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_2.java b/VanillaCustomizer-nms-v26_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_2.java new file mode 100644 index 0000000..8a820af --- /dev/null +++ b/VanillaCustomizer-nms-v26_2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v26_2.java @@ -0,0 +1,48 @@ +package dev.lone.vanillacustomizer.nms.items.impl; + +import dev.lone.vanillacustomizer.nms.items.IItemsNms; +import dev.lone.vanillacustomizer.nms.items.Rarity; +import net.minecraft.core.component.DataComponents; +import net.minecraft.world.food.FoodProperties; +import net.minecraft.world.level.block.Block; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.inventory.ItemStack; + +@SuppressWarnings("unused") +public class v26_2 implements IItemsNms +{ + @Override + public Rarity getRarity(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack item = CraftItemStack.asNMSCopy(bukkitItem); + return Rarity.values()[item.getRarity().ordinal()]; + } + + @Override + public float getDestroySpeed(ItemStack bukkitItem) + { + Block block = CraftMagicNumbers.getBlock(bukkitItem.getType()); + return block.defaultBlockState().getDestroySpeed(null, null); + } + + @Override + public int getNutrition(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.nutrition(); + return 0; + } + + @Override + public float getSaturation(ItemStack bukkitItem) + { + net.minecraft.world.item.ItemStack itemStack = CraftItemStack.asNMSCopy(bukkitItem); + FoodProperties foodProperties = itemStack.get(DataComponents.FOOD); + if(foodProperties != null) + return foodProperties.saturation(); + return 0; + } +} diff --git a/pom.xml b/pom.xml index 8868b19..85886c6 100644 --- a/pom.xml +++ b/pom.xml @@ -32,6 +32,9 @@ VanillaCustomizer-nms-v1_21_8 VanillaCustomizer-nms-v1_21_10 VanillaCustomizer-nms-v1_21_11 + VanillaCustomizer-nms-v26_1_1 + VanillaCustomizer-nms-v26_1_2 + VanillaCustomizer-nms-v26_2 VanillaCustomizer-nms-v26_3 From 1c79cf84de6a62f237ffa398b3e09b4ccee3a224 Mon Sep 17 00:00:00 2001 From: PuppyTransGirl <74014559+PuppyTransGirl@users.noreply.github.com> Date: Fri, 25 Sep 2026 21:36:28 +0200 Subject: [PATCH 3/4] feat(customizations): add affixes NBT ranges and ignore rules --- .../vanillacustomizer/Customizations.java | 36 ++++-- .../customization/Customization.java | 3 +- .../customization/changes/TextAffix.java | 69 +++++++++++ .../matchers/RuleNbtMatcher.java | 116 +++++++++++------- .../lone/vanillacustomizer/IgnoreCheck.java | 27 ++++ .../customization/changes/TextAffixCheck.java | 22 ++++ .../matchers/RuleNbtMatcherCheck.java | 26 ++++ 7 files changed, 245 insertions(+), 54 deletions(-) create mode 100644 VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/TextAffix.java create mode 100644 VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/IgnoreCheck.java create mode 100644 VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/changes/TextAffixCheck.java create mode 100644 VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcherCheck.java diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Customizations.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Customizations.java index 9181d6d..d253c59 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Customizations.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Customizations.java @@ -61,6 +61,8 @@ public void load() ConfigurationSection section = config.getConfigurationSection("customizations." + key); assert section != null; + customization.ignore = section.getBoolean("ignore", false); + if(!section.getBoolean("enabled", true)) continue; @@ -129,9 +131,12 @@ public void load() } case "nbt" -> { + Object value = rulesSection.get(matcherKey + ".value"); + if (value == null) + throwMissingProperty("nbt.value"); RuleNbtMatcher nbtMatcher = new RuleNbtMatcher( - rulesSection.getString(matcherKey + ".path"), - rulesSection.getString(matcherKey + ".value"), + getStringOrThrow(rulesSection, matcherKey + ".path"), + value, rulesSection.getString(matcherKey + ".type", "string") ); customization.addRule(nbtMatcher); @@ -192,13 +197,13 @@ public void load() } ConfigurationSection changesSection = section.getConfigurationSection("changes"); - if (changesSection == null) + if (changesSection == null && !customization.ignore) { Msg.error("Error: Customization '" + key + "' missing 'changes'. File: " + config.getPartialFilePath()); continue; } - for (String changeKey : changesSection.getKeys(false)) + for (String changeKey : changesSection == null ? Collections.emptySet() : changesSection.getKeys(false)) { try { @@ -215,6 +220,10 @@ public void load() String json = changesSection.getString(changeKey); customization.addChange(new RenamerJson(json)); } + case "name_prefix", "rename_prefix" -> customization.addChange(new TextAffix(false, getStringOrThrow(changesSection, changeKey), "")); + case "name_suffix", "rename_suffix" -> customization.addChange(new TextAffix(false, "", getStringOrThrow(changesSection, changeKey))); + case "lore_prefix" -> customization.addChange(new TextAffix(true, getStringOrThrow(changesSection, changeKey), "")); + case "lore_suffix" -> customization.addChange(new TextAffix(true, "", getStringOrThrow(changesSection, changeKey))); case "replace_word_display_name" -> { ConfigurationSection thisSection = changesSection.getConfigurationSection(changeKey); @@ -488,11 +497,12 @@ public void handle(ItemStack itemStack, Player player) boolean trackChanges = MainCommand.hasDebugTag(player); ChangeSession session = new ChangeSession(itemStack, player, trackChanges); - for (Map.Entry entry : customizations.entrySet()) - { - Customization customization = entry.getValue(); - customization.handle(session); - } + if (isIgnored(session)) + return; + + for (Customization customization : customizations.values()) + if (!customization.ignore) + customization.handle(session); // Warning! This doesn't edit the session data. Do not access use "customization" obj // after this line since it would result not updated with changes done by the API handlers. @@ -511,6 +521,14 @@ public void handle(ItemStack itemStack, Player player) } } + boolean isIgnored(ChangeSession session) + { + for (Customization customization : customizations.values()) + if (customization.ignore && customization.matchesAll(session)) + return true; + return false; + } + private static List getAllYmlFiles() { File cosmeticsDir = new File(Main.inst().getDataFolder().getAbsolutePath() + "/contents/"); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/Customization.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/Customization.java index efc9af3..9cdde4d 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/Customization.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/Customization.java @@ -18,6 +18,7 @@ public class Customization public List rules = new ArrayList<>(); public List changes = new ArrayList<>(); + public boolean ignore; public Customization(boolean ignoreInventoriesEnabled, boolean ignoreAnyCustomInventory, List ignoreInventoriesByTitle) { @@ -41,7 +42,7 @@ public void addChange(IChange change) changes.add(change); } - boolean matchesAll(ChangeSession session) + public boolean matchesAll(ChangeSession session) { InventoryView openInventory = session.getPlayer().getOpenInventory(); if(ignoreInventoriesEnabled) diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/TextAffix.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/TextAffix.java new file mode 100644 index 0000000..9d348f1 --- /dev/null +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/TextAffix.java @@ -0,0 +1,69 @@ +package dev.lone.vanillacustomizer.customization.changes; + +import beer.devs.fastnbt.nms.nbt.NItem; +import dev.lone.vanillacustomizer.ChangeSession; +import dev.lone.vanillacustomizer.utils.Comp; +import dev.lone.vanillacustomizer.utils.ConfigFile; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; + +import java.util.List; + +public class TextAffix implements IChange +{ + private final boolean lore; + private final String prefix; + private final String suffix; + + public TextAffix(boolean lore, String prefix, String suffix) + { + this.lore = lore; + this.prefix = ConfigFile.convertColor(prefix); + this.suffix = ConfigFile.convertColor(suffix); + } + + @Override + public void apply(ChangeSession session) + { + NItem nbt = session.nbt(); + if (lore) + { + List lines = nbt.getLoreCopy(); + if (lines == null) + return; + for (int i = 0; i < lines.size(); i++) + lines.set(i, Comp.componentToNms(decorate(Comp.nmsToComponent(lines.get(i)), session))); + nbt.setLore(lines); + } + else + { + Object name = nbt.getCustomName(); + if (name == null) + name = nbt.getItemName(); + Component component = Comp.nmsToComponent(name); + if (component == null) + return; + nbt.setCustomName(Comp.componentToJson(decorate(component, session))); + } + nbt.save(); + } + + private Component decorate(Component original, ChangeSession session) + { + return decorate(original, + Comp.text(IChange.replacePlaceholders(session, prefix)), + Comp.text(IChange.replacePlaceholders(session, suffix))); + } + + static Component decorate(Component original, Component prefix, Component suffix) + { + PlainTextComponentSerializer plain = PlainTextComponentSerializer.plainText(); + String text = plain.serialize(original); + // ponytail: A naturally matching edge is treated as already added; use a persistent marker if provenance matters. + if (!text.startsWith(plain.serialize(prefix))) + original = prefix.append(original); + if (!text.endsWith(plain.serialize(suffix))) + original = original.append(suffix); + return original; + } +} diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcher.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcher.java index 424f2b3..0bf5e3e 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcher.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcher.java @@ -8,19 +8,26 @@ import org.bukkit.ChatColor; import org.bukkit.inventory.ItemStack; +import java.util.ArrayList; +import java.util.List; +import java.util.function.DoublePredicate; + public class RuleNbtMatcher implements IRule { final String nbtPath; - Object nbtValue; + final Object nbtValue; + final List values = new ArrayList<>(); + final List bounds = new ArrayList<>(); String[] nbtPathSplit; NBTType nbtValueType; - public RuleNbtMatcher(String nbtPath, String nbtValueStr, String nbtValueTypeStr) + public RuleNbtMatcher(String nbtPath, Object nbtValue, String nbtValueTypeStr) { + if (nbtPath == null || nbtPath.isBlank() || nbtValue == null) + throw new IllegalArgumentException("nbt.path and nbt.value are required."); this.nbtPath = nbtPath; - this.nbtValue = nbtValueStr; String nbtTypeFixed = "NBTTag" + StringUtils.capitalize(nbtValueTypeStr.toLowerCase()); @@ -34,26 +41,39 @@ public RuleNbtMatcher(String nbtPath, String nbtValueStr, String nbtValueTypeStr ChatColor.GRAY + " Allowed: string, int, float, double, byte, short"); } - switch (nbtValueType) + List entries = nbtValue instanceof List ? (List) nbtValue : List.of(nbtValue); + if (entries.isEmpty()) + throw new IllegalArgumentException("nbt.value must contain at least one value for '" + nbtPath + "'."); + for (Object entry : entries) { - case NBTTagString: - break; - case NBTTagInt: - nbtValue = Integer.parseInt(nbtValueStr); - break; - case NBTTagFloat: - nbtValue = Float.parseFloat(nbtValueStr); - break; - case NBTTagDouble: - nbtValue = Double.parseDouble(nbtValueStr); - break; - case NBTTagByte: - nbtValue = Byte.parseByte(nbtValueStr); - break; - case NBTTagShort: - nbtValue = Short.parseShort(nbtValueStr); - break; + String value = String.valueOf(entry).trim(); + if (nbtValueType != NBTType.NBTTagString && value.matches("^(>=|<=|>|<).+")) + { + int operatorLength = value.charAt(1) == '=' ? 2 : 1; + String operator = value.substring(0, operatorLength); + double threshold = Double.parseDouble(value.substring(operatorLength).trim()); + bounds.add(actual -> switch (operator) + { + case ">=" -> actual >= threshold; + case "<=" -> actual <= threshold; + case ">" -> actual > threshold; + default -> actual < threshold; + }); + } + else + { + values.add(switch (nbtValueType) + { + case NBTTagInt -> Integer.parseInt(value); + case NBTTagFloat -> Float.parseFloat(value); + case NBTTagDouble -> Double.parseDouble(value); + case NBTTagByte -> Byte.parseByte(value); + case NBTTagShort -> Short.parseShort(value); + default -> String.valueOf(entry); + }); + } } + this.nbtValue = nbtValue instanceof List || values.isEmpty() ? nbtValue : values.get(0); this.nbtPathSplit = nbtPath.split("\\."); } @@ -72,21 +92,16 @@ public Object getNbtValue() public boolean matches(ItemStack item) { NBTItem nbt = new NBTItem(item); - if (!nbt.hasTag(nbtPathSplit[0])) - return false; - - NBTCompound currentCompound = nbt.getCompound(nbtPathSplit[0]); - if(currentCompound == null) - return false; - for (int i = 1; i < nbtPathSplit.length - 1; i++) + NBTCompound currentCompound = nbt; + for (int i = 0; i < nbtPathSplit.length - 1; i++) { - assert currentCompound != null; if (!currentCompound.hasTag(nbtPathSplit[i])) return false; currentCompound = currentCompound.getCompound(nbtPathSplit[i]); + if (currentCompound == null) + return false; } - assert currentCompound != null; if (!currentCompound.hasTag(nbtPathSplit[nbtPathSplit.length - 1])) return false; @@ -94,19 +109,32 @@ public boolean matches(ItemStack item) if (nbtType != nbtValueType) return false; - if (nbtType == NBTType.NBTTagString) - return (currentCompound.getString(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue)); - else if (nbtType == NBTType.NBTTagInt) - return (currentCompound.getInteger(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue)); - else if (nbtType == NBTType.NBTTagDouble) - return (currentCompound.getDouble(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue)); - else if (nbtType == NBTType.NBTTagFloat) - return (currentCompound.getFloat(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue)); - else if (nbtType == NBTType.NBTTagByte) - return (currentCompound.getByte(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue)); - else if (nbtType == NBTType.NBTTagShort) - return (currentCompound.getShort(nbtPathSplit[nbtPathSplit.length - 1]).equals(nbtValue)); - - return false; + Object actual = switch (nbtType) + { + case NBTTagString -> currentCompound.getString(nbtPathSplit[nbtPathSplit.length - 1]); + case NBTTagInt -> currentCompound.getInteger(nbtPathSplit[nbtPathSplit.length - 1]); + case NBTTagDouble -> currentCompound.getDouble(nbtPathSplit[nbtPathSplit.length - 1]); + case NBTTagFloat -> currentCompound.getFloat(nbtPathSplit[nbtPathSplit.length - 1]); + case NBTTagByte -> currentCompound.getByte(nbtPathSplit[nbtPathSplit.length - 1]); + case NBTTagShort -> currentCompound.getShort(nbtPathSplit[nbtPathSplit.length - 1]); + default -> null; + }; + return matchesValue(actual); + } + + boolean matchesValue(Object actual) + { + if (actual == null || (!values.isEmpty() && !values.contains(actual))) + return false; + if (!bounds.isEmpty()) + { + if (!(actual instanceof Number)) + return false; + double number = ((Number) actual).doubleValue(); + for (DoublePredicate bound : bounds) + if (!bound.test(number)) + return false; + } + return true; } } diff --git a/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/IgnoreCheck.java b/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/IgnoreCheck.java new file mode 100644 index 0000000..86cad92 --- /dev/null +++ b/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/IgnoreCheck.java @@ -0,0 +1,27 @@ +package dev.lone.vanillacustomizer; + +import dev.lone.vanillacustomizer.customization.Customization; +import org.bukkit.entity.Player; + +import java.lang.reflect.Proxy; +public class IgnoreCheck +{ + public static void main(String[] args) + { + Customizations customizations = new Customizations(); + Customization first = new Customization(false, false, null); + first.addRule(item -> true); + customizations.customizations.put("first", first); + + Customization ignore = new Customization(false, false, null); + ignore.ignore = true; + ignore.addRule(item -> true); + customizations.customizations.put("ignore", ignore); + + Player player = (Player) Proxy.newProxyInstance(Player.class.getClassLoader(), new Class[]{Player.class}, + (proxy, method, arguments) -> null); + if (!customizations.isIgnored(new ChangeSession(null, player, false))) + throw new AssertionError("Matching ignore rule was missed after another customization"); + System.out.println("Ignore rule check passed"); + } +} diff --git a/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/changes/TextAffixCheck.java b/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/changes/TextAffixCheck.java new file mode 100644 index 0000000..6d91508 --- /dev/null +++ b/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/changes/TextAffixCheck.java @@ -0,0 +1,22 @@ +package dev.lone.vanillacustomizer.customization.changes; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; + +public class TextAffixCheck +{ + public static void main(String[] args) + { + Component original = Component.text("Firstlore").color(NamedTextColor.RED); + Component result = TextAffix.decorate(original, Component.text("AAA"), Component.text("BBB")); + if (!PlainTextComponentSerializer.plainText().serialize(result).equals("AAAFirstloreBBB")) + throw new AssertionError("Affix text missing"); + if (!result.children().contains(original)) + throw new AssertionError("Original formatting lost"); + Component repeated = TextAffix.decorate(result, Component.text("AAA"), Component.text("BBB")); + if (!PlainTextComponentSerializer.plainText().serialize(repeated).equals("AAAFirstloreBBB")) + throw new AssertionError("Affixes duplicated on a second pass"); + System.out.println("Text affix checks passed"); + } +} diff --git a/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcherCheck.java b/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcherCheck.java new file mode 100644 index 0000000..2bdfda0 --- /dev/null +++ b/VanillaCustomizer-core/src/test/java/dev/lone/vanillacustomizer/customization/matchers/RuleNbtMatcherCheck.java @@ -0,0 +1,26 @@ +package dev.lone.vanillacustomizer.customization.matchers; + +import java.util.Arrays; + +public class RuleNbtMatcherCheck +{ + public static void main(String[] args) + { + check(new RuleNbtMatcher("itemsadder.id", Arrays.asList("spiritual_sand", "abnormal_slab"), "string").matchesValue("abnormal_slab")); + check(!new RuleNbtMatcher("itemsadder.id", Arrays.asList("spiritual_sand", "abnormal_slab"), "string").matchesValue("stone")); + RuleNbtMatcher range = new RuleNbtMatcher("ItemDamage.Value", Arrays.asList(">=15.5", "<25"), "int"); + check(range.matchesValue(16)); + check(!range.matchesValue(15)); + check(!range.matchesValue(25)); + RuleNbtMatcher scalar = new RuleNbtMatcher("x.y", "7", "int"); + check(scalar.matchesValue(7)); + check(scalar.getNbtValue().equals(7)); + System.out.println("NBT matcher checks passed"); + } + + private static void check(boolean result) + { + if (!result) + throw new AssertionError("NBT matcher check failed"); + } +} From 494175f6c99541e8eccacb7736129e85219b9a79 Mon Sep 17 00:00:00 2001 From: PuppyTransGirl <74014559+PuppyTransGirl@users.noreply.github.com> Date: Fri, 25 Sep 2026 21:53:47 +0200 Subject: [PATCH 4/4] chore: bump plugin version to 0.5 --- VanillaCustomizer-core/src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VanillaCustomizer-core/src/main/resources/plugin.yml b/VanillaCustomizer-core/src/main/resources/plugin.yml index 236cfd6..4e5cbc3 100644 --- a/VanillaCustomizer-core/src/main/resources/plugin.yml +++ b/VanillaCustomizer-core/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: VanillaCustomizer -version: 0.3 +version: 0.5 main: dev.lone.vanillacustomizer.Main api-version: 1.13 commands: