forked from Upstream/mmocore
Added extra comments
This commit is contained in:
parent
0e17de3e6e
commit
e2bf9ff034
@ -6,7 +6,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -28,6 +27,7 @@ import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.mmogroup.mmolib.MMOLib;
|
||||
import net.mmogroup.mmolib.api.item.NBTItem;
|
||||
import net.mmogroup.mmolib.version.VersionMaterial;
|
||||
|
||||
public class MMOCoreUtils {
|
||||
@ -201,10 +201,20 @@ public class MMOCoreUtils {
|
||||
target.setHealth(target.getHealth() + gain);
|
||||
}
|
||||
|
||||
public static void decreaseDurability(Player player, EquipmentSlot slot) {
|
||||
/**
|
||||
* Method used when mining a custom block or fishing, as the corresponding
|
||||
* interaction event is cancelled durability is not handled. This method is
|
||||
* needed and actually calls a damage event so that MMOItems can listen to
|
||||
* it
|
||||
*
|
||||
* @param player Player holding the item with durability
|
||||
* @param slot The slot of the item with durability
|
||||
* @param damage Damage that needs to be applied
|
||||
*/
|
||||
public static void decreaseDurability(Player player, EquipmentSlot slot, int damage) {
|
||||
ItemStack item = player.getInventory().getItem(slot);
|
||||
|
||||
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, 1);
|
||||
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, damage);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled())
|
||||
return;
|
||||
@ -212,7 +222,7 @@ public class MMOCoreUtils {
|
||||
NBTItem nbt = NBTItem.get(item);
|
||||
if (!nbt.getBoolean("Unbreakable") && item.hasItemMeta() && item.getItemMeta() instanceof Damageable) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + 1);
|
||||
((Damageable) meta).setDamage(((Damageable) meta).getDamage() + damage);
|
||||
item.setItemMeta(meta);
|
||||
if (((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
|
||||
|
@ -1,6 +1,5 @@
|
||||
package net.Indyuce.mmocore.listener;
|
||||
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -17,7 +16,6 @@ import org.bukkit.event.block.BlockFormEvent;
|
||||
import org.bukkit.event.block.BlockPistonExtendEvent;
|
||||
import org.bukkit.event.block.BlockPistonRetractEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
@ -27,6 +25,7 @@ import net.Indyuce.mmocore.api.block.BlockInfo;
|
||||
import net.Indyuce.mmocore.api.block.VanillaBlockType;
|
||||
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.mmogroup.mmolib.UtilityMethods;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
@ -108,7 +107,7 @@ public class BlockListener implements Listener {
|
||||
if (!info.hasVanillaDrops()) {
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
MMOCoreUtils.decreaseDurability(player, EquipmentSlot.HAND);
|
||||
MMOCoreUtils.decreaseDurability(player, EquipmentSlot.HAND, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -152,7 +152,7 @@ public class FishingListener implements Listener {
|
||||
close();
|
||||
|
||||
ItemStack mainhand = player.getInventory().getItem(EquipmentSlot.HAND);
|
||||
MMOCoreUtils.decreaseDurability(player, (mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND);
|
||||
MMOCoreUtils.decreaseDurability(player, (mainhand != null && mainhand.getType() == Material.FISHING_ROD) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND, 1);
|
||||
|
||||
if (!isCrit() && random.nextDouble() < PlayerData.get(player).getStats().getStat(StatType.CRITICAL_FISHING_FAILURE_CHANCE) / 100) {
|
||||
player.setVelocity(hook.getLocation().subtract(player.getLocation()).toVector().setY(0).multiply(3).setY(.5));
|
||||
|
Loading…
Reference in New Issue
Block a user