Merge branch 'master' of github.com:mcMMO-Dev/mcMMO

This commit is contained in:
nossr50 2020-06-26 14:45:52 -07:00
commit cf78b51052

View File

@ -17,11 +17,13 @@ import com.gmail.nossr50.util.skills.CombatUtils;
import com.gmail.nossr50.util.skills.RankUtils; import com.gmail.nossr50.util.skills.RankUtils;
import com.gmail.nossr50.util.skills.SkillActivationType; import com.gmail.nossr50.util.skills.SkillActivationType;
import com.gmail.nossr50.util.skills.SkillUtils; import com.gmail.nossr50.util.skills.SkillUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.ArrayList;
@ -112,7 +114,7 @@ public class WoodcuttingManager extends SkillManager {
} }
// If the tool can't sustain the durability loss // If the tool can't sustain the durability loss
if (!handleDurabilityLoss(treeFellerBlocks, player.getInventory().getItemInMainHand())) { if (!handleDurabilityLoss(treeFellerBlocks, player.getInventory().getItemInMainHand(), player)) {
NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Woodcutting.Skills.TreeFeller.Splinter"); NotificationManager.sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE_FAILED, "Woodcutting.Skills.TreeFeller.Splinter");
double health = player.getHealth(); double health = player.getHealth();
@ -200,9 +202,10 @@ public class WoodcuttingManager extends SkillManager {
* *
* @param treeFellerBlocks List of blocks to be removed * @param treeFellerBlocks List of blocks to be removed
* @param inHand tool being used * @param inHand tool being used
* @param player the player holding the item
* @return True if the tool can sustain the durability loss * @return True if the tool can sustain the durability loss
*/ */
private static boolean handleDurabilityLoss(Set<BlockState> treeFellerBlocks, ItemStack inHand) { private static boolean handleDurabilityLoss(Set<BlockState> treeFellerBlocks, ItemStack inHand, Player player) {
//Treat the NBT tag for unbreakable and the durability enchant differently //Treat the NBT tag for unbreakable and the durability enchant differently
if(inHand.getItemMeta() != null && inHand.getItemMeta().isUnbreakable()) { if(inHand.getItemMeta() != null && inHand.getItemMeta().isUnbreakable()) {
return true; return true;
@ -217,6 +220,14 @@ public class WoodcuttingManager extends SkillManager {
} }
} }
// Call PlayerItemDamageEvent first to make sure it's not cancelled
final PlayerItemDamageEvent event = new PlayerItemDamageEvent(player, inHand, durabilityLoss);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return true;
}
SkillUtils.handleDurabilityChange(inHand, durabilityLoss); SkillUtils.handleDurabilityChange(inHand, durabilityLoss);
return (inHand.getDurability() < (mcMMO.getRepairableManager().isRepairable(type) ? mcMMO.getRepairableManager().getRepairable(type).getMaximumDurability() : type.getMaxDurability())); return (inHand.getDurability() < (mcMMO.getRepairableManager().isRepairable(type) ? mcMMO.getRepairableManager().getRepairable(type).getMaximumDurability() : type.getMaxDurability()));
} }