From 40dcb9a3361d1a95628138ea3e8c9e03b56f594c Mon Sep 17 00:00:00 2001 From: Telesphoreo Date: Sat, 15 Jul 2023 19:07:47 -0500 Subject: [PATCH] Push changes --- build.gradle.kts | 27 +- core/build.gradle.kts | 4 +- .../dev/plex/itemizerx/ItemizerXBase.java | 3 + .../dev/plex/itemizerx/ItemizerXCommand.java | 799 +++++++++++------- settings.gradle.kts | 4 + shared/build.gradle.kts | 4 +- .../dev/plex/itemizerx/IAttributeManager.java | 4 +- v1_17_R1/build.gradle.kts | 6 +- .../itemizerx/v1_17_R1/AttributeManager.java | 148 ++-- v1_18_R1/build.gradle.kts | 6 +- .../itemizerx/v1_18_R1/AttributeManager.java | 152 ++-- v1_18_R2/build.gradle.kts | 5 +- .../itemizerx/v1_18_R2/AttributeManager.java | 152 ++-- v1_19_R1/build.gradle.kts | 5 +- .../itemizerx/v1_19_R1/AttributeManager.java | 152 ++-- v1_19_R2/build.gradle.kts | 5 +- .../itemizerx/v1_19_R2/AttributeManager.java | 152 ++-- v1_19_R3/build.gradle.kts | 5 +- .../itemizerx/v1_19_R3/AttributeManager.java | 152 ++-- v1_20_R1/build.gradle.kts | 2 +- .../itemizerx/v1_20_R1/AttributeManager.java | 150 ++-- 21 files changed, 1173 insertions(+), 764 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9b40a50..bd583ac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,23 +1,26 @@ plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" + id("io.papermc.paperweight.userdev") version "1.5.5" apply false + id("xyz.jpenilla.run-paper") version "2.1.0" apply false } group = "dev.plex" version = "2.1" +java { + toolchain.languageVersion.set(JavaLanguageVersion.of(17)) +} + subprojects { apply(plugin = "java") apply(plugin = "com.github.johnrengelman.shadow") - java.sourceCompatibility = JavaVersion.VERSION_17 + apply(plugin = "io.papermc.paperweight.userdev") + apply(plugin = "xyz.jpenilla.run-paper") repositories { mavenCentral() - maven { - url = uri("https://repo.codemc.org/repository/nms/") - } - maven { url = uri("https://repo.papermc.io/repository/maven-public/") } @@ -41,9 +44,23 @@ tasks { archiveBaseName.set("ItemizerX") archiveClassifier.set("") archiveVersion.set("") + + // helper function to relocate a package into our package + fun reloc(pkg: String) = relocate(pkg, "io.papermc.paperweight.testplugin.dependency.$pkg") + + // relocate cloud and it's transitive dependencies + reloc("cloud.commandframework") + reloc("io.leangen.geantyref") } + + compileJava { + options.encoding = Charsets.UTF_8.name() + options.release.set(17) + } + assemble { dependsOn("shadowJar") + dependsOn("reobfJar") } jar { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 59fd431..a2c25c9 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,5 +1,6 @@ +apply(plugin = "io.papermc.paperweight.userdev") + dependencies { - implementation(project(":shared")) implementation(project(":v1_20_R1")) implementation(project(":v1_19_R3")) implementation(project(":v1_19_R2")) @@ -8,4 +9,5 @@ dependencies { implementation(project(":v1_18_R1")) implementation(project(":v1_17_R1")) compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") + paperDevBundle("1.20.1-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/core/src/main/java/dev/plex/itemizerx/ItemizerXBase.java b/core/src/main/java/dev/plex/itemizerx/ItemizerXBase.java index 06e007b..75c77c9 100644 --- a/core/src/main/java/dev/plex/itemizerx/ItemizerXBase.java +++ b/core/src/main/java/dev/plex/itemizerx/ItemizerXBase.java @@ -1,5 +1,8 @@ package dev.plex.itemizerx; +import net.kyori.adventure.text.minimessage.MiniMessage; + public interface ItemizerXBase { ItemizerX plugin = ItemizerX.plugin; + MiniMessage mm = MiniMessage.miniMessage(); } diff --git a/core/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java b/core/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java index 414bc55..0d790b4 100644 --- a/core/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java +++ b/core/src/main/java/dev/plex/itemizerx/ItemizerXCommand.java @@ -1,7 +1,17 @@ package dev.plex.itemizerx; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import net.kyori.adventure.text.Component; import org.apache.commons.lang3.StringUtils; -import org.bukkit.*; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.block.Block; import org.bukkit.block.Sign; import org.bukkit.command.Command; @@ -19,37 +29,31 @@ import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { - +public class ItemizerXCommand implements CommandExecutor, ItemizerXBase +{ final List POTIONS = Arrays.asList(Material.POTION, Material.LINGERING_POTION, Material.SPLASH_POTION); CoreProtectBridge cpb = new CoreProtectBridge(); @Override - public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) { - if (!sender.hasPermission("itemizer.use")) { - sender.sendMessage("&4You don't have permission to use this command!"); + public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args) + { + if (!sender.hasPermission("itemizer.use")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 0) { - sender.sendMessage(ChatColor.AQUA + "ItemizerX " + ChatColor.GOLD + "v" - + Bukkit.getPluginManager().getPlugin("ItemizerX").getDescription().getVersion() - + ChatColor.AQUA + " by " + ChatColor.GOLD - + StringUtils.join(Bukkit.getPluginManager().getPlugin("ItemizerX").getDescription().getAuthors(), ", ")); - sender.sendMessage(ChatColor.AQUA + "Type " + ChatColor.GOLD + "/itemizer help " - + ChatColor.AQUA + "for help"); + if (args.length == 0) + { + sender.sendMessage(mm.deserialize("ItemizerX v" + plugin.getDescription().getVersion() + + " by " + StringUtils.join(plugin.getDescription().getAuthors(), ", "))); + sender.sendMessage(mm.deserialize("Type /itemizer help for help")); return true; } - if (!(sender instanceof final Player player)) { - sender.sendMessage(colorize("&4You must be a player to execute this command!")); + if (!(sender instanceof final Player player)) + { + sender.sendMessage(mm.deserialize("You must be a player to execute this command!")); return true; } @@ -59,240 +63,298 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { final boolean hasBook = item.getType() == Material.WRITTEN_BOOK; final ItemMeta meta = item.getItemMeta(); - switch (args[0]) { - case "help" -> { - sender.sendMessage(colorize(""" - &3=============&f[&dItemizerX Commands&f]&3============= - &b/itemizer name <&fname&b> &c- &6Name your item - &b/itemizer id <&fid&b> &c- &6Change the item's material - &b/itemizer lore &c- &6Lore editing command - &b/itemizer potion &c- &6Potion editing command - &b/itemizer attr &c- &6Attribute editing command - &b/itemizer flag &c- &6Flag editing command - &b/itemizer enchant &c- &6Enchant editing command - &b/itemizer title <&fname&b> &c- &6Set the book's title - &b/itemizer author <&fname&b> &c- &6Set the book's author - &b/itemizer head <&fname&b> &c- &6Set the player of the head - &b/itemizer sign <&fline&b> <&ftext&b> &c- &6Change the line on the sign - &b/itemizer clearall &c- &6Clears all metadata from your item""")); + switch (args[0]) + { + case "help" -> + { + sender.sendMessage(mm.deserialize(""" + =============[ItemizerX Commands]============= + /itemizer name <name> - Name your item + /itemizer id <id> - Change the item's material + /itemizer lore - Lore editing command + /itemizer potion - Potion editing command + /itemizer attr - Attribute editing command + /itemizer flag - Flag editing command + /itemizer enchant - Enchant editing command + /itemizer title <name> - Set the book's title + /itemizer author <name> - Set the book's author + /itemizer head <name> - Set the player of the head + /itemizer sign <line> <text> - Change the line on the sign + /itemizer clearall - Clears all metadata from your item""")); return true; } - case "name" -> { - if (!sender.hasPermission("itemizer.name")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "name" -> + { + if (!sender.hasPermission("itemizer.name")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { - sender.sendMessage(colorize("&3===============&f[&dName Commands&f]&3===============\n" - + "&b/itemizer name <&fname&b> &c - &6Name your item")); - } else { - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (args.length == 1) + { + sender.sendMessage(mm.deserialize("===============[Name Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer name <name> - Name your item")); + } + else + { + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; } - String name = colorize(StringUtils.join(args, " ", 1, args.length)); + Component name = mm.deserialize(StringUtils.join(args, " ", 1, args.length)); assert meta != null; - meta.setDisplayName(name); + meta.displayName(name); item.setItemMeta(meta); - sender.sendMessage(colorize("&2The name of the item in your hand has been set to &f'" + name + "&f'")); + sender.sendMessage(mm.deserialize("The name of the item in your hand has been set to '" + mm.serialize(name) + "'")); } return true; } - case "id" -> { - if (!sender.hasPermission("itemizer.id")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "id" -> + { + if (!sender.hasPermission("itemizer.id")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { - sender.sendMessage(colorize("&3===============&f[&dID Commands&f]&3===============\n" - + "&b/itemizer id <&fid&b> &c- &6Change the item's material")); + if (args.length == 1) + { + sender.sendMessage(mm.deserialize("===============[ID Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer id <id> - Change the item's material")); return true; } - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; } Material material = Material.matchMaterial(args[1].toUpperCase()); - if (material == null) { - sender.sendMessage(colorize("&4The material &f\"" + args[1] + "&f\"&4 does not exist!")); + if (material == null) + { + sender.sendMessage(mm.deserialize("The material \"" + args[1] + "\" does not exist!")); return true; } item.setType(material); - sender.sendMessage(colorize("&2The material of the item has changed to &f'" + material.name() + "'")); + sender.sendMessage(mm.deserialize("The material of the item has changed to '" + material.name() + "'")); return true; } - case "lore" -> { - if (!sender.hasPermission("itemizer.lore")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "lore" -> + { + if (!sender.hasPermission("itemizer.lore")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { - sender.sendMessage(colorize(""" - &3===============&f[&dLore Commands&f]&3=============== - &b/itemizer lore add <&ftext&b> &c- &6Add a line of text to your item's lore - &b/itemizer lore remove <&findex&b> &c- &6Remove a line of text from your item's lore - &b/itemizer lore change <&findex&b> <&ftext&b> &c- &6Change a line of text in your item's lore - &b/itemizer lore clear &c- &6Clear the item's lore""")); + if (args.length == 1) + { + sender.sendMessage(mm.deserialize(""" + ===============[Lore Commands]=============== + /itemizer lore add <text> - Add a line of text to your item's lore + /itemizer lore remove <index> - Remove a line of text from your item's lore + /itemizer lore change <index> <text> - Change a line of text in your item's lore + /itemizer lore clear - Clear the item's lore""")); return true; } - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; - } else { - switch (args[1]) { - case "add" -> { - if (!sender.hasPermission("itemizer.lore.add")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + } + else + { + switch (args[1]) + { + case "add" -> + { + if (!sender.hasPermission("itemizer.lore.add")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dLore Commands&f]&3===============\n" - + "&b/itemizer lore add <&ftext&b> &c- &6Add a line of text to your item's lore")); + if (args.length == 2) + { + sender.sendMessage(mm.deserialize("===============[Lore Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer lore add <text> - Add a line of text to your item's lore")); return true; } - String lore = colorize(StringUtils.join(args, " ", 2, args.length)); + Component lore = mm.deserialize(StringUtils.join(args, " ", 2, args.length)); assert meta != null; - List lores = new ArrayList<>(); - if (meta.getLore() != null) { - lores = meta.getLore(); + List lores = new ArrayList<>(); + if (meta.lore() != null) + { + lores = meta.lore(); } lores.add(lore); - meta.setLore(lores); + meta.lore(lores); item.setItemMeta(meta); - sender.sendMessage(colorize("&2Line &f'" + lore + "&f'&2 added to the item's lore")); + sender.sendMessage(mm.deserialize("Line '" + mm.serialize(lore) + "' added to the item's lore")); return true; } - case "remove" -> { - if (!sender.hasPermission("itemizer.lore.remove")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "remove" -> + { + if (!sender.hasPermission("itemizer.lore.remove")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 2) { - sender.sendMessage(colorize("&3===============&f[&dLore Commands&f]&3===============\n" - + "&b/itemizer lore remove <&findex&b> &c- &6Remove a line of text from your item's lore")); + if (args.length == 2) + { + sender.sendMessage(mm.deserialize("===============[Lore Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer lore remove <index> - Remove a line of text from your item's lore")); return true; } Integer index = parseInt(sender, args[2]); - if (index == null) { + if (index == null) + { return true; } assert meta != null; - List lores; - if (meta.getLore() != null) { - lores = meta.getLore(); - } else { - sender.sendMessage(colorize("&eThis item has no lores.")); + List lores; + if (meta.lore() != null) + { + lores = meta.lore(); + } + else + { + sender.sendMessage(mm.deserialize("This item has no lores.")); return true; } - if (index > lores.size()) { - sender.sendMessage(colorize("&4The item's lore doesn't have line &f'" + index + "'")); + if (index > lores.size()) + { + sender.sendMessage(mm.deserialize("The item's lore doesn't have line '" + index + "'")); return true; } lores.remove(index - 1); - meta.setLore(lores); + meta.lore(lores); item.setItemMeta(meta); - sender.sendMessage(colorize("&2Line &f'" + index + "&f'&2 removed from the item's lore")); + sender.sendMessage(mm.deserialize("Line '" + index + "' removed from the item's lore")); return true; } - case "change" -> { - if (!sender.hasPermission("itemizer.lore.change")) { + case "change" -> + { + if (!sender.hasPermission("itemizer.lore.change")) + { sender.sendMessage(colorize("&4You don't have permission to use this command!")); return true; } - if (args.length < 4) { - sender.sendMessage(colorize("&3===============&f[&dLore Commands&f]&3===============\n" - + "&b/itemizer lore change <&findex&b> <&ftext&b> &c- &6Change a line of text in your item's lore")); + if (args.length < 4) + { + sender.sendMessage(mm.deserialize("===============[Lore Commands]===============")); + sender.sendMessage(mm.deserialize("/itemizer lore change <index> <text> - Change a line of text in your item's lore")); return true; } Integer index = parseInt(sender, args[2]); - if (index == null) { + if (index == null) + { return true; } - String lore = colorize(StringUtils.join(args, " ", 3, args.length)); + Component lore = mm.deserialize(StringUtils.join(args, " ", 3, args.length)); assert meta != null; - List lores; - if (meta.getLore() != null) { - lores = meta.getLore(); - } else { - sender.sendMessage(colorize("&eThis item has no lores.")); + List lores; + if (meta.lore() != null) + { + lores = meta.lore(); + } + else + { + sender.sendMessage(mm.deserialize("This item has no lores.")); return true; } - if (index > lores.size()) { + if (index > lores.size()) + { + sender.sendMessage(mm.deserialize("")); sender.sendMessage(colorize("&4The item's lore doesn't have line &f'" + index + "'")); return true; } lores.set(index - 1, lore); - meta.setLore(lores); + meta.lore(lores); item.setItemMeta(meta); - sender.sendMessage(colorize("&2Line &f'" + index + "'&2 has changed to &f'" + lore + "&f'")); + sender.sendMessage(mm.deserialize("Line '" + index + "' has been changed to '" + lore + "'")); return true; } - case "clear" -> { - if (!sender.hasPermission("itemizer.lore.clear")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "clear" -> + { + if (!sender.hasPermission("itemizer.lore.clear")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } assert meta != null; - if (meta.getLore() == null || meta.getLore().isEmpty()) { - sender.sendMessage(colorize("&4The item has no lores.")); + if (meta.lore() == null || meta.lore().isEmpty()) + { + sender.sendMessage(mm.deserialize("The item has no lores.")); return true; } - meta.setLore(null); + meta.lore(null); item.setItemMeta(meta); - sender.sendMessage(colorize("&2The item's lore has been cleared!")); + sender.sendMessage(mm.deserialize("The item's lore has been cleared!")); return true; } - default -> { - sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer lore &bfor help.")); + default -> + { + sender.sendMessage(mm.deserialize("Unknown sub-command. Type for help.")); return true; } } } } - case "potion" -> { - if (!sender.hasPermission("itemizer.potion")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "potion" -> + { + if (!sender.hasPermission("itemizer.potion")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize(""" - &3===============&f[&dPotion Commands&f]&3=============== - &b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect - &b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect - &b/itemizer potion change <&fname&b> &c- &6Change the potion type - &b/itemizer potion color <&fhexcolor&b> &c- &6Set the potion color - &b/itemizer potion list &c- &6List all potion effects""")); + &3===============&f[&dPotion Commands&f]&3=============== + &b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect + &b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect + &b/itemizer potion change <&fname&b> &c- &6Change the potion type + &b/itemizer potion color <&fhexcolor&b> &c- &6Set the potion color + &b/itemizer potion list &c- &6List all potion effects""")); return true; } - if (!hasPotion) { + if (!hasPotion) + { sender.sendMessage("Get a POTION in hand!"); return true; - } else { - switch (args[1]) { - case "add" -> { - if (!sender.hasPermission("itemizer.potion.add")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + } + else + { + switch (args[1]) + { + case "add" -> + { + if (!sender.hasPermission("itemizer.potion.add")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length < 5) { + if (args.length < 5) + { sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" + "&b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect")); return true; } PotionEffectType potType = PotionEffectType.getByName(args[2].toUpperCase()); - if (potType == null) { + if (potType == null) + { sender.sendMessage(colorize("&4The potion &f\"" + args[2] + "&f\"&4 does not exist!")); return true; } Integer level = parseInt(sender, args[3]); Integer tick = parseInt(sender, args[4]); - if (level == null || tick == null) { + if (level == null || tick == null) + { return true; } final PotionEffect pot = new PotionEffect(potType, tick, level); - final PotionMeta potionMeta = (PotionMeta) meta; + final PotionMeta potionMeta = (PotionMeta)meta; assert potionMeta != null; - if (potionMeta.hasCustomEffect(pot.getType())) { + if (potionMeta.hasCustomEffect(pot.getType())) + { sender.sendMessage(colorize("&4This potion already has &f" + pot.getType().getName())); return true; } @@ -301,24 +363,29 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sender.sendMessage(colorize(pot.getType().getName() + " &2has been added to the potion")); return true; } - case "remove" -> { - if (!sender.hasPermission("itemizer.potion.remove")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "remove" -> + { + if (!sender.hasPermission("itemizer.potion.remove")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 2) { + if (args.length == 2) + { sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" + "&b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect")); return true; } PotionEffectType potType = PotionEffectType.getByName(args[2].toUpperCase()); - if (potType == null) { + if (potType == null) + { sender.sendMessage("&4The potion effect &f\"" + args[2] + "&f\"&4 does not exist!"); return true; } - final PotionMeta potionMeta = (PotionMeta) meta; + final PotionMeta potionMeta = (PotionMeta)meta; assert potionMeta != null; - if (!potionMeta.hasCustomEffect(potType)) { + if (!potionMeta.hasCustomEffect(potType)) + { sender.sendMessage(colorize("This potion does not have &f" + potType.getName())); return true; } @@ -327,18 +394,22 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sender.sendMessage(colorize(potType.getName() + " &2has been removed from the potion")); return true; } - case "change" -> { - if (!sender.hasPermission("itemizer.potion.change")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "change" -> + { + if (!sender.hasPermission("itemizer.potion.change")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 2) { + if (args.length == 2) + { sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" + "&b/itemizer potion change <&fname&b> &c- &6Change the potion type")); return true; } Material material = Material.matchMaterial(args[2]); - if (material == null || !POTIONS.contains(material)) { + if (material == null || !POTIONS.contains(material)) + { sender.sendMessage(colorize(material != null ? "&f'" + material.name() + "' &4is not a potion type!" : @@ -349,150 +420,189 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sender.sendMessage(colorize("&2The potion in hand has changed to &f'" + material.name() + "'")); return true; } - case "color" -> { - if (!sender.hasPermission("itemizer.potion.color")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "color" -> + { + if (!sender.hasPermission("itemizer.potion.color")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length < 3) { + if (args.length < 3) + { sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n" + "&b/itemizer potion color <&fhexcolor&b> &c- &6Set a potion color")); return true; } - final PotionMeta potionMeta = (PotionMeta) meta; + final PotionMeta potionMeta = (PotionMeta)meta; assert potionMeta != null; - try { + try + { java.awt.Color awtColor = java.awt.Color.decode(args[2]); Color color = Color.fromRGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue()); potionMeta.setColor(color); item.setItemMeta(potionMeta); sender.sendMessage(colorize(args[2] + " &2has been set as potion color")); - } catch (NumberFormatException ignored) { + } + catch (NumberFormatException ignored) + { sender.sendMessage(colorize("&4The hex &f\"" + args[2] + "&f\"&4 is invalid!")); return true; } return true; } - case "list" -> { - if (!sender.hasPermission("itemizer.potion.list")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "list" -> + { + if (!sender.hasPermission("itemizer.potion.list")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } StringBuilder sb = new StringBuilder(); PotionEffectType[] effects; - for (int i = 0; i < (effects = PotionEffectType.values()).length; i++) { + for (int i = 0; i < (effects = PotionEffectType.values()).length; i++) + { sb.append(", ").append(effects[i].getName()); } sender.sendMessage(colorize("&2Available potion effects: &e" + sb.toString().replaceFirst(", ", ""))); return true; } - default -> { + default -> + { sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer potion &bfor help.")); return true; } } } } - case "attr" -> { - if (!sender.hasPermission("itemizer.attr")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "attr" -> + { + if (!sender.hasPermission("itemizer.attr")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize(""" - &3===============&f[&dAttribute Commands&f]&3=============== - &b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c - &6Add an attribute - &b/itemizer attr remove <&fname&b> &c- &6Remove an attribute - &b/itemizer attr list &c- &6List all item's attributes - &b/itemizer attr listall &c- &6List all supported attributes""")); + &3===============&f[&dAttribute Commands&f]&3=============== + &b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c - &6Add an attribute + &b/itemizer attr remove <&fname&b> &c- &6Remove an attribute + &b/itemizer attr list &c- &6List all item's attributes + &b/itemizer attr listall &c- &6List all supported attributes""")); return true; } - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; - } else { - switch (args[1]) { - case "add" -> { - if (!sender.hasPermission("itemizer.attr.add")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + } + else + { + switch (args[1]) + { + case "add" -> + { + if (!sender.hasPermission("itemizer.attr.add")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } plugin.attr.addAttr(player, args); return true; } - case "remove" -> { - if (!sender.hasPermission("itemizer.attr.remove")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "remove" -> + { + if (!sender.hasPermission("itemizer.attr.remove")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } plugin.attr.removeAttr(player, args[2]); return true; } - case "list" -> { - if (!sender.hasPermission("itemizer.attr.list")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "list" -> + { + if (!sender.hasPermission("itemizer.attr.list")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } plugin.attr.listAttr(player); return true; } - case "listall" -> { - if (!sender.hasPermission("itemizer.attr.listall")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "listall" -> + { + if (!sender.hasPermission("itemizer.attr.listall")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } sender.sendMessage(colorize("&2Supported attributes: " + "&e" + Attributes.getAttributes())); return true; } - default -> { + default -> + { sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer attr &bfor help.")); return true; } } } } - case "flag" -> { - if (!sender.hasPermission("itemizer.flag")) { - sender.sendMessage("&4You don't have permission to use this command!"); + case "flag" -> + { + if (!sender.hasPermission("itemizer.flag")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize(""" - &3===============&f[&dFlag Commands&f]&3=============== - &b/itemizer flag add <&fname&b> &c- &6Add a flag - &b/itemizer flag remove <&fname&b> &c- &6Remove a flag - &b/itemizer flag list &c- &6List all item's flag - &b/itemizer flag listall &c- &6List all available flags""")); + &3===============&f[&dFlag Commands&f]&3=============== + &b/itemizer flag add <&fname&b> &c- &6Add a flag + &b/itemizer flag remove <&fname&b> &c- &6Remove a flag + &b/itemizer flag list &c- &6List all item's flag + &b/itemizer flag listall &c- &6List all available flags""")); return true; } - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; } - switch (args[1]) { - case "add" -> { - if (!sender.hasPermission("itemizer.flag.add")) { + switch (args[1]) + { + case "add" -> + { + if (!sender.hasPermission("itemizer.flag.add")) + { sender.sendMessage(colorize("&4You don't have permission to use this command!")); return true; } - if (args.length == 2) { + if (args.length == 2) + { sender.sendMessage(colorize("&3===============&f[&dFlag Commands&f]&3===============\n" + "&b/itemizer flag add <&fname&b> &c- &6Add a flag")); return true; } ItemFlag flag = null; - try { + try + { flag = ItemFlag.valueOf(args[2].toUpperCase()); - } catch (Exception ignored) { } - if (flag == null) { + catch (Exception ignored) + { + } + if (flag == null) + { sender.sendMessage(colorize("&4The flag &f\"" + args[2] + "&f\" does not exist!")); return true; } assert meta != null; - if (meta.getItemFlags().contains(flag)) { + if (meta.getItemFlags().contains(flag)) + { sender.sendMessage(colorize("&4The flag &f'" + args[2].toUpperCase() + "' &4already added to the item!")); return true; } @@ -501,27 +611,35 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sender.sendMessage(colorize("&2The flag &f'" + args[2].toUpperCase() + "' &2has been added to your item!")); return true; } - case "remove" -> { - if (!sender.hasPermission("itemizer.flag.remove")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "remove" -> + { + if (!sender.hasPermission("itemizer.flag.remove")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 2) { + if (args.length == 2) + { sender.sendMessage(colorize("&3===============&f[&dFlag Commands&f]&3===============\n" + "&b/itemizer flag remove <&fname&b> &c- &6remove a flag")); return true; } ItemFlag flag = null; - try { + try + { flag = ItemFlag.valueOf(args[2].toUpperCase()); - } catch (Exception ignored) { } - if (flag == null) { + catch (Exception ignored) + { + } + if (flag == null) + { sender.sendMessage(colorize("&4The flag &f\"" + args[2] + "&f\" does not exist!")); return true; } assert meta != null; - if (!meta.getItemFlags().contains(flag)) { + if (!meta.getItemFlags().contains(flag)) + { sender.sendMessage(colorize("&4The flag &f'" + args[2].toUpperCase() + "' &4has not been added the item!")); return true; } @@ -530,13 +648,16 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sender.sendMessage(colorize("&2The flag &f'" + args[2].toUpperCase() + "' &2has been removed from your item!")); return true; } - case "list" -> { - if (!sender.hasPermission("itemizer.flag.list")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "list" -> + { + if (!sender.hasPermission("itemizer.flag.list")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } assert meta != null; - if (Objects.requireNonNull(meta.getItemFlags()).isEmpty()) { + if (Objects.requireNonNull(meta.getItemFlags()).isEmpty()) + { sender.sendMessage(colorize("&4The item in your hand does not have any flags")); return true; } @@ -544,84 +665,103 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { + StringUtils.join(meta.getItemFlags(), ", "))); return true; } - case "listall" -> { - if (!sender.hasPermission("itemizer.flag.listall")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "listall" -> + { + if (!sender.hasPermission("itemizer.flag.listall")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } sender.sendMessage(colorize("&2Available item flags: &e" + StringUtils.join(ItemFlag.values(), ", "))); return true; } - default -> { + default -> + { sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer flag &bfor help")); return true; } } } - case "enchant" -> { - if (!sender.hasPermission("itemizer.enchant")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "enchant" -> + { + if (!sender.hasPermission("itemizer.enchant")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize(""" - &3===============&f[&dEnchant Commands&f]&3=============== - &b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant - &b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant - &b/itemizer enchant list &c- &6List all item's enchants - &b/itemizer enchant listall &c- &6List all available enchants""")); + &3===============&f[&dEnchant Commands&f]&3=============== + &b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant + &b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant + &b/itemizer enchant list &c- &6List all item's enchants + &b/itemizer enchant listall &c- &6List all available enchants""")); return true; } - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; } - switch (args[1]) { - case "add" -> { - if (!sender.hasPermission("itemizer.enchant.add")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + switch (args[1]) + { + case "add" -> + { + if (!sender.hasPermission("itemizer.enchant.add")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length < 4) { + if (args.length < 4) + { sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n" + "&b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant")); return true; } final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase())); - if (ench == null) { + if (ench == null) + { sender.sendMessage(colorize("&4The enchantment &f'" + args[2] + "&f' &4does not exist!")); return true; } Integer level = parseInt(sender, args[3]); - if (level == null) { + if (level == null) + { return true; } item.addUnsafeEnchantment(ench, level); sender.sendMessage(colorize("&2The enchant &f'" + ench.getKey().getKey() + "' &2has been added to your item")); return true; } - case "remove" -> { - if (!sender.hasPermission("itemizer.enchant.remove")) { - sender.sendMessage("&4You don't have permission to use this command!"); + case "remove" -> + { + if (!sender.hasPermission("itemizer.enchant.remove")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 2) { + if (args.length == 2) + { sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n" + "&b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant")); return true; } final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase())); - if (ench == null) { + if (ench == null) + { sender.sendMessage(colorize("&4The enchantment &f'" + args[2] + "&f' &4does not exist!")); return true; } assert meta != null; - if (Objects.requireNonNull(meta.getEnchants()).isEmpty()) { + if (Objects.requireNonNull(meta.getEnchants()).isEmpty()) + { sender.sendMessage(colorize("&4This item doesn't hold any enchants")); return true; } - if (!meta.getEnchants().containsKey(ench)) { + if (!meta.getEnchants().containsKey(ench)) + { sender.sendMessage(colorize("&4This item doesn't have &f'" + ench.getKey().getKey() + "' &4enchant!")); return true; } @@ -629,13 +769,16 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { sender.sendMessage(colorize("&2The enchant &f'" + ench.getKey().getKey() + "' &2has been removed from your item")); return true; } - case "list" -> { - if (!sender.hasPermission("itemizer.enchant.list")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "list" -> + { + if (!sender.hasPermission("itemizer.enchant.list")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } assert meta != null; - if (Objects.requireNonNull(meta.getEnchants()).isEmpty()) { + if (Objects.requireNonNull(meta.getEnchants()).isEmpty()) + { sender.sendMessage(colorize("&4This item doesn't hold any enchants")); return true; } @@ -643,154 +786,186 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { + StringUtils.join(meta.getEnchants().keySet(), ", "))); return true; } - case "listall" -> { - if (!sender.hasPermission("itemizer.enchant.listall")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "listall" -> + { + if (!sender.hasPermission("itemizer.enchant.listall")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } StringBuilder sb = new StringBuilder(); Enchantment[] enchantments; - for (int i = 0; i < (enchantments = Enchantment.values()).length; i++) { + for (int i = 0; i < (enchantments = Enchantment.values()).length; i++) + { sb.append(", ").append(enchantments[i].getKey().getKey()); } sender.sendMessage(colorize("&2Available item enchants: &e" + sb.toString().replaceFirst(", ", ""))); return true; } - default -> { + default -> + { sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer enchant &bfor help.")); return true; } } } - case "title" -> { - if (!sender.hasPermission("itemizer.title")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "title" -> + { + if (!sender.hasPermission("itemizer.title")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize("&3===============&f[&dTitle Command&f]&3===============\n" + "&b/itemizer title <&fname&b> &c- &6Set the book's title")); return true; } - if (!hasBook) { - sender.sendMessage("Get a WRITTEN_BOOK in hand!"); + if (!hasBook) + { + sender.sendMessage(mm.deserialize("You do not have a Written Book in your hand.")); return true; } String name = colorize(StringUtils.join(args, " ", 1, args.length)); - final BookMeta bookMeta = (BookMeta) meta; + final BookMeta bookMeta = (BookMeta)meta; assert bookMeta != null; bookMeta.setTitle(name); item.setItemMeta(bookMeta); sender.sendMessage(colorize("&2The title of the book has been set to &f'" + name + "&f'")); return true; } - case "author" -> { - if (!sender.hasPermission("itemizer.author")) { - sender.sendMessage("&4You don't have permission to use this command!"); + case "author" -> + { + if (!sender.hasPermission("itemizer.author")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize("&3===============&f[&dAuthor Command&f]&3===============\n" + "&b/itemizer author <&fname&b> &c- &6Set the book's title")); return true; } - if (!hasBook) { - sender.sendMessage("Get a WRITTEN_BOOK in hand!"); + if (!hasBook) + { + sender.sendMessage(mm.deserialize("You do not have a Written Book in your hand.")); return true; } String name = colorize(args[1]); - final BookMeta bookMeta = (BookMeta) meta; + final BookMeta bookMeta = (BookMeta)meta; assert bookMeta != null; bookMeta.setAuthor(name); item.setItemMeta(bookMeta); sender.sendMessage(colorize("&2The author of the book has been set to &f'" + name + "&f'")); return true; } - case "head" -> { - if (!sender.hasPermission("itemizer.head")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "head" -> + { + if (!sender.hasPermission("itemizer.head")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length == 1) { + if (args.length == 1) + { sender.sendMessage(colorize("&3===============&f[&dHead Command&f]&3===============\n" + "&b/itemizer head <&fname&b> &c- &6Set the player of the head")); return true; } - if (item.getType() != Material.PLAYER_HEAD) { - sender.sendMessage("Get a SKULL in hand!"); + if (item.getType() != Material.PLAYER_HEAD) + { + sender.sendMessage(mm.deserialize("You do not have a Skull in your hand.")); return true; } String name = args[1]; - if (name.length() > 16) { + if (name.length() > 16) + { name = name.substring(0, 16); } - final SkullMeta skullMeta = (SkullMeta) meta; + final SkullMeta skullMeta = (SkullMeta)meta; assert skullMeta != null; skullMeta.setOwner(name); item.setItemMeta(skullMeta); sender.sendMessage(colorize("&2The player of the head has been set to &f'" + name + "&f'")); return true; } - case "sign" -> { - if (!sender.hasPermission("itemizer.sign")) { - sender.sendMessage("&4You don't have permission to use this command!"); + case "sign" -> + { + if (!sender.hasPermission("itemizer.sign")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (args.length < 3) { + if (args.length < 3) + { sender.sendMessage(colorize("&3===============&f[&dSign Command&f]&3===============\n" + "&b/itemizer sign <&fline&b> <&ftext&b> &c- &6Change the line on the sign")); return true; } final Block block = player.getTargetBlockExact(20); if (block == null || block.getType() == Material.AIR - || !block.getType().toString().contains("SIGN")) { + || !block.getType().toString().contains("SIGN")) + { sender.sendMessage(colorize("&4Please look at a sign!")); return true; } Integer line = parseInt(sender, args[1]); - if (line == null) { + if (line == null) + { return true; - } else if (line > 4) { + } + else if (line > 4) + { sender.sendMessage(colorize("&4There's maximum of 4 lines on a sign")); return true; } String text = colorize(StringUtils.join(args, " ", 2, args.length)); - if (cpb.getAPI() != null) { + if (cpb.getAPI() != null) + { cpb.getAPI().logRemoval(player.getName(), block.getLocation(), block.getType(), block.getBlockData()); } - Sign sign = (Sign) block.getState(); + Sign sign = (Sign)block.getState(); sign.setLine(line - 1, text); sign.update(); - if (cpb.getAPI() != null) { + if (cpb.getAPI() != null) + { cpb.getAPI().logPlacement(player.getName(), sign.getLocation(), sign.getType(), sign.getBlockData()); } sender.sendMessage(colorize("&2Line &f'" + line + "'&2 has successfully changed to &f'" + text + "&f'")); return true; } - case "clearall" -> { - if (!sender.hasPermission("itemizer.clearall")) { - sender.sendMessage(colorize("&4You don't have permission to use this command!")); + case "clearall" -> + { + if (!sender.hasPermission("itemizer.clearall")) + { + sender.sendMessage(mm.deserialize("You don't have permission to use this command!")); return true; } - if (!hasItem) { - sender.sendMessage("Get an ITEM in hand!"); + if (!hasItem) + { + sender.sendMessage(mm.deserialize("You do not have an item in your hand.")); return true; } item.setItemMeta(null); sender.sendMessage(colorize("&2All data cleared from your item")); return true; } - default -> { + default -> + { sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer help &bfor help.")); return true; } } } - private String colorize(String string) { + private String colorize(String string) + { Matcher matcher = Pattern.compile("&#[a-fA-F0-9]{6}").matcher(string); - while (matcher.find()) { + while (matcher.find()) + { String code = matcher.group().replace("&", ""); string = string.replace("&" + code, net.md_5.bungee.api.ChatColor.of(code) + ""); } @@ -798,10 +973,14 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase { return string; } - private Integer parseInt(CommandSender sender, String string) { - try { + private Integer parseInt(CommandSender sender, String string) + { + try + { return Integer.parseInt(string); - } catch (NumberFormatException ex) { + } + catch (NumberFormatException ex) + { sender.sendMessage(colorize("&f\"" + string + "&f\"&4 is not a valid number!")); } return null; diff --git a/settings.gradle.kts b/settings.gradle.kts index 553894c..842b0ac 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,3 +1,7 @@ +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version("0.5.0") +} + rootProject.name = "ItemizerX" include("core") include("shared") diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index c15f5f1..7d01ba5 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -1,4 +1,6 @@ +apply(plugin = "io.papermc.paperweight.userdev") + dependencies { compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") - compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT") + paperDevBundle("1.20.1-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/shared/src/main/java/dev/plex/itemizerx/IAttributeManager.java b/shared/src/main/java/dev/plex/itemizerx/IAttributeManager.java index f55f38a..c4195ae 100644 --- a/shared/src/main/java/dev/plex/itemizerx/IAttributeManager.java +++ b/shared/src/main/java/dev/plex/itemizerx/IAttributeManager.java @@ -1,11 +1,11 @@ package dev.plex.itemizerx; -import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.ListTag; import net.minecraft.world.item.ItemStack; import org.bukkit.entity.Player; public interface IAttributeManager { - NBTTagList getAttrList(final ItemStack item); + ListTag getAttrList(final ItemStack item); void addAttr(final Player player, final String[] args); diff --git a/v1_17_R1/build.gradle.kts b/v1_17_R1/build.gradle.kts index d997be4..ec08643 100644 --- a/v1_17_R1/build.gradle.kts +++ b/v1_17_R1/build.gradle.kts @@ -1,3 +1,7 @@ +apply(plugin = "io.papermc.paperweight.userdev") +apply(plugin = "xyz.jpenilla.run-paper") + dependencies { - compileOnly("org.spigotmc:spigot:1.17.1-R0.1-SNAPSHOT") + paperDevBundle("1.17.1-R0.1-SNAPSHOT") + implementation("net.kyori:adventure-text-minimessage:4.14.0") } \ No newline at end of file diff --git a/v1_17_R1/src/main/java/dev/plex/itemizerx/v1_17_R1/AttributeManager.java b/v1_17_R1/src/main/java/dev/plex/itemizerx/v1_17_R1/AttributeManager.java index a32b476..ac44e51 100644 --- a/v1_17_R1/src/main/java/dev/plex/itemizerx/v1_17_R1/AttributeManager.java +++ b/v1_17_R1/src/main/java/dev/plex/itemizerx/v1_17_R1/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_17_R1; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); - if (attrmod == null) { - item.getTag().set("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.getString("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.setString("Name", args[2]); - c.setString("AttributeName", a.mcName); - c.setDouble("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.setInt("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.setIntArray("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.setString("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.getTag().set("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.getString("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.getTag().set("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.getString("AttributeName")).mcName + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } -} \ No newline at end of file +} diff --git a/v1_18_R1/build.gradle.kts b/v1_18_R1/build.gradle.kts index 8b05208..c4b5b6d 100644 --- a/v1_18_R1/build.gradle.kts +++ b/v1_18_R1/build.gradle.kts @@ -1,3 +1,7 @@ +apply(plugin = "io.papermc.paperweight.userdev") +apply(plugin = "xyz.jpenilla.run-paper") + dependencies { - compileOnly("org.spigotmc:spigot:1.18.1-R0.1-SNAPSHOT") + paperDevBundle("1.18.1-R0.1-SNAPSHOT") + implementation("net.kyori:adventure-text-minimessage:4.14.0") } \ No newline at end of file diff --git a/v1_18_R1/src/main/java/dev/plex/itemizerx/v1_18_R1/AttributeManager.java b/v1_18_R1/src/main/java/dev/plex/itemizerx/v1_18_R1/AttributeManager.java index dc76ca1..d38af25 100644 --- a/v1_18_R1/src/main/java/dev/plex/itemizerx/v1_18_R1/AttributeManager.java +++ b/v1_18_R1/src/main/java/dev/plex/itemizerx/v1_18_R1/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_18_R1; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.t().c("AttributeModifiers", 10); - if (attrmod == null) { - item.t().a("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } - return item.t().c("AttributeModifiers", 10); + return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.l("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.a("Name", args[2]); - c.a("AttributeName", a.mcName); - c.a("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.a("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.a("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.a("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.t().a("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.l("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.t().a("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName - + ", " + c.k("Amount"))); + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } -} \ No newline at end of file +} diff --git a/v1_18_R2/build.gradle.kts b/v1_18_R2/build.gradle.kts index cd1ea9c..85c85c7 100644 --- a/v1_18_R2/build.gradle.kts +++ b/v1_18_R2/build.gradle.kts @@ -1,3 +1,6 @@ +apply(plugin = "io.papermc.paperweight.userdev") +apply(plugin = "xyz.jpenilla.run-paper") + dependencies { - compileOnly("org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT") + paperDevBundle("1.18.2-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_18_R2/src/main/java/dev/plex/itemizerx/v1_18_R2/AttributeManager.java b/v1_18_R2/src/main/java/dev/plex/itemizerx/v1_18_R2/AttributeManager.java index 77e3389..b30bb40 100644 --- a/v1_18_R2/src/main/java/dev/plex/itemizerx/v1_18_R2/AttributeManager.java +++ b/v1_18_R2/src/main/java/dev/plex/itemizerx/v1_18_R2/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_18_R2; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.u().c("AttributeModifiers", 10); - if (attrmod == null) { - item.u().a("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } - return item.u().c("AttributeModifiers", 10); + return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.l("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.a("Name", args[2]); - c.a("AttributeName", a.mcName); - c.a("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.a("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.a("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.a("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.u().a("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.l("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.u().a("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName - + ", " + c.k("Amount"))); + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } -} \ No newline at end of file +} diff --git a/v1_19_R1/build.gradle.kts b/v1_19_R1/build.gradle.kts index ba20734..86a4664 100644 --- a/v1_19_R1/build.gradle.kts +++ b/v1_19_R1/build.gradle.kts @@ -1,3 +1,6 @@ +apply(plugin = "io.papermc.paperweight.userdev") +apply(plugin = "xyz.jpenilla.run-paper") + dependencies { - compileOnly("org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT") + paperDevBundle("1.19.2-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_19_R1/src/main/java/dev/plex/itemizerx/v1_19_R1/AttributeManager.java b/v1_19_R1/src/main/java/dev/plex/itemizerx/v1_19_R1/AttributeManager.java index b48ede9..7c8fd3b 100644 --- a/v1_19_R1/src/main/java/dev/plex/itemizerx/v1_19_R1/AttributeManager.java +++ b/v1_19_R1/src/main/java/dev/plex/itemizerx/v1_19_R1/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_19_R1; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.v().c("AttributeModifiers", 10); - if (attrmod == null) { - item.u().a("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } - return item.u().c("AttributeModifiers", 10); + return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.l("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.a("Name", args[2]); - c.a("AttributeName", a.mcName); - c.a("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.a("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.a("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.a("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.u().a("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.l("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.u().a("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName - + ", " + c.k("Amount"))); + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } -} \ No newline at end of file +} diff --git a/v1_19_R2/build.gradle.kts b/v1_19_R2/build.gradle.kts index ca90d4a..47c91cd 100644 --- a/v1_19_R2/build.gradle.kts +++ b/v1_19_R2/build.gradle.kts @@ -1,3 +1,6 @@ +apply(plugin = "io.papermc.paperweight.userdev") +apply(plugin = "xyz.jpenilla.run-paper") + dependencies { - compileOnly("org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT") + paperDevBundle("1.19.3-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_19_R2/src/main/java/dev/plex/itemizerx/v1_19_R2/AttributeManager.java b/v1_19_R2/src/main/java/dev/plex/itemizerx/v1_19_R2/AttributeManager.java index ced8c39..65fefee 100644 --- a/v1_19_R2/src/main/java/dev/plex/itemizerx/v1_19_R2/AttributeManager.java +++ b/v1_19_R2/src/main/java/dev/plex/itemizerx/v1_19_R2/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_19_R2; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.v().c("AttributeModifiers", 10); - if (attrmod == null) { - item.u().a("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } - return item.u().c("AttributeModifiers", 10); + return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.l("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.a("Name", args[2]); - c.a("AttributeName", a.mcName); - c.a("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.a("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.a("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.a("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.u().a("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.l("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.u().a("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName - + ", " + c.k("Amount"))); + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } -} \ No newline at end of file +} diff --git a/v1_19_R3/build.gradle.kts b/v1_19_R3/build.gradle.kts index 213f831..0b87cbd 100644 --- a/v1_19_R3/build.gradle.kts +++ b/v1_19_R3/build.gradle.kts @@ -1,3 +1,6 @@ +apply(plugin = "io.papermc.paperweight.userdev") +apply(plugin = "xyz.jpenilla.run-paper") + dependencies { - compileOnly("org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT") + paperDevBundle("1.19.4-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_19_R3/src/main/java/dev/plex/itemizerx/v1_19_R3/AttributeManager.java b/v1_19_R3/src/main/java/dev/plex/itemizerx/v1_19_R3/AttributeManager.java index e21acd1..0c1c69f 100644 --- a/v1_19_R3/src/main/java/dev/plex/itemizerx/v1_19_R3/AttributeManager.java +++ b/v1_19_R3/src/main/java/dev/plex/itemizerx/v1_19_R3/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_19_R3; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.v().c("AttributeModifiers", 10); - if (attrmod == null) { - item.u().a("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } - return item.u().c("AttributeModifiers", 10); + return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.l("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.a("Name", args[2]); - c.a("AttributeName", a.mcName); - c.a("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.a("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.a("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.a("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.u().a("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.l("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.u().a("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName - + ", " + c.k("Amount"))); + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } -} \ No newline at end of file +} diff --git a/v1_20_R1/build.gradle.kts b/v1_20_R1/build.gradle.kts index 5052a96..5ad2ffb 100644 --- a/v1_20_R1/build.gradle.kts +++ b/v1_20_R1/build.gradle.kts @@ -1,3 +1,3 @@ dependencies { - compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT") + paperDevBundle("1.20.1-R0.1-SNAPSHOT") } \ No newline at end of file diff --git a/v1_20_R1/src/main/java/dev/plex/itemizerx/v1_20_R1/AttributeManager.java b/v1_20_R1/src/main/java/dev/plex/itemizerx/v1_20_R1/AttributeManager.java index 51c4ea9..c38180c 100644 --- a/v1_20_R1/src/main/java/dev/plex/itemizerx/v1_20_R1/AttributeManager.java +++ b/v1_20_R1/src/main/java/dev/plex/itemizerx/v1_20_R1/AttributeManager.java @@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_20_R1; import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.IAttributeManager; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.Tag; import net.minecraft.world.item.ItemStack; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.entity.Player; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; - -public class AttributeManager implements IAttributeManager { +public class AttributeManager implements IAttributeManager +{ + private final MiniMessage mm = MiniMessage.miniMessage(); @Override - public NBTTagList getAttrList(final ItemStack item) { - NBTTagList attrmod = item.w().c("AttributeModifiers", 10); - if (attrmod == null) { - item.v().a("AttributeModifiers", new NBTTagList()); + public ListTag getAttrList(final ItemStack item) + { + ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); + if (attrmod == null) + { + item.getTag().put("AttributeModifiers", new CompoundTag()); } - return item.v().c("AttributeModifiers", 10); + return item.getTag().getList("AttributeModifiers", 10); } @Override - public void addAttr(final Player player, final String[] args) { + public void addAttr(final Player player, final String[] args) + { int op; - if (args.length < 4) { - player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " - + "&6Add an attribute")); + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); return; } final Attributes a = Attributes.get(args[2]); - if (a == null) { - player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); return; } double amount; - try { + try + { amount = Double.parseDouble(args[3]); - } catch (NumberFormatException ex) { - player.sendMessage(colorize("&4\"" + args[3] + "\" is not a valid number.")); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); return; } - if (Double.isNaN(amount)) { - player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); return; } final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (c.l("Name").equals(args[2])) { - player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); return; } } - final NBTTagCompound c = new NBTTagCompound(); - c.a("Name", args[2]); - c.a("AttributeName", a.mcName); - c.a("Amount", amount); + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); op = a.op; - c.a("Operation", op); + c.putInt("Operation", op); final Random random = new Random(); - c.a("UUID", new int[] + c.putIntArray("UUID", new int[] { random.nextInt(), random.nextInt(), random.nextInt(), random.nextInt() }); - if (args.length == 5) { + if (args.length == 5) + { final List options = new ArrayList<>(); options.add("mainhand"); options.add("offhand"); @@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager { options.add("chest"); options.add("legs"); options.add("feet"); - if (!options.contains(args[4].toLowerCase())) { - player.sendMessage(colorize("&2Supported options:\n" - + "&e" + StringUtils.join(options, ", "))); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); return; } - c.a("Slot", args[4].toLowerCase()); + c.putString("Slot", args[4].toLowerCase()); } attrmod.add(c); - nms.v().a("AttributeModifiers", attrmod); + nms.getTag().put("AttributeModifiers", attrmod); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute added!")); + player.sendMessage(mm.deserialize("Attribute added!")); } @Override - public void removeAttr(final Player player, final String string) { + public void removeAttr(final Player player, final String string) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - final NBTTagList newList = new NBTTagList(); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); boolean r = false; - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - if (!c.l("Name").equals(string)) { + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + if (!c.getString("Name").equals(string)) + { newList.add(nbtBase); - } else { + } + else + { r = true; } } - if (!r) { - player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); return; } - nms.v().a("AttributeModifiers", newList); + nms.getTag().put("AttributeModifiers", newList); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); player.getInventory().setItemInMainHand(is); - player.sendMessage(colorize("&2Attribute removed!")); + player.sendMessage(mm.deserialize("Attribute removed!")); } @Override - public void listAttr(final Player player) { + public void listAttr(final Player player) + { final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); - final NBTTagList attrmod = getAttrList(nms); - if (attrmod.size() == 0) { - player.sendMessage(colorize("&eThis item has no attributes.")); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); return; } - player.sendMessage(colorize("&2Item attributes: ")); - for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { - final NBTTagCompound c = (NBTTagCompound) nbtBase; - player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName - + ", " + c.k("Amount"))); + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag)nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); } } @Override - public String colorize(String string) { + public String colorize(String string) + { return ChatColor.translateAlternateColorCodes('&', string); } }