mirror of
https://github.com/plexusorg/ItemizerX.git
synced 2024-11-12 16:06:06 +00:00
Update for 1.20.2 (untested)
This commit is contained in:
parent
7254ddcce3
commit
90bf17b3b2
@ -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>("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"))
|
||||
|
@ -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")
|
||||
|
@ -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")
|
||||
}
|
@ -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());
|
||||
|
42
v1_20_R2/.gitignore
vendored
Normal file
42
v1_20_R2/.gitignore
vendored
Normal file
@ -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
|
3
v1_20_R2/build.gradle.kts
Normal file
3
v1_20_R2/build.gradle.kts
Normal file
@ -0,0 +1,3 @@
|
||||
dependencies {
|
||||
paperDevBundle("1.20.2-R0.1-SNAPSHOT")
|
||||
}
|
@ -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("<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")));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user