diff --git a/.assets/banner.png b/.assets/banner.png new file mode 100644 index 0000000..22234eb Binary files /dev/null and b/.assets/banner.png differ diff --git a/.assets/banner_big.png b/.assets/banner_big.png new file mode 100644 index 0000000..7168751 Binary files /dev/null and b/.assets/banner_big.png differ diff --git a/.assets/icon.png b/.assets/icon.png new file mode 100644 index 0000000..ff5fe45 Binary files /dev/null and b/.assets/icon.png differ diff --git a/.assets/product_page.png b/.assets/product_page.png new file mode 100644 index 0000000..2b57919 Binary files /dev/null and b/.assets/product_page.png differ diff --git a/.assets/screenshots/screen1.png b/.assets/screenshots/screen1.png new file mode 100644 index 0000000..3d442af Binary files /dev/null and b/.assets/screenshots/screen1.png differ diff --git a/.assets/screenshots/screen2.png b/.assets/screenshots/screen2.png new file mode 100644 index 0000000..3b5d6f6 Binary files /dev/null and b/.assets/screenshots/screen2.png differ diff --git a/.assets/screenshots/screen3.png b/.assets/screenshots/screen3.png new file mode 100644 index 0000000..5737734 Binary files /dev/null and b/.assets/screenshots/screen3.png differ diff --git a/.assets/screenshots/screen4.png b/.assets/screenshots/screen4.png new file mode 100644 index 0000000..95eba1f Binary files /dev/null and b/.assets/screenshots/screen4.png differ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe0770..0000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/.gitignore b/.gitignore index 2293b2e..151529c 100644 --- a/.gitignore +++ b/.gitignore @@ -111,9 +111,9 @@ buildNumber.properties # Common working directory run/ + +# My stuff /.cache/ -/output/ /.paper-nms/ -/custom_mapping.txt -/.assets/ -target \ No newline at end of file +/output/ + diff --git a/.mvn-exec/CopyFile.bat b/.mvn-exec/CopyFile.bat deleted file mode 100644 index e37fd65..0000000 --- a/.mvn-exec/CopyFile.bat +++ /dev/null @@ -1 +0,0 @@ -echo f | xcopy C:\Progetti\Minecraft\Spigot\VanillaCustomizer\output\VanillaCustomizer.jar C:\Progetti\Minecraft\TestServer\blank_template\1.20\plugins\VanillaCustomizer.jar /Y diff --git a/VanillaCustomizer-core/pom.xml b/VanillaCustomizer-core/pom.xml index 05c4892..6a7ccf4 100644 --- a/VanillaCustomizer-core/pom.xml +++ b/VanillaCustomizer-core/pom.xml @@ -5,13 +5,14 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 VanillaCustomizer-core + spigot-repo https://hub.spigotmc.org/nexus/content/repositories/snapshots/ @@ -25,34 +26,71 @@ https://oss.sonatype.org/content/groups/public - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ + sonatype + https://oss.sonatype.org/content/groups/public/ - matteodev - https://www.matteodev.it/spigot/public/maven/ + papermc + https://papermc.io/repo/repository/maven-public/ + + + sk89q-repo + https://maven.enginehub.org/repo/ + + + codemc + https://repo.codemc.org/repository/maven-public/ + + + jitpack.io + https://jitpack.io + + + + net.md-5 + bungeecord-chat + 1.20-R0.2 + provided + + + io.papermc.paper + paper-api + 1.21.1-R0.1-SNAPSHOT + provided + org.spigotmc - spigot-api - 1.19.2-R0.1-SNAPSHOT + spigot + 1.21.1-R0.1-SNAPSHOT provided - dev.lone + dev.lone.LoneLibs LoneLibs - 1.0.50 + 1.0 + system + ${jars_libs_folder}/LoneLibs.jar - com.comphenix.protocol + libs ProtocolLib - 5.1.0 - provided + 1.0 + system + ${jars_libs_folder}/ProtocolLib.jar + + org.jetbrains + annotations + 24.0.0 + compile + + + \ No newline at end of file diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/ChangeSession.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/ChangeSession.java index 9fc7205..279f1fa 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/ChangeSession.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/ChangeSession.java @@ -1,8 +1,11 @@ package dev.lone.vanillacustomizer; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; -import dev.lone.LoneLibs.annotations.Nullable; +import org.jetbrains.annotations.Nullable; import dev.lone.vanillacustomizer.customization.rules.RuleVanillaItemMatcher; +import dev.lone.vanillacustomizer.nms.NMS; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; +import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -10,20 +13,23 @@ import org.bukkit.inventory.meta.ItemMeta; public class ChangeSession { public final ItemStack item; + private final Player player; public final ItemStack originalItem; public ItemMeta meta; - public NBTItem nbt; + public NBTItem nbtLegacy; + public NItem nbt; public final boolean isVanilla; @Nullable private Boolean hasChanged_cached; - public ChangeSession(ItemStack item, boolean trackChanges) + public ChangeSession(ItemStack item, Player player, boolean trackChanges) { this.item = item; + this.player = player; if(trackChanges) this.originalItem = item.clone(); else @@ -32,6 +38,11 @@ public class ChangeSession isVanilla = RuleVanillaItemMatcher.satisfy(item); } + public Player getPlayer() + { + return player; + } + public ItemMeta refreshMeta() { // Meta always needs to be refreshed as Spigot caches it! @@ -39,16 +50,26 @@ public class ChangeSession return meta; } - private void refreshNbt() + private void refreshNBT() { - nbt = new NBTItem(item); + nbtLegacy = new NBTItem(item); + if(NMS.is_v1_1_20_5_or_greater) + nbt = new NItem(item); } - public NBTItem nbt() + public NBTItem nbtLegacy() + { + if(nbtLegacy != null) + return nbtLegacy; + refreshNBT(); + return nbtLegacy; + } + + public NItem nbt() { if(nbt != null) return nbt; - refreshNbt(); + refreshNBT(); return nbt; } @@ -59,12 +80,14 @@ public class ChangeSession public void saveNbt() { // nbt.saveMetaChanges(); // TODO: idk if I need to somehow save the data or not, probably new NBT api lib doesn't require it anymore. + if(nbt != null) + nbt.save(); } public void applyMeta() { this.item.setItemMeta(this.meta); - refreshNbt(); + refreshNBT(); } public boolean hasChanged() @@ -80,7 +103,7 @@ public class ChangeSession public void refreshAll() { - refreshNbt(); + refreshNBT(); refreshMeta(); } } 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 46ac7a6..9e8f28e 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Customizations.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Customizations.java @@ -2,7 +2,8 @@ package dev.lone.vanillacustomizer; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import dev.lone.LoneLibs.annotations.Nullable; +import dev.lone.vanillacustomizer.exception.InvalidCustomizationPropertyException; +import org.jetbrains.annotations.Nullable; import dev.lone.vanillacustomizer.api.VanillaCustomizerApi; import dev.lone.vanillacustomizer.commands.registered.MainCommand; import dev.lone.vanillacustomizer.customization.changes.*; @@ -39,13 +40,21 @@ public class Customizations { ConfigFile config = new ConfigFile(Main.inst(), false, file.toPath().toString(), false, false); - ConfigurationSection cosmeticsSection = config.getConfigurationSection("customizations"); - if (cosmeticsSection == null) // File has no rules + boolean ignoreInventoriesEnabled = config.getBoolean("settings.ignore_inventories.enabled"); + boolean ignoreAnyCustomInventory = ignoreInventoriesEnabled && config.getBoolean("settings.ignore_inventories.any_custom", false); + List ignoreInventoriesByTitle = ignoreInventoriesEnabled ? config.getStringList("settings.ignore_inventories.by_title"): null; + + ConfigurationSection customizationsSection = config.getConfigurationSection("customizations"); + if (customizationsSection == null) // File has no rules continue; - for (String key : cosmeticsSection.getKeys(false)) + for (String key : customizationsSection.getKeys(false)) { - Customization customization = new Customization(); + Customization customization = new Customization( + ignoreInventoriesEnabled, + ignoreAnyCustomInventory, + ignoreInventoriesByTitle + ); ConfigurationSection section = config.getConfigurationSection("customizations." + key); assert section != null; @@ -169,7 +178,7 @@ public class Customizations } catch (Throwable ex) { - if(ex instanceof InvalidCustomizationPropertyExtension) + if(ex instanceof InvalidCustomizationPropertyException) { Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath()); Main.msg.error(ex.getMessage()); @@ -282,10 +291,10 @@ public class Customizations } else if (tmp.length == 2) { - if (Utilz.isNumeric(tmp[1])) + if (Utils.isNumeric(tmp[1])) { enchant = Enchantment.getByName(tmp[0]); - enchantLevel = Utilz.parseInt(tmp[1], 1); + enchantLevel = Utils.parseInt(tmp[1], 1); if (enchant == null) enchant = Enchantment.getByKey(NamespacedKey.minecraft(tmp[0])); @@ -298,7 +307,7 @@ public class Customizations else if (tmp.length == 3) { enchant = Enchantment.getByKey(new NamespacedKey(tmp[0], tmp[1])); - enchantLevel = Utilz.parseInt(tmp[2], 1); + enchantLevel = Utils.parseInt(tmp[2], 1); } enchants.put(enchant, enchantLevel); @@ -324,7 +333,7 @@ public class Customizations } else if (tmp.length == 2) { - if (Utilz.isNumeric(tmp[1])) + if (Utils.isNumeric(tmp[1])) { enchant = Enchantment.getByName(tmp[0]); if (enchant == null) @@ -360,11 +369,11 @@ public class Customizations throwInvalidConfig(); @Nullable String attributeStr = getStringOrThrow(attributeSection, "attribute"); - Attribute attribute = Utilz.strToAttributeType(attributeStr); + Attribute attribute = Utils.strToAttributeType(attributeStr); if (attribute == null) throwInvalidPropertyValue("attribute"); @Nullable String slotStr = getStringOrThrow(attributeSection, "slot"); - EquipmentSlot slot = Utilz.strToVanillaEquipmentSlot(slotStr); + EquipmentSlot slot = Utils.strToVanillaEquipmentSlot(slotStr); if (slot == null) throwInvalidPropertyValue("slot"); @@ -422,7 +431,7 @@ public class Customizations } catch (Throwable ex) { - if(ex instanceof InvalidCustomizationPropertyExtension) + if(ex instanceof InvalidCustomizationPropertyException) { Main.msg.error("Error loading customization '" + key + "'. File: " + config.getPartialFilePath()); Main.msg.error(ex.getMessage()); @@ -451,22 +460,22 @@ public class Customizations private void throwInvalidConfig() { - throw new InvalidCustomizationPropertyExtension("Invalid configuration. Please check the tutorials."); + throw new InvalidCustomizationPropertyException("Invalid configuration. Please check the tutorials."); } private void throwMissingProperty(String name) { - throw new InvalidCustomizationPropertyExtension("Missing property '" + name + "'."); + throw new InvalidCustomizationPropertyException("Missing property '" + name + "'."); } private void throwInvalidPropertyValue(String name) { - throw new InvalidCustomizationPropertyExtension("Invalid value for property '" + name + "'."); + throw new InvalidCustomizationPropertyException("Invalid value for property '" + name + "'."); } private void throwInvalidPropertyValue(String name, String value) { - throw new InvalidCustomizationPropertyExtension("Invalid value for property '" + name + "' -> '" + value + "'."); + throw new InvalidCustomizationPropertyException("Invalid value for property '" + name + "' -> '" + value + "'."); } public void handle(ItemStack itemStack, Player player) @@ -475,7 +484,7 @@ public class Customizations return; boolean trackChanges = MainCommand.hasDebugTag(player); - ChangeSession session = new ChangeSession(itemStack, trackChanges); + ChangeSession session = new ChangeSession(itemStack, player, trackChanges); for (Map.Entry entry : customizations.entrySet()) { Customization customization = entry.getValue(); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/InvalidCustomizationPropertyExtension.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/InvalidCustomizationPropertyExtension.java deleted file mode 100644 index b2a2e7b..0000000 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/InvalidCustomizationPropertyExtension.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.lone.vanillacustomizer; - -public class InvalidCustomizationPropertyExtension extends IllegalArgumentException -{ - public InvalidCustomizationPropertyExtension(String text) - { - super(text); - } -} diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Main.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Main.java index f01a5e1..e779062 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Main.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/Main.java @@ -27,6 +27,7 @@ public final class Main extends JavaPlugin implements Listener // https://game8.co/games/Minecraft/archives/378457#hl_1 //DO NOT SET AS "final" OR SPIGOT.MC won't replace it. + @SuppressWarnings("unused") public static String b = "%%__USER__%%"; public static Msg msg; diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/CommandRun.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/CommandRun.java index 67309d4..70d9549 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/CommandRun.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/CommandRun.java @@ -1,6 +1,6 @@ package dev.lone.vanillacustomizer.commands; -import dev.lone.LoneLibs.annotations.NotNull; +import org.jetbrains.annotations.NotNull; import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/registered/MainCommand.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/registered/MainCommand.java index 14581d6..68df565 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/registered/MainCommand.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/commands/registered/MainCommand.java @@ -1,10 +1,10 @@ package dev.lone.vanillacustomizer.commands.registered; -import dev.lone.LoneLibs.annotations.NotNull; import dev.lone.vanillacustomizer.Main; import dev.lone.vanillacustomizer.commands.CommandRun; import dev.lone.vanillacustomizer.utils.SmallCaps; import fr.mrmicky.fastinv.FastInv; +import org.jetbrains.annotations.NotNull; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.Command; @@ -58,7 +58,11 @@ public class MainCommand extends CommandRun break; case "small": - + if(args.length < 2) + { + Main.msg.send(player, "Usage: /vanillacustomizer small "); + return; + } String text = args[1]; Main.msg.send(player, SmallCaps.apply(text)); break; @@ -130,6 +134,8 @@ public class MainCommand extends CommandRun @Override public List onTabComplete(@NotNull CommandSender sender, Command command, @NotNull String alias, @NotNull String[] args) { - return List.of("reload", "showdebugtag", "small", "debugmenu"); + if(args.length == 1) + return List.of("reload", "showdebugtag", "small", "debugmenu"); + return List.of(); } } 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 c347e1f..127a550 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 @@ -3,16 +3,29 @@ package dev.lone.vanillacustomizer.customization; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.vanillacustomizer.customization.changes.IChange; import dev.lone.vanillacustomizer.customization.rules.IRule; -import org.bukkit.inventory.ItemStack; +import dev.lone.vanillacustomizer.utils.Utils; +import org.apache.commons.io.FilenameUtils; +import org.bukkit.inventory.InventoryView; import java.util.ArrayList; import java.util.List; public class Customization { + public final boolean ignoreInventoriesEnabled; + public final boolean ignoreAnyCustomInventory; + public final List ignoreInventoriesByTitle; + public List rules = new ArrayList<>(); public List changes = new ArrayList<>(); + public Customization(boolean ignoreInventoriesEnabled, boolean ignoreAnyCustomInventory, List ignoreInventoriesByTitle) + { + this.ignoreAnyCustomInventory = ignoreAnyCustomInventory; + this.ignoreInventoriesByTitle = ignoreInventoriesByTitle; + this.ignoreInventoriesEnabled = ignoreInventoriesEnabled; + } + public boolean isEmpty() { return rules.isEmpty() && changes.isEmpty(); @@ -28,8 +41,24 @@ public class Customization changes.add(change); } - public boolean matchesAll(ChangeSession session) + boolean matchesAll(ChangeSession session) { + InventoryView openInventory = session.getPlayer().getOpenInventory(); + if(ignoreInventoriesEnabled) + { + if(ignoreAnyCustomInventory) + { + if(Utils.isCustomInventory(openInventory)) + return false; + } + + for (String wildcard : ignoreInventoriesByTitle) + { + if (FilenameUtils.wildcardMatch(openInventory.getTitle(), wildcard)) + return false; + } + } + for (IRule rule : rules) { if(!rule.matches(session)) diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesAdd.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesAdd.java index 24ef2a1..59dcecf 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesAdd.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesAdd.java @@ -6,8 +6,8 @@ import dev.lone.vanillacustomizer.ChangeSession; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.inventory.EquipmentSlot; -import dev.lone.LoneLibs.annotations.NotNull; -import dev.lone.LoneLibs.annotations.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.UUID; diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesRemove.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesRemove.java index f58777f..5517c7e 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesRemove.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/AttributesRemove.java @@ -6,12 +6,12 @@ import dev.lone.vanillacustomizer.ChangeSession; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.inventory.EquipmentSlot; -import dev.lone.LoneLibs.annotations.NotNull; -import dev.lone.LoneLibs.annotations.Nullable; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.UUID; -@Deprecated //TODO +@Deprecated //TODO implement this shit public class AttributesRemove implements IChange { Multimap modifiers; diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsert.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsert.java index d45a963..47835d9 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsert.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsert.java @@ -5,8 +5,12 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.LoneLibs.chat.Comp; +import dev.lone.vanillacustomizer.nms.NMS; import dev.lone.vanillacustomizer.utils.ConfigFile; +import dev.lone.vanillacustomizer.utils.Utils; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; +import java.util.ArrayList; import java.util.List; public class LoreInsert implements IChange @@ -23,10 +27,44 @@ public class LoreInsert implements IChange @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + List loreNMS = nbt.getLoreCopy(); + if (loreNMS == null) + { + loreNMS = new ArrayList<>(); + for (String line : lines) + loreNMS.add(Utils.jsonToNMS(IChange.replacePlaceholders(session, line))); + } + else + { + // If the index is correctly inside the already existing lore range I can put the new lines there. + if (index < loreNMS.size()) + { + int i = index; + for (String line : lines) + { + loreNMS.add(i, Utils.legacyToNMS(IChange.replacePlaceholders(session, line))); + i++; + } + } + else // If it's out of bounds I just append at the end. + { + for (String line : lines) + loreNMS.add(Comp.legacyToJson(IChange.replacePlaceholders(session, line))); + } + } + + nbt.setLore(loreNMS); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); - if(!display.hasTag("Lore")) + if (!display.hasTag("Lore")) { NBTList lore = display.getStringList("Lore"); for (String line : lines) @@ -36,7 +74,7 @@ public class LoreInsert implements IChange { NBTList lore = display.getStringList("Lore"); // If the index is correctly inside the already existing lore range I can put the new lines there. - if(index < lore.size()) + if (index < lore.size()) { int i = index; for (String line : lines) @@ -51,13 +89,31 @@ public class LoreInsert implements IChange lore.add(Comp.legacyToJson(IChange.replacePlaceholders(session, line))); } } - session.saveNbt(); } public static void putLine(ChangeSession session, int index, String line) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + List loreNMS = nbt.getLoreCopy(); + if (loreNMS == null) + { + loreNMS = new ArrayList<>(); + loreNMS.add(Utils.legacyToNMS(line)); + } + else + { + loreNMS.add(index, Utils.legacyToNMS(line)); + } + + nbt.setLore(loreNMS); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); NBTList lore = display.getStringList("Lore"); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsertJson.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsertJson.java index af93e63..467d64c 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsertJson.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreInsertJson.java @@ -3,8 +3,11 @@ package dev.lone.vanillacustomizer.customization.changes; import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTList; +import dev.lone.fastnbt_benchmark.libs.org.jetbrains.annotations.Nullable; import dev.lone.vanillacustomizer.ChangeSession; -import dev.lone.vanillacustomizer.utils.Utilz; +import dev.lone.vanillacustomizer.nms.NMS; +import dev.lone.vanillacustomizer.utils.Utils; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; import java.util.ArrayList; import java.util.List; @@ -16,21 +19,47 @@ public class LoreInsertJson implements IChange public LoreInsertJson(List linesJson, int index) { - this.linesJson = Utilz.fixJsonFormatting(linesJson); + this.linesJson = Utils.fixJsonFormatting(linesJson); this.index = index; } @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + + List newLinesNMS = new ArrayList<>(); + for (String lineJson : linesJson) + newLinesNMS.add(Utils.jsonToNMS(IChange.replacePlaceholders(session, lineJson))); + + @Nullable List loreNMS = nbt.getLoreCopy(); + if(loreNMS == null) + { + loreNMS = new ArrayList<>(newLinesNMS); + } + else + { + if (index < loreNMS.size()) + loreNMS.addAll(index, newLinesNMS); + else + loreNMS.addAll(newLinesNMS); + } + + nbt.setLore(loreNMS); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); List newLinesJson = new ArrayList<>(); for (String lineJson : linesJson) newLinesJson.add(IChange.replacePlaceholders(session, lineJson)); - if(!display.hasTag("Lore")) + if (!display.hasTag("Lore")) { NBTList lore = display.getStringList("Lore"); lore.addAll(newLinesJson); @@ -38,14 +67,10 @@ public class LoreInsertJson implements IChange else { NBTList lore = display.getStringList("Lore"); - if(index < lore.size()) - { + if (index < lore.size()) lore.addAll(index, newLinesJson); - } else - { lore.addAll(newLinesJson); - } } session.saveNbt(); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSet.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSet.java index 6d8e501..622cbc4 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSet.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSet.java @@ -5,8 +5,13 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.LoneLibs.chat.Comp; +import dev.lone.vanillacustomizer.nms.NMS; import dev.lone.vanillacustomizer.utils.ConfigFile; +import dev.lone.vanillacustomizer.utils.Utils; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; +import lonelibs.net.kyori.adventure.text.Component; +import java.util.ArrayList; import java.util.List; public class LoreSet implements IChange @@ -21,7 +26,23 @@ public class LoreSet implements IChange @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + List loreNMS = new ArrayList<>(); + for (String line : lines) + { + String json = Comp.legacyToJson(IChange.replacePlaceholders(session, line)); + Component component = Utils.jsonToComponent(json); + Object nms = Comp.componentToNms(component); + loreNMS.add(nms); + } + nbt.setLore(loreNMS); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); display.removeKey("Lore"); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSetJson.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSetJson.java index 59ecc40..9fe87df 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSetJson.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/LoreSetJson.java @@ -4,8 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.vanillacustomizer.ChangeSession; -import dev.lone.LoneLibs.chat.Comp; -import dev.lone.vanillacustomizer.utils.Utilz; +import dev.lone.vanillacustomizer.nms.NMS; +import dev.lone.vanillacustomizer.utils.Utils; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; import java.util.ArrayList; import java.util.List; @@ -16,13 +17,24 @@ public class LoreSetJson implements IChange public LoreSetJson(List linesJson) { - this.linesJson = Utilz.fixJsonFormatting(linesJson); + this.linesJson = Utils.fixJsonFormatting(linesJson); } @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + List loreNMS = new ArrayList<>(); + for (String line : linesJson) + loreNMS.add(Utils.jsonToNMS(IChange.replacePlaceholders(session, line))); + nbt.setLore(loreNMS); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); display.removeKey("Lore"); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ProtectNbtData.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ProtectNbtData.java index 16bc599..3c682f3 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ProtectNbtData.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ProtectNbtData.java @@ -8,7 +8,7 @@ public class ProtectNbtData implements IChange @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + NBTItem nbt = session.nbtLegacy(); nbt.removeKey("PublicBukkitValues"); nbt.removeKey("itemsadder"); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/Renamer.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/Renamer.java index 1b29920..6d80f41 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/Renamer.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/Renamer.java @@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.LoneLibs.chat.Comp; +import dev.lone.vanillacustomizer.nms.NMS; import dev.lone.vanillacustomizer.utils.ConfigFile; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; import org.bukkit.ChatColor; public class Renamer implements IChange @@ -20,7 +22,15 @@ public class Renamer implements IChange @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + nbt.setCustomName(Comp.legacyToJson(IChange.replacePlaceholders(session, name))); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); display.setString("Name", Comp.legacyToJson(IChange.replacePlaceholders(session, name))); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/RenamerJson.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/RenamerJson.java index d77af32..c720cdc 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/RenamerJson.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/RenamerJson.java @@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.LoneLibs.chat.Comp; -import dev.lone.vanillacustomizer.utils.Utilz; +import dev.lone.vanillacustomizer.nms.NMS; +import dev.lone.vanillacustomizer.utils.Utils; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; public class RenamerJson implements IChange { @@ -14,15 +16,24 @@ public class RenamerJson implements IChange { // This should validate if the json is valid and throw an exception if not. // NOTE: test if it is actually the case. - Comp.jsonToComponent(json); + Utils.jsonToComponent(json); - this.json = Utilz.fixJsonFormatting(json); + this.json = Utils.fixJsonFormatting(json); } @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + String json = IChange.replacePlaceholders(session, this.json); + nbt.setCustomName(json); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); display.setString("Name", IChange.replacePlaceholders(session, json)); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceCustomModelData.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceCustomModelData.java index f23ec9e..fced268 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceCustomModelData.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceCustomModelData.java @@ -15,7 +15,7 @@ public class ReplaceCustomModelData implements IChange @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + NBTItem nbt = session.nbtLegacy(); nbt.setInteger("CustomModelData", id); session.saveNbt(); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordDisplayName.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordDisplayName.java index 4b2320f..033d49c 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordDisplayName.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordDisplayName.java @@ -4,7 +4,9 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTCompound; import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.LoneLibs.chat.Comp; +import dev.lone.vanillacustomizer.nms.NMS; import dev.lone.vanillacustomizer.utils.ConfigFile; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; public class ReplaceWordDisplayName implements IChange { @@ -27,7 +29,15 @@ public class ReplaceWordDisplayName implements IChange String name = session.refreshMeta().getDisplayName().replace(from, to); - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + nbt.setCustomName(Comp.legacyToJson(name)); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); display.setString("Name", Comp.legacyToJson(name)); diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordLore.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordLore.java index 1243af6..15d5118 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordLore.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/changes/ReplaceWordLore.java @@ -5,10 +5,15 @@ import dev.lone.LoneLibs.nbt.nbtapi.NBTItem; import dev.lone.LoneLibs.nbt.nbtapi.NBTList; import dev.lone.vanillacustomizer.ChangeSession; import dev.lone.LoneLibs.chat.Comp; +import dev.lone.vanillacustomizer.nms.NMS; import dev.lone.vanillacustomizer.utils.ConfigFile; +import dev.lone.vanillacustomizer.utils.Utils; +import lonelibs.dev.lone.fastnbt.nms.nbt.NItem; import lonelibs.net.kyori.adventure.text.Component; import lonelibs.net.kyori.adventure.text.TextReplacementConfig; +import java.util.List; + public class ReplaceWordLore implements IChange { TextReplacementConfig textReplacement; @@ -27,7 +32,26 @@ public class ReplaceWordLore implements IChange @Override public void apply(ChangeSession session) { - NBTItem nbt = session.nbt(); + if(NMS.is_v1_1_20_5_or_greater) + { + NItem nbt = session.nbt(); + List loreNMS = nbt.getLoreCopy(); + if(loreNMS == null) + return; + + for (int i = 0; i < loreNMS.size(); i++) + { + Object lineNMS = loreNMS.get(i); + Component component = Comp.nmsToComponent(lineNMS); + component = component.replaceText(textReplacement); + loreNMS.set(i, Comp.componentToNms(component)); + } + nbt.setLore(loreNMS); + nbt.save(); + return; + } + + NBTItem nbt = session.nbtLegacy(); NBTCompound display = nbt.getOrCreateCompound("display"); if(!display.hasTag("Lore")) return; @@ -36,7 +60,7 @@ public class ReplaceWordLore implements IChange for (int i = 0; i < lore.size(); i++) { String lineJson = lore.get(i); - Component component = Comp.jsonToComponent(lineJson); + Component component = Utils.jsonToComponent(lineJson); component = component.replaceText(textReplacement); lore.set(i, Comp.componentToJson(component)); } 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 c569622..b9aca9b 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 @@ -28,7 +28,7 @@ public class RuleNbtMatcher implements IRule { nbtValueType = NBTType.valueOf(nbtTypeFixed); } - catch(IllegalArgumentException exc) + catch (IllegalArgumentException exc) { throw new IllegalArgumentException("Unknown nbt.type '" + nbtValueTypeStr + "' for nbt path '" + nbtPath + "'." + ChatColor.GRAY + " Allowed: string, int, float, double, byte, short"); @@ -49,6 +49,7 @@ public class RuleNbtMatcher implements IRule break; case NBTTagByte: nbtValue = Byte.parseByte(nbtValueStr); + break; case NBTTagShort: nbtValue = Short.parseShort(nbtValueStr); break; @@ -71,36 +72,40 @@ public class RuleNbtMatcher implements IRule public boolean matches(ItemStack item) { NBTItem nbt = new NBTItem(item); - if (!nbt.hasTag(nbtPathSplit[0])) return false; NBTCompound currentCompound = nbt.getCompound(nbtPathSplit[0]); - for(int i=1; i wildcardStart; diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RulePlaceable.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RulePlaceable.java index a8af794..99fc7b7 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RulePlaceable.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RulePlaceable.java @@ -14,6 +14,8 @@ public class RulePlaceable implements IRule @Override public boolean matches(ItemStack item) { - return item.getType().isBlock(); + if(placeable) + return item.getType().isBlock(); + return !item.getType().isBlock(); } } diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RuleVanillaItemMatcher.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RuleVanillaItemMatcher.java index d6d38b7..36395d3 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RuleVanillaItemMatcher.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/customization/rules/RuleVanillaItemMatcher.java @@ -1,7 +1,7 @@ package dev.lone.vanillacustomizer.customization.rules; import dev.lone.vanillacustomizer.ChangeSession; -import dev.lone.vanillacustomizer.utils.Utilz; +import dev.lone.vanillacustomizer.utils.Utils; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -27,14 +27,14 @@ public class RuleVanillaItemMatcher implements IRule return true; // TODO: warning, items with no lore would still be considered vanilla while they might be custom. - // might need to check NBT + // Might need to check NBT. if(meta.hasLore()) - { return false; - } + + // TODO: check if it has PersistentDataContainer, for example. String displayName = meta.getDisplayName(); - displayName = Utilz.backColor(displayName); + displayName = Utils.backColor(displayName); // Check if italic, means that might have been renamed using anvil. return !displayName.startsWith("&o"); @@ -49,6 +49,8 @@ public class RuleVanillaItemMatcher implements IRule @Override public boolean matches(ChangeSession session) { - return session.isVanilla; + if(isVanilla) + return session.isVanilla; + return !session.isVanilla; } } diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/exception/InvalidCustomizationPropertyException.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/exception/InvalidCustomizationPropertyException.java new file mode 100644 index 0000000..7b9b595 --- /dev/null +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/exception/InvalidCustomizationPropertyException.java @@ -0,0 +1,9 @@ +package dev.lone.vanillacustomizer.exception; + +public class InvalidCustomizationPropertyException extends IllegalArgumentException +{ + public InvalidCustomizationPropertyException(String text) + { + super(text); + } +} 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 963d79c..006943d 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,8 +1,9 @@ package dev.lone.vanillacustomizer.nms; -import dev.lone.LoneLibs.annotations.Nullable; +import org.jetbrains.annotations.Nullable; import dev.lone.LoneLibs.nbt.nbtapi.utils.MinecraftVersion; import dev.lone.vanillacustomizer.Main; +import lonelibs.dev.lone.fastnbt.nms.Version; import org.bukkit.Bukkit; import java.lang.reflect.InvocationTargetException; @@ -10,19 +11,13 @@ import java.lang.reflect.InvocationTargetException; /** * Utility to initialize NMS wrappers and avoid Maven circular dependency problems. */ -public class Nms +public class NMS { - public static boolean is_v18_2_or_greater; - public static boolean is_v19_2_or_greater; - public static boolean is_v17_or_greater; - public static boolean is_v1_16_or_greater; + public static boolean is_v1_1_20_5_or_greater; static { - is_v19_2_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_19_R1); - is_v18_2_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_18_R1); - is_v17_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_17_R1); - is_v1_16_or_greater = MinecraftVersion.isAtLeastVersion(MinecraftVersion.MC1_16_R1); + is_v1_1_20_5_or_greater = Version.isAtLeast(Version.v1_20_5); } /** @@ -36,9 +31,9 @@ public class Nms */ @Nullable @SuppressWarnings("unchecked") - public static T findImplementation(Class implClazz, Object nmsHolder, boolean ignoreError) + public static T findImplementation(@SuppressWarnings("unused") Class implClazz, Object nmsHolder, boolean ignoreError) { - String nmsVersion = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; + String nmsVersion = Version.get().name(); try { diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/ItemsNms.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/ItemsNms.java index 388baa7..8bccba4 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/ItemsNms.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/ItemsNms.java @@ -1,6 +1,6 @@ package dev.lone.vanillacustomizer.nms.items; -import dev.lone.vanillacustomizer.nms.Nms; +import dev.lone.vanillacustomizer.nms.NMS; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.CookingRecipe; @@ -17,7 +17,7 @@ public class ItemsNms ItemsNms() { - nms = Nms.findImplementation(IItemsNms.class, this, false); + nms = NMS.findImplementation(IItemsNms.class, this, false); } public static ItemsNms inst() diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/Rarity.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/Rarity.java index ed45363..a0b7d60 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/Rarity.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/nms/items/Rarity.java @@ -2,6 +2,7 @@ package dev.lone.vanillacustomizer.nms.items; import org.bukkit.Color; +@SuppressWarnings("unused") public enum Rarity { COMMON(Color.WHITE), diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/ConfigFile.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/ConfigFile.java index 18aa42c..339314a 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/ConfigFile.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/ConfigFile.java @@ -1,8 +1,8 @@ package dev.lone.vanillacustomizer.utils; -import dev.lone.LoneLibs.annotations.NotNull; +import org.jetbrains.annotations.NotNull; import dev.lone.vanillacustomizer.Main; -import dev.lone.vanillacustomizer.nms.Nms; +import dev.lone.vanillacustomizer.nms.NMS; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; @@ -15,7 +15,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.EntityType; import org.bukkit.plugin.Plugin; import org.bukkit.potion.PotionEffectType; -import dev.lone.LoneLibs.annotations.Nullable; +import org.jetbrains.annotations.Nullable; import java.io.*; import java.nio.charset.StandardCharsets; @@ -30,6 +30,7 @@ import java.util.regex.Pattern; /** * 2020-01-08 LoneDev */ +@SuppressWarnings("unused") public class ConfigFile { private static final Pattern hexPattern = Pattern.compile("%#([A-Fa-f0-9]){6}%"); @@ -220,17 +221,14 @@ public class ConfigFile private static String convertColor0(String message) { - if (Nms.is_v1_16_or_greater) + Matcher matcher = hexPattern.matcher(message); + while (matcher.find()) { - Matcher matcher = hexPattern.matcher(message); - while (matcher.find()) - { - final net.md_5.bungee.api.ChatColor hexColor = net.md_5.bungee.api.ChatColor.of(matcher.group().substring(1, matcher.group().length() - 1)); - final String before = message.substring(0, matcher.start()); - final String after = message.substring(matcher.end()); - message = before + hexColor + after; - matcher = hexPattern.matcher(message); - } + final net.md_5.bungee.api.ChatColor hexColor = net.md_5.bungee.api.ChatColor.of(matcher.group().substring(1, matcher.group().length() - 1)); + final String before = message.substring(0, matcher.start()); + final String after = message.substring(matcher.end()); + message = before + hexColor + after; + matcher = hexPattern.matcher(message); } return message.replace("&", "\u00A7"); } diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/SmallCaps.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/SmallCaps.java index b47ad75..e6053f4 100644 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/SmallCaps.java +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/SmallCaps.java @@ -1,6 +1,6 @@ package dev.lone.vanillacustomizer.utils; -import dev.lone.LoneLibs.annotations.NotNull; +import org.jetbrains.annotations.NotNull; public class SmallCaps { diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/Utils.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/Utils.java new file mode 100644 index 0000000..a5ae623 --- /dev/null +++ b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/Utils.java @@ -0,0 +1,131 @@ +package dev.lone.vanillacustomizer.utils; + +import com.google.gson.JsonSyntaxException; +import dev.lone.LoneLibs.chat.Comp; +import dev.lone.vanillacustomizer.nms.NMS; +import lonelibs.net.kyori.adventure.text.Component; +import lonelibs.net.kyori.adventure.text.format.TextColor; +import lonelibs.net.kyori.adventure.text.format.TextDecoration; +import lonelibs.org.jetbrains.annotations.NotNull; +import org.bukkit.attribute.Attribute; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.InventoryView; + +import java.util.*; +import java.util.regex.Pattern; + +public class Utils +{ + private static final Pattern PATTERN_IS_NUMERIC = Pattern.compile("-?\\d+(\\.\\d+)?"); + + public static String backColor(String name) + { + return name.replace("\u00A7", "&"); + } + + /** + * @param strNum check if it is numeric + */ + public static boolean isNumeric(String strNum) + { + if (strNum == null) + return false; + return PATTERN_IS_NUMERIC.matcher(strNum).matches(); + } + + public static int parseInt(String number, int defaultValue) + { + try + { + return Integer.parseInt(number); + } + catch (Throwable ignored) + { + } + return defaultValue; + } + + // https://minecraft.wiki/w/Attribute + public static Attribute strToAttributeType(String attributeModifier) + { + attributeModifier = attributeModifier.replace("minecraft:", ""); + return switch (attributeModifier) + { + case "generic.max_health" -> Attribute.GENERIC_MAX_HEALTH; + case "generic.follow_range" -> Attribute.GENERIC_FOLLOW_RANGE; + case "generic.knockback_resistance" -> Attribute.GENERIC_KNOCKBACK_RESISTANCE; + case "generic.movement_speed" -> Attribute.GENERIC_MOVEMENT_SPEED; + case "generic.flying_speed" -> Attribute.GENERIC_FLYING_SPEED; + case "generic.attack_damage" -> Attribute.GENERIC_ATTACK_DAMAGE; + case "generic.attack_knockback" -> // 1.16+ + Attribute.GENERIC_ATTACK_KNOCKBACK; + case "generic.attack_speed" -> Attribute.GENERIC_ATTACK_SPEED; + case "generic.armor" -> Attribute.GENERIC_ARMOR; + case "generic.armor_toughness" -> Attribute.GENERIC_ARMOR_TOUGHNESS; + case "generic.luck" -> Attribute.GENERIC_LUCK; + case "zombie.spawn_reinforcements" -> Attribute.ZOMBIE_SPAWN_REINFORCEMENTS; + case "horse.jump_strength" -> + { + if (NMS.is_v1_1_20_5_or_greater) + yield Attribute.valueOf("HORSE_JUMP_STRENGTH"); + yield Attribute.GENERIC_JUMP_STRENGTH; + } + default -> null; + }; + } + + public static EquipmentSlot strToVanillaEquipmentSlot(String str) + { + return switch (str.toLowerCase()) + { + case "head" -> EquipmentSlot.HEAD; + case "chest" -> EquipmentSlot.CHEST; + case "legs" -> EquipmentSlot.LEGS; + case "feet" -> EquipmentSlot.FEET; + case "mainhand" -> EquipmentSlot.HAND; + case "offhand" -> EquipmentSlot.OFF_HAND; + default -> null; + }; + } + + public static List fixJsonFormatting(List linesJson) + { + for (int i = 0, linesJsonSize = linesJson.size(); i < linesJsonSize; i++) + { + String jsonLine = linesJson.get(i); + linesJson.set(i, fixJsonFormatting(jsonLine)); + } + + return linesJson; + } + + public static String fixJsonFormatting(String jsonString) + { + Component component = Utils.jsonToComponent(jsonString); + component = component.colorIfAbsent(TextColor.color(255, 255, 255)); + component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE); + return Comp.componentToJson(component); + } + + public static Object jsonToNMS(String json) + { + return Comp.componentToNms(Utils.jsonToComponent(json)); + } + + public static Object legacyToNMS(String text) + { + return Comp.componentToNms(jsonToComponent(Comp.legacyToJson(text))); + } + + public static @NotNull Component jsonToComponent(String json) throws JsonSyntaxException + { + if ((json.startsWith("{") && json.endsWith("}") || (json.startsWith("[") && json.endsWith("]")))) + return Comp.GSON_SERIALIZER.deserialize(json); + return Component.text(json).style(Comp.WHITE_NORMAL_TEXT_STYLE); + } + + public static boolean isCustomInventory(InventoryView openInventory) + { + return openInventory.getTopInventory().getClass().toString().endsWith("CraftInventoryCustom"); + } +} \ No newline at end of file diff --git a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/Utilz.java b/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/Utilz.java deleted file mode 100644 index 163c328..0000000 --- a/VanillaCustomizer-core/src/main/java/dev/lone/vanillacustomizer/utils/Utilz.java +++ /dev/null @@ -1,599 +0,0 @@ -package dev.lone.vanillacustomizer.utils; - -import dev.lone.LoneLibs.chat.Comp; -import lonelibs.net.kyori.adventure.text.Component; -import lonelibs.net.kyori.adventure.text.format.TextColor; -import lonelibs.net.kyori.adventure.text.format.TextDecoration; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.lang.reflect.FieldUtils; -import org.bukkit.Bukkit; -import org.bukkit.Color; -import org.bukkit.Material; -import org.bukkit.attribute.Attribute; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.inventory.ItemStack; - -import java.io.File; -import java.math.BigDecimal; -import java.math.RoundingMode; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.text.CharacterIterator; -import java.text.DecimalFormat; -import java.text.SimpleDateFormat; -import java.text.StringCharacterIterator; -import java.util.*; -import java.util.regex.Pattern; -import java.util.stream.Collectors; - -public class Utilz -{ - public static Random random = new Random(); - - private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("##.00"); - private static final Pattern PATTERN_HEX = Pattern.compile("%#([A-Fa-f0-9]){6}%"); - private static final Pattern PATTERN_IS_NUMERIC = Pattern.compile("-?\\d+(\\.\\d+)?"); - - public static void removeEnchantments(ItemStack item) - { - item.getEnchantments().keySet().forEach(item::removeEnchantment); - } - - public static String addSpace(String s) - { - return s.replace("-", " "); - } - - public static float getRandom(String level) - { - if (level.contains("-")) - { - String[] spl = level.split("-"); - return round(randomNumber(Float.parseFloat(spl[0]), Float.parseFloat(spl[1])), 2); - } - else return Integer.parseInt(level); - } - - public static int getRandomInt(String level) - { - if (level.contains("-")) - { - String[] spl = level.split("-"); - return getRandomInt(Integer.parseInt(spl[0]), Integer.parseInt(spl[1])); - } - else return Integer.parseInt(level); - } - - public static float round(float d, int decimalPlace) - { - BigDecimal bd = new BigDecimal(Float.toString(d)); - bd = bd.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP); - return bd.floatValue(); - } - - public static String round(double value, int places, boolean showZeroes) - { - if (places < 0) throw new IllegalArgumentException(); - - BigDecimal bd = BigDecimal.valueOf(value); - bd = bd.setScale(places, RoundingMode.HALF_UP); - - String result = bd.doubleValue() + ""; - if (!showZeroes) - result = result - .replace(".00", "") - .replace(".0", ""); - return result; - } - - public static float randomNumber(float f, float g) - { - return random.nextFloat() * (g - f) + f; - } - - /** - * Returns a 0 to 1 random double. - * - * @return A random double from 0 to 1. - */ - public static double randomNumber() - { - return random.nextDouble(); - } - - /** - * Supports negative min - */ - public static int getRandomInt(int min, int max) - { - if (max == min) - return max; - return random.nextInt((max - min) + 1) + min; - } - - /** - * Supports negative min - */ - public static int getRandomInt(Random random, int min, int max) - { - if (max == min) - return max; - return random.nextInt((max - min) + 1) + min; - } - - public static boolean getSuccess(int percent) - { - int i = getRandomInt(1, 100); - return i <= percent; - } - - public static boolean hasPermmision(Player p, String perm) - { - if (p.hasPermission(perm)) return true; - return p.isOp(); - } - - public static String backColor(String name) - { - return name.replace("\u00A7", "&"); - } - - public static boolean isColored(String str) - { - return str.contains("\u00A7([0-fk-or])") || str.contains("&([0-fk-or])"); - } - - /** - * @param strNum check if it is numeric - */ - public static boolean isNumeric(String strNum) - { - if (strNum == null) - return false; - return PATTERN_IS_NUMERIC.matcher(strNum).matches(); - } - - private static java.awt.Color hex2Rgb(String colorStr) - { - try - { - return new java.awt.Color( - Integer.valueOf(colorStr.substring(1, 3), 16), - Integer.valueOf(colorStr.substring(3, 5), 16), - Integer.valueOf(colorStr.substring(5, 7), 16) - ); - } - catch (Throwable e) - { - e.printStackTrace(); - } - return null; - } - - public static Color hexToBukkitColor(String colorStr) - { - if (colorStr == null) - return null; - //fix java.lang.NumberFormatException: For input string: ".0" - if (colorStr.endsWith(".0")) - colorStr = colorStr.replace(".0", ""); - colorStr = colorStr.replace(".", ""); - //fix java.lang.StringIndexOutOfBoundsException: String index out of range: 7 - while (colorStr.length() < 7) - colorStr = colorStr + "0"; - if (!colorStr.startsWith("#")) - colorStr = "#" + colorStr; - - java.awt.Color javaColor = hex2Rgb(colorStr); - return Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue()); - } - - public static String colorToHexString(int rgb) - { - java.awt.Color tmp = new java.awt.Color(rgb); - return colorToHexString(tmp.getRed(), tmp.getGreen(), tmp.getBlue()); - } - - public static String colorToHexString(Color color, boolean hashtagPrefix) - { - java.awt.Color tmp = new java.awt.Color(color.asRGB()); - return colorToHexString(tmp.getRed(), tmp.getGreen(), tmp.getBlue(), hashtagPrefix); - } - - public static String colorToHexString(int r, int g, int b) - { - return colorToHexString(r, g, b, true); - } - - public static String colorToHexString(int r, int g, int b, boolean hashtagPrefix) - { - if (hashtagPrefix) - return String.format("#%02x%02x%02x", r, g, b); - return String.format("%02x%02x%02x", r, g, b); - } - - public static Color bukkitColor(int rgb) - { - java.awt.Color tmp = new java.awt.Color(rgb); - return Color.fromRGB(tmp.getRed(), tmp.getGreen(), tmp.getBlue()); - } - - public static int ceilDivision(float a, float b) - { - return (int) Math.ceil(a / b); - - } - - public static int parseInt(String number, int defaultValue) - { - try - { - return Integer.parseInt(number); - } - catch (Throwable ignored){} - return defaultValue; - } - - public static float parseFloat(String number, float defaultValue) - { - try - { - return Float.parseFloat(number); - } - catch (Throwable ignored){} - return defaultValue; - } - - public static Color bukkitColorFromString(String potionColorStr) - { - try - { - return (Color) FieldUtils.readStaticField(Color.class, potionColorStr); - } - catch (Exception e) - { - try - { - if (!Utilz.isNumeric(potionColorStr)) - { - if (potionColorStr == null) - return null; - //fix java.lang.NumberFormatException: For input string: ".0" - if (potionColorStr.endsWith(".0")) - potionColorStr = potionColorStr.replace(".0", ""); - potionColorStr = potionColorStr.replace(".", ""); - //fix java.lang.StringIndexOutOfBoundsException: String index out of range: 7 - while (potionColorStr.length() < 7) - potionColorStr = potionColorStr + "0"; - if (!potionColorStr.startsWith("#")) - potionColorStr = "#" + potionColorStr; - - java.awt.Color javaColor = hex2Rgb(potionColorStr); - return Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue()); - } - else - { - Color.fromBGR(Integer.parseInt(potionColorStr)); - } - } - catch (Throwable ignored) - { - } - } - return null; - } - - public static int bukkitColorFromString_integer(String potionColorStr) - { - try - { - return ((Color) FieldUtils.readStaticField(Color.class, potionColorStr)).asRGB(); - } - catch (Exception e) - { - try - { - if (!Utilz.isNumeric(potionColorStr)) - { - if (potionColorStr == null) - return -1; - //fix java.lang.NumberFormatException: For input string: ".0" - if (potionColorStr.endsWith(".0")) - potionColorStr = potionColorStr.replace(".0", ""); - potionColorStr = potionColorStr.replace(".", ""); - //fix java.lang.StringIndexOutOfBoundsException: String index out of range: 7 - while (potionColorStr.length() < 7) - potionColorStr = potionColorStr + "0"; - if (!potionColorStr.startsWith("#")) - potionColorStr = "#" + potionColorStr; - - java.awt.Color javaColor = hex2Rgb(potionColorStr); - return Color.fromRGB(javaColor.getRed(), javaColor.getGreen(), javaColor.getBlue()).asRGB(); - } - else - { - return Integer.parseInt(potionColorStr); - } - } - catch (Throwable ignored){} - } - return -1; - } - - public static boolean isBetween(int number, int min, int max, boolean equals) - { - if (equals) - return number >= min && number <= max; - return number > min && number < max; - } - - public static boolean isBetween(int number, int min, int max) - { - return isBetween(number, min, max, true); - } - - public static String getDateNowFormatted() - { - return getDateFormatted(new Date()); - } - - public static String getDateFormatted(Date date) - { - return new SimpleDateFormat("yyyy-MM-dd_HH-mm").format(date); - } - - public static void printFunctionCaller() - { - try - { - StackTraceElement[] stackTrace = new Throwable().fillInStackTrace().getStackTrace(); - StringBuilder a = new StringBuilder(); - for (int i = 1; i < stackTrace.length; i++) - a.append(stackTrace[i].getMethodName() + ":" + stackTrace[i].getLineNumber()).append("->"); - System.out.println(a.toString()); - } - catch (Throwable ignored) - { - } - } - - public static void showBook(Player player, String json) - { - ItemStack book = new ItemStack(Material.WRITTEN_BOOK); - Bukkit.getUnsafe().modifyItemStack(book, json); - player.openBook(book); - } - - public static int rgb(int r, int g, int b) - { - return new java.awt.Color(r, g, b, 255).getRGB(); - } - - public static boolean mkdirs(String path, boolean printErrors) - { - File file = new File(path); - if (file.exists()) - return true; - - try - { - Files.createDirectories(file.toPath()); - } - catch (Throwable e) - { - if (printErrors) - e.printStackTrace(); - return false; - } - - return true; - } - - public static Set getKeysByValue(Map map, E value) - { - return map.entrySet() - .stream() - .filter(entry -> Objects.equals(entry.getValue(), value)) - .map(Map.Entry::getKey) - .collect(Collectors.toSet()); - } - - /** See: {@link Utilz#partialFilePath(String)}. */ - public static String partialFilePath(File file) - { - return partialFilePath(file.getAbsolutePath()); - } - - /** - * Input: - * "C:/Progetti/Minecraft/TestServer/1.19/plugins/ItemsAdder/contents/_iainternal/resourcepack/assets/_iainternal/textures/icons/icon_next_orange.png" - * "C:/Progetti/Minecraft/TestServer/blank_template/1.19.4/plugins/ModelEngine/resource pack/contents/prova/123/asd" - * Output: - * "contents/_iainternal/resourcepack/assets/_iainternal/textures/icons/icon_next_orange.png" - * "resource pack/contents/prova/123/asd" - */ - public static String partialFilePath(String fileAbsolutePath) - { - if (fileAbsolutePath == null) - return null; - - String finalPath = fileAbsolutePath.replace("\\", "/"); - - int indexOfPlugins = finalPath.indexOf("plugins/"); - if(indexOfPlugins != -1) - finalPath = finalPath.substring(indexOfPlugins); - - // Remove the plugins/XXX/ text - int indexOfSlash = finalPath.indexOf("/"); - if(indexOfSlash != -1) - finalPath = finalPath.substring(indexOfSlash + 1); - indexOfSlash = finalPath.indexOf("/"); - if(indexOfSlash != -1) - finalPath = finalPath.substring(indexOfSlash + 1); - - return finalPath; - } - - public static int getFilesCount(File dir) - { - String[] list = dir.list(); - if (list == null) - return 0; - return list.length; - } - - public static String getPathRelativeToServerRoot(File file) - { - String serveRootPath = Bukkit.getServer().getWorldContainer().getAbsolutePath(); - if (serveRootPath.endsWith(".")) - serveRootPath = serveRootPath.substring(0, serveRootPath.length() - 2); - File serverRootDir = new File(serveRootPath).getParentFile(); - return file.getAbsolutePath().replace(serverRootDir.getAbsolutePath(), ""); - } - - public static Path path(String path) - { - return new File(path).toPath(); - } - - /** - * Very important, zip files must use / not \\ or Minecraft won't recognize files.. - */ - public static String sanitizePath(String str) - { - str = str.replace("\\", "/"); - if (str.startsWith("/")) - str = str.substring(1); - return str; - } - - public static String sanitizedPath(File file) - { - return sanitizePath(file.getAbsolutePath()); - } - - public static String removeStartsWith(String str, String starsWith) - { - if (str.startsWith(starsWith)) - return str.substring(starsWith.length()); - return str; - } - - public static String removeEndsWith(String str, String endsWith) - { - return str.replaceFirst(endsWith + "$", ""); - } - - public static String getLastNormalizedPathEntry(String str) - { - return str.substring(str.lastIndexOf('/') + 1); - } - - public static String cloneString(String str) - { - return new String(str.getBytes(StandardCharsets.UTF_8)); - } - - public static T[] copy(T[] matrix) - { - return Arrays.copyOf(matrix, matrix.length); - } - - public static String fileExtension(File file) - { - return FilenameUtils.getExtension(file.getAbsolutePath()); - } - - public static String fileName(File file, boolean extension) - { - if(extension) - return file.getName(); - return FilenameUtils.getBaseName(file.getAbsolutePath()); - } - - public static String humanReadableByteCountSI(long bytes) - { - if (-1000 < bytes && bytes < 1000) - { - return bytes + " B"; - } - CharacterIterator ci = new StringCharacterIterator("kMGTPE"); - while (bytes <= -999_950 || bytes >= 999_950) - { - bytes /= 1000; - ci.next(); - } - return String.format("%.1f %cB", bytes / 1000.0, ci.current()); - } - - public static int minMax(int value, int min, int max) - { - if(value < min) - return min; - return Math.min(value, max); - } - - public static String substringBefore(String string, String before) - { - return string.substring(string.indexOf(before)); - } - - public static Attribute strToAttributeType(String attributeModifier) - { - attributeModifier = attributeModifier.replace("minecraft:", ""); - return switch (attributeModifier) - { - case "generic.max_health" -> Attribute.GENERIC_MAX_HEALTH; - case "generic.follow_range" -> Attribute.GENERIC_FOLLOW_RANGE; - case "generic.knockback_resistance" -> Attribute.GENERIC_KNOCKBACK_RESISTANCE; - case "generic.movement_speed" -> Attribute.GENERIC_MOVEMENT_SPEED; - case "generic.flying_speed" -> Attribute.GENERIC_FLYING_SPEED; - case "generic.attack_damage" -> Attribute.GENERIC_ATTACK_DAMAGE; - case "generic.attack_knockback" -> // 1.16+ - Attribute.GENERIC_ATTACK_KNOCKBACK; - case "generic.attack_speed" -> Attribute.GENERIC_ATTACK_SPEED; - case "generic.armor" -> Attribute.GENERIC_ARMOR; - case "generic.armor_toughness" -> Attribute.GENERIC_ARMOR_TOUGHNESS; - case "generic.luck" -> Attribute.GENERIC_LUCK; - case "zombie.spawn_reinforcements" -> Attribute.ZOMBIE_SPAWN_REINFORCEMENTS; - case "horse.jump_strength" -> Attribute.HORSE_JUMP_STRENGTH; - default -> null; - }; - } - - public static EquipmentSlot strToVanillaEquipmentSlot(String str) - { - return switch (str.toLowerCase()) - { - case "head" -> EquipmentSlot.HEAD; - case "chest" -> EquipmentSlot.CHEST; - case "legs" -> EquipmentSlot.LEGS; - case "feet" -> EquipmentSlot.FEET; - case "mainhand" -> EquipmentSlot.HAND; - case "offhand" -> EquipmentSlot.OFF_HAND; - default -> null; - }; - } - - public static List fixJsonFormatting(List linesJson) - { - for (int i = 0, linesJsonSize = linesJson.size(); i < linesJsonSize; i++) - { - String jsonLine = linesJson.get(i); - linesJson.set(i, fixJsonFormatting(jsonLine)); - } - - return linesJson; - } - - public static String fixJsonFormatting(String jsonString) - { - Component component = Comp.jsonToComponent(jsonString); - component = component.colorIfAbsent(TextColor.color(255, 255, 255)); - component = component.decorationIfAbsent(TextDecoration.ITALIC, TextDecoration.State.FALSE); - return Comp.componentToJson(component); - } -} \ No newline at end of file diff --git a/VanillaCustomizer-core/src/main/resources/plugin.yml b/VanillaCustomizer-core/src/main/resources/plugin.yml index 79f5d4b..fdf2e17 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.2 +version: 0.3 main: dev.lone.vanillacustomizer.Main api-version: 1.13 commands: diff --git a/VanillaCustomizer-jar/pom.xml b/VanillaCustomizer-jar/pom.xml index 1bb438a..e128c84 100644 --- a/VanillaCustomizer-jar/pom.xml +++ b/VanillaCustomizer-jar/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -46,23 +46,21 @@ - org.codehaus.mojo - exec-maven-plugin - 1.2.1 + org.apache.maven.plugins + maven-antrun-plugin + 3.1.0 - CopyFile package - cmd - ${project.parent.basedir} - - /C - .mvn-exec\CopyFile.bat - + + + + + - exec + run @@ -84,38 +82,48 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 + + dev.lone + VanillaCustomizer-nms-v1_21_1 + 1.0 + + + dev.lone + VanillaCustomizer-nms-v1_20_6 + 1.0 + dev.lone VanillaCustomizer-nms-v1_20_R3 - VERSION + 1.0 dev.lone VanillaCustomizer-nms-v1_20_R2 - VERSION + 1.0 dev.lone VanillaCustomizer-nms-v1_20_R1 - VERSION + 1.0 dev.lone VanillaCustomizer-nms-v1_19_R3 - VERSION + 1.0 dev.lone VanillaCustomizer-nms-v1_18_R2 - VERSION + 1.0 dev.lone VanillaCustomizer-nms-v1_17_R1 - VERSION + 1.0 diff --git a/VanillaCustomizer-nms-v1_17_R1/pom.xml b/VanillaCustomizer-nms-v1_17_R1/pom.xml index c3378bf..a718335 100644 --- a/VanillaCustomizer-nms-v1_17_R1/pom.xml +++ b/VanillaCustomizer-nms-v1_17_R1/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -47,7 +47,7 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 provided diff --git a/VanillaCustomizer-nms-v1_17_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_17_R1.java b/VanillaCustomizer-nms-v1_17_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_17_R1.java index 6a65d04..6dade9b 100644 --- a/VanillaCustomizer-nms-v1_17_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_17_R1.java +++ b/VanillaCustomizer-nms-v1_17_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_17_R1.java @@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_17_R1.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; +@SuppressWarnings("unused") public class v1_17_R1 implements IItemsNms { @Override diff --git a/VanillaCustomizer-nms-v1_18_R2/pom.xml b/VanillaCustomizer-nms-v1_18_R2/pom.xml index e703893..066b3e3 100644 --- a/VanillaCustomizer-nms-v1_18_R2/pom.xml +++ b/VanillaCustomizer-nms-v1_18_R2/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -47,7 +47,7 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 provided diff --git a/VanillaCustomizer-nms-v1_18_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_18_R2.java b/VanillaCustomizer-nms-v1_18_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_18_R2.java index 4ddd9e1..af73f2e 100644 --- a/VanillaCustomizer-nms-v1_18_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_18_R2.java +++ b/VanillaCustomizer-nms-v1_18_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_18_R2.java @@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R2.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; +@SuppressWarnings("unused") public class v1_18_R2 implements IItemsNms { @Override diff --git a/VanillaCustomizer-nms-v1_19_R3/pom.xml b/VanillaCustomizer-nms-v1_19_R3/pom.xml index 7da79fd..afbbb67 100644 --- a/VanillaCustomizer-nms-v1_19_R3/pom.xml +++ b/VanillaCustomizer-nms-v1_19_R3/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -47,7 +47,7 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 provided diff --git a/VanillaCustomizer-nms-v1_19_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_19_R3.java b/VanillaCustomizer-nms-v1_19_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_19_R3.java index 585e217..7d04132 100644 --- a/VanillaCustomizer-nms-v1_19_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_19_R3.java +++ b/VanillaCustomizer-nms-v1_19_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_19_R3.java @@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R3.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; +@SuppressWarnings("unused") public class v1_19_R3 implements IItemsNms { @Override diff --git a/VanillaCustomizer-nms-v1_20_6/pom.xml b/VanillaCustomizer-nms-v1_20_6/pom.xml new file mode 100644 index 0000000..d09d01c --- /dev/null +++ b/VanillaCustomizer-nms-v1_20_6/pom.xml @@ -0,0 +1,55 @@ + + + + VanillaCustomizer + dev.lone + 1.0 + + 4.0.0 + + VanillaCustomizer-nms-v1_20_6 + + + 17 + 17 + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.4 + + + process-classes + + remap + + + + + + + + + + + ca.bkaw + paper-nms + 1.20.6-SNAPSHOT + provided + + + + dev.lone + VanillaCustomizer-core + 1.0 + provided + + + + \ No newline at end of file diff --git a/VanillaCustomizer-nms-v1_20_6/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_6.java b/VanillaCustomizer-nms-v1_20_6/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_6.java new file mode 100644 index 0000000..e6c90b3 --- /dev/null +++ b/VanillaCustomizer-nms-v1_20_6/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_6.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 v1_20_6 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().destroySpeed; + } + + @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-v1_20_R1/pom.xml b/VanillaCustomizer-nms-v1_20_R1/pom.xml index 9a46a8e..5bd9c5c 100644 --- a/VanillaCustomizer-nms-v1_20_R1/pom.xml +++ b/VanillaCustomizer-nms-v1_20_R1/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -47,7 +47,7 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 provided diff --git a/VanillaCustomizer-nms-v1_20_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R1.java b/VanillaCustomizer-nms-v1_20_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R1.java index 2eadb73..9711e7d 100644 --- a/VanillaCustomizer-nms-v1_20_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R1.java +++ b/VanillaCustomizer-nms-v1_20_R1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R1.java @@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R1.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; +@SuppressWarnings("unused") public class v1_20_R1 implements IItemsNms { @Override diff --git a/VanillaCustomizer-nms-v1_20_R2/pom.xml b/VanillaCustomizer-nms-v1_20_R2/pom.xml index 15e3b60..00fcdf1 100644 --- a/VanillaCustomizer-nms-v1_20_R2/pom.xml +++ b/VanillaCustomizer-nms-v1_20_R2/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -47,7 +47,7 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 provided diff --git a/VanillaCustomizer-nms-v1_20_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R2.java b/VanillaCustomizer-nms-v1_20_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R2.java index f94c044..cb38bfd 100644 --- a/VanillaCustomizer-nms-v1_20_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R2.java +++ b/VanillaCustomizer-nms-v1_20_R2/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R2.java @@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; +@SuppressWarnings("unused") public class v1_20_R2 implements IItemsNms { @Override diff --git a/VanillaCustomizer-nms-v1_20_R3/pom.xml b/VanillaCustomizer-nms-v1_20_R3/pom.xml index b6e89d8..2d9b9e7 100644 --- a/VanillaCustomizer-nms-v1_20_R3/pom.xml +++ b/VanillaCustomizer-nms-v1_20_R3/pom.xml @@ -5,7 +5,7 @@ VanillaCustomizer dev.lone - VERSION + 1.0 4.0.0 @@ -47,7 +47,7 @@ dev.lone VanillaCustomizer-core - VERSION + 1.0 provided diff --git a/VanillaCustomizer-nms-v1_20_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R3.java b/VanillaCustomizer-nms-v1_20_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R3.java index b17a3a3..acdc221 100644 --- a/VanillaCustomizer-nms-v1_20_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R3.java +++ b/VanillaCustomizer-nms-v1_20_R3/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_20_R3.java @@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.v1_20_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R3.util.CraftMagicNumbers; import org.bukkit.inventory.ItemStack; +@SuppressWarnings("unused") public class v1_20_R3 implements IItemsNms { @Override diff --git a/VanillaCustomizer-nms-v1_21_1/pom.xml b/VanillaCustomizer-nms-v1_21_1/pom.xml new file mode 100644 index 0000000..023be91 --- /dev/null +++ b/VanillaCustomizer-nms-v1_21_1/pom.xml @@ -0,0 +1,55 @@ + + + + VanillaCustomizer + dev.lone + 1.0 + + 4.0.0 + + VanillaCustomizer-nms-v1_21_1 + + + 21 + 21 + + + + + + + ca.bkaw + paper-nms-maven-plugin + 1.4.4 + + + process-classes + + remap + + + + + + + + + + + ca.bkaw + paper-nms + 1.21.1-SNAPSHOT + provided + + + + dev.lone + VanillaCustomizer-core + 1.0 + provided + + + + \ No newline at end of file diff --git a/VanillaCustomizer-nms-v1_21_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_21_1.java b/VanillaCustomizer-nms-v1_21_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_21_1.java new file mode 100644 index 0000000..39fe36d --- /dev/null +++ b/VanillaCustomizer-nms-v1_21_1/src/main/java/dev/lone/vanillacustomizer/nms/items/impl/v1_21_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 v1_21_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().destroySpeed; + } + + @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 8493618..524f376 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ dev.lone VanillaCustomizer - VERSION + 1.0 VanillaCustomizer pom @@ -22,6 +22,8 @@ VanillaCustomizer-core VanillaCustomizer-jar + VanillaCustomizer-nms-v1_21_1 + VanillaCustomizer-nms-v1_20_6 VanillaCustomizer-nms-v1_20_R3 VanillaCustomizer-nms-v1_20_R2 VanillaCustomizer-nms-v1_20_R1