mirror of
https://github.com/plexusorg/ItemizerX.git
synced 2024-11-21 11:55:00 +00:00
Push changes
This commit is contained in:
parent
2da2ab5e13
commit
40dcb9a336
@ -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 {
|
||||
|
@ -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")
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,7 @@
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version("0.5.0")
|
||||
}
|
||||
|
||||
rootProject.name = "ItemizerX"
|
||||
include("core")
|
||||
include("shared")
|
||||
|
@ -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")
|
||||
}
|
@ -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);
|
||||
|
||||
|
@ -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")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,3 @@
|
||||
dependencies {
|
||||
compileOnly("org.spigotmc:spigot:1.20.1-R0.1-SNAPSHOT")
|
||||
paperDevBundle("1.20.1-R0.1-SNAPSHOT")
|
||||
}
|
@ -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("<aqua>/itemizer attr add <<white>name<aqua>> <<white>strength<aqua>>" +
|
||||
"[<white>slot<aqua>] <red>- <gold>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("<dark_red>\"" + 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("<dark_red>\"" + 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("<dark_red>Please do not use <white>'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("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>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("<dark_green>Item attributes: "));
|
||||
for (Tag nbtBase : attrmod)
|
||||
{
|
||||
final CompoundTag c = (CompoundTag)nbtBase;
|
||||
player.sendMessage(mm.deserialize("<yellow>" + Attributes.get(c.getString("AttributeName")).mcName
|
||||
+ ", " + c.getDouble("Amount")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String colorize(String string) {
|
||||
public String colorize(String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user