Java Code Examples for org.bukkit.event.player.PlayerItemDamageEvent#getItem()

The following examples show how to use org.bukkit.event.player.PlayerItemDamageEvent#getItem() . 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: ItemListener.java    From MineTinker with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onItemUse(PlayerItemDamageEvent event) {
	ItemStack item = event.getItem();

	if (modManager.isToolViable(item) && modManager.isArmorViable(item) && modManager.isWandViable(item)) {
		return;
	}

	if (!MineTinker.getPlugin().getConfig().getBoolean("ItemBehaviour.ConvertItemsOnUse", true)) {
		return;
	}

	modManager.convertItemStack(event.getItem(), event.getPlayer());
}
 
Example 2
Source File: PlayerCustomItemDamageEvent.java    From AdditionsAPI with MIT License 5 votes vote down vote up
public PlayerCustomItemDamageEvent(PlayerItemDamageEvent event, CustomItem cItem) {
	super(event.getPlayer(), event.getItem(), event.getDamage());
	if (cItem.isUnbreakable()) {
		this.setDamage(0);
	}
	this.setCancelled(event.isCancelled());
	this.cItem = cItem;
}
 
Example 3
Source File: CustomItemManager.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOW)
public void onItemDurabilityChange(PlayerItemDamageEvent event) {
	ItemStack stack = event.getItem();
	
	LoreCraftableMaterial craftMat = LoreCraftableMaterial.getCraftMaterial(stack);
	if (craftMat == null) {
		return;
	}
	craftMat.onItemDurabilityChange(event);
}
 
Example 4
Source File: SelfRepair.java    From MineTinker with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void effect(PlayerItemDamageEvent event) {
	if (useMending) {
		return;
	}

	ItemStack tool = event.getItem();
	if (!modManager.isToolViable(tool) && !modManager.isArmorViable(tool)) {
		return;
	}

	if (!event.getPlayer().hasPermission("minetinker.modifiers.selfrepair.use")) {
		return;
	}

	if (!modManager.hasMod(tool, this)) {
		return;
	}

	int level = modManager.getModLevel(tool, this);
	Random rand = new Random();
	int n = rand.nextInt(100);
	int c = this.percentagePerLevel * level;

	if (n <= c) {
		if (tool.getItemMeta() instanceof Damageable) {
			Damageable damageable = (Damageable) tool.getItemMeta();
			int dura = damageable.getDamage();
			int newDura = dura - this.healthRepair;

			if (newDura < 0) {
				newDura = 0;
			}

			damageable.setDamage(newDura);

			tool.setItemMeta((ItemMeta) damageable);
			ChatWriter.logModifier(event.getPlayer(), event, this, tool, String.format("Chance(%d/%d)", n, c),
					String.format("Repair(%d -> %d)", dura, newDura));
			return;
		}
	}
	ChatWriter.logModifier(event.getPlayer(), event, this, tool, String.format("Chance(%d/%d)", n, c));
}