mirror of
https://github.com/plexusorg/ItemizerX.git
synced 2024-11-14 00:43:32 +00:00
Fix issues and drop 1.17.1 to 1.18.1 support
This commit is contained in:
parent
c5aa6510d9
commit
0190098656
@ -1,23 +1,17 @@
|
||||
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" apply false
|
||||
id("xyz.jpenilla.run-paper") version "2.1.0" apply false
|
||||
id("io.papermc.paperweight.userdev") version "1.5.5"
|
||||
id("xyz.jpenilla.run-paper") version "2.1.0"
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
||||
}
|
||||
|
||||
group = "dev.plex"
|
||||
version = "2.1"
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "java")
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
version = "2.2"
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
|
||||
@ -27,16 +21,24 @@ subprojects {
|
||||
|
||||
maven {
|
||||
url = uri("https://maven.playpro.com/")
|
||||
content {
|
||||
includeGroup("net.coreprotect")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "java")
|
||||
apply(plugin = "com.github.johnrengelman.shadow")
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
if (project.name != "shared") {
|
||||
implementation(project(":shared"))
|
||||
}
|
||||
|
||||
compileOnly("net.coreprotect:coreprotect:21.3")
|
||||
}
|
||||
|
||||
tasks {
|
||||
assemble {
|
||||
dependsOn("reobfJar")
|
||||
@ -44,11 +46,44 @@ subprojects {
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
|
||||
bukkit {
|
||||
name = "ItemizerX"
|
||||
version = rootProject.version.toString()
|
||||
description = "A new way to edit your items"
|
||||
authors = listOf("Focusvity", "Telesphoreo")
|
||||
main = "dev.plex.itemizerx.ItemizerX"
|
||||
apiVersion = "1.17"
|
||||
foliaSupported = true
|
||||
softDepend = listOf("CoreProtect")
|
||||
commands {
|
||||
register("itemizer") {
|
||||
description = "The main command for ItemizerX"
|
||||
aliases = listOf("ii", "it")
|
||||
usage = "/<command>"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from PlotSquared
|
||||
val supportedVersions = listOf("1.18.2", "1.19", "1.19.1", "1.19.2", "1.19.3", "1.19.4", "1.20", "1.20.1")
|
||||
tasks {
|
||||
shadowJar {
|
||||
archiveBaseName.set("ItemizerX")
|
||||
archiveClassifier.set("")
|
||||
archiveVersion.set("")
|
||||
supportedVersions.forEach {
|
||||
register<RunServer>("runServer-$it") {
|
||||
minecraftVersion(it)
|
||||
pluginJars(layout.buildDirectory.file("libs/ItemizerX-${rootProject.version}.jar"))
|
||||
jvmArgs("-DPaper.IgnoreJavaVersion=true", "-Dcom.mojang.eula.agree=true")
|
||||
group = "run paper"
|
||||
runDirectory.set(file("run-$it"))
|
||||
}
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn("shadowJar")
|
||||
dependsOn("reobfJar")
|
||||
}
|
||||
|
||||
compileJava {
|
||||
@ -56,23 +91,21 @@ tasks {
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
assemble {
|
||||
dependsOn("shadowJar")
|
||||
}
|
||||
|
||||
jar {
|
||||
enabled = false
|
||||
shadowJar {
|
||||
relocate("org.bstats", "dev.plex")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(path = ":core", configuration = "shadow"))
|
||||
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")
|
||||
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_R1", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_19_R3", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_19_R2", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_19_R1", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_18_R2", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_18_R1", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_17_R1", configuration = "shadow"))
|
||||
}
|
42
core/.gitignore
vendored
42
core/.gitignore
vendored
@ -1,42 +0,0 @@
|
||||
.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
|
@ -1,13 +0,0 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
implementation(project(":v1_20_R1"))
|
||||
implementation(project(":v1_19_R3"))
|
||||
implementation(project(":v1_19_R2"))
|
||||
implementation(project(":v1_19_R1"))
|
||||
implementation(project(":v1_18_R2"))
|
||||
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,14 +0,0 @@
|
||||
name: ItemizerX
|
||||
version: 2.1
|
||||
api-version: 1.17
|
||||
description: A rewrite of Itemizer
|
||||
author: Focusvity, Telesphoreo
|
||||
main: dev.plex.itemizerx.ItemizerX
|
||||
folia-supported: true
|
||||
softdepend:
|
||||
- CoreProtect
|
||||
commands:
|
||||
itemizer:
|
||||
description: The main command for ItemizerX
|
||||
usage: /<command>
|
||||
aliases: [ii, it]
|
@ -3,14 +3,11 @@ plugins {
|
||||
}
|
||||
|
||||
rootProject.name = "ItemizerX"
|
||||
include("core")
|
||||
include("shared")
|
||||
include("v1_20_R1")
|
||||
include("v1_19_R3")
|
||||
include("v1_19_R2")
|
||||
include("v1_19_R1")
|
||||
include("v1_18_R2")
|
||||
include("v1_18_R1")
|
||||
include("v1_17_R1")
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
|
||||
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")
|
||||
}
|
@ -1,68 +1,70 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class ItemizerX extends JavaPlugin {
|
||||
public class ItemizerX extends JavaPlugin
|
||||
{
|
||||
|
||||
public static ItemizerX plugin;
|
||||
CoreProtectBridge cpb = new CoreProtectBridge();
|
||||
IAttributeManager attr;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
public void onLoad()
|
||||
{
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
public void onEnable()
|
||||
{
|
||||
plugin = this;
|
||||
// Metrics at https://bstats.org/plugin/bukkit/ItemizerX/19104
|
||||
new Metrics(this, 19104);
|
||||
cpb.getCoreProtect();
|
||||
getCommand("itemizer").setExecutor(new ItemizerXCommand());
|
||||
getCommand("itemizer").setTabCompleter(new ItemizerXTab());
|
||||
switch (getNMSVersion()) {
|
||||
case "v1_20_R1": {
|
||||
switch (getNMSVersion())
|
||||
{
|
||||
case "v1_20_R1" ->
|
||||
{
|
||||
attr = new dev.plex.itemizerx.v1_20_R1.AttributeManager();
|
||||
return;
|
||||
}
|
||||
case "v1_19_R3": {
|
||||
case "v1_19_R3" ->
|
||||
{
|
||||
attr = new dev.plex.itemizerx.v1_19_R3.AttributeManager();
|
||||
return;
|
||||
}
|
||||
case "v1_19_R2": {
|
||||
case "v1_19_R2" ->
|
||||
{
|
||||
attr = new dev.plex.itemizerx.v1_19_R2.AttributeManager();
|
||||
return;
|
||||
}
|
||||
case "v1_19_R1": {
|
||||
case "v1_19_R1" ->
|
||||
{
|
||||
attr = new dev.plex.itemizerx.v1_19_R1.AttributeManager();
|
||||
return;
|
||||
}
|
||||
case "v1_18_R2": {
|
||||
case "v1_18_R2" ->
|
||||
{
|
||||
attr = new dev.plex.itemizerx.v1_18_R2.AttributeManager();
|
||||
return;
|
||||
}
|
||||
case "v1_18_R1": {
|
||||
attr = new dev.plex.itemizerx.v1_18_R1.AttributeManager();
|
||||
return;
|
||||
}
|
||||
case "v1_17_R1": {
|
||||
attr = new dev.plex.itemizerx.v1_17_R1.AttributeManager();
|
||||
return;
|
||||
}
|
||||
default: {
|
||||
default ->
|
||||
{
|
||||
getLogger().severe("You are trying to run ItemizerX on an incompatible server version.");
|
||||
getLogger().severe("ItemizerX only supports versions 1.17 to 1.20.1, disabling plugin.");
|
||||
getLogger().severe("ItemizerX only supports versions 1.18.2 to 1.20.1, disabling plugin.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String getNMSVersion() {
|
||||
public String getNMSVersion()
|
||||
{
|
||||
String v = getServer().getClass().getPackage().getName();
|
||||
return v.substring(v.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
public void onDisable()
|
||||
{
|
||||
plugin = null;
|
||||
}
|
||||
}
|
@ -518,6 +518,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
sender.sendMessage(mm.deserialize("<dark_red>You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
// NPE to fix here
|
||||
plugin.attr.removeAttr(player, args[2]);
|
||||
return true;
|
||||
}
|
42
v1_17_R1/.gitignore
vendored
42
v1_17_R1/.gitignore
vendored
@ -1,42 +0,0 @@
|
||||
.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
|
@ -1,7 +0,0 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.17.1-R0.1-SNAPSHOT")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.14.0")
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
package dev.plex.itemizerx.v1_17_R1;
|
||||
|
||||
import dev.plex.itemizerx.Attributes;
|
||||
import dev.plex.itemizerx.IAttributeManager;
|
||||
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;
|
||||
|
||||
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("<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(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
|
||||
return;
|
||||
}
|
||||
double amount;
|
||||
try
|
||||
{
|
||||
amount = Double.parseDouble(args[3]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>\"" + args[3] + "\" is not a valid number."));
|
||||
return;
|
||||
}
|
||||
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 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 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>This item has no attributes."));
|
||||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
42
v1_18_R1/.gitignore
vendored
42
v1_18_R1/.gitignore
vendored
@ -1,42 +0,0 @@
|
||||
.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
|
@ -1,7 +0,0 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.18.1-R0.1-SNAPSHOT")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.14.0")
|
||||
}
|
@ -1,167 +0,0 @@
|
||||
package dev.plex.itemizerx.v1_18_R1;
|
||||
|
||||
import dev.plex.itemizerx.Attributes;
|
||||
import dev.plex.itemizerx.IAttributeManager;
|
||||
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;
|
||||
|
||||
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("<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(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
|
||||
return;
|
||||
}
|
||||
double amount;
|
||||
try
|
||||
{
|
||||
amount = Double.parseDouble(args[3]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>\"" + args[3] + "\" is not a valid number."));
|
||||
return;
|
||||
}
|
||||
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 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 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<String> 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("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + 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("<dark_aqua>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("<dark_red>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("<dark_green>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("<yellow>This item has no attributes."));
|
||||
return;
|
||||
}
|
||||
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)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.18.2-R0.1-SNAPSHOT")
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.19.2-R0.1-SNAPSHOT")
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.19.3-R0.1-SNAPSHOT")
|
||||
}
|
@ -1,6 +1,3 @@
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
apply(plugin = "xyz.jpenilla.run-paper")
|
||||
|
||||
dependencies {
|
||||
paperDevBundle("1.19.4-R0.1-SNAPSHOT")
|
||||
}
|
Loading…
Reference in New Issue
Block a user