mirror of
https://github.com/plexusorg/ItemizerX.git
synced 2026-06-03 19:26:54 +00:00
Updated ItemizerX to the latest stable Paper version (1.21.8)
Given the complexity of the NMS update (including data components), I have decided to omit the support of older MC versions and maintain multiversion compatibility from 1.21.8 onwards from v2.4. I suspect this may not change much in the future, making it easier to maintain. In the future, I may look into moving away from NMS provided Paper is now exposing them in Paper API via Data Components This also closes #1
This commit is contained in:
+11
-15
@@ -2,14 +2,14 @@ import xyz.jpenilla.runpaper.task.RunServer
|
||||
|
||||
plugins {
|
||||
id("java")
|
||||
id("io.github.goooler.shadow") version "8.1.7"
|
||||
id("io.papermc.paperweight.userdev") version "1.7.1"
|
||||
id("xyz.jpenilla.run-paper") version "2.3.0"
|
||||
id("net.minecrell.plugin-yml.bukkit") version "0.6.0"
|
||||
id("com.gradleup.shadow") version "9.2.2"
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.19"
|
||||
id("xyz.jpenilla.run-paper") version "3.0.2"
|
||||
id("de.eldoria.plugin-yml.bukkit") version "0.8.0"
|
||||
}
|
||||
|
||||
group = "dev.plex"
|
||||
version = "2.3"
|
||||
version = "2.4"
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
@@ -30,7 +30,7 @@ allprojects {
|
||||
|
||||
subprojects {
|
||||
apply(plugin = "java")
|
||||
apply(plugin = "io.github.goooler.shadow")
|
||||
apply(plugin = "com.gradleup.shadow")
|
||||
apply(plugin = "io.papermc.paperweight.userdev")
|
||||
|
||||
dependencies {
|
||||
@@ -56,7 +56,7 @@ bukkit {
|
||||
description = "A new way to edit your items"
|
||||
authors = listOf("Focusvity", "Telesphoreo")
|
||||
main = "dev.plex.itemizerx.ItemizerX"
|
||||
apiVersion = "1.19"
|
||||
apiVersion = "1.21"
|
||||
foliaSupported = true
|
||||
softDepend = listOf("CoreProtect")
|
||||
commands {
|
||||
@@ -69,8 +69,7 @@ bukkit {
|
||||
}
|
||||
|
||||
// Adapted from PlotSquared
|
||||
val supportedVersions =
|
||||
listOf("1.20.2", "1.20.4", "1.20.6", "1.21")
|
||||
val supportedVersions = listOf("1.21.8")
|
||||
tasks {
|
||||
supportedVersions.forEach {
|
||||
register<RunServer>("runServer-$it") {
|
||||
@@ -98,14 +97,11 @@ tasks {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.6-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
|
||||
compileOnly("net.coreprotect:coreprotect:22.4")
|
||||
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_21_R1", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_20_R4", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_20_R3", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_20_R2", configuration = "shadow"))
|
||||
implementation(project(path = ":v1_21_R1", configuration = "shadow"))
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
+1
-4
@@ -4,7 +4,4 @@ plugins {
|
||||
|
||||
rootProject.name = "ItemizerX"
|
||||
include("shared")
|
||||
//include("v1_21_R1")
|
||||
include("v1_20_R4")
|
||||
include("v1_20_R3")
|
||||
include("v1_20_R2")
|
||||
include("v1_21_R1")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
dependencies {
|
||||
compileOnly("io.papermc.paper:paper-api:1.20.2-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
|
||||
compileOnly("net.coreprotect:coreprotect:22.2")
|
||||
compileOnly("io.papermc.paper:paper-api:1.21..8-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT")
|
||||
compileOnly("net.coreprotect:coreprotect:22.4")
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -7,27 +9,29 @@ import java.util.List;
|
||||
|
||||
public enum Attributes
|
||||
{
|
||||
MAX_HEALTH("generic.max_health", 0),
|
||||
FOLLOW_RANGE("generic.follow_range", 1),
|
||||
KNOCKBACK_RESISTANCE("generic.knockback_resistance", 1),
|
||||
MOVEMENT_SPEED("generic.movement_speed", 1),
|
||||
FLYING_SPEED("generic.flying_speed", 1),
|
||||
DAMAGE("generic.attack_damage", 0),
|
||||
ATTACK_KNOCKBACK("generic.attack_knockback", 0),
|
||||
ATTACK_SPEED("generic.attack_speed", 1),
|
||||
ARMOR("generic.armor", 0),
|
||||
ARMOR_TOUGHNESS("generic.armor_toughness", 0),
|
||||
LUCK("generic.luck", 0),
|
||||
HORSE_JUMP("horse.jump_strength", 1),
|
||||
ZOMBIE_REINFORCEMENTS("zombie.spawn_reinforcements", 1);
|
||||
MAX_HEALTH("generic.max_health", 0, net.minecraft.world.entity.ai.attributes.Attributes.MAX_HEALTH),
|
||||
FOLLOW_RANGE("generic.follow_range", 1, net.minecraft.world.entity.ai.attributes.Attributes.FOLLOW_RANGE),
|
||||
KNOCKBACK_RESISTANCE("generic.knockback_resistance", 1, net.minecraft.world.entity.ai.attributes.Attributes.KNOCKBACK_RESISTANCE),
|
||||
MOVEMENT_SPEED("generic.movement_speed", 1, net.minecraft.world.entity.ai.attributes.Attributes.MOVEMENT_SPEED),
|
||||
FLYING_SPEED("generic.flying_speed", 1, net.minecraft.world.entity.ai.attributes.Attributes.FLYING_SPEED),
|
||||
DAMAGE("generic.attack_damage", 0, net.minecraft.world.entity.ai.attributes.Attributes.ATTACK_DAMAGE),
|
||||
ATTACK_KNOCKBACK("generic.attack_knockback", 0, net.minecraft.world.entity.ai.attributes.Attributes.ATTACK_KNOCKBACK),
|
||||
ATTACK_SPEED("generic.attack_speed", 1, net.minecraft.world.entity.ai.attributes.Attributes.ATTACK_SPEED),
|
||||
ARMOR("generic.armor", 0, net.minecraft.world.entity.ai.attributes.Attributes.ARMOR),
|
||||
ARMOR_TOUGHNESS("generic.armor_toughness", 0, net.minecraft.world.entity.ai.attributes.Attributes.ARMOR_TOUGHNESS),
|
||||
LUCK("generic.luck", 0, net.minecraft.world.entity.ai.attributes.Attributes.LUCK),
|
||||
JUMP_STRENGTH("generic.jump_strength", 1, net.minecraft.world.entity.ai.attributes.Attributes.JUMP_STRENGTH),
|
||||
ZOMBIE_REINFORCEMENTS("zombie.spawn_reinforcements", 1, net.minecraft.world.entity.ai.attributes.Attributes.SPAWN_REINFORCEMENTS_CHANCE);
|
||||
|
||||
public final String mcName;
|
||||
public final int op;
|
||||
public final Holder<Attribute> attributeHolder;
|
||||
|
||||
Attributes(String mcName, int op)
|
||||
Attributes(String mcName, int op, Holder<Attribute> attributeHolder)
|
||||
{
|
||||
this.mcName = mcName;
|
||||
this.op = op;
|
||||
this.attributeHolder = attributeHolder;
|
||||
}
|
||||
|
||||
public static Attributes get(String name)
|
||||
|
||||
@@ -1,25 +1,9 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface IAttributeManager
|
||||
{
|
||||
default ListTag getAttrList(final ItemStack item)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
default List<AttributeModifier> getAttrList(final Item item)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
void addAttr(final Player player, final String[] args);
|
||||
|
||||
void removeAttr(final Player player, final String string);
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface IEnchantmentManager {
|
||||
|
||||
void addEnchantment(Player player, ItemStack item, String[] args);
|
||||
|
||||
void removeEnchantment(Player player, ItemStack item, String[] args);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public class ItemizerX extends JavaPlugin
|
||||
public static ItemizerX plugin;
|
||||
CoreProtectBridge cpb = new CoreProtectBridge();
|
||||
IAttributeManager attr;
|
||||
IEnchantmentManager ench;
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
@@ -26,30 +27,16 @@ public class ItemizerX extends JavaPlugin
|
||||
getCommand("itemizer").setTabCompleter(new ItemizerXTab());
|
||||
switch (getServerVersion())
|
||||
{
|
||||
/*case "1.21" ->
|
||||
case "1.21.8" ->
|
||||
{
|
||||
getCommand("itemizer").setExecutor(new ItemizerXCommand());
|
||||
attr = new dev.plex.itemizerx.v1_21_R1.AttributeManager();
|
||||
}*/
|
||||
case "1.20.5", "1.20.6" ->
|
||||
{
|
||||
getCommand("itemizer").setExecutor(new ItemizerXCommand());
|
||||
attr = new dev.plex.itemizerx.v1_20_R4.AttributeManager();
|
||||
}
|
||||
case "1.20.4" ->
|
||||
{
|
||||
getCommand("itemizer").setExecutor(new ItemizerXCommand());
|
||||
attr = new dev.plex.itemizerx.v1_20_R3.AttributeManager();
|
||||
}
|
||||
case "1.20.3", "1.20.2" ->
|
||||
{
|
||||
getCommand("itemizer").setExecutor(new ItemizerXCommand());
|
||||
attr = new dev.plex.itemizerx.v1_20_R2.AttributeManager();
|
||||
ench = new dev.plex.itemizerx.v1_21_R1.EnchantmentManager();
|
||||
}
|
||||
default ->
|
||||
{
|
||||
getLogger().severe("You are trying to run ItemizerX on an incompatible server version.");
|
||||
getLogger().severe("ItemizerX only supports versions 1.20.2 to 1.21, disabling plugin.");
|
||||
getLogger().severe("ItemizerX only supports version 1.21.8, disabling plugin.");
|
||||
getServer().getPluginManager().disablePlugin(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -9,14 +11,11 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.enchantments.EnchantmentWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -59,6 +58,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
put("&9", "<blue>");
|
||||
put("&0", "<black>");
|
||||
}};
|
||||
|
||||
CoreProtectBridge cpb = new CoreProtectBridge();
|
||||
MiniMessage mm = MiniMessage.miniMessage();
|
||||
|
||||
@@ -161,7 +161,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
sender.sendMessage(mm.deserialize("<dark_red>The material <white>\"" + args[1] + "<white>\" <dark_red>does not exist!"));
|
||||
return true;
|
||||
}
|
||||
item.setType(material);
|
||||
player.getInventory().setItemInMainHand(item.withType(material));
|
||||
sender.sendMessage(mm.deserialize("<dark_green>The material of the item has changed to <reset>'" + material.name() + "'"));
|
||||
return true;
|
||||
}
|
||||
@@ -439,7 +439,8 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
sender.sendMessage(mm.deserialize(material != null ? "<white>'" + material.name() + "' <dark_red>is not a potion type!" : "<dark_red>That material doesn't exist!"));
|
||||
return true;
|
||||
}
|
||||
item.setType(material);
|
||||
|
||||
player.getInventory().setItemInMainHand(item.withType(material));
|
||||
sender.sendMessage(mm.deserialize("<dark_green>The potion in hand has changed to <white>'" + material.name() + "'"));
|
||||
return true;
|
||||
}
|
||||
@@ -481,11 +482,9 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
return true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
PotionEffectType[] effects;
|
||||
for (int i = 0; i < (effects = PotionEffectType.values()).length; i++)
|
||||
{
|
||||
sb.append(", ").append(effects[i].getName());
|
||||
}
|
||||
RegistryAccess.registryAccess().getRegistry(RegistryKey.MOB_EFFECT).iterator().forEachRemaining(effect -> {
|
||||
sb.append(", ").append(effect.getKey().getKey());
|
||||
});
|
||||
sender.sendMessage(mm.deserialize("<dark_green>Available potion effects: <yellow>" + sb.toString().replaceFirst(", ", "")));
|
||||
return true;
|
||||
}
|
||||
@@ -540,6 +539,11 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
sender.sendMessage(mm.deserialize("<dark_red>You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length != 3) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// NPE to fix here
|
||||
plugin.attr.removeAttr(player, args[2]);
|
||||
return true;
|
||||
@@ -734,25 +738,8 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
sender.sendMessage(mm.deserialize("<dark_red>You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 4)
|
||||
{
|
||||
sender.sendMessage(mm.deserialize("<dark_aqua>===============<white>[<light_purple>Enchant Commands<white>]<dark_aqua>==============="));
|
||||
sender.sendMessage(mm.deserialize("<aqua>/itemizer enchant add <<white>name<aqua>> <<white>level<aqua>> <red>- <gold>Add an enchant"));
|
||||
return true;
|
||||
}
|
||||
final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase()));
|
||||
if (ench == null)
|
||||
{
|
||||
sender.sendMessage(mm.deserialize("<dark_red>The enchantment <white>'" + args[2] + "<white>' <dark_red>does not exist!"));
|
||||
return true;
|
||||
}
|
||||
Integer level = parseInt(sender, args[3]);
|
||||
if (level == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
item.addUnsafeEnchantment(ench, level);
|
||||
sender.sendMessage(mm.deserialize("<dark_green>The enchant <white>'" + ench.getKey().getKey() + "' <dark_green>has been added to your item"));
|
||||
|
||||
plugin.ench.addEnchantment(player, item, args);
|
||||
return true;
|
||||
}
|
||||
case "remove" ->
|
||||
@@ -762,31 +749,8 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
sender.sendMessage(mm.deserialize("<dark_red>You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(mm.deserialize("<dark_aqua>===============<white>[<light_purple>Enchant Commands<white>]<dark_aqua>==============="));
|
||||
sender.sendMessage(mm.deserialize("<aqua>/itemizer enchant remove <<white>name<aqua>> <red>- <gold>Remove an enchant"));
|
||||
return true;
|
||||
}
|
||||
final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase()));
|
||||
if (ench == null)
|
||||
{
|
||||
sender.sendMessage(mm.deserialize("<dark_red>The enchantment <white>'" + args[2] + "<white>' <dark_red>does not exist!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (Objects.requireNonNull(meta.getEnchants()).isEmpty())
|
||||
{
|
||||
sender.sendMessage(mm.deserialize("<dark_red>This item doesn't hold any enchants"));
|
||||
return true;
|
||||
}
|
||||
if (!meta.getEnchants().containsKey(ench))
|
||||
{
|
||||
sender.sendMessage(mm.deserialize("<dark_red>This item doesn't have <white<'" + ench.getKey().getKey() + "' <dark_red>enchant!"));
|
||||
return true;
|
||||
}
|
||||
item.removeEnchantment(ench);
|
||||
sender.sendMessage(mm.deserialize("<dark_green>The enchant <white>'" + ench.getKey().getKey() + "' <dark_green>has been removed from your item"));
|
||||
|
||||
plugin.ench.removeEnchantment(player, item, args);
|
||||
return true;
|
||||
}
|
||||
case "list" ->
|
||||
@@ -813,12 +777,10 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
return true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Enchantment[] enchantments;
|
||||
for (int i = 0; i < (enchantments = Enchantment.values()).length; i++)
|
||||
{
|
||||
sb.append(", ").append(enchantments[i].getKey().getKey());
|
||||
}
|
||||
sender.sendMessage(mm.deserialize("<dark_green>Available item enchants: <yellow>" + sb.toString().replaceFirst(", ", "")));
|
||||
RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).iterator().forEachRemaining(enchantment -> {
|
||||
sb.append(", ").append(enchantment.getKey().getKey());
|
||||
});
|
||||
sender.sendMessage(mm.deserialize("<dark_green>Available item enchantments: <yellow>" + sb.toString().replaceFirst(", ", "")));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
@@ -945,7 +907,7 @@ public class ItemizerXCommand implements CommandExecutor, ItemizerXBase
|
||||
cpb.getAPI().logRemoval(player.getName(), block.getLocation(), block.getType(), block.getBlockData());
|
||||
}
|
||||
Sign sign = (Sign) block.getState();
|
||||
sign.line(line - 1, text);
|
||||
sign.getTargetSide(player).line(line - 1, text);
|
||||
sign.update();
|
||||
if (cpb.getAPI() != null)
|
||||
{
|
||||
|
||||
@@ -1,990 +0,0 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.enchantments.EnchantmentWrapper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.BookMeta;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ItemizerXCompatCommand implements CommandExecutor, ItemizerXBase
|
||||
{
|
||||
final List<Material> POTIONS = Arrays.asList(Material.POTION, Material.LINGERING_POTION, Material.SPLASH_POTION);
|
||||
CoreProtectBridge cpb = new CoreProtectBridge();
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String string, String[] args)
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.use"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.sendMessage(ChatColor.AQUA + "ItemizerX " + ChatColor.GOLD + "v"
|
||||
+ plugin.getDescription().getVersion()
|
||||
+ ChatColor.AQUA + " by " + ChatColor.GOLD
|
||||
+ StringUtils.join(plugin.getDescription().getAuthors(), ", "));
|
||||
sender.sendMessage(ChatColor.AQUA + "Type " + ChatColor.GOLD + "/itemizer help "
|
||||
+ ChatColor.AQUA + "for help");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(sender instanceof final Player player))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You must be a player to execute this command!"));
|
||||
return true;
|
||||
}
|
||||
|
||||
final ItemStack item = player.getInventory().getItemInMainHand();
|
||||
final boolean hasItem = item.getType() != Material.AIR;
|
||||
final boolean hasPotion = POTIONS.contains(item.getType());
|
||||
final boolean hasBook = item.getType() == Material.WRITTEN_BOOK;
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "help" ->
|
||||
{
|
||||
sender.sendMessage(colorize("""
|
||||
&3=============&f[&dItemizerX Commands&f]&3=============
|
||||
&b/itemizer name <&fname&b> &c- &6Name your item
|
||||
&b/itemizer id <&fid&b> &c- &6Change the item's material
|
||||
&b/itemizer lore &c- &6Lore editing command
|
||||
&b/itemizer potion &c- &6Potion editing command
|
||||
&b/itemizer attr &c- &6Attribute editing command
|
||||
&b/itemizer flag &c- &6Flag editing command
|
||||
&b/itemizer enchant &c- &6Enchant editing command
|
||||
&b/itemizer title <&fname&b> &c- &6Set the book's title
|
||||
&b/itemizer author <&fname&b> &c- &6Set the book's author
|
||||
&b/itemizer head <&fname&b> &c- &6Set the player of the head
|
||||
&b/itemizer sign <&fline&b> <&ftext&b> &c- &6Change the line on the sign
|
||||
&b/itemizer clearall &c- &6Clears all metadata from your item"""));
|
||||
return true;
|
||||
}
|
||||
case "name" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.name"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dName Commands&f]&3===============\n"
|
||||
+ "&b/itemizer name <&fname&b> &c- &6Name your item"));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
String name = colorize(StringUtils.join(args, " ", 1, args.length));
|
||||
assert meta != null;
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2The name of the item in your hand has been set to &f'" + name + "&f'"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "id" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.id"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dID Commands&f]&3===============\n"
|
||||
+ "&b/itemizer id <&fid&b> &c- &6Change the item's material"));
|
||||
return true;
|
||||
}
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
Material material = Material.matchMaterial(args[1].toUpperCase());
|
||||
if (material == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The material &f\"" + args[1] + "&f\"&4 does not exist!"));
|
||||
return true;
|
||||
}
|
||||
item.setType(material);
|
||||
sender.sendMessage(colorize("&2The material of the item has changed to &f'" + material.name() + "'"));
|
||||
return true;
|
||||
}
|
||||
case "lore" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.lore"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("""
|
||||
&3===============&f[&dLore Commands&f]&3===============
|
||||
&b/itemizer lore add <&ftext&b> &c- &6Add a line of text to your item's lore
|
||||
&b/itemizer lore remove <&findex&b> &c- &6Remove a line of text from your item's lore
|
||||
&b/itemizer lore change <&findex&b> <&ftext&b> &c- &6Change a line of text in your item's lore
|
||||
&b/itemizer lore clear &c- &6Clear the item's lore"""));
|
||||
return true;
|
||||
}
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (args[1])
|
||||
{
|
||||
case "add" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.lore.add"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dLore Commands&f]&3===============\n"
|
||||
+ "&b/itemizer lore add <&ftext&b> &c- &6Add a line of text to your item's lore"));
|
||||
return true;
|
||||
}
|
||||
String lore = colorize(StringUtils.join(args, " ", 2, args.length));
|
||||
assert meta != null;
|
||||
List<String> lores = new ArrayList<>();
|
||||
if (meta.getLore() != null)
|
||||
{
|
||||
lores = meta.getLore();
|
||||
}
|
||||
lores.add(lore);
|
||||
meta.setLore(lores);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2Line &f'" + lore + "&f'&2 added to the item's lore"));
|
||||
return true;
|
||||
}
|
||||
case "remove" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.lore.remove"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dLore Commands&f]&3===============\n"
|
||||
+ "&b/itemizer lore remove <&findex&b> &c- &6Remove a line of text from your item's lore"));
|
||||
return true;
|
||||
}
|
||||
Integer index = parseInt(sender, args[2]);
|
||||
if (index == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
List<String> lores;
|
||||
if (meta.getLore() != null)
|
||||
{
|
||||
lores = meta.getLore();
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(colorize("&eThis item has no lores."));
|
||||
return true;
|
||||
}
|
||||
if (index > lores.size())
|
||||
{
|
||||
sender.sendMessage(colorize("&4The item's lore doesn't have line &f'" + index + "'"));
|
||||
return true;
|
||||
}
|
||||
lores.remove(index - 1);
|
||||
meta.setLore(lores);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2Line &f'" + index + "&f'&2 removed from the item's lore"));
|
||||
return true;
|
||||
}
|
||||
case "change" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.lore.change"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 4)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dLore Commands&f]&3===============\n"
|
||||
+ "&b/itemizer lore change <&findex&b> <&ftext&b> &c- &6Change a line of text in your item's lore"));
|
||||
return true;
|
||||
}
|
||||
Integer index = parseInt(sender, args[2]);
|
||||
if (index == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
String lore = colorize(StringUtils.join(args, " ", 3, args.length));
|
||||
assert meta != null;
|
||||
List<String> lores;
|
||||
if (meta.getLore() != null)
|
||||
{
|
||||
lores = meta.getLore();
|
||||
}
|
||||
else
|
||||
{
|
||||
sender.sendMessage(colorize("&eThis item has no lores."));
|
||||
return true;
|
||||
}
|
||||
if (index > lores.size())
|
||||
{
|
||||
sender.sendMessage(colorize("&4The item's lore doesn't have line &f'" + index + "'"));
|
||||
return true;
|
||||
}
|
||||
lores.set(index - 1, lore);
|
||||
meta.setLore(lores);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2Line &f'" + index + "'&2 has changed to &f'" + lore + "&f'"));
|
||||
return true;
|
||||
}
|
||||
case "clear" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.lore.clear"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (meta.getLore() == null || meta.getLore().isEmpty())
|
||||
{
|
||||
sender.sendMessage(colorize("&4The item has no lores."));
|
||||
return true;
|
||||
}
|
||||
meta.setLore(null);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2The item's lore has been cleared!"));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer lore &bfor help."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case "potion" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.potion"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("""
|
||||
&3===============&f[&dPotion Commands&f]&3===============
|
||||
&b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect
|
||||
&b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect
|
||||
&b/itemizer potion change <&fname&b> &c- &6Change the potion type
|
||||
&b/itemizer potion color <&fhexcolor&b> &c- &6Set the potion color
|
||||
&b/itemizer potion list &c- &6List all potion effects"""));
|
||||
return true;
|
||||
}
|
||||
if (!hasPotion)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have a potion in your hand."));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (args[1])
|
||||
{
|
||||
case "add" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.potion.add"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 5)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n"
|
||||
+ "&b/itemizer potion add <&feffect&b> <&flevel&b> <&ftime[tick]&b> &c- &6Add a potion effect"));
|
||||
return true;
|
||||
}
|
||||
PotionEffectType potType = PotionEffectType.getByName(args[2].toUpperCase());
|
||||
if (potType == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The potion &f\"" + args[2] + "&f\"&4 does not exist!"));
|
||||
return true;
|
||||
}
|
||||
Integer level = parseInt(sender, args[3]);
|
||||
Integer tick = parseInt(sender, args[4]);
|
||||
if (level == null || tick == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
final PotionEffect pot = new PotionEffect(potType, tick, level);
|
||||
final PotionMeta potionMeta = (PotionMeta) meta;
|
||||
assert potionMeta != null;
|
||||
if (potionMeta.hasCustomEffect(pot.getType()))
|
||||
{
|
||||
sender.sendMessage(colorize("&4This potion already has &f" + pot.getType().getName()));
|
||||
return true;
|
||||
}
|
||||
potionMeta.addCustomEffect(pot, false);
|
||||
item.setItemMeta(potionMeta);
|
||||
sender.sendMessage(colorize(pot.getType().getName() + " &2has been added to the potion"));
|
||||
return true;
|
||||
}
|
||||
case "remove" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.potion.remove"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n"
|
||||
+ "&b/itemizer potion remove <&feffect&b> &c- &6Remove a potion effect"));
|
||||
return true;
|
||||
}
|
||||
PotionEffectType potType = PotionEffectType.getByName(args[2].toUpperCase());
|
||||
if (potType == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The potion effect &f\"" + args[2] + "&f\"&4 does not exist!"));
|
||||
return true;
|
||||
}
|
||||
final PotionMeta potionMeta = (PotionMeta) meta;
|
||||
assert potionMeta != null;
|
||||
if (!potionMeta.hasCustomEffect(potType))
|
||||
{
|
||||
sender.sendMessage(colorize("This potion does not have &f" + potType.getName()));
|
||||
return true;
|
||||
}
|
||||
potionMeta.removeCustomEffect(potType);
|
||||
item.setItemMeta(potionMeta);
|
||||
sender.sendMessage(colorize(potType.getName() + " &2has been removed from the potion"));
|
||||
return true;
|
||||
}
|
||||
case "change" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.potion.change"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n"
|
||||
+ "&b/itemizer potion change <&fname&b> &c- &6Change the potion type"));
|
||||
return true;
|
||||
}
|
||||
Material material = Material.matchMaterial(args[2]);
|
||||
if (material == null || !POTIONS.contains(material))
|
||||
{
|
||||
sender.sendMessage(colorize(material != null ?
|
||||
"&f'" + material.name() + "' &4is not a potion type!"
|
||||
:
|
||||
"&4That material doesn't exist!"));
|
||||
return true;
|
||||
}
|
||||
item.setType(material);
|
||||
sender.sendMessage(colorize("&2The potion in hand has changed to &f'" + material.name() + "'"));
|
||||
return true;
|
||||
}
|
||||
case "color" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.potion.color"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dPotion Commands&f]&3===============\n"
|
||||
+ "&b/itemizer potion color <&fhexcolor&b> &c- &6Set a potion color"));
|
||||
return true;
|
||||
}
|
||||
final PotionMeta potionMeta = (PotionMeta) meta;
|
||||
assert potionMeta != null;
|
||||
try
|
||||
{
|
||||
java.awt.Color awtColor = java.awt.Color.decode(args[2]);
|
||||
Color color = Color.fromRGB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue());
|
||||
potionMeta.setColor(color);
|
||||
item.setItemMeta(potionMeta);
|
||||
sender.sendMessage(colorize(args[2] + " &2has been set as potion color"));
|
||||
}
|
||||
catch (NumberFormatException ignored)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The hex &f\"" + args[2] + "&f\"&4 is invalid!"));
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case "list" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.potion.list"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
PotionEffectType[] effects;
|
||||
for (int i = 0; i < (effects = PotionEffectType.values()).length; i++)
|
||||
{
|
||||
sb.append(", ").append(effects[i].getName());
|
||||
}
|
||||
sender.sendMessage(colorize("&2Available potion effects: &e"
|
||||
+ sb.toString().replaceFirst(", ", "")));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer potion &bfor help."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case "attr" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.attr"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("""
|
||||
&3===============&f[&dAttribute Commands&f]&3===============
|
||||
&b/itemizer attr add <&fname&b> <&fstrength&b> [&fslot&b] &c- &6Add an attribute
|
||||
&b/itemizer attr remove <&fname&b> &c- &6Remove an attribute
|
||||
&b/itemizer attr list &c- &6List all item's attributes
|
||||
&b/itemizer attr listall &c- &6List all supported attributes"""));
|
||||
return true;
|
||||
}
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (args[1])
|
||||
{
|
||||
case "add" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.attr.add"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
plugin.attr.addAttr(player, args);
|
||||
return true;
|
||||
}
|
||||
case "remove" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.attr.remove"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
plugin.attr.removeAttr(player, args[2]);
|
||||
return true;
|
||||
}
|
||||
case "list" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.attr.list"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
plugin.attr.listAttr(player);
|
||||
return true;
|
||||
}
|
||||
case "listall" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.attr.listall"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(colorize("&2Supported attributes: "
|
||||
+ "&e" + Attributes.getAttributes()));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer attr &bfor help."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case "flag" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.flag"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("""
|
||||
&3===============&f[&dFlag Commands&f]&3===============
|
||||
&b/itemizer flag add <&fname&b> &c- &6Add a flag
|
||||
&b/itemizer flag remove <&fname&b> &c- &6Remove a flag
|
||||
&b/itemizer flag list &c- &6List all item's flag
|
||||
&b/itemizer flag listall &c- &6List all available flags"""));
|
||||
return true;
|
||||
}
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
switch (args[1])
|
||||
{
|
||||
case "add" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.flag.add"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dFlag Commands&f]&3===============\n"
|
||||
+ "&b/itemizer flag add <&fname&b> &c- &6Add a flag"));
|
||||
return true;
|
||||
}
|
||||
ItemFlag flag = null;
|
||||
try
|
||||
{
|
||||
flag = ItemFlag.valueOf(args[2].toUpperCase());
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
if (flag == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The flag &f\"" + args[2] + "&f\" does not exist!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (meta.getItemFlags().contains(flag))
|
||||
{
|
||||
sender.sendMessage(colorize("&4The flag &f'" + args[2].toUpperCase() + "' &4already added to the item!"));
|
||||
return true;
|
||||
}
|
||||
meta.addItemFlags(flag);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2The flag &f'" + args[2].toUpperCase() + "' &2has been added to your item!"));
|
||||
return true;
|
||||
}
|
||||
case "remove" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.flag.remove"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dFlag Commands&f]&3===============\n"
|
||||
+ "&b/itemizer flag remove <&fname&b> &c- &6Remove a flag"));
|
||||
return true;
|
||||
}
|
||||
ItemFlag flag = null;
|
||||
try
|
||||
{
|
||||
flag = ItemFlag.valueOf(args[2].toUpperCase());
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
if (flag == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The flag &f\"" + args[2] + "&f\" does not exist!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (!meta.getItemFlags().contains(flag))
|
||||
{
|
||||
sender.sendMessage(colorize("&4The flag &f'" + args[2].toUpperCase() + "' &4has not been added the item!"));
|
||||
return true;
|
||||
}
|
||||
meta.removeItemFlags(flag);
|
||||
item.setItemMeta(meta);
|
||||
sender.sendMessage(colorize("&2The flag &f'" + args[2].toUpperCase() + "' &2has been removed from your item!"));
|
||||
return true;
|
||||
}
|
||||
case "list" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.flag.list"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (Objects.requireNonNull(meta.getItemFlags()).isEmpty())
|
||||
{
|
||||
sender.sendMessage(colorize("&4The item in your hand does not have any flags"));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(colorize("&2Item flags: &e"
|
||||
+ StringUtils.join(meta.getItemFlags(), ", ")));
|
||||
return true;
|
||||
}
|
||||
case "listall" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.flag.listall"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(colorize("&2Available item flags: &e"
|
||||
+ StringUtils.join(ItemFlag.values(), ", ")));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer flag &bfor help"));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
case "enchant" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.enchant"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("""
|
||||
&3===============&f[&dEnchant Commands&f]&3===============
|
||||
&b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant
|
||||
&b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant
|
||||
&b/itemizer enchant list &c- &6List all item's enchants
|
||||
&b/itemizer enchant listall &c- &6List all available enchants"""));
|
||||
return true;
|
||||
}
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
switch (args[1])
|
||||
{
|
||||
case "add" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.enchant.add"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 4)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n"
|
||||
+ "&b/itemizer enchant add <&fname&b> <&flevel&b> &c- &6Add an enchant"));
|
||||
return true;
|
||||
}
|
||||
final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase()));
|
||||
if (ench == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The enchantment &f'" + args[2] + "&f' &4does not exist!"));
|
||||
return true;
|
||||
}
|
||||
Integer level = parseInt(sender, args[3]);
|
||||
if (level == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
item.addUnsafeEnchantment(ench, level);
|
||||
sender.sendMessage(colorize("&2The enchant &f'" + ench.getKey().getKey() + "' &2has been added to your item"));
|
||||
return true;
|
||||
}
|
||||
case "remove" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.enchant.remove"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dEnchant Commands&f]&3===============\n"
|
||||
+ "&b/itemizer enchant remove <&fname&b> &c- &6Remove an enchant"));
|
||||
return true;
|
||||
}
|
||||
final Enchantment ench = EnchantmentWrapper.getByKey(NamespacedKey.minecraft(args[2].toLowerCase()));
|
||||
if (ench == null)
|
||||
{
|
||||
sender.sendMessage(colorize("&4The enchantment &f'" + args[2] + "&f' &4does not exist!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (Objects.requireNonNull(meta.getEnchants()).isEmpty())
|
||||
{
|
||||
sender.sendMessage(colorize("&4This item doesn't hold any enchants"));
|
||||
return true;
|
||||
}
|
||||
if (!meta.getEnchants().containsKey(ench))
|
||||
{
|
||||
sender.sendMessage(colorize("&4This item doesn't have &f'" + ench.getKey().getKey() + "' &4enchant!"));
|
||||
return true;
|
||||
}
|
||||
item.removeEnchantment(ench);
|
||||
sender.sendMessage(colorize("&2The enchant &f'" + ench.getKey().getKey() + "' &2has been removed from your item"));
|
||||
return true;
|
||||
}
|
||||
case "list" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.enchant.list"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
assert meta != null;
|
||||
if (Objects.requireNonNull(meta.getEnchants()).isEmpty())
|
||||
{
|
||||
sender.sendMessage(colorize("&4This item doesn't hold any enchants"));
|
||||
return true;
|
||||
}
|
||||
sender.sendMessage(colorize("&2Item enchants: &e"
|
||||
+ StringUtils.join(meta.getEnchants().keySet(), ", ")));
|
||||
return true;
|
||||
}
|
||||
case "listall" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.enchant.listall"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Enchantment[] enchantments;
|
||||
for (int i = 0; i < (enchantments = Enchantment.values()).length; i++)
|
||||
{
|
||||
sb.append(", ").append(enchantments[i].getKey().getKey());
|
||||
}
|
||||
sender.sendMessage(colorize("&2Available item enchants: &e"
|
||||
+ sb.toString().replaceFirst(", ", "")));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer enchant &bfor help."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
case "title" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.title"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dTitle Command&f]&3===============\n"
|
||||
+ "&b/itemizer title <&fname&b> &c- &6Set the book's title"));
|
||||
return true;
|
||||
}
|
||||
if (!hasBook)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have a Written Book in your hand."));
|
||||
return true;
|
||||
}
|
||||
String name = colorize(StringUtils.join(args, " ", 1, args.length));
|
||||
final BookMeta bookMeta = (BookMeta) meta;
|
||||
assert bookMeta != null;
|
||||
bookMeta.setTitle(name);
|
||||
item.setItemMeta(bookMeta);
|
||||
sender.sendMessage(colorize("&2The title of the book has been set to &f'" + name + "&f'"));
|
||||
return true;
|
||||
}
|
||||
case "author" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.author"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dAuthor Command&f]&3===============\n"
|
||||
+ "&b/itemizer author <&fname&b> &c- &6Set the book's author"));
|
||||
return true;
|
||||
}
|
||||
if (!hasBook)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have a Written Book in your hand."));
|
||||
return true;
|
||||
}
|
||||
String name = colorize(args[1]);
|
||||
final BookMeta bookMeta = (BookMeta) meta;
|
||||
assert bookMeta != null;
|
||||
bookMeta.setAuthor(name);
|
||||
item.setItemMeta(bookMeta);
|
||||
sender.sendMessage(colorize("&2The author of the book has been set to &f'" + name + "&f'"));
|
||||
return true;
|
||||
}
|
||||
case "head" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.head"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dHead Command&f]&3===============\n"
|
||||
+ "&b/itemizer head <&fname&b> &c- &6Set the player of the head"));
|
||||
return true;
|
||||
}
|
||||
if (item.getType() != Material.PLAYER_HEAD)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have a Skull in your hand."));
|
||||
return true;
|
||||
}
|
||||
String name = args[1];
|
||||
if (name.length() > 16)
|
||||
{
|
||||
name = name.substring(0, 16);
|
||||
}
|
||||
final SkullMeta skullMeta = (SkullMeta) meta;
|
||||
assert skullMeta != null;
|
||||
skullMeta.setOwner(name);
|
||||
item.setItemMeta(skullMeta);
|
||||
sender.sendMessage(colorize("&2The player of the head has been set to &f'" + name + "&f'"));
|
||||
return true;
|
||||
}
|
||||
case "sign" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.sign"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (args.length < 3)
|
||||
{
|
||||
sender.sendMessage(colorize("&3===============&f[&dSign Command&f]&3===============\n"
|
||||
+ "&b/itemizer sign <&fline&b> <&ftext&b> &c- &6Change the line on the sign"));
|
||||
return true;
|
||||
}
|
||||
final Block block = player.getTargetBlockExact(20);
|
||||
if (block == null || block.getType() == Material.AIR
|
||||
|| !block.getType().toString().contains("SIGN"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4Please look at a sign!"));
|
||||
return true;
|
||||
}
|
||||
Integer line = parseInt(sender, args[1]);
|
||||
if (line == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (line > 4)
|
||||
{
|
||||
sender.sendMessage(colorize("&4There's maximum of 4 lines on a sign"));
|
||||
return true;
|
||||
}
|
||||
String text = colorize(StringUtils.join(args, " ", 2, args.length));
|
||||
if (cpb.getAPI() != null)
|
||||
{
|
||||
cpb.getAPI().logRemoval(player.getName(), block.getLocation(), block.getType(), block.getBlockData());
|
||||
}
|
||||
Sign sign = (Sign) block.getState();
|
||||
sign.setLine(line - 1, text);
|
||||
sign.update();
|
||||
if (cpb.getAPI() != null)
|
||||
{
|
||||
cpb.getAPI().logPlacement(player.getName(), sign.getLocation(), sign.getType(), sign.getBlockData());
|
||||
}
|
||||
sender.sendMessage(colorize("&2Line &f'" + line + "'&2 has successfully changed to &f'" + text + "&f'"));
|
||||
return true;
|
||||
}
|
||||
case "clearall" ->
|
||||
{
|
||||
if (!sender.hasPermission("itemizer.clearall"))
|
||||
{
|
||||
sender.sendMessage(colorize("&4You don't have permission to use this command!"));
|
||||
return true;
|
||||
}
|
||||
if (!hasItem)
|
||||
{
|
||||
sender.sendMessage(colorize("&cYou do not have an item in your hand."));
|
||||
return true;
|
||||
}
|
||||
item.setItemMeta(null);
|
||||
sender.sendMessage(colorize("&2All data cleared from your item"));
|
||||
return true;
|
||||
}
|
||||
default ->
|
||||
{
|
||||
sender.sendMessage(colorize("&bUnknown sub-command. Type &6/itemizer help &bfor help."));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String colorize(String string)
|
||||
{
|
||||
Matcher matcher = Pattern.compile("&#[a-fA-F0-9]{6}").matcher(string);
|
||||
while (matcher.find())
|
||||
{
|
||||
String code = matcher.group().replace("&", "");
|
||||
string = string.replace("&" + code, net.md_5.bungee.api.ChatColor.of(code) + "");
|
||||
}
|
||||
string = ChatColor.translateAlternateColorCodes('&', string);
|
||||
return string;
|
||||
}
|
||||
|
||||
private Integer parseInt(CommandSender sender, String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Integer.parseInt(string);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
sender.sendMessage(colorize("&f\"" + string + "&f\"&4 is not a valid number!"));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
package dev.plex.itemizerx;
|
||||
|
||||
import io.papermc.paper.registry.RegistryAccess;
|
||||
import io.papermc.paper.registry.RegistryKey;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -70,10 +70,9 @@ public class ItemizerXTab implements TabCompleter
|
||||
case "remove":
|
||||
{
|
||||
List<String> potions = new ArrayList<>();
|
||||
for (PotionEffectType effect : PotionEffectType.values())
|
||||
{
|
||||
potions.add(effect.getName());
|
||||
}
|
||||
RegistryAccess.registryAccess().getRegistry(RegistryKey.MOB_EFFECT).iterator().forEachRemaining(effect -> {
|
||||
potions.add(effect.getKey().getKey());
|
||||
});
|
||||
return potions;
|
||||
}
|
||||
}
|
||||
@@ -113,10 +112,9 @@ public class ItemizerXTab implements TabCompleter
|
||||
case "remove":
|
||||
{
|
||||
List<String> enchantments = new ArrayList<>();
|
||||
for (Enchantment enchantment : Enchantment.values())
|
||||
{
|
||||
RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).iterator().forEachRemaining(enchantment -> {
|
||||
enchantments.add(enchantment.getKey().getKey());
|
||||
}
|
||||
});
|
||||
return enchantments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,3 +0,0 @@
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.20.2-R0.1-SNAPSHOT")
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
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")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.20.4-R0.1-SNAPSHOT")
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
package dev.plex.itemizerx.v1_20_R3;
|
||||
|
||||
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_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
|
||||
{
|
||||
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")));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT")
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package dev.plex.itemizerx.v1_20_R4;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum Attributes_v1_20_R4
|
||||
{
|
||||
MAX_HEALTH("generic.max_health", 0, Attributes.MAX_HEALTH),
|
||||
FOLLOW_RANGE("generic.follow_range", 1, Attributes.FOLLOW_RANGE),
|
||||
KNOCKBACK_RESISTANCE("generic.knockback_resistance", 1, Attributes.KNOCKBACK_RESISTANCE),
|
||||
MOVEMENT_SPEED("generic.movement_speed", 1, Attributes.MOVEMENT_SPEED),
|
||||
FLYING_SPEED("generic.flying_speed", 1, Attributes.FLYING_SPEED),
|
||||
DAMAGE("generic.attack_damage", 0, Attributes.ATTACK_DAMAGE),
|
||||
ATTACK_KNOCKBACK("generic.attack_knockback", 0, Attributes.ATTACK_KNOCKBACK),
|
||||
ATTACK_SPEED("generic.attack_speed", 1, Attributes.ATTACK_SPEED),
|
||||
ARMOR("generic.armor", 0, Attributes.ARMOR),
|
||||
ARMOR_TOUGHNESS("generic.armor_toughness", 0, Attributes.ARMOR_TOUGHNESS),
|
||||
LUCK("generic.luck", 0, Attributes.LUCK),
|
||||
JUMP_STRENGTH("generic.jump_strength", 1, Attributes.JUMP_STRENGTH),
|
||||
ZOMBIE_REINFORCEMENTS("zombie.spawn_reinforcements", 1, Attributes.SPAWN_REINFORCEMENTS_CHANCE);
|
||||
|
||||
public final String mcName;
|
||||
public final int op;
|
||||
public final Holder<Attribute> attributeHolder;
|
||||
|
||||
Attributes_v1_20_R4(String mcName, int op, Holder<Attribute> attributeHolder)
|
||||
{
|
||||
this.mcName = mcName;
|
||||
this.op = op;
|
||||
this.attributeHolder = attributeHolder;
|
||||
}
|
||||
|
||||
public static Attributes_v1_20_R4 get(String name)
|
||||
{
|
||||
for (Attributes_v1_20_R4 attr : values())
|
||||
{
|
||||
if (attr.name().equalsIgnoreCase(name) || attr.mcName.equalsIgnoreCase(name.replace("minecraft:", "")))
|
||||
{
|
||||
return attr;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getAttributes()
|
||||
{
|
||||
return StringUtils.join(values(), ", ");
|
||||
}
|
||||
|
||||
public static List<String> getAttributeList()
|
||||
{
|
||||
List<String> attributes = new ArrayList<>();
|
||||
for (Attributes_v1_20_R4 attr : values())
|
||||
{
|
||||
attributes.add(attr.name());
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
dependencies {
|
||||
paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT")
|
||||
}
|
||||
+52
-63
@@ -1,16 +1,18 @@
|
||||
package dev.plex.itemizerx.v1_20_R4;
|
||||
package dev.plex.itemizerx.v1_21_R1;
|
||||
|
||||
import dev.plex.itemizerx.Attributes;
|
||||
import dev.plex.itemizerx.IAttributeManager;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.component.ItemAttributeModifiers;
|
||||
import net.minecraft.world.item.component.ItemAttributeModifiers.Entry;
|
||||
@@ -18,36 +20,20 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
public class AttributeManager implements IAttributeManager {
|
||||
|
||||
public class AttributeManager implements IAttributeManager
|
||||
{
|
||||
private final MiniMessage mm = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public List<AttributeModifier> getAttrList(final Item item)
|
||||
{
|
||||
ItemAttributeModifiers attrmod = item.components().getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
||||
List<AttributeModifier> modifiers = new ArrayList<>();
|
||||
for (Entry modifier : attrmod.modifiers())
|
||||
{
|
||||
modifiers.add(modifier.modifier());
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttr(final Player player, final String[] args)
|
||||
{
|
||||
public void addAttr(Player player, String[] args) {
|
||||
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"));
|
||||
"[<white>slot<aqua>] <red>- <gold>Add an attribute"));
|
||||
return;
|
||||
}
|
||||
|
||||
final Attributes_v1_20_R4 a = Attributes_v1_20_R4.get(args[2]);
|
||||
Attributes a = Attributes.get(args[2]);
|
||||
if (a == null)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>\"" + args[2] + "\" is not a valid attribute type."));
|
||||
@@ -72,10 +58,10 @@ public class AttributeManager implements IAttributeManager
|
||||
}
|
||||
|
||||
ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
|
||||
final List<AttributeModifier> attrmod = getAttrList(nms.getItem());
|
||||
for (AttributeModifier modifier : attrmod)
|
||||
final List<Entry> entries = nms.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY).modifiers();
|
||||
for (Entry entry : entries)
|
||||
{
|
||||
if (modifier.name().equalsIgnoreCase(args[2]))
|
||||
if (entry.attribute().getRegisteredName().equalsIgnoreCase(args[2]))
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>An attribute with the name \"<white>" + args[2] + "<dark_red>\" already exists!"));
|
||||
return;
|
||||
@@ -93,66 +79,69 @@ public class AttributeManager implements IAttributeManager
|
||||
catch (IllegalArgumentException ignored)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_green>Supported options:"));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(Arrays.stream(EquipmentSlot.values()).map(s -> s.getName().toLowerCase()).toArray(), ", ")));
|
||||
player.sendMessage(mm.deserialize("<yellow>" + StringUtils.join(
|
||||
Arrays.stream(EquipmentSlot.values()).map(s -> s.getName().toLowerCase()).toArray(), ", ")));
|
||||
return;
|
||||
}
|
||||
|
||||
group.set(EquipmentSlotGroup.bySlot(slot));
|
||||
}
|
||||
|
||||
final AttributeModifier modifier = new AttributeModifier(a.mcName, amount, Operation.BY_ID.apply(a.op));
|
||||
final ResourceLocation locationID = ResourceLocation.fromNamespaceAndPath("itemizerx", String.format("modifier_%s", a.mcName));
|
||||
final AttributeModifier modifier = new AttributeModifier(locationID, amount, Operation.BY_ID.apply(a.op));
|
||||
nms.update(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY, x ->
|
||||
x.withModifierAdded(a.attributeHolder, modifier, group.get()).withTooltip(true));
|
||||
x.withModifierAdded(a.attributeHolder, modifier, group.get()));
|
||||
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)
|
||||
public void removeAttr(Player player, String string) {
|
||||
Attributes a = Attributes.get(string);
|
||||
if (a == null)
|
||||
{
|
||||
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!"));
|
||||
player.sendMessage(mm.deserialize("<dark_red>\"" + string + "\" is not a valid attribute type."));
|
||||
return;
|
||||
}
|
||||
//nms.getTag().put("AttributeModifiers", newList);
|
||||
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
|
||||
player.getInventory().setItemInMainHand(is);*/
|
||||
player.sendMessage(mm.deserialize("<red>Removing attributes isn't supported at the moment!"));
|
||||
|
||||
ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
|
||||
ItemAttributeModifiers attrModifiers = nms.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY);
|
||||
final List<Entry> entries = attrModifiers.modifiers();
|
||||
Optional<Entry> optionalEntry = entries.stream().filter(e -> e.attribute().equals(a.attributeHolder)).findFirst();
|
||||
|
||||
ItemAttributeModifiers.Builder builder = ItemAttributeModifiers.builder();
|
||||
optionalEntry.ifPresentOrElse(entry -> {
|
||||
entries.forEach(e -> {
|
||||
if (e.attribute().equals(a.attributeHolder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.add(entry.attribute(), entry.modifier(), entry.slot(), entry.display());
|
||||
});
|
||||
|
||||
nms.set(DataComponents.ATTRIBUTE_MODIFIERS, builder.build());
|
||||
final org.bukkit.inventory.ItemStack is = CraftItemStack.asCraftMirror(nms);
|
||||
player.getInventory().setItemInMainHand(is);
|
||||
player.sendMessage(mm.deserialize("<dark_aqua>Attribute removed!"));
|
||||
}, () -> player.sendMessage(mm.deserialize("<dark_red>The attribute \"" + string + "\" doesn't exist!")));
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listAttr(final Player player)
|
||||
{
|
||||
public void listAttr(Player player) {
|
||||
final ItemStack nms = CraftItemStack.asNMSCopy(player.getInventory().getItemInMainHand());
|
||||
final List<AttributeModifier> attrmod = getAttrList(nms.getItem());
|
||||
if (attrmod.isEmpty())
|
||||
{
|
||||
|
||||
List<Entry> entries = nms.getOrDefault(DataComponents.ATTRIBUTE_MODIFIERS, ItemAttributeModifiers.EMPTY).modifiers();
|
||||
if (entries.isEmpty()) {
|
||||
player.sendMessage(mm.deserialize("<yellow>This item has no attributes."));
|
||||
return;
|
||||
}
|
||||
|
||||
player.sendMessage(mm.deserialize("<dark_green>Item attributes: "));
|
||||
for (AttributeModifier modifier : attrmod)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<yellow>" + modifier.name() + ", " + modifier.amount()));
|
||||
}
|
||||
entries.forEach(entry -> {
|
||||
player.sendMessage(mm.deserialize("<yellow>" + entry.attribute().getRegisteredName() + ", " + entry.modifier().amount() + ", " + entry.slot()));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package dev.plex.itemizerx.v1_21_R1;
|
||||
|
||||
import dev.plex.itemizerx.IEnchantmentManager;
|
||||
import java.util.Objects;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public class EnchantmentManager implements IEnchantmentManager {
|
||||
|
||||
private final MiniMessage mm = MiniMessage.miniMessage();
|
||||
|
||||
@Override
|
||||
public void addEnchantment(Player player, ItemStack item, String[] args) {
|
||||
if (args.length < 4)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_aqua>===============<white>[<light_purple>Enchant Commands<white>]<dark_aqua>==============="));
|
||||
player.sendMessage(mm.deserialize("<aqua>/itemizer enchant add <<white>name<aqua>> <<white>level<aqua>> <red>- <gold>Add an enchantment"));
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantmentMap map = EnchantmentMap.fromName(args[2]);
|
||||
if (map == null) {
|
||||
player.sendMessage(mm.deserialize("<dark_red>The <white>'" + args[2] + "<white>' <dark_red>enchantment does not exist!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Enchantment enchantment = map.asEnchantment();
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
if (meta.getEnchants().containsKey(enchantment))
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>This item already have the <white>'" + enchantment.getKey().getKey() + "' <dark_red>enchantment!"));
|
||||
return;
|
||||
}
|
||||
|
||||
int level;
|
||||
try
|
||||
{
|
||||
level = Integer.parseInt(args[3]);
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<white>\"" + args[3] + "<white>\"<dark_red> is not a valid number!"));
|
||||
return;
|
||||
}
|
||||
|
||||
item.addUnsafeEnchantment(enchantment, level);
|
||||
player.sendMessage(mm.deserialize("<dark_green>The enchant <white>'" + enchantment.getKey().getKey() + "' <dark_green>has been added to your item"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeEnchantment(Player player, ItemStack item, String[] args) {
|
||||
if (args.length == 2)
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_aqua>===============<white>[<light_purple>Enchant Commands<white>]<dark_aqua>==============="));
|
||||
player.sendMessage(mm.deserialize("<aqua>/itemizer enchant remove <<white>name<aqua>> <red>- <gold>Remove an enchantment"));
|
||||
return;
|
||||
}
|
||||
|
||||
EnchantmentMap map = EnchantmentMap.fromName(args[2]);
|
||||
if (map == null) {
|
||||
player.sendMessage(mm.deserialize("<dark_red>The <white>'" + args[2] + "<white>' <dark_red> enchantment does not exist!"));
|
||||
return;
|
||||
}
|
||||
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
if (Objects.requireNonNull(meta.getEnchants()).isEmpty())
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>This item doesn't hold any enchants"));
|
||||
return;
|
||||
}
|
||||
|
||||
Enchantment enchantment = map.asEnchantment();
|
||||
if (!meta.getEnchants().containsKey(enchantment))
|
||||
{
|
||||
player.sendMessage(mm.deserialize("<dark_red>This item doesn't have the <white>'" + enchantment.getKey().getKey() + "' <dark_red>enchantment!"));
|
||||
return;
|
||||
}
|
||||
item.removeEnchantment(enchantment);
|
||||
player.sendMessage(mm.deserialize("<dark_green>The <white>'" + enchantment.getKey().getKey() + "' <dark_green>enchantment has been removed from your item"));
|
||||
}
|
||||
|
||||
private enum EnchantmentMap {
|
||||
PROTECTION(Enchantment.PROTECTION),
|
||||
FIRE_PROTECTION(Enchantment.FIRE_PROTECTION),
|
||||
FEATHER_FALLING(Enchantment.FEATHER_FALLING),
|
||||
BLAST_PROTECTION(Enchantment.BLAST_PROTECTION),
|
||||
PROJECTILE_PROTECTION(Enchantment.PROJECTILE_PROTECTION),
|
||||
RESPIRATION(Enchantment.RESPIRATION),
|
||||
AQUA_AFFINITY(Enchantment.AQUA_AFFINITY),
|
||||
THORNS(Enchantment.THORNS),
|
||||
DEPTH_STRIDER(Enchantment.DEPTH_STRIDER),
|
||||
FROST_WALKER(Enchantment.FROST_WALKER),
|
||||
BINDING_CURSE(Enchantment.BINDING_CURSE),
|
||||
SHARPNESS(Enchantment.SHARPNESS),
|
||||
SMITE(Enchantment.SMITE),
|
||||
BANE_OF_ARTHROPODS(Enchantment.BANE_OF_ARTHROPODS),
|
||||
KNOCKBACK(Enchantment.KNOCKBACK),
|
||||
FIRE_ASPECT(Enchantment.FIRE_ASPECT),
|
||||
LOOTING(Enchantment.LOOTING),
|
||||
SWEEPING_EDGE(Enchantment.SWEEPING_EDGE),
|
||||
EFFICIENCY(Enchantment.EFFICIENCY),
|
||||
SILK_TOUCH(Enchantment.SILK_TOUCH),
|
||||
UNBREAKING(Enchantment.UNBREAKING),
|
||||
FORTUNE(Enchantment.FORTUNE),
|
||||
POWER(Enchantment.POWER),
|
||||
PUNCH(Enchantment.PUNCH),
|
||||
FLAME(Enchantment.FLAME),
|
||||
INFINITY(Enchantment.INFINITY),
|
||||
LUCK_OF_THE_SEA(Enchantment.LUCK_OF_THE_SEA),
|
||||
LURE(Enchantment.LURE),
|
||||
LOYALTY(Enchantment.LOYALTY),
|
||||
IMPALING(Enchantment.IMPALING),
|
||||
RIPTIDE(Enchantment.RIPTIDE),
|
||||
CHANNELING(Enchantment.CHANNELING),
|
||||
MULTISHOT(Enchantment.MULTISHOT),
|
||||
QUICK_CHARGE(Enchantment.QUICK_CHARGE),
|
||||
PIERCING(Enchantment.PIERCING),
|
||||
DENSITY(Enchantment.DENSITY),
|
||||
BREACH(Enchantment.BREACH),
|
||||
WIND_BURST(Enchantment.WIND_BURST),
|
||||
MENDING(Enchantment.MENDING),
|
||||
VANISHING_CURSE(Enchantment.VANISHING_CURSE),
|
||||
SOUL_SPEED(Enchantment.SOUL_SPEED),
|
||||
SWIFT_SNEAK(Enchantment.SWIFT_SNEAK);
|
||||
|
||||
private final Enchantment enchantment;
|
||||
|
||||
EnchantmentMap(Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
public static EnchantmentMap fromName(String name) {
|
||||
for (EnchantmentMap map : values()) {
|
||||
if (map.name().equalsIgnoreCase(name)) {
|
||||
return map;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Enchantment asEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package dev.plex.itemizerx.v1_21_R1;
|
||||
|
||||
public class Main
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user