mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2025-01-08 07:27:39 +01:00
MMOCore now supports MI item durability
This commit is contained in:
parent
3960a26104
commit
d94d193f24
@ -17,7 +17,10 @@ import net.Indyuce.mmoitems.comp.mmocore.stat.Required_Attribute;
|
||||
import net.Indyuce.mmoitems.comp.rpg.RPGHandler;
|
||||
|
||||
public class MMOCoreHook implements RPGHandler, Listener {
|
||||
/* called when MMOItems enables */
|
||||
|
||||
/**
|
||||
* Called when MMOItems enables
|
||||
*/
|
||||
public MMOCoreHook() {
|
||||
/*
|
||||
* only works when the server is reloaded. needs /reload when changing
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.Indyuce.mmoitems.listener;
|
||||
|
||||
import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -13,20 +15,19 @@ import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.event.player.PlayerItemMendEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import net.Indyuce.mmoitems.api.interaction.util.DurabilityItem;
|
||||
|
||||
public class DurabilityListener implements Listener {
|
||||
private final List<DamageCause> ignoredCauses = Arrays.asList(DamageCause.DROWNING, DamageCause.SUICIDE,
|
||||
DamageCause.FALL, DamageCause.VOID, DamageCause.FIRE_TICK, DamageCause.SUFFOCATION,
|
||||
DamageCause.POISON, DamageCause.WITHER, DamageCause.STARVATION, DamageCause.MAGIC);
|
||||
private final List<DamageCause> ignoredCauses = Arrays.asList(DamageCause.DROWNING, DamageCause.SUICIDE, DamageCause.FALL, DamageCause.VOID,
|
||||
DamageCause.FIRE_TICK, DamageCause.SUFFOCATION, DamageCause.POISON, DamageCause.WITHER, DamageCause.STARVATION, DamageCause.MAGIC);
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void playerDamage(EntityDamageEvent event) {
|
||||
if(event.getEntityType() != EntityType.PLAYER || ignoredCauses.contains(event.getCause())) return;
|
||||
if (event.getEntityType() != EntityType.PLAYER || ignoredCauses.contains(event.getCause()))
|
||||
return;
|
||||
Player player = (Player) event.getEntity();
|
||||
if(player.getEquipment().getHelmet() == null ||
|
||||
player.getEquipment().getHelmet().getType() != Material.PLAYER_HEAD) return;
|
||||
if (player.getEquipment().getHelmet() == null || player.getEquipment().getHelmet().getType() != Material.PLAYER_HEAD)
|
||||
return;
|
||||
ItemStack helmet = player.getEquipment().getHelmet();
|
||||
DurabilityItem item = new DurabilityItem(player, helmet);
|
||||
|
||||
@ -34,7 +35,8 @@ public class DurabilityListener implements Listener {
|
||||
/*
|
||||
* Calculate item durability loss
|
||||
*
|
||||
* This uses the vanilla formula of 1 durability per 4 damage. (rounded down, but never below 1)
|
||||
* This uses the vanilla formula of 1 durability per 4 damage.
|
||||
* (rounded down, but never below 1)
|
||||
*/
|
||||
item.decreaseDurability(Math.max((int) event.getDamage() / 4, 1));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user