mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2025-01-08 07:27:41 +01:00
Fixed custom fishing not taking into account Unbreaking enchant
This commit is contained in:
parent
caf6b38363
commit
d9fa24a730
@ -8,6 +8,7 @@ import io.lumine.mythic.lib.version.VersionMaterial;
|
|||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -264,6 +265,8 @@ public class MMOCoreUtils {
|
|||||||
target.setHealth(target.getHealth() + gain);
|
target.setHealth(target.getHealth() + gain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final Random RANDOM = new Random();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method used when mining a custom block or fishing, as the corresponding
|
* Method used when mining a custom block or fishing, as the corresponding
|
||||||
* interaction event is cancelled durability is not handled. This method is
|
* interaction event is cancelled durability is not handled. This method is
|
||||||
@ -283,12 +286,16 @@ public class MMOCoreUtils {
|
|||||||
if (item == null || item.getType().getMaxDurability() == 0 || item.getItemMeta().isUnbreakable())
|
if (item == null || item.getType().getMaxDurability() == 0 || item.getItemMeta().isUnbreakable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// Check unbreakable, ignore if necessary
|
||||||
|
final ItemMeta meta = item.getItemMeta();
|
||||||
|
final int unbreakingLevel = meta.getEnchantLevel(Enchantment.DURABILITY);
|
||||||
|
if (unbreakingLevel > 0 && RANDOM.nextInt(unbreakingLevel + 1) != 0) return;
|
||||||
|
|
||||||
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
|
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
|
||||||
final int newDamage = event.getDamage() + ((Damageable) meta).getDamage();
|
final int newDamage = event.getDamage() + ((Damageable) meta).getDamage();
|
||||||
if (newDamage >= item.getType().getMaxDurability()) {
|
if (newDamage >= item.getType().getMaxDurability()) {
|
||||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
|
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
|
||||||
|
Loading…
Reference in New Issue
Block a user