diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 9e25e8e..515f33d 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index e6264e3..e98d1af 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml index 0d6392f..38b3b14 100644 --- a/.idea/dictionaries/project.xml +++ b/.idea/dictionaries/project.xml @@ -2,6 +2,7 @@ grimms + soulbound \ No newline at end of file diff --git a/build/libs/GrimmsServer-1.5.6.jar b/build/libs/GrimmsServer-1.5.6.jar index f2b41cc..09be8ea 100644 Binary files a/build/libs/GrimmsServer-1.5.6.jar and b/build/libs/GrimmsServer-1.5.6.jar differ diff --git a/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/Enchant.java b/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/Enchant.java new file mode 100644 index 0000000..fdec08f --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/Enchant.java @@ -0,0 +1,170 @@ +package org.gsdistance.grimmsServer.Commands.GUtilCommand; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.gsdistance.grimmsServer.Constructable.Item.CustomEnchantmentHandler; +import org.gsdistance.grimmsServer.Data.CustomEnchantments; + +import java.util.Map; + +public class Enchant { + + public Enchant() { + } + + public static boolean subCommand(Player player, String[] args) { + // Guard: Permission Check + if (!player.hasPermission("grimmsserver.util.admin")) { + player.sendMessage(ChatColor.RED + "You do not have permission to use this command."); + return false; + } + + // Guard: Minimum arguments requirement + if (args.length < 2) { + return false; + } + + String action = args[1].toLowerCase(); + ItemStack item = player.getInventory().getItemInMainHand(); + + if (item == null || item.getType().isAir()) { + player.sendMessage(ChatColor.RED + "You must hold an item in your main hand."); + return false; + } + + switch (action) { + case "add" -> { + if (args.length < 4) { + player.sendMessage(ChatColor.RED + "Usage: /gutil enchant add [level]"); + return false; + } + + try { + CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase()); + int level = args.length >= 4 ? Integer.parseInt(args[3]) : 1; + + CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item); + if (handler.addEnchantment(enchantment, level)) { + player.sendMessage(ChatColor.GREEN + "Added " + ChatColor.GOLD + enchantment.enchantmentName + + ChatColor.GREEN + " level " + ChatColor.YELLOW + level + ChatColor.GREEN + " to " + item.getType()); + return true; + } else { + player.sendMessage(ChatColor.RED + "Failed to add enchantment. Check if level exceeds maximum or enchantment already exists."); + return false; + } + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + "Invalid level: " + args[3]); + return false; + } catch (IllegalArgumentException e) { + player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]); + return false; + } + } + + case "remove" -> { + if (args.length < 3) { + player.sendMessage(ChatColor.RED + "Usage: /gutil enchant remove "); + return false; + } + + try { + CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase()); + + CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item); + if (handler.removeEnchantment(enchantment)) { + player.sendMessage(ChatColor.GREEN + "Removed " + ChatColor.GOLD + enchantment.enchantmentName + ChatColor.GREEN + " from " + item.getType()); + return true; + } else { + player.sendMessage(ChatColor.RED + "Item does not have that enchantment."); + return false; + } + } catch (IllegalArgumentException e) { + player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]); + return false; + } + } + + case "set" -> { + if (args.length < 4) { + player.sendMessage(ChatColor.RED + "Usage: /gutil enchant set "); + return false; + } + + try { + CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase()); + int level = Integer.parseInt(args[3]); + + CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item); + if (handler.setEnchantmentLevel(enchantment, level)) { + player.sendMessage(ChatColor.GREEN + "Set " + ChatColor.GOLD + enchantment.enchantmentName + + ChatColor.GREEN + " to level " + ChatColor.YELLOW + level + ChatColor.GREEN + " on " + item.getType()); + return true; + } else { + player.sendMessage(ChatColor.RED + "Failed to set enchantment level. Check if level is valid."); + return false; + } + } catch (NumberFormatException e) { + player.sendMessage(ChatColor.RED + "Invalid level: " + args[3]); + return false; + } catch (IllegalArgumentException e) { + player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]); + return false; + } + } + + case "list" -> { + CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item); + Map enchantments = handler.getAllEnchantments(); + + if (enchantments.isEmpty()) { + player.sendMessage(ChatColor.GRAY + "Item has no custom enchantments."); + return true; + } + + player.sendMessage(ChatColor.GOLD + "Custom Enchantments on " + item.getType() + ":"); + for (Map.Entry entry : enchantments.entrySet()) { + player.sendMessage(ChatColor.YELLOW + "- " + entry.getKey().enchantmentName + + ChatColor.GRAY + " (Level " + entry.getValue() + "/" + entry.getKey().maxLevel + ")"); + } + return true; + } + + case "clear" -> { + CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item); + handler.clearAllEnchantments(); + player.sendMessage(ChatColor.GREEN + "Cleared all custom enchantments from " + item.getType()); + return true; + } + + case "has" -> { + if (args.length < 3) { + player.sendMessage(ChatColor.RED + "Usage: /gutil enchant has "); + return false; + } + + try { + CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase()); + CustomEnchantmentHandler handler = CustomEnchantmentHandler.getHandler(item); + + if (handler.hasEnchantment(enchantment)) { + int level = handler.getEnchantmentLevel(enchantment); + player.sendMessage(ChatColor.GREEN + "Item has " + ChatColor.GOLD + enchantment.enchantmentName + + ChatColor.GREEN + " at level " + ChatColor.YELLOW + level); + } else { + player.sendMessage(ChatColor.RED + "Item does not have " + enchantment.enchantmentName); + } + return true; + } catch (IllegalArgumentException e) { + player.sendMessage(ChatColor.RED + "Invalid enchantment: " + args[2]); + return false; + } + } + + default -> { + player.sendMessage(ChatColor.RED + "Unknown enchant command: " + action); + return false; + } + } + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilBaseCommand.java b/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilBaseCommand.java index 2f6d25a..157f274 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilBaseCommand.java +++ b/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilBaseCommand.java @@ -24,6 +24,12 @@ public class GUtilBaseCommand implements CommandExecutor { } return false; } + case "enchant" -> { + if (sender instanceof Player player) { + return Enchant.subCommand(player, args); + } + return false; + } case "capability" -> { if (sender instanceof Player player) { return Capability.subCommand(player, args); diff --git a/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilTabCompleter.java b/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilTabCompleter.java index b4e0458..6033e74 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilTabCompleter.java +++ b/src/main/java/org/gsdistance/grimmsServer/Commands/GUtilCommand/GUtilTabCompleter.java @@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; import org.gsdistance.grimmsServer.Constructable.Player.PlayerMetadata; +import org.gsdistance.grimmsServer.Data.CustomEnchantments; import org.gsdistance.grimmsServer.Data.Player.PlayerInventoryData; import org.gsdistance.grimmsServer.Stats.PlayerTitles; import org.jetbrains.annotations.NotNull; @@ -20,16 +21,22 @@ import java.util.stream.Stream; public class GUtilTabCompleter implements TabCompleter { public static final List defSubCommands = List.of("version", "setting", "spawn"); - public static final List adminSubCommands = List.of("relic", "capability", "broadcast", "inventoryrestore", "fly", "god", "heal", "speed", "enderchest", "invsee", "addtitle", "removetitle", "unlevelentity", "sudo", "levelentity"); + public static final List adminSubCommands = List.of("relic", "enchant", "capability", "broadcast", "inventoryrestore", "fly", "god", "heal", "speed", "enderchest", "invsee", "addtitle", "removetitle", "unlevelentity", "sudo", "levelentity"); + + private CommandMap cachedCommandMap; public GUtilTabCompleter() { } private CommandMap getCommandMap() { + if (cachedCommandMap != null) { + return cachedCommandMap; + } try { Field commandMapField = Bukkit.getServer().getClass().getDeclaredField("commandMap"); commandMapField.setAccessible(true); - return (CommandMap) commandMapField.get(Bukkit.getServer()); + cachedCommandMap = (CommandMap) commandMapField.get(Bukkit.getServer()); + return cachedCommandMap; } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException("Failed to get command map", e); } @@ -73,13 +80,16 @@ public class GUtilTabCompleter implements TabCompleter { case "relic" -> { return List.of("make", "set", "recalc", "reroll"); } + case "enchant" -> { + return List.of("add", "remove", "set", "list", "clear", "has"); + } case "version" -> { return List.of("check", "update"); } case "setting" -> { return PlayerMetadata.getPlayerMetadata(player).settings.stream().toList(); } - case "inventoryrestore", "heal", "spawn", "enderchest", "invsee", "addtitle", "removetitle", "sudo", "unlevelentity", "levelentity" -> { + case "inventoryrestore", "heal", "spawn", "enderchest", "invsee", "addtitle", "removetitle", "sudo" -> { return Bukkit.getOnlinePlayers().stream() .map(Player::getName) .filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase())) @@ -95,12 +105,54 @@ public class GUtilTabCompleter implements TabCompleter { .filter(type -> type.startsWith(args[1].toLowerCase())) .toList(); } + case "levelentity", "unlevelentity" -> { + return player.getWorld().getEntities().stream() + .map(entity -> entity.getUniqueId().toString()) + .filter(uuid -> uuid.toLowerCase().startsWith(args[1].toLowerCase())) + .collect(Collectors.toList()); + } default -> { return List.of(); } } + } else if (args.length > 3 && args[0].equalsIgnoreCase("sudo")) { + // Handle nested tab completion for sudo command + String commandName = args[2]; + org.bukkit.command.Command targetCommand = getCommandMap().getCommand(commandName); + if (targetCommand != null) { + TabCompleter tabCompleter = getTabCompleter(targetCommand); + if (tabCompleter != null) { + // Build the args array for the target command + String[] targetArgs = new String[args.length - 3]; + System.arraycopy(args, 3, targetArgs, 0, targetArgs.length); + return tabCompleter.onTabComplete(sender, targetCommand, commandName, targetArgs); + } + } + return List.of(); } else if (args.length == 3) { switch (args[0].toLowerCase()) { + case "enchant" -> { + if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove") || + args[1].equalsIgnoreCase("set") || args[1].equalsIgnoreCase("has")) { + return java.util.Arrays.stream(CustomEnchantments.values()) + .map(enchant -> enchant.name().toLowerCase()) + .filter(name -> name.startsWith(args[2].toLowerCase())) + .collect(Collectors.toList()); + } + return List.of(); + } + case "relic" -> { + if (args[1].equalsIgnoreCase("set")) { + List tiers = new ArrayList<>(); + for (int i = 1; i <= 10; i++) { + tiers.add(String.valueOf(i)); + } + return tiers.stream() + .filter(tier -> tier.startsWith(args[2])) + .toList(); + } + return List.of(); + } case "speed" -> { List speeds = new ArrayList<>(); for (int i = 1; i <= 10; i++) { @@ -149,20 +201,59 @@ public class GUtilTabCompleter implements TabCompleter { return List.of(); } } - } else if (args.length >= 3 && args[0].equalsIgnoreCase("sudo")) { - // Handle nested tab completion for sudo command - String commandName = args[2]; - org.bukkit.command.Command targetCommand = getCommandMap().getCommand(commandName); - if (targetCommand != null) { - TabCompleter tabCompleter = getTabCompleter(targetCommand); - if (tabCompleter != null) { - // Build the args array for the target command - String[] targetArgs = new String[args.length - 3]; - System.arraycopy(args, 3, targetArgs, 0, targetArgs.length); - return tabCompleter.onTabComplete(sender, targetCommand, commandName, targetArgs); + } else if (args.length == 4) { + switch (args[0].toLowerCase()) { + case "enchant" -> { + if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("set")) { + try { + CustomEnchantments enchantment = CustomEnchantments.valueOf(args[2].toUpperCase()); + List levels = new ArrayList<>(); + for (int i = 1; i <= enchantment.maxLevel; i++) { + levels.add(String.valueOf(i)); + } + return levels.stream() + .filter(level -> level.startsWith(args[3])) + .collect(Collectors.toList()); + } catch (IllegalArgumentException e) { + return List.of(); + } + } + return List.of(); + } + case "relic" -> { + if (args[1].equalsIgnoreCase("set")) { + List grades = new ArrayList<>(); + for (int i = 1; i <= 10; i++) { + grades.add(String.valueOf(i)); + } + return grades.stream() + .filter(grade -> grade.startsWith(args[3])) + .toList(); + } + return List.of(); + } + default -> { + return List.of(); + } + } + } else if (args.length == 5) { + switch (args[0].toLowerCase()) { + case "relic" -> { + if (args[1].equalsIgnoreCase("set")) { + List resistances = new ArrayList<>(); + for (int i = 1; i <= 100; i++) { + resistances.add(String.valueOf(i)); + } + return resistances.stream() + .filter(res -> res.startsWith(args[4])) + .toList(); + } + return List.of(); + } + default -> { + return List.of(); } } - return List.of(); } else { return List.of(); } diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomEnchantmentHandler.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomEnchantmentHandler.java new file mode 100644 index 0000000..08c4830 --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomEnchantmentHandler.java @@ -0,0 +1,131 @@ +package org.gsdistance.grimmsServer.Constructable.Item; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.persistence.PersistentDataType; +import org.gsdistance.grimmsServer.Data.CustomEnchantments; + +import java.util.HashMap; +import java.util.Map; + +public class CustomEnchantmentHandler { + private final ItemStack item; + private final ItemDataHandler dataHandler; + private static final String ENCHANTMENT_PREFIX = "custom_enchant_"; + + public CustomEnchantmentHandler(ItemStack item) { + this.item = item; + this.dataHandler = ItemDataHandler.getItemDataHandler(item); + } + + public static CustomEnchantmentHandler getHandler(ItemStack item) { + return new CustomEnchantmentHandler(item); + } + + /** + * Add a custom enchantment to the item + * @param enchantment The enchantment to add + * @param level The level of the enchantment + * @return true if successful, false if level exceeds max or enchantment already exists + */ + public boolean addEnchantment(CustomEnchantments enchantment, int level) { + if (level < 1 || level > enchantment.maxLevel) { + return false; + } + + if (hasEnchantment(enchantment)) { + return false; + } + + String key = ENCHANTMENT_PREFIX + enchantment.name(); + dataHandler.setItemNBTData(key, level, PersistentDataType.INTEGER); + return true; + } + + /** + * Remove a custom enchantment from the item + * @param enchantment The enchantment to remove + * @return true if the enchantment was removed, false if it didn't exist + */ + public boolean removeEnchantment(CustomEnchantments enchantment) { + if (!hasEnchantment(enchantment)) { + return false; + } + + String key = ENCHANTMENT_PREFIX + enchantment.name(); + // To remove, we set it to null or use a different approach + // Since ItemDataHandler doesn't have a remove method, we'll need to handle this + // For now, let's implement a workaround by setting to 0 + dataHandler.setItemNBTData(key, 0, PersistentDataType.INTEGER); + return true; + } + + /** + * Check if the item has a specific custom enchantment + * @param enchantment The enchantment to check for + * @return true if the item has the enchantment with level > 0 + */ + public boolean hasEnchantment(CustomEnchantments enchantment) { + return getEnchantmentLevel(enchantment) > 0; + } + + /** + * Get the level of a custom enchantment on the item + * @param enchantment The enchantment to check + * @return The level of the enchantment, or 0 if not present + */ + public int getEnchantmentLevel(CustomEnchantments enchantment) { + String key = ENCHANTMENT_PREFIX + enchantment.name(); + Integer level = dataHandler.getItemNBTData(key, PersistentDataType.INTEGER); + return level != null ? level : 0; + } + + /** + * Get all custom enchantments on the item + * @return A map of enchantments to their levels + */ + public Map getAllEnchantments() { + Map enchantments = new HashMap<>(); + + for (CustomEnchantments enchantment : CustomEnchantments.values()) { + int level = getEnchantmentLevel(enchantment); + if (level > 0) { + enchantments.put(enchantment, level); + } + } + + return enchantments; + } + + /** + * Set the level of an enchantment (overwrites existing) + * @param enchantment The enchantment to set + * @param level The level to set + * @return true if successful, false if level is invalid + */ + public boolean setEnchantmentLevel(CustomEnchantments enchantment, int level) { + if (level < 0 || level > enchantment.maxLevel) { + return false; + } + + String key = ENCHANTMENT_PREFIX + enchantment.name(); + dataHandler.setItemNBTData(key, level, PersistentDataType.INTEGER); + return true; + } + + /** + * Clear all custom enchantments from the item + */ + public void clearAllEnchantments() { + for (CustomEnchantments enchantment : CustomEnchantments.values()) { + setEnchantmentLevel(enchantment, 0); + } + } + + /** + * Check if the item has any custom enchantments + * @return true if the item has at least one custom enchantment + */ + public boolean hasAnyEnchantments() { + return !getAllEnchantments().isEmpty(); + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItem.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItem.java new file mode 100644 index 0000000..b8e583b --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItem.java @@ -0,0 +1,52 @@ +package org.gsdistance.grimmsServer.Constructable.Item; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +public abstract class CustomItem { + private final String itemId; + private final ItemStack itemStack; + private final CustomItemHandler handler; + + public CustomItem(String itemId, ItemStack itemStack) { + this.itemId = itemId; + this.itemStack = itemStack; + this.handler = CustomItemHandler.getHandler(itemStack); + if (this.handler == null) { + throw new IllegalArgumentException("ItemStack must be initialized with CustomItemHandler first"); + } + this.handler.setCustomItemId(itemId); + this.initializeItem(); + } + + protected abstract void initializeItem(); + + public String getItemId() { + return itemId; + } + + public ItemStack getItemStack() { + return itemStack; + } + + public CustomItemHandler getHandler() { + return handler; + } + + public Material getMaterial() { + return itemStack.getType(); + } + + public ItemMeta getItemMeta() { + return itemStack.getItemMeta(); + } + + public void setItemMeta(ItemMeta meta) { + itemStack.setItemMeta(meta); + } + + public abstract String getDisplayName(); + + public abstract String getDescription(); +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemExample.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemExample.java new file mode 100644 index 0000000..8386151 --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemExample.java @@ -0,0 +1,67 @@ +package org.gsdistance.grimmsServer.Constructable.Item; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +/** + * Example custom item implementation showing how to create and register custom items. + * This is a template for creating your own custom items. + */ +public class CustomItemExample extends CustomItem { + + public CustomItemExample(String itemId, ItemStack itemStack) { + super(itemId, itemStack); + } + + @Override + protected void initializeItem() { + // Set up the item's initial properties + ItemMeta meta = getItemMeta(); + if (meta != null) { + meta.setDisplayName(ChatColor.GOLD + "Custom Example Item"); + meta.setCustomModelData(1001); // Optional: Set custom model data for resource packs + setItemMeta(meta); + } + + // Store custom data specific to this item type + getHandler().setCustomData("exampleValue", 42, org.bukkit.persistence.PersistentDataType.INTEGER); + } + + @Override + public String getDisplayName() { + return ChatColor.GOLD + "Custom Example Item"; + } + + @Override + public String getDescription() { + return "An example custom item with special properties."; + } + + /** + * Example method to register this custom item. + * Call this during your plugin's onEnable() method. + */ + public static void register() { + CustomItemRegistry.registerCustomItem("custom_example", itemStack -> { + // Create the ItemStack (can be any material) + ItemStack stack = new ItemStack(Material.DIAMOND_SWORD); + + // Initialize it as a custom item + CustomItemHandler.createHandler(stack); + + // Create and return the custom item instance + return new CustomItemExample("custom_example", stack); + }); + } + + /** + * Example method to create an instance of this custom item. + */ + public static ItemStack create() { + ItemStack stack = new ItemStack(Material.DIAMOND_SWORD); + CustomItemHandler.createHandler(stack); + return CustomItemRegistry.createCustomItem("custom_example", stack).getItemStack(); + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemHandler.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemHandler.java new file mode 100644 index 0000000..5d0c5ae --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemHandler.java @@ -0,0 +1,78 @@ +package org.gsdistance.grimmsServer.Constructable.Item; + +import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; +import org.bukkit.plugin.java.JavaPlugin; +import org.gsdistance.grimmsServer.GrimmsServer; + +import javax.annotation.Nullable; + +public class CustomItemHandler { + private final ItemStack item; + private final ItemDataHandler dataHandler; + private static final String CUSTOM_ITEM_KEY = "customItemId"; + private static final String IS_CUSTOM_ITEM_KEY = "isCustomItem"; + + public CustomItemHandler(ItemStack item, @Nullable JavaPlugin plugin) { + this.item = item; + this.dataHandler = new ItemDataHandler(item, plugin); + } + + public static CustomItemHandler getHandler(ItemStack item) { + if (item == null || !item.hasItemMeta()) { + return null; + } + return new CustomItemHandler(item, GrimmsServer.instance); + } + + public static CustomItemHandler createHandler(ItemStack item) { + CustomItemHandler handler = new CustomItemHandler(item, GrimmsServer.instance); + handler.initializeCustomItem(); + return handler; + } + + private void initializeCustomItem() { + if (!isCustomItem(this.item)) { + this.dataHandler.setItemNBTData(IS_CUSTOM_ITEM_KEY, true, PersistentDataType.BOOLEAN); + // Set default item ID to vanilla material name + String vanillaId = CustomItemRegistry.getVanillaItemId(this.item.getType()); + this.dataHandler.setItemNBTData(CUSTOM_ITEM_KEY, vanillaId, PersistentDataType.STRING); + } + } + + public static boolean isCustomItem(ItemStack item) { + if (item == null || !item.hasItemMeta()) { + return false; + } + ItemDataHandler dataHandler = new ItemDataHandler(item, GrimmsServer.instance); + Boolean isCustom = dataHandler.getItemNBTData(IS_CUSTOM_ITEM_KEY, PersistentDataType.BOOLEAN); + return isCustom != null && isCustom; + } + + public String getCustomItemId() { + return this.dataHandler.getItemNBTData(CUSTOM_ITEM_KEY, PersistentDataType.STRING); + } + + public void setCustomItemId(String itemId) { + this.dataHandler.setItemNBTData(CUSTOM_ITEM_KEY, itemId, PersistentDataType.STRING); + } + + public T getCustomData(String key, PersistentDataType type) { + return this.dataHandler.getItemNBTData("custom_" + key, type); + } + + public void setCustomData(String key, T value, PersistentDataType type) { + this.dataHandler.setItemNBTData("custom_" + key, value, type); + } + + public ItemStack getItemStack() { + return item; + } + + public ItemDataHandler getDataHandler() { + return dataHandler; + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemRegistry.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemRegistry.java new file mode 100644 index 0000000..de7cf3f --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomItemRegistry.java @@ -0,0 +1,54 @@ +package org.gsdistance.grimmsServer.Constructable.Item; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +public class CustomItemRegistry { + private static final Map customItems = new HashMap<>(); + private static final Map> itemConstructors = new HashMap<>(); + + public static void registerCustomItem(String itemId, Function constructor) { + if (customItems.containsKey(itemId)) { + throw new IllegalArgumentException("Custom item with ID " + itemId + " is already registered"); + } + itemConstructors.put(itemId, constructor); + } + + public static CustomItem createCustomItem(String itemId, ItemStack itemStack) { + Function constructor = itemConstructors.get(itemId); + if (constructor == null) { + throw new IllegalArgumentException("No custom item registered with ID " + itemId); + } + CustomItem customItem = constructor.apply(itemStack); + customItems.put(itemId, customItem); + return customItem; + } + + public static boolean isCustomItemRegistered(String itemId) { + return itemConstructors.containsKey(itemId); + } + + public static CustomItem getCustomItem(String itemId) { + return customItems.get(itemId); + } + + public static String getItemId(ItemStack itemStack) { + CustomItemHandler handler = CustomItemHandler.getHandler(itemStack); + if (handler == null) { + return null; + } + return handler.getCustomItemId(); + } + + public static boolean isCustomItem(ItemStack itemStack) { + return getItemId(itemStack) != null; + } + + public static String getVanillaItemId(Material material) { + return material.name().toLowerCase(); + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomRelicItem.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomRelicItem.java new file mode 100644 index 0000000..81ecf29 --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/CustomRelicItem.java @@ -0,0 +1,107 @@ +package org.gsdistance.grimmsServer.Constructable.Item; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +/** + * Custom item implementation for relics that integrates with the new CustomItem system. + * This wraps the existing RelicHandler functionality while providing the CustomItem interface. + */ +public class CustomRelicItem extends CustomItem { + private final RelicHandler relicHandler; + + public CustomRelicItem(String itemId, ItemStack itemStack) { + super(itemId, itemStack); + this.relicHandler = RelicHandler.getRelicHandler(itemStack); + } + + @Override + protected void initializeItem() { + // Relic initialization is handled by RelicHandler.makeRelic() + // This method is called after the item is already set up as a relic + updateDisplayName(); + } + + private void updateDisplayName() { + ItemMeta meta = getItemMeta(); + if (meta != null) { + String relicType = relicHandler.getRelicType(); + int tier = relicHandler.getRelicTier(); + ChatColor tierColor = switch (tier) { + case 1 -> ChatColor.GREEN; + case 2 -> ChatColor.BLUE; + case 3 -> ChatColor.DARK_PURPLE; + default -> ChatColor.WHITE; + }; + + String displayName = tierColor + (relicType.isEmpty() ? "" : relicType.substring(0, 1).toUpperCase() + relicType.substring(1)) + + " Relic " + ChatColor.GRAY + "[" + tierColor + "Tier " + tier + ChatColor.GRAY + "]"; + meta.setDisplayName(displayName); + setItemMeta(meta); + } + } + + @Override + public String getDisplayName() { + ItemMeta meta = getItemMeta(); + if (meta != null && meta.hasDisplayName()) { + return meta.getDisplayName(); + } + return ChatColor.GOLD + "Relic"; + } + + @Override + public String getDescription() { + return "A powerful relic with enhanced abilities."; + } + + // Delegate methods to RelicHandler for backward compatibility + public RelicHandler getRelicHandler() { + return relicHandler; + } + + public int getRelicTier() { + return relicHandler.getRelicTier(); + } + + public int getRelicGrade() { + return relicHandler.getRelicGrade(); + } + + public int getRelicDurabilityResistance() { + return relicHandler.getRelicDurabilityResistance(); + } + + public String getRelicType() { + return relicHandler.getRelicType(); + } + + /** + * Register relic items in the CustomItemRegistry. + * Call this during plugin startup to enable relic integration. + */ + public static void registerRelicTypes() { + // Register each relic type as a custom item + String[] relicTypes = {"sword", "pickaxe", "axe", "shovel", "hoe", "armor"}; + + for (String type : relicTypes) { + String itemId = "relic_" + type; + CustomItemRegistry.registerCustomItem(itemId, itemStack -> { + // This constructor is used when loading existing relics from NBT + // The relic should already be initialized via RelicHandler + return new CustomRelicItem(itemId, itemStack); + }); + } + } + + /** + * Create a new relic item from a vanilla ItemStack. + * This is the preferred way to create new relics. + */ + public static ItemStack createRelic(ItemStack vanillaItem) { + RelicHandler.makeRelic(vanillaItem); + return vanillaItem; + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/ItemStats.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/ItemStats.java index ed8ca88..e667739 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/ItemStats.java +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/ItemStats.java @@ -27,6 +27,23 @@ public class ItemStats { public List getItemStats() { List toolStats = new ArrayList<>(); + if (CustomItemHandler.isCustomItem(this.item)) { + CustomItemHandler customItemHandler = CustomItemHandler.getHandler(this.item); + String customItemId = customItemHandler.getCustomItemId(); + toolStats.add(ChatColor.BOLD + "Item: " + ChatColor.RESET + ChatColor.WHITE + customItemId); + + // Check if this is a registered custom item with additional info + if (CustomItemRegistry.isCustomItemRegistered(customItemId)) { + CustomItem customItem = CustomItemRegistry.getCustomItem(customItemId); + if (customItem != null) { + String description = customItem.getDescription(); + if (description != null && !description.isEmpty()) { + toolStats.add(ChatColor.GRAY + description); + } + } + } + } + if (ItemLevelHandler.isItemLevelable(this.item)) { ItemLevelHandler levelHandler = ItemLevelHandler.getLevelHandler(this.item, null); toolStats.add(ChatColor.GOLD + "Level: " + ChatColor.YELLOW + Shared.formatNumber(levelHandler.getLevel())); diff --git a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/RelicHandler.java b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/RelicHandler.java index a746104..65a76d2 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/RelicHandler.java +++ b/src/main/java/org/gsdistance/grimmsServer/Constructable/Item/RelicHandler.java @@ -17,6 +17,7 @@ import java.util.UUID; public class RelicHandler { ItemStack item; ItemDataHandler dataHandler; + private static final Random RANDOM = new Random(); public RelicHandler(ItemStack item) { this.item = item; @@ -28,11 +29,26 @@ public class RelicHandler { return isRelic != null && isRelic; } + /** + * Migrates existing relics to the new CustomItem system. + * Call this during plugin startup to update legacy relics. + */ + public static void migrateRelicToCustomItem(ItemStack item) { + if (isRelic(item) && !CustomItemHandler.isCustomItem(item)) { + CustomItemHandler customHandler = CustomItemHandler.createHandler(item); + String relicType = getRelicHandler(item).getRelicType(); + customHandler.setCustomItemId("relic_" + relicType); + } + } + public static RelicHandler getRelicHandler(ItemStack item) { return new RelicHandler(item); } public static void makeRelic(ItemStack item) { + // Initialize as a custom item first + CustomItemHandler customHandler = CustomItemHandler.createHandler(item); + RelicHandler relicHandler = new RelicHandler(item); relicHandler.dataHandler.setItemNBTData("isRelic", true, PersistentDataType.BOOLEAN); relicHandler.dataHandler.setItemNBTData("relicUUID", UUID.randomUUID().toString(), PersistentDataType.STRING); @@ -54,13 +70,17 @@ public class RelicHandler { } relicHandler.dataHandler.setItemNBTData("relicType", relicType, PersistentDataType.STRING); + + // Set custom item ID to relic type for identification + customHandler.setCustomItemId("relic_" + relicType); + relicHandler.initRandomRelicStats(); } public void initRandomRelicStats() { - int tier = (new Random()).nextInt(1, 4); - int grade = (new Random()).nextInt(1, 101); - int durabilityResistance = (new Random()).nextInt(1, 81); + int tier = RANDOM.nextInt(1, 4); + int grade = RANDOM.nextInt(1, 101); + int durabilityResistance = RANDOM.nextInt(1, 81); this.setRelicStats(tier, grade, durabilityResistance); this.recalculateBaseAttributes(); ItemStats.getItemStats(this.item).UpdateItemStats(); @@ -97,11 +117,11 @@ public class RelicHandler { }; switch (this.getRelicType()) { case "sword": - this.dataHandler.setAttribute(Attribute.ATTACK_DAMAGE, new AttributeModifier(Shared.getNamespacedKey("reliic_attack_damage"), baseDamage + Math.pow(Math.max(2.0F, (double) grade / (double) 25.0F), tier), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND)); + this.dataHandler.setAttribute(Attribute.ATTACK_DAMAGE, new AttributeModifier(Shared.getNamespacedKey("relic_attack_damage"), baseDamage + Math.pow(Math.max(2.0F, (double) grade / (double) 25.0F), tier), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND)); if (tier == 1) { - this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("reliic_attack_speed"), -2.4, Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND)); + this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("relic_attack_speed"), -2.4, Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND)); } else { - this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("reliic_attack_speed"), -(2.4 - Math.max(Math.max((Math.sqrt(grade) * (double) tier / (double) 10.0F), 2), 1)), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND)); + this.dataHandler.setAttribute(Attribute.ATTACK_SPEED, new AttributeModifier(Shared.getNamespacedKey("relic_attack_speed"), -(2.4 - Math.max(Math.max((Math.sqrt(grade) * (double) tier / (double) 10.0F), 2), 1)), Operation.ADD_NUMBER, EquipmentSlotGroup.MAINHAND)); } break; case "armor": diff --git a/src/main/java/org/gsdistance/grimmsServer/Data/CustomEnchantments.java b/src/main/java/org/gsdistance/grimmsServer/Data/CustomEnchantments.java new file mode 100644 index 0000000..31e2882 --- /dev/null +++ b/src/main/java/org/gsdistance/grimmsServer/Data/CustomEnchantments.java @@ -0,0 +1,15 @@ +package org.gsdistance.grimmsServer.Data; + +public enum CustomEnchantments { + TRUE_DAMAGE("True Damage", 3), + SOULBOUND("Soulbound", 1); + + public final String enchantmentName; + public final int maxLevel; + + + CustomEnchantments(String enchantmentName, int maxLevel) { + this.enchantmentName = enchantmentName; + this.maxLevel = maxLevel; + } +} diff --git a/src/main/java/org/gsdistance/grimmsServer/Data/FactionRank.java b/src/main/java/org/gsdistance/grimmsServer/Data/FactionRank.java index 823a070..6f939b0 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Data/FactionRank.java +++ b/src/main/java/org/gsdistance/grimmsServer/Data/FactionRank.java @@ -19,16 +19,6 @@ public enum FactionRank { return this.displayName; } - public static FactionRank fromWeight(int weight) { - for (FactionRank rank : values()) { - if (rank.weight == weight) { - return rank; - } - } - - return NONE; - } - public static FactionRank fromString(String name) { for (FactionRank rank : values()) { if (rank.displayName.equalsIgnoreCase(name)) { @@ -38,9 +28,4 @@ public enum FactionRank { return NONE; } - - // $FF: synthetic method - private static FactionRank[] $values() { - return new FactionRank[]{LEADER, OFFICER, MEMBER, RECRUIT, NONE}; - } } diff --git a/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerCapability.java b/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerCapability.java index 7139bf6..426e17c 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerCapability.java +++ b/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerCapability.java @@ -15,9 +15,4 @@ public enum PlayerCapability { this.description = description; this.capabilityId = capabilityId; } - - // $FF: synthetic method - private static PlayerCapability[] $values() { - return new PlayerCapability[]{AUTOSELL, MAGNET, VEINMINER, SATURATION_PERK}; - } } diff --git a/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerInventoryData.java b/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerInventoryData.java index cda5a2f..59a5545 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerInventoryData.java +++ b/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerInventoryData.java @@ -20,6 +20,11 @@ public class PlayerInventoryData { public String[] armorContents; // Store as Base64 strings public String[] extraContents; // Store as Base64 strings public List previousInventories; + + // Soulbound items - these items are kept on death and restored on respawn + public Map soulboundInventoryContents; // Store as Base64 strings + public String[] soulboundArmorContents; // Store as Base64 strings + public String[] soulboundExtraContents; // Store as Base64 strings public PlayerInventoryData(UUID uuid) { this.uuid = uuid; @@ -28,6 +33,11 @@ public class PlayerInventoryData { this.armorContents = new String[4]; this.extraContents = new String[36]; this.previousInventories = new ArrayList<>(); + + // Initialize soulbound storage + this.soulboundInventoryContents = new HashMap<>(); + this.soulboundArmorContents = new String[4]; + this.soulboundExtraContents = new String[36]; } public void addPreviousInventory(InventorySnapshot snapshot) { @@ -139,6 +149,97 @@ public class PlayerInventoryData { return result; } + // Soulbound item management methods + + // Mark an item as soulbound by slot (removes from saved inventory, adds to soulbound storage) + public void markSoulboundItem(int slot, String itemType) { + if (itemType == null) return; + + if (itemType.equals("inventory")) { + String item = this.inventoryContents.remove(slot); + if (item != null) { + this.soulboundInventoryContents.put(slot, item); + } + } else if (itemType.equals("armor")) { + if (slot >= 0 && slot < 4) { + String item = this.armorContents[slot]; + if (item != null) { + this.soulboundArmorContents[slot] = item; + this.armorContents[slot] = null; + } + } + } else if (itemType.equals("extra")) { + if (slot >= 0 && slot < this.extraContents.length) { + String item = this.extraContents[slot]; + if (item != null) { + this.soulboundExtraContents[slot] = item; + this.extraContents[slot] = null; + } + } + } + } + + // Mark an ItemStack as soulbound (converts to Base64 and marks) + public void markSoulboundItemStack(int slot, ItemStack itemStack, String itemType) { + if (itemStack == null) return; + + try { + String base64 = itemStackToBase64(itemStack); + markSoulboundItem(slot, itemType); + } catch (IOException e) { + GrimmsServer.logger.warning("Failed to serialize soulbound ItemStack at slot " + slot); + } + } + + // Get soulbound inventory as ItemStacks + public Map getSoulboundInventoryAsItemStacks() { + Map result = new HashMap<>(); + for (Map.Entry entry : this.soulboundInventoryContents.entrySet()) { + try { + ItemStack itemStack = itemStackFromBase64(entry.getValue()); + if (itemStack != null) { + result.put(entry.getKey(), itemStack); + } + } catch (IOException | ClassNotFoundException e) { + GrimmsServer.logger.warning("Failed to deserialize soulbound ItemStack at slot " + entry.getKey()); + } + } + return result; + } + + // Get soulbound armor as ItemStack array + public ItemStack[] getSoulboundArmorAsItemStacks() { + ItemStack[] result = new ItemStack[4]; + for (int i = 0; i < this.soulboundArmorContents.length && i < 4; i++) { + try { + result[i] = itemStackFromBase64(this.soulboundArmorContents[i]); + } catch (IOException | ClassNotFoundException e) { + GrimmsServer.logger.warning("Failed to deserialize soulbound armor slot " + i); + } + } + return result; + } + + // Get soulbound extra contents as ItemStack array + public ItemStack[] getSoulboundExtraAsItemStacks() { + ItemStack[] result = new ItemStack[this.soulboundExtraContents.length]; + for (int i = 0; i < this.soulboundExtraContents.length; i++) { + try { + result[i] = itemStackFromBase64(this.soulboundExtraContents[i]); + } catch (IOException | ClassNotFoundException e) { + GrimmsServer.logger.warning("Failed to deserialize soulbound extra slot " + i); + } + } + return result; + } + + // Clear all soulbound items (called after restoring on respawn) + public void clearSoulboundItems() { + this.soulboundInventoryContents.clear(); + this.soulboundArmorContents = new String[4]; + this.soulboundExtraContents = new String[36]; + } + public static class InventorySnapshot { public final String timestamp; public Map inventoryContents; // Store as Base64 strings diff --git a/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerRank.java b/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerRank.java index 6b7d51a..30dcd49 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerRank.java +++ b/src/main/java/org/gsdistance/grimmsServer/Data/Player/PlayerRank.java @@ -40,8 +40,4 @@ public enum PlayerRank { return DEFAULT; } - // $FF: synthetic method - private static PlayerRank[] $values() { - return new PlayerRank[]{DEFAULT, VIP, MVP, MODERATOR, ADMIN, OWNER}; - } } diff --git a/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityDeathEvent.java b/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityDeathEvent.java index af5fc23..792122e 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityDeathEvent.java +++ b/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/EntityDeathEvent.java @@ -7,7 +7,9 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.gsdistance.grimmsServer.Config.ActiveConfig; import org.gsdistance.grimmsServer.Config.ConfigKey; +import org.gsdistance.grimmsServer.Constructable.Item.CustomEnchantmentHandler; import org.gsdistance.grimmsServer.Constructable.Player.PlayerLevelHandler; +import org.gsdistance.grimmsServer.Data.CustomEnchantments; import org.gsdistance.grimmsServer.Data.Player.PlayerInventoryData; import org.gsdistance.grimmsServer.Data.Player.PlayerTitleChecker; import org.gsdistance.grimmsServer.GrimmsServer; @@ -55,7 +57,8 @@ public class EntityDeathEvent { // Save inventory if keepInventory is off Player player = (Player) event.getEntity(); - if (!player.getWorld().getGameRuleValue(GameRule.KEEP_INVENTORY)) { + Boolean keepInventory = player.getWorld().getGameRuleValue(GameRule.KEEP_INVENTORY); + if (keepInventory == null || !keepInventory) { PlayerInventoryData inventoryData = PlayerInventoryData.getPlayerInventoryData(player.getUniqueId()); // Convert current inventory to Base64 for saving @@ -85,7 +88,9 @@ public class EntityDeathEvent { ItemStack[] armor = player.getInventory().getArmorContents(); for (int i = 0; i < armor.length && i < 4; i++) { try { - armorBase64[i] = PlayerInventoryData.itemStackToBase64(armor[i]); + if (armor[i] != null) { + armorBase64[i] = PlayerInventoryData.itemStackToBase64(armor[i]); + } } catch (IOException e) { GrimmsServer.logger.warning("Failed to serialize armor slot " + i); } @@ -95,7 +100,9 @@ public class EntityDeathEvent { ItemStack[] extra = player.getInventory().getExtraContents(); for (int i = 0; i < extraBase64.length; i++) { try { - extraBase64[i] = PlayerInventoryData.itemStackToBase64(extra[i]); + if (extra[i] != null) { + extraBase64[i] = PlayerInventoryData.itemStackToBase64(extra[i]); + } } catch (IOException e) { GrimmsServer.logger.warning("Failed to serialize extra slot " + i); } @@ -114,8 +121,46 @@ public class EntityDeathEvent { inventoryData.setExtraFromItemStacks(player.getInventory().getExtraContents()); inventoryData.saveToPDS(); + // Mark soulbound items (items that should not drop on death) + // Check each item for soulbound enchantment + for (Map.Entry entry : currentInventory.entrySet()) { + ItemStack item = entry.getValue(); + if (item != null) { + CustomEnchantmentHandler enchantHandler = CustomEnchantmentHandler.getHandler(item); + if (enchantHandler.hasEnchantment(CustomEnchantments.SOULBOUND)) { + inventoryData.markSoulboundItemStack(entry.getKey(), item, "inventory"); + } + } + } + + // Check armor for soulbound items + for (int i = 0; i < armor.length && i < 4; i++) { + ItemStack item = armor[i]; + if (item != null) { + CustomEnchantmentHandler enchantHandler = CustomEnchantmentHandler.getHandler(item); + if (enchantHandler.hasEnchantment(CustomEnchantments.SOULBOUND)) { + inventoryData.markSoulboundItemStack(i, item, "armor"); + } + } + } + + // Check extra contents for soulbound items + for (int i = 0; i < extra.length && i < 36; i++) { + ItemStack item = extra[i]; + if (item != null) { + CustomEnchantmentHandler enchantHandler = CustomEnchantmentHandler.getHandler(item); + if (enchantHandler.hasEnchantment(CustomEnchantments.SOULBOUND)) { + inventoryData.markSoulboundItemStack(i, item, "extra"); + } + } + } + + // Save again after marking soulbound items to update the saved data + inventoryData.saveToPDS(); + // Clear inventory if config allows - boolean clearInventory = ActiveConfig.getConfigValue(ConfigKey.CLEAR_INVENTORY_ON_DEATH, Boolean.class); + Boolean clearInventoryConfig = ActiveConfig.getConfigValue(ConfigKey.CLEAR_INVENTORY_ON_DEATH, Boolean.class); + boolean clearInventory = clearInventoryConfig != null && clearInventoryConfig; if (clearInventory) { player.getInventory().clear(); } diff --git a/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/PlayerRespawnEvent.java b/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/PlayerRespawnEvent.java index e1b8022..a4f5bee 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/PlayerRespawnEvent.java +++ b/src/main/java/org/gsdistance/grimmsServer/Events/Listeners/PlayerRespawnEvent.java @@ -2,9 +2,15 @@ package org.gsdistance.grimmsServer.Events.Listeners; import org.bukkit.Location; import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.gsdistance.grimmsServer.Data.PerSessionDataStorage; +import org.gsdistance.grimmsServer.Data.Player.PlayerInventoryData; +import org.gsdistance.grimmsServer.GrimmsServer; import org.gsdistance.grimmsServer.Indexers.DynamicDimensionGen; +import java.util.Map; + public class PlayerRespawnEvent { public PlayerRespawnEvent() { } @@ -22,7 +28,43 @@ public class PlayerRespawnEvent { } } } + } + // Restore soulbound items on respawn + Player player = event.getPlayer(); + PlayerInventoryData inventoryData = PlayerInventoryData.getPlayerInventoryData(player.getUniqueId()); + + // Check if there are soulbound items to restore + if (!inventoryData.soulboundInventoryContents.isEmpty() || + hasNonNullItems(inventoryData.soulboundArmorContents) || + hasNonNullItems(inventoryData.soulboundExtraContents)) { + + // Restore soulbound inventory items + Map soulboundInventory = inventoryData.getSoulboundInventoryAsItemStacks(); + for (Map.Entry entry : soulboundInventory.entrySet()) { + player.getInventory().setItem(entry.getKey(), entry.getValue()); + } + + // Restore soulbound armor + ItemStack[] soulboundArmor = inventoryData.getSoulboundArmorAsItemStacks(); + player.getInventory().setArmorContents(soulboundArmor); + + // Restore soulbound extra contents + ItemStack[] soulboundExtra = inventoryData.getSoulboundExtraAsItemStacks(); + player.getInventory().setExtraContents(soulboundExtra); + + // Clear soulbound items after restoration + inventoryData.clearSoulboundItems(); + inventoryData.saveToPDS(); } } + + // Helper method to check if array has non-null items + private static boolean hasNonNullItems(String[] array) { + if (array == null) return false; + for (String item : array) { + if (item != null) return true; + } + return false; + } } diff --git a/src/main/java/org/gsdistance/grimmsServer/Stats/TitleGenerator.java b/src/main/java/org/gsdistance/grimmsServer/Stats/TitleGenerator.java index 740cf2f..1f7450a 100644 --- a/src/main/java/org/gsdistance/grimmsServer/Stats/TitleGenerator.java +++ b/src/main/java/org/gsdistance/grimmsServer/Stats/TitleGenerator.java @@ -53,8 +53,8 @@ public class TitleGenerator { killTitles.put(10L, "Novice Hunter"); killTitles.put(100L, "Hunter"); killTitles.put(1000L, "Slayer"); - killTitles.put(10000L, "Executioneer"); - killTitles.put(100000L, "Destroyer"); + killTitles.put(10000L, "Hitman"); + killTitles.put(100000L, "Mob Eater"); killTitles.put(1000000L, "Godslayer"); killTitles.put(10000000L, "World Ender"); killTitles.put(100000000L, "Mass Murderer");