mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-12-29 05:47:36 +01:00
Merge branch 'master' of https://git.lumine.io/mythiccraft/mmocore
This commit is contained in:
commit
0e17de3e6e
@ -6,16 +6,22 @@ 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;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
||||
import org.bukkit.event.player.PlayerItemDamageEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.Damageable;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
@ -194,4 +200,24 @@ public class MMOCoreUtils {
|
||||
if (!event.isCancelled())
|
||||
target.setHealth(target.getHealth() + gain);
|
||||
}
|
||||
|
||||
public static void decreaseDurability(Player player, EquipmentSlot slot) {
|
||||
ItemStack item = player.getInventory().getItem(slot);
|
||||
|
||||
PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, item, 1);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
|
||||
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);
|
||||
item.setItemMeta(meta);
|
||||
if(((Damageable) meta).getDamage() >= item.getType().getMaxDurability()) {
|
||||
player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1F, 1F);
|
||||
player.getInventory().setItem(slot, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
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,6 +18,7 @@ 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;
|
||||
|
||||
@ -106,7 +108,7 @@ public class BlockListener implements Listener {
|
||||
if (!info.hasVanillaDrops()) {
|
||||
event.setCancelled(true);
|
||||
event.getBlock().setType(Material.AIR);
|
||||
Bukkit.getPluginManager().callEvent(new PlayerItemDamageEvent(player, item, 1));
|
||||
MMOCoreUtils.decreaseDurability(player, EquipmentSlot.HAND);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5,8 +5,10 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.FishHook;
|
||||
import org.bukkit.entity.Item;
|
||||
@ -17,6 +19,7 @@ import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerFishEvent.State;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
@ -126,8 +129,6 @@ public class FishingListener implements Listener {
|
||||
/*
|
||||
* lose the catch if the current fish is gone!
|
||||
*/
|
||||
// TODO: Cancelling the event also cancels Rod damage (so it's
|
||||
// technically unbreakable)
|
||||
event.setCancelled(true);
|
||||
if (isTimedOut()) {
|
||||
close();
|
||||
@ -150,6 +151,9 @@ 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);
|
||||
|
||||
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));
|
||||
hook.getWorld().spawnParticle(Particle.SMOKE_NORMAL, location, 24, 0, 0, 0, .08);
|
||||
|
Loading…
Reference in New Issue
Block a user