org.bukkit.event.player.PlayerItemDamageEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerItemDamageEvent. 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 MineTinker with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onElytraDamage(PlayerItemDamageEvent event) {
	if (!event.getPlayer().isGliding()) {
		return;
	}

	if (event.getItem().getType() != Material.ELYTRA) {
		return;
	}

	if (!modManager.isArmorViable(event.getItem())) {
		return;
	}

	Random rand = new Random();
	int chance = rand.nextInt(100);

	if (chance < ConfigurationManager.getConfig("Elytra.yml").getInt("ExpChanceWhileFlying")) {
		modManager.addExp(event.getPlayer(), event.getItem(), MineTinker.getPlugin().getConfig().getInt("ExpPerEntityHit"));
	}
}
 
Example #2
Source File: NoVanillaDurability.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
	@Override
	public void onDurabilityChange(PlayerItemDamageEvent event) {
		event.setDamage(0);
		event.getPlayer().updateInventory();
		
		
		
//		LinkedList<ItemDurabilityEntry> entries = CustomItemManager.itemDuraMap.get(player.getName());
//		
//		if (entries == null) {
//			entries = new LinkedList<ItemDurabilityEntry>();
//		}
//		
//		ItemDurabilityEntry entry = new ItemDurabilityEntry();
//		entry.stack = stack;
//		entry.oldValue = stack.getDurability();
//		
//		entries.add(entry);
//		CustomItemManager.itemDuraMap.put(player.getName(), entries);
//		
//		if (!CustomItemManager.duraTaskScheduled) {
//			TaskMaster.syncTask(new ItemDuraSyncTask());
//		}
	}
 
Example #3
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 #4
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 #5
Source File: DurabilityBar.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemDamage(PlayerItemDamageEvent event) {
	if (event.isCancelled())
		return;
	Player player = event.getPlayer();
	Bukkit.getScheduler().scheduleSyncDelayedTask(AdditionsAPI.getInstance(), () -> {
		sendDurabilityBossBar(player, player.getInventory().getItemInMainHand(), EquipmentSlot.HAND);
		sendDurabilityBossBar(player, player.getInventory().getItemInOffHand(), EquipmentSlot.OFF_HAND);
	});
}
 
Example #6
Source File: CustomItemStack.java    From AdditionsAPI with MIT License 5 votes vote down vote up
/**
 * Reduces the durability of the CustomItemStack, whether it's using Fake
 * Durability or not. It uses the {@link PlayerCustomItemDamageEvent}, so it
 * could be cancelled.
 * 
 * @param durabilityToReduce
 *            The amount of durability that will be reduced
 */
public CustomItemStack reduceDurability(Player player, int durabilityToReduce) {
	GameMode gm = player.getGameMode();
	if (itemStack == null)
		return this;
	if ((gm.equals(GameMode.SURVIVAL) || gm.equals(GameMode.ADVENTURE)))
		if (cItem.hasFakeDurability())
			Bukkit.getPluginManager()
					.callEvent(new PlayerCustomItemDamageEvent(player, getItemStack(), durabilityToReduce, cItem));
		else if (!cItem.isUnbreakable())
			Bukkit.getPluginManager().callEvent(new PlayerItemDamageEvent(player, itemStack, durabilityToReduce));
	return this;
}
 
Example #7
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemDamageEvent(PlayerItemDamageEvent event)
{
	Player player = event.getPlayer();
	
	ApplicableRegionSet regions = this.plugin.getWorldGuardCommunicator().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
	if (WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.ITEM_DURABILITY) == State.DENY)
	{
		event.setCancelled(true);
	}
}
 
Example #8
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 #9
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));
}
 
Example #10
Source File: PlayerCustomArmorDamageEvent.java    From AdditionsAPI with MIT License 4 votes vote down vote up
public PlayerCustomArmorDamageEvent(PlayerItemDamageEvent event, CustomArmor cArmor, DamageCause damageCause, short durability) {
	super(event, cArmor);
	event.setDamage(durability);
	setDamageCause(damageCause);
}
 
Example #11
Source File: PlayerCustomItemDamage.java    From AdditionsAPI with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void customItemCheck(PlayerItemDamageEvent event) {
	if (AdditionsAPI.isCustomItem(event.getItem()) && !(event instanceof PlayerCustomItemDamageEvent))
		event.setCancelled(true);
}
 
Example #12
Source File: LoreCraftableMaterial.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public void onItemDurabilityChange(PlayerItemDamageEvent event) {
	for (ItemComponent comp : this.components.values()) {
		comp.onDurabilityChange(event);
	}
}
 
Example #13
Source File: ItemComponent.java    From civcraft with GNU General Public License v2.0 votes vote down vote up
public void onDurabilityChange(PlayerItemDamageEvent event) {}