org.bukkit.inventory.meta.Repairable Java Examples
The following examples show how to use
org.bukkit.inventory.meta.Repairable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoDisenchanter.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void transferEnchantments(ItemStack item, ItemStack book, Map<Enchantment, Integer> enchantments) { ItemMeta itemMeta = item.getItemMeta(); ItemMeta bookMeta = book.getItemMeta(); ((Repairable) bookMeta).setRepairCost(((Repairable) itemMeta).getRepairCost()); ((Repairable) itemMeta).setRepairCost(0); item.setItemMeta(itemMeta); book.setItemMeta(bookMeta); EnchantmentStorageMeta meta = (EnchantmentStorageMeta) book.getItemMeta(); for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) { item.removeEnchantment(entry.getKey()); meta.addStoredEnchant(entry.getKey(), entry.getValue(), true); } book.setItemMeta(meta); }
Example #2
Source File: RepairCommands.java From NyaaUtils with MIT License | 5 votes |
@SubCommand(value = "info", permission = "nu.repair") public void repairInfo(CommandSender sender, Arguments args) { ItemStack item = getItemInHand(sender); ItemMeta itemMeta = item.getItemMeta(); RepairInstance info = new RepairInstance(item, plugin.cfg.repair, plugin); new Message(I18n.format("user.repair.info_1")).append(item).send(asPlayer(sender)); msg(sender, "user.repair.info_2", item.getType().name()); if (info.stat != REPAIRABLE) { msg(sender, "user.repair.info_3", I18n.format("user.repair.unrepairable." + info.stat.name())); } if (info.stat == UNREPAIRABLE) return; int fullDur = item.getType().getMaxDurability(); int currDur = fullDur - ((Damageable) itemMeta).getDamage(); msg(sender, "user.repair.info_4", currDur, fullDur, (double) currDur / (double) fullDur * 100); new Message(I18n.format("user.repair.info_5")).append(new ItemStack(info.repairMaterial)).send(asPlayer(sender)); msg(sender, "user.repair.info_6", info.expConsumption); msg(sender, "user.repair.info_7", info.durRecovered, (double) info.durRecovered / (double) fullDur * 100); if (info.repairLimit <= 0) { msg(sender, "user.repair.info_8"); } else { int repairTime = ((Repairable) itemMeta).getRepairCost(); msg(sender, "user.repair.info_9", repairTime, info.repairLimit); } if (info.stat == REPAIRABLE) { msg(sender, "user.repair.info_10", (int) Math.ceil(((Damageable) itemMeta).getDamage() / (double) info.durRecovered)); } }
Example #3
Source File: RepairCommands.java From NyaaUtils with MIT License | 5 votes |
private void increaseReapirCount(ItemStack item, int x) { if (x == 0) return; ItemMeta meta = item.getItemMeta(); if (meta instanceof Repairable) { Repairable r = (Repairable) meta; int count = r.getRepairCost() + x; if (count < 0) count = 0; r.setRepairCost(count); item.setItemMeta(meta); } }
Example #4
Source File: RepairInstance.java From NyaaUtils with MIT License | 4 votes |
public RepairInstance(ItemStack item, RepairConfig config, NyaaUtils plugin) { if (item == null || item.getType() == Material.AIR) return; RepairConfig.RepairConfigItem cfg = config.getRepairConfig(item.getType()); if (cfg == null) return; if (!(item.getItemMeta() instanceof Repairable)) return; if (item.hasItemMeta() && item.getItemMeta().hasLore()) { if (!plugin.cfg.globalLoreBlacklist.canRepair(item.getItemMeta().getLore())) { stat = RepairStat.UNREPAIRABLE; return; } } stat = RepairStat.REPAIRABLE; if (item.getItemMeta().isUnbreakable()) { stat = RepairStat.UNREPAIRABLE_UNBREAKABLE; } Repairable repairableMeta = (Repairable) item.getItemMeta(); Damageable damageableMeta = (Damageable) item.getItemMeta(); repairLimit = cfg.repairLimit; if (repairLimit > 0 && repairableMeta.getRepairCost() >= repairLimit) { stat = RepairStat.UNREPAIRABLE_RLE; } Material toolMaterial = item.getType(); repairMaterial = cfg.material; int currentDurability = damageableMeta.getDamage(); if (currentDurability <= 0) { stat = RepairStat.UNREPAIRABLE_REPAIRED; } int enchLevel = 0; for (Enchantment ench : Enchantment.values()) { enchLevel += Math.max(item.getEnchantmentLevel(ench), 0); } int fullDurability = toolMaterial.getMaxDurability(); durRecovered = (int) Math.floor((double) fullDurability / ((double) cfg.fullRepairCost + (double) enchLevel * cfg.enchantCostPerLv)); expConsumption = (int) Math.floor(cfg.expCost + cfg.enchantCostPerLv * enchLevel); if (durRecovered <= 0) { stat = RepairStat.UNREPAIRABLE_LOWRECOVER; } }