Push changes

This commit is contained in:
Telesphoreo 2023-07-15 19:07:47 -05:00
parent 2da2ab5e13
commit 40dcb9a336
No known key found for this signature in database
GPG Key ID: 9D1991811E093C02
21 changed files with 1173 additions and 764 deletions

View File

@ -1,23 +1,26 @@
plugins { plugins {
id("java") id("java")
id("com.github.johnrengelman.shadow") version "8.1.1" 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" group = "dev.plex"
version = "2.1" version = "2.1"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
}
subprojects { subprojects {
apply(plugin = "java") apply(plugin = "java")
apply(plugin = "com.github.johnrengelman.shadow") apply(plugin = "com.github.johnrengelman.shadow")
java.sourceCompatibility = JavaVersion.VERSION_17 apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
repositories { repositories {
mavenCentral() mavenCentral()
maven {
url = uri("https://repo.codemc.org/repository/nms/")
}
maven { maven {
url = uri("https://repo.papermc.io/repository/maven-public/") url = uri("https://repo.papermc.io/repository/maven-public/")
} }
@ -41,9 +44,23 @@ tasks {
archiveBaseName.set("ItemizerX") archiveBaseName.set("ItemizerX")
archiveClassifier.set("") archiveClassifier.set("")
archiveVersion.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 { assemble {
dependsOn("shadowJar") dependsOn("shadowJar")
dependsOn("reobfJar")
} }
jar { jar {

View File

@ -1,5 +1,6 @@
apply(plugin = "io.papermc.paperweight.userdev")
dependencies { dependencies {
implementation(project(":shared"))
implementation(project(":v1_20_R1")) implementation(project(":v1_20_R1"))
implementation(project(":v1_19_R3")) implementation(project(":v1_19_R3"))
implementation(project(":v1_19_R2")) implementation(project(":v1_19_R2"))
@ -8,4 +9,5 @@ dependencies {
implementation(project(":v1_18_R1")) implementation(project(":v1_18_R1"))
implementation(project(":v1_17_R1")) implementation(project(":v1_17_R1"))
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT")
paperDevBundle("1.20.1-R0.1-SNAPSHOT")
} }

View File

@ -1,5 +1,8 @@
package dev.plex.itemizerx; package dev.plex.itemizerx;
import net.kyori.adventure.text.minimessage.MiniMessage;
public interface ItemizerXBase { public interface ItemizerXBase {
ItemizerX plugin = ItemizerX.plugin; ItemizerX plugin = ItemizerX.plugin;
MiniMessage mm = MiniMessage.miniMessage();
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,7 @@
plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version("0.5.0")
}
rootProject.name = "ItemizerX" rootProject.name = "ItemizerX"
include("core") include("core")
include("shared") include("shared")

View File

@ -1,4 +1,6 @@
apply(plugin = "io.papermc.paperweight.userdev")
dependencies { dependencies {
compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") 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")
} }

View File

@ -1,11 +1,11 @@
package dev.plex.itemizerx; package dev.plex.itemizerx;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.ListTag;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public interface IAttributeManager { public interface IAttributeManager {
NBTTagList getAttrList(final ItemStack item); ListTag getAttrList(final ItemStack item);
void addAttr(final Player player, final String[] args); void addAttr(final Player player, final String[] args);

View File

@ -1,3 +1,7 @@
apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
dependencies { 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")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_17_R1;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.getTag().set("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.getTag().getList("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.getString("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.setString("Name", args[2]); c.putString("Name", args[2]);
c.setString("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.setDouble("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.setInt("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.setIntArray("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.setString("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.getTag().set("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.getString("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.getTag().set("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.getString("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount"))); + ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }

View File

@ -1,3 +1,7 @@
apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
dependencies { 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")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_18_R1;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.t().c("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.t().a("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.t().c("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.l("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.a("Name", args[2]); c.putString("Name", args[2]);
c.a("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.a("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.a("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.a("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.a("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.t().a("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.l("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.t().a("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
+ ", " + c.k("Amount"))); player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }

View File

@ -1,3 +1,6 @@
apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
dependencies { dependencies {
compileOnly("org.spigotmc:spigot:1.18.2-R0.1-SNAPSHOT") paperDevBundle("1.18.2-R0.1-SNAPSHOT")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_18_R2;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.u().c("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.u().a("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.u().c("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.l("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.a("Name", args[2]); c.putString("Name", args[2]);
c.a("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.a("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.a("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.a("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.a("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.l("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.u().a("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
+ ", " + c.k("Amount"))); player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }

View File

@ -1,3 +1,6 @@
apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
dependencies { dependencies {
compileOnly("org.spigotmc:spigot:1.19.2-R0.1-SNAPSHOT") paperDevBundle("1.19.2-R0.1-SNAPSHOT")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_19_R1;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.v().c("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.u().a("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.u().c("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.l("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.a("Name", args[2]); c.putString("Name", args[2]);
c.a("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.a("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.a("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.a("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.a("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.l("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.u().a("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
+ ", " + c.k("Amount"))); player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }

View File

@ -1,3 +1,6 @@
apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
dependencies { dependencies {
compileOnly("org.spigotmc:spigot:1.19.3-R0.1-SNAPSHOT") paperDevBundle("1.19.3-R0.1-SNAPSHOT")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_19_R2;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.v().c("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.u().a("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.u().c("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.l("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.a("Name", args[2]); c.putString("Name", args[2]);
c.a("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.a("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.a("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.a("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.a("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.l("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.u().a("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
+ ", " + c.k("Amount"))); player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }

View File

@ -1,3 +1,6 @@
apply(plugin = "io.papermc.paperweight.userdev")
apply(plugin = "xyz.jpenilla.run-paper")
dependencies { dependencies {
compileOnly("org.spigotmc:spigot:1.19.4-R0.1-SNAPSHOT") paperDevBundle("1.19.4-R0.1-SNAPSHOT")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_19_R3;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.v().c("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.u().a("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.u().c("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.l("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.a("Name", args[2]); c.putString("Name", args[2]);
c.a("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.a("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.a("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.a("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.a("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.u().a("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.l("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.u().a("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
+ ", " + c.k("Amount"))); player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }

View File

@ -1,3 +1,3 @@
dependencies { dependencies {
compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT") paperDevBundle("1.20.1-R0.1-SNAPSHOT")
} }

View File

@ -2,77 +2,92 @@ package dev.plex.itemizerx.v1_20_R1;
import dev.plex.itemizerx.Attributes; import dev.plex.itemizerx.Attributes;
import dev.plex.itemizerx.IAttributeManager; import dev.plex.itemizerx.IAttributeManager;
import net.minecraft.nbt.NBTTagCompound; import java.util.ArrayList;
import net.minecraft.nbt.NBTTagList; 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 net.minecraft.world.item.ItemStack;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_20_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList; public class AttributeManager implements IAttributeManager
import java.util.List; {
import java.util.Random; private final MiniMessage mm = MiniMessage.miniMessage();
public class AttributeManager implements IAttributeManager {
@Override @Override
public NBTTagList getAttrList(final ItemStack item) { public ListTag getAttrList(final ItemStack item)
NBTTagList attrmod = item.w().c("AttributeModifiers", 10); {
if (attrmod == null) { ListTag attrmod = item.getOrCreateTag().getList("AttributeModifiers", 10);
item.v().a("AttributeModifiers", new NBTTagList()); if (attrmod == null)
{
item.getTag().put("AttributeModifiers", new CompoundTag());
} }
return item.v().c("AttributeModifiers", 10); return item.getTag().getList("AttributeModifiers", 10);
} }
@Override @Override
public void addAttr(final Player player, final String[] args) { public void addAttr(final Player player, final String[] args)
{
int op; int op;
if (args.length < 4) { if (args.length < 4)
player.sendMessage(colorize("&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- " {
+ "&6Add an attribute")); player.sendMessage(mm.deserialize("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
return; return;
} }
final Attributes a = Attributes.get(args[2]); final Attributes a = Attributes.get(args[2]);
if (a == null) { if (a == null)
player.sendMessage(colorize("&4\"" + args[2] + "\" is not a valid attribute type.")); {
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
return; return;
} }
double amount; double amount;
try { try
{
amount = Double.parseDouble(args[3]); 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("<dark_red>\"" + args[3] + "\" is not a valid number."));
return; return;
} }
if (Double.isNaN(amount)) { if (Double.isNaN(amount))
player.sendMessage(colorize("&4Please do not use &f'NaN (Not a Number)'")); {
player.sendMessage(mm.deserialize("<dark_red>Please do not use <white>'NaN (Not a Number)'"));
return; return;
} }
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (c.l("Name").equals(args[2])) { final CompoundTag c = (CompoundTag)nbtBase;
player.sendMessage(colorize("&4An attribute with the name \"&f" + args[2] + "&4\" already exists!")); if (c.getString("Name").equals(args[2]))
{
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
return; return;
} }
} }
final NBTTagCompound c = new NBTTagCompound(); final CompoundTag c = new CompoundTag();
c.a("Name", args[2]); c.putString("Name", args[2]);
c.a("AttributeName", a.mcName); c.putString("AttributeName", a.mcName);
c.a("Amount", amount); c.putDouble("Amount", amount);
op = a.op; op = a.op;
c.a("Operation", op); c.putInt("Operation", op);
final Random random = new Random(); final Random random = new Random();
c.a("UUID", new int[] c.putIntArray("UUID", new int[]
{ {
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt(), random.nextInt(),
random.nextInt() random.nextInt()
}); });
if (args.length == 5) { if (args.length == 5)
{
final List<String> options = new ArrayList<>(); final List<String> options = new ArrayList<>();
options.add("mainhand"); options.add("mainhand");
options.add("offhand"); options.add("offhand");
@ -80,62 +95,73 @@ public class AttributeManager implements IAttributeManager {
options.add("chest"); options.add("chest");
options.add("legs"); options.add("legs");
options.add("feet"); options.add("feet");
if (!options.contains(args[4].toLowerCase())) { if (!options.contains(args[4].toLowerCase()))
player.sendMessage(colorize("&2Supported options:\n" {
+ "&e" + StringUtils.join(options, ", "))); player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(options, ", ")));
return; return;
} }
c.a("Slot", args[4].toLowerCase()); c.putString("Slot", args[4].toLowerCase());
} }
attrmod.add(c); attrmod.add(c);
nms.v().a("AttributeModifiers", attrmod); nms.getTag().put("AttributeModifiers", attrmod);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute added!")); player.sendMessage(mm.deserialize("<dark_aqua>Attribute added!"));
} }
@Override @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 ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
final NBTTagList newList = new NBTTagList(); final ListTag newList = new ListTag();
boolean r = false; boolean r = false;
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
if (!c.l("Name").equals(string)) { final CompoundTag c = (CompoundTag)nbtBase;
if (!c.getString("Name").equals(string))
{
newList.add(nbtBase); newList.add(nbtBase);
} else { }
else
{
r = true; r = true;
} }
} }
if (!r) { if (!r)
player.sendMessage(colorize("&4The attribute \"" + string + "\" doesn't exist!")); {
player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!"));
return; return;
} }
nms.v().a("AttributeModifiers", newList); nms.getTag().put("AttributeModifiers", newList);
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
player.getInventory().setItemInMainHand(is); player.getInventory().setItemInMainHand(is);
player.sendMessage(colorize("&2Attribute removed!")); player.sendMessage(mm.deserialize("<dark_green>Attribute removed!"));
} }
@Override @Override
public void listAttr(final Player player) { public void listAttr(final Player player)
{
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
final NBTTagList attrmod = getAttrList(nms); final ListTag attrmod = getAttrList(nms);
if (attrmod.size() == 0) { if (attrmod.size() == 0)
player.sendMessage(colorize("&eThis item has no attributes.")); {
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
return; return;
} }
player.sendMessage(colorize("&2Item attributes: ")); player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
for (net.minecraft.nbt.NBTBase nbtBase : attrmod) { for (Tag nbtBase : attrmod)
final NBTTagCompound c = (NBTTagCompound) nbtBase; {
player.sendMessage(colorize("&e" + Attributes.get(c.l("AttributeName")).mcName final CompoundTag c = (CompoundTag)nbtBase;
+ ", " + c.k("Amount"))); player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
+ ", " + c.getDouble("Amount")));
} }
} }
@Override @Override
public String colorize(String string) { public String colorize(String string)
{
return ChatColor.translateAlternateColorCodes('&', string); return ChatColor.translateAlternateColorCodes('&', string);
} }
} }