Untitled
unknown
plain_text
2 years ago
2.5 kB
5
Indexable
public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); this.getCommand("durabilitytest").setExecutor(new DurabilityTestCommand()); } private class DurabilityTestCommand implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "This command can only be run by a player."); return true; } Player player = (Player) sender; ItemStack item = player.getInventory().getItemInMainHand(); if (item == null || item.getType().isAir()) { player.sendMessage(ChatColor.RED + "Please hold an item in your main hand."); return true; } // Set a custom max durability value for testing purposes int testMaxDurability = 500; DurabilityAPI.setItemMaxDurability(item, testMaxDurability); return true; } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); ItemStack item = player.getInventory().getItemInMainHand(); // Check if the player is holding an item if (item == null || !item.hasItemMeta()) { return; } ItemMeta meta = item.getItemMeta(); // Message the player the type of item they are holding Material itemType = item.getType(); player.sendMessage(ChatColor.YELLOW + "You are holding: " + itemType.toString()); // Send the current durability of the item using ItemsAdder API int currentDurability = ItemsAdder.getCustomItemDurability(item); int maxDurability = ItemsAdder.getCustomItemMaxDurability(item); if (maxDurability > 0) { // Assuming a value of 0 means it's not damageable player.sendMessage(ChatColor.BLUE + "Current durability: " + currentDurability + "/" + maxDurability); } else { player.sendMessage(ChatColor.GRAY + "This item doesn't have durability."); } // Check if the item has custom model data if (meta.hasCustomModelData()) { int customModelData = meta.getCustomModelData(); player.sendMessage(ChatColor.GREEN + "This item has Custom Model Data: " + customModelData); } else { player.sendMessage(ChatColor.RED + "This item does not have Custom Model Data."); } }
Editor is loading...