diff --git a/build.gradle.kts b/build.gradle.kts index 981fa02..228a37f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,8 +3,8 @@ import xyz.jpenilla.runpaper.task.RunServer plugins { id("java") id("com.github.johnrengelman.shadow") version "8.1.1" - id("io.papermc.paperweight.userdev") version "1.5.5" - id("xyz.jpenilla.run-paper") version "2.1.0" + id("io.papermc.paperweight.userdev") version "1.5.7" + id("xyz.jpenilla.run-paper") version "2.2.0" id("net.minecrell.plugin-yml.bukkit") version "0.6.0" } @@ -70,7 +70,7 @@ bukkit { // Adapted from PlotSquared val supportedVersions = - listOf("1.17.1", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1") + listOf("1.17.1", "1.18.1", "1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1", "1.20.2") tasks { supportedVersions.forEach { register("runServer-$it") { @@ -99,11 +99,12 @@ tasks { dependencies { paperDevBundle("1.20.1-R0.1-SNAPSHOT") - compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") - compileOnly("net.coreprotect:coreprotect:21.3") + compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") + compileOnly("net.coreprotect:coreprotect:22.2") implementation("org.bstats:bstats-base:3.0.2") implementation("org.bstats:bstats-bukkit:3.0.2") implementation(project(path = ":shared", configuration = "shadow")) + implementation(project(path = ":v1_20_R2", configuration = "shadow")) implementation(project(path = ":v1_20_R1", configuration = "shadow")) implementation(project(path = ":v1_19_R3", configuration = "shadow")) implementation(project(path = ":v1_19_R2", configuration = "shadow")) diff --git a/settings.gradle.kts b/settings.gradle.kts index 5cb759c..39ad803 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,7 @@ plugins { rootProject.name = "ItemizerX" include("shared") +include("v1_20_R2") include("v1_20_R1") include("v1_19_R3") include("v1_19_R2") diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index ce07f75..bf83048 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -1,5 +1,5 @@ dependencies { - compileOnly("io.papermc.paper:paper-api:1.20.1-R0.1-SNAPSHOT") - paperDevBundle("1.20.1-R0.1-SNAPSHOT") - compileOnly("net.coreprotect:coreprotect:21.3") + compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT") + paperDevBundle("1.20.2-R0.1-SNAPSHOT") + compileOnly("net.coreprotect:coreprotect:22.2") } \ No newline at end of file diff --git a/src/main/java/dev/plex/itemizerx/ItemizerX.java b/src/main/java/dev/plex/itemizerx/ItemizerX.java index 15cf074..134f820 100644 --- a/src/main/java/dev/plex/itemizerx/ItemizerX.java +++ b/src/main/java/dev/plex/itemizerx/ItemizerX.java @@ -25,6 +25,11 @@ public class ItemizerX extends JavaPlugin getCommand("itemizer").setTabCompleter(new ItemizerXTab()); switch (getNMSVersion()) { + case "v1_20_R2" -> + { + getCommand("itemizer").setExecutor(new ItemizerXCommand()); + attr = new dev.plex.itemizerx.v1_20_R2.AttributeManager(); + } case "v1_20_R1" -> { getCommand("itemizer").setExecutor(new ItemizerXCommand()); diff --git a/v1_20_R2/.gitignore b/v1_20_R2/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/v1_20_R2/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/v1_20_R2/build.gradle.kts b/v1_20_R2/build.gradle.kts new file mode 100644 index 0000000..92e4458 --- /dev/null +++ b/v1_20_R2/build.gradle.kts @@ -0,0 +1,3 @@ +dependencies { + paperDevBundle("1.20.2-R0.1-SNAPSHOT") +} \ No newline at end of file diff --git a/v1_20_R2/src/main/java/dev/plex/itemizerx/v1_20_R2/AttributeManager.java b/v1_20_R2/src/main/java/dev/plex/itemizerx/v1_20_R2/AttributeManager.java new file mode 100644 index 0000000..dde9c46 --- /dev/null +++ b/v1_20_R2/src/main/java/dev/plex/itemizerx/v1_20_R2/AttributeManager.java @@ -0,0 +1,161 @@ +package dev.plex.itemizerx.v1_20_R2; + +import dev.plex.itemizerx.Attributes; +import dev.plex.itemizerx.IAttributeManager; +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.lang3.StringUtils; +import org.bukkit.craftbukkit.v1_20_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 +{ + private final MiniMessage mm = MiniMessage.miniMessage(); + + @Override + 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) + { + int op; + if (args.length < 4) + { + player.sendMessage(mm.deserialize("/itemizer attr add <name> <strength>" + + "[slot] - Add an attribute")); + return; + } + final Attributes a = Attributes.get(args[2]); + if (a == null) + { + player.sendMessage(mm.deserialize("\"" + args[2] + "\" is not a valid attribute type.")); + return; + } + double amount; + try + { + amount = Double.parseDouble(args[3]); + } + catch (NumberFormatException ex) + { + player.sendMessage(mm.deserialize("\"" + args[3] + "\" is not a valid number.")); + return; + } + if (Double.isNaN(amount)) + { + player.sendMessage(mm.deserialize("Please do not use 'NaN (Not a Number)'")); + return; + } + final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); + final ListTag attrmod = getAttrList(nms); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag) nbtBase; + if (c.getString("Name").equals(args[2])) + { + player.sendMessage(mm.deserialize("An attribute with the name \"" + args[2] + "\" already exists!")); + return; + } + } + final CompoundTag c = new CompoundTag(); + c.putString("Name", args[2]); + c.putString("AttributeName", a.mcName); + c.putDouble("Amount", amount); + op = a.op; + c.putInt("Operation", op); + final Random random = new Random(); + c.putIntArray("UUID", new int[] + { + random.nextInt(), + random.nextInt(), + random.nextInt(), + random.nextInt() + }); + if (args.length == 5) + { + final List options = new ArrayList<>(); + options.add("mainhand"); + options.add("offhand"); + options.add("head"); + options.add("chest"); + options.add("legs"); + options.add("feet"); + if (!options.contains(args[4].toLowerCase())) + { + player.sendMessage(mm.deserialize("Supported options:")); + player.sendMessage(mm.deserialize("" + StringUtils.join(options, ", "))); + return; + } + c.putString("Slot", args[4].toLowerCase()); + } + attrmod.add(c); + nms.getTag().put("AttributeModifiers", attrmod); + final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); + player.getInventory().setItemInMainHand(is); + player.sendMessage(mm.deserialize("Attribute added!")); + } + + @Override + public void removeAttr(final Player player, final String string) + { + final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); + final ListTag attrmod = getAttrList(nms); + final ListTag newList = new ListTag(); + boolean r = false; + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag) nbtBase; + if (!c.getString("Name").equals(string)) + { + newList.add(nbtBase); + } + else + { + r = true; + } + } + if (!r) + { + player.sendMessage(mm.deserialize("The attribute \"" + string + "\" doesn't exist!")); + return; + } + nms.getTag().put("AttributeModifiers", newList); + final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms); + player.getInventory().setItemInMainHand(is); + player.sendMessage(mm.deserialize("Attribute removed!")); + } + + @Override + public void listAttr(final Player player) + { + final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand()); + final ListTag attrmod = getAttrList(nms); + if (attrmod.size() == 0) + { + player.sendMessage(mm.deserialize("This item has no attributes.")); + return; + } + player.sendMessage(mm.deserialize("Item attributes: ")); + for (Tag nbtBase : attrmod) + { + final CompoundTag c = (CompoundTag) nbtBase; + player.sendMessage(mm.deserialize("" + Attributes.get(c.getString("AttributeName")).mcName + + ", " + c.getDouble("Amount"))); + } + } +}