Legacy compat: Move THORNS to BridgeEnchant.

This commit is contained in:
asofold 2015-11-26 11:21:35 +01:00
parent 1e80b5320a
commit 92b5d0ff60
2 changed files with 27 additions and 21 deletions

View File

@ -19,7 +19,6 @@ import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import fr.neatmonster.nocheatplus.NCPAPIProvider;
import fr.neatmonster.nocheatplus.checks.CheckListener;
@ -33,6 +32,7 @@ import fr.neatmonster.nocheatplus.checks.moving.locations.LocationTrace;
import fr.neatmonster.nocheatplus.checks.moving.locations.LocationTrace.TraceEntry;
import fr.neatmonster.nocheatplus.checks.moving.model.LiftOffEnvelope;
import fr.neatmonster.nocheatplus.checks.moving.util.MovingUtil;
import fr.neatmonster.nocheatplus.compat.BridgeEnchant;
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.components.JoinLeaveListener;
import fr.neatmonster.nocheatplus.logging.Streams;
@ -394,23 +394,6 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
return cancelled;
}
/**
* Check if a player might return some damage due to the "thorns" enchantment.
* @param player
* @return
*/
public static final boolean hasThorns(final Player player){
final PlayerInventory inv = player.getInventory();
final ItemStack[] contents = inv.getArmorContents();
for (int i = 0; i < contents.length; i++){
final ItemStack stack = contents[i];
if (stack != null && stack.getEnchantmentLevel(Enchantment.THORNS) > 0){
return true;
}
}
return false;
}
/**
* We listen to EntityDamage events for obvious reasons.
*
@ -450,7 +433,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
if (damagedPlayer != null && !damagedIsDead){
// TODO: check once more when to set this (!) in terms of order.
FightData.getData(damagedPlayer).damageTakenByEntityTick = tick;
if (hasThorns(damagedPlayer)){
if (BridgeEnchant.hasThorns(damagedPlayer)){
// TODO: Cleanup here.
// Remember the id of the attacker to allow counter damage.
damagedData.thornsId = damager.getEntityId();

View File

@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.compat;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
@ -18,16 +19,18 @@ public final class BridgeEnchant {
private final static Enchantment DEPTH_STRIDER = parseEnchantment("DEPTH_STRIDER");
private final static Enchantment THORNS = parseEnchantment("THORNS");
/**
*
* @param player
* @return Maximum level of DEPTH_STRIDER found on armor items, capped at 3. Will return 0 if not available.
*/
public static int getDepthStriderLevel(Player player) {
public static int getDepthStriderLevel(final Player player) {
int level = 0;
if (DEPTH_STRIDER != null) {
// Find the maximum level of depth strider.
ItemStack[] armor = player.getInventory().getArmorContents();
final ItemStack[] armor = player.getInventory().getArmorContents();
for (int i = 0; i < armor.length; i++) {
final ItemStack item = armor[i];
if (!BlockProperties.isAir(item)) {
@ -43,4 +46,24 @@ public final class BridgeEnchant {
return DEPTH_STRIDER != null;
}
/**
* Check if a player might return some damage due to the "thorns" enchantment.
* @param player
* @return
*/
public static boolean hasThorns(final Player player) {
if (THORNS == null) {
return false;
}
final PlayerInventory inv = player.getInventory();
final ItemStack[] contents = inv.getArmorContents();
for (int i = 0; i < contents.length; i++){
final ItemStack stack = contents[i];
if (stack != null && stack.getEnchantmentLevel(THORNS) > 0){
return true;
}
}
return false;
}
}