org.bukkit.event.player.PlayerItemBreakEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerItemBreakEvent. 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: KitMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onArmorBreak(final PlayerItemBreakEvent event) {
  MatchPlayer player = this.match.getPlayer(event.getPlayer());
  if (player == null) {
    return;
  }

  ItemStack[] armor = event.getPlayer().getInventory().getArmorContents();
  for (ArmorType armorType : ArmorType.values()) {
    int slot = armorType.ordinal();
    // Bukkit specifies the amount will be zero
    if (armor[slot] != null
        && armor[slot].getAmount() == 0
        && armor[slot].isSimilar(event.getBrokenItem())) {
      this.lockedArmorSlots.remove(player, armorType);
      break;
    }
  }
}
 
Example #2
Source File: ArmorListener.java    From AdditionsAPI with MIT License 6 votes vote down vote up
@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 #3
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@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 #4
Source File: QuestItemHandler.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@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 #5
Source File: TalismanListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onItemBreak(PlayerItemBreakEvent e) {
    if (Talisman.checkFor(e, SlimefunItems.TALISMAN_ANVIL)) {
        PlayerInventory inv = e.getPlayer().getInventory();
        int slot = inv.getHeldItemSlot();

        // Did the tool in our hand broke or was it an Armorpiece?
        if (!inv.getItem(inv.getHeldItemSlot()).equals(e.getBrokenItem())) {
            for (int s : armorSlots) {
                if (e.getBrokenItem().equals(inv.getItem(s))) {
                    slot = s;
                    break;
                }
            }
        }

        ItemStack item = e.getBrokenItem().clone();
        ItemMeta meta = item.getItemMeta();

        if (meta instanceof Damageable) {
            ((Damageable) meta).setDamage(0);
        }

        item.setItemMeta(meta);

        int itemSlot = slot;

        // Update the item forcefully
        Slimefun.runSync(() -> inv.setItem(itemSlot, item), 1L);
    }
}
 
Example #6
Source File: CEListener.java    From ce with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void PlayerItemBreakEvent(PlayerItemBreakEvent e) {

    for (ItemStack i : e.getPlayer().getInventory().getArmorContents())
        if (i != null && i.getType() != Material.AIR)
            if (i.getAmount() == 0)
                CEventHandler.handleArmor(e.getPlayer(), e.getBrokenItem(), true, e);

}
 
Example #7
Source File: ItemListener.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@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 #8
Source File: ArmorListener.java    From ViaVersion with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onItemBreak(PlayerItemBreakEvent e) {
    sendDelayedArmorUpdate(e.getPlayer());
}
 
Example #9
Source File: ToolsBrokenListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@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());

}
 
Example #10
Source File: ObserverModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerItemBreak(PlayerItemBreakEvent event) {
    refreshView(event.getPlayer().getUniqueId());
}