Java Code Examples for org.bukkit.event.player.PlayerItemBreakEvent#getBrokenItem()
The following examples show how to use
org.bukkit.event.player.PlayerItemBreakEvent#getBrokenItem() .
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: ArmorListener.java From AdditionsAPI with MIT License | 6 votes |
@EventHandler public void itemBreakEvent(PlayerItemBreakEvent e){ ArmorType type = ArmorType.matchType(e.getBrokenItem()); if(type != null){ Player p = e.getPlayer(); ArmorEquipEvent armorEquipEvent = new ArmorEquipEvent(p, EquipMethod.BROKE, type, e.getBrokenItem(), null); Bukkit.getServer().getPluginManager().callEvent(armorEquipEvent); if(armorEquipEvent.isCancelled()){ ItemStack i = e.getBrokenItem().clone(); i.setAmount(1); i.setDurability((short) (i.getDurability() - 1)); if(type.equals(ArmorType.HELMET)){ p.getInventory().setHelmet(i); }else if(type.equals(ArmorType.CHESTPLATE)){ p.getInventory().setChestplate(i); }else if(type.equals(ArmorType.LEGGINGS)){ p.getInventory().setLeggings(i); }else if(type.equals(ArmorType.BOOTS)){ p.getInventory().setBoots(i); } } } }
Example 2
Source File: DurabilityBar.java From AdditionsAPI with MIT License | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onItemBreak(PlayerItemBreakEvent event) { ItemStack broken = event.getBrokenItem(); Player player = event.getPlayer(); PlayerInventory inv = player.getInventory(); if (broken.equals(inv.getItemInMainHand())) hideDurabilityBossBar(player, EquipmentSlot.HAND); else if (broken.equals(inv.getItemInOffHand())) hideDurabilityBossBar(player, EquipmentSlot.OFF_HAND); }
Example 3
Source File: QuestItemHandler.java From BetonQuest with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @EventHandler(ignoreCancelled = true) public void onItemBreak(final PlayerItemBreakEvent event) { if (BetonQuest.getInstance().getConfig().getString("quest_items_unbreakable").equalsIgnoreCase("false")) { return; } // prevent quest items from breaking if (Utils.isQuestItem(event.getBrokenItem())) { final ItemStack original = event.getBrokenItem(); original.setDurability((short) 0); final ItemStack copy = original.clone(); event.getPlayer().getInventory().removeItem(original); event.getPlayer().getInventory().addItem(copy); } }
Example 4
Source File: ItemListener.java From MineTinker with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true) public void onItemBreak(PlayerItemBreakEvent event) { Player player = event.getPlayer(); ItemStack item = event.getBrokenItem(); if (!MineTinker.getPlugin().getConfig().getBoolean("UnbreakableTools", true)) { return; } if (Lists.WORLDS.contains(player.getWorld().getName())) { return; } if (!modManager.isToolViable(item) && !modManager.isArmorViable(item)) { return; } if (!MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.StopBreakEvent", true)) { return; } if (MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.AlertPlayerOnBreak", true)) { player.sendMessage(LanguageManager.getString("Alert.OnItemBreak", player)); } ItemMeta meta = item.getItemMeta(); if (meta instanceof Damageable) { ((Damageable) meta).setDamage(item.getType().getMaxDurability() - 1); } if (meta instanceof CrossbowMeta) { //TODO: Crossbow will still shoot arrow ((CrossbowMeta) meta).setChargedProjectiles(new ArrayList<>()); } item.setItemMeta(meta); if (player.getInventory().addItem(item).size() != 0) { //adds items to (full) inventory if (!MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.DisableDroppingBehaviour")) { PlayerDropItemEvent dropItemEvent = new PlayerDropItemEvent(player, player.getWorld().dropItem(player.getLocation(), item)); Bukkit.getPluginManager().callEvent(dropItemEvent); //To trigger item behaviour } else { player.getWorld().dropItem(player.getLocation(), item); } } // no else as it gets added in if-clause }
Example 5
Source File: ToolsBrokenListener.java From Statz with GNU General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onToolBreak(final PlayerItemBreakEvent event) { final PlayerStat stat = PlayerStat.TOOLS_BROKEN; // Get player final Player player = event.getPlayer(); // Do general check if (!plugin.doGeneralCheck(player, stat)) return; ItemStack item = event.getBrokenItem(); PlayerStatSpecification specification = new ToolsBrokenSpecification(player.getUniqueId(), 1, player.getWorld().getName(), item.getType()); // Update value to new stat. plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery()); }