[BLEEDING] Adapt to health changes + set NCPCore dependency to 1.6.1.

This commit is contained in:
asofold 2013-07-10 01:50:44 +02:00
parent ccc9c74a76
commit a8d1aded59
16 changed files with 124 additions and 38 deletions

View File

@ -17,6 +17,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffectType;
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.compat.blocks.BlockPropertiesSetup;
import fr.neatmonster.nocheatplus.config.WorldConfigProvider;
@ -130,9 +131,9 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
public void dealFallDamage(final Player player, final double damage) {
// TODO: account for armor, other.
player.damage(damage);
player.damage((int) Math.round(damage));
}
@Override
@ -143,7 +144,7 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
@Override
public boolean shouldBeZombie(final Player player) {
// Not sure :) ...
return player.getHealth() <= 0 && !player.isDead();
return BridgeHealth.getHealth(player) <= 0.0 && !player.isDead();
}
@Override

View File

@ -123,8 +123,8 @@ public class MCAccessCB2511 implements MCAccess {
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -121,8 +121,8 @@ public class MCAccessCB2512 implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -121,8 +121,8 @@ public class MCAccessCB2545 implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -122,8 +122,8 @@ public class MCAccessCB2602 implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -123,8 +123,8 @@ public class MCAccessCB2645 implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -123,8 +123,8 @@ public class MCAccessCB2691 implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -123,8 +123,8 @@ public class MCAccessCB2763 implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -123,8 +123,8 @@ public class MCAccessCBDev implements MCAccess{
}
@Override
public void dealFallDamage(final Player player, final int damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, damage);
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
}
@Override

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.5.2-R1.0</version>
<version>1.6.1-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>fr.neatmonster</groupId>

View File

@ -282,7 +282,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
// It requested to "cancel" the players invulnerability, so set his noDamageTicks to 0.
damagedPlayer.setNoDamageTicks(0);
}
if (damagedPlayer.getHealth() == damagedPlayer.getMaxHealth()){
if (BridgeHealth.getHealth(damagedPlayer) == BridgeHealth.getMaxHealth(damagedPlayer)){
// TODO: Might use the same FightData instance for GodMode.
if (damagedData.fastHealBuffer < 0){
// Reduce negative buffer with each full health.

View File

@ -5,6 +5,7 @@ import org.bukkit.entity.Player;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
import fr.neatmonster.nocheatplus.utilities.TickTask;
@ -53,7 +54,7 @@ public class GodMode extends Check {
final int dNDT = data.lastNoDamageTicks - noDamageTicks;
final int delta = dTick - dNDT;
final double health = player.getHealth();
final double health = BridgeHealth.getHealth(player);
// TODO: Adjust to double values.
@ -79,7 +80,7 @@ public class GodMode extends Check {
// Check if reduced more than expected or new/count down fully.
// TODO: Mostly workarounds.
if (delta <= 0 || data.lastNoDamageTicks <= player.getMaximumNoDamageTicks() / 2 || dTick > data.lastNoDamageTicks || damage > player.getLastDamage() || damage == 0){
if (delta <= 0 || data.lastNoDamageTicks <= player.getMaximumNoDamageTicks() / 2 || dTick > data.lastNoDamageTicks || damage > BridgeHealth.getLastDamage(player)|| damage == 0){
// Not resetting acc.
legit = set = true;
}
@ -181,8 +182,8 @@ public class GodMode extends Check {
public void death(final Player player) {
// TODO: Is this still relevant ?
// First check if the player is really dead (e.g. another plugin could have just fired an artificial event).
if (player.getHealth() <= 0 && player.isDead())
try {
if (BridgeHealth.getHealth(player) <= 0 && player.isDead()){
try {
// Schedule a task to be executed in roughly 1.5 seconds.
// TODO: Get plugin otherwise !?
Bukkit.getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("NoCheatPlus"), new Runnable() {
@ -198,5 +199,6 @@ public class GodMode extends Check {
}
}, 30);
} catch (final Exception e) {}
}
}
}

View File

@ -1218,7 +1218,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
final double maxD = NoFall.getDamage(Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance))) + (allowReset ? 0 : 3);
if (maxD > damage){
// TODO: respect dealDamage ?
event.setDamage((int) Math.round(maxD)); // TODO: Byte code compatibility !?
BridgeHealth.setDamage(event, maxD);
if (cc.debug){
System.out.println(player.getName() + " Adjust fall damage to: " + maxD);
}

View File

@ -8,6 +8,7 @@ import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.compat.BridgeHealth;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
@ -77,14 +78,13 @@ public class NoFall extends Check {
private void dealFallDamage(final Player player, final double damage) {
@SuppressWarnings("deprecation")
// TODO: Byte code compatibility ?
final EntityDamageEvent event = new EntityDamageEvent(player, DamageCause.FALL, (int) Math.round(damage));
final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()){
// TODO: account for no damage ticks etc.
player.setLastDamageCause(event);
mcAccess.dealFallDamage(player, (int) Math.round(event.getDamage())); // TODO: Adjust signature to double (!).
mcAccess.dealFallDamage(player, BridgeHealth.getDamage(event));
}
// TODO: let this be done by the damage event (!).
// data.clearNoFallData(); // -> currently done in the damage eventhandling method.

View File

@ -3,8 +3,10 @@ package fr.neatmonster.nocheatplus.compat;
import java.util.HashSet;
import java.util.Set;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import fr.neatmonster.nocheatplus.logging.LogUtil;
@ -12,6 +14,9 @@ import fr.neatmonster.nocheatplus.utilities.ReflectionUtil;
/**
* Utility class with static access methods to bridge compatibility issues, such as arising from changes in Bukkit from MC 1.5.2 to 1.6.1.
* <br>NOTES:
* <li>To simplify code IncompatibleClassChangeError is caught instead of AbstractMethodError and NoSuchMethodError etc.</li>
* <li>TODO: Since API dependency is now 1.6.1+, some things can be simplified to just call the "int-methods".</li>
* @author mc_dev
*
*/
@ -55,13 +60,13 @@ public class BridgeHealth {
* Get the amount of health added with the event.
* @param event
* @return
* @throws RuntimeException, in case of an AbstractMethodError without success on recovery attempts.
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static double getAmount(final EntityRegainHealthEvent event){
try{
return event.getAmount();
}
catch(AbstractMethodError e){
catch(IncompatibleClassChangeError e){
return getDoubleOrInt(event, "getAmount", e);
}
}
@ -70,28 +75,44 @@ public class BridgeHealth {
* Get the damage from an EntityDamageEvent.
* @param event
* @return
* @throws RuntimeException, in case of an AbstractMethodError without success on recovery attempts.
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static double getDamage(final EntityDamageEvent event){
try{
return event.getDamage();
}
catch(AbstractMethodError e){
catch(IncompatibleClassChangeError e){
return getDoubleOrInt(event, "getDamage", e);
}
}
/**
* Set the damage from an EntityDamageEvent.
* @param event
* @param damage
* @return
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static void setDamage(final EntityDamageEvent event, final double damage){
try{
event.setDamage(damage);
}
catch(IncompatibleClassChangeError e){
invokeVoid(event, "setDamage", (int) Math.round(damage), e);
}
}
/**
* Get the health for an entity (LivingEntity).
* @param entity
* @return
* @throws RuntimeException, in case of an AbstractMethodError without success on recovery attempts.
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static double getHealth(final LivingEntity entity){
try{
return entity.getHealth();
}
catch(AbstractMethodError e){
catch(IncompatibleClassChangeError e){
return getDoubleOrInt(entity, "getHealth", e);
}
}
@ -100,15 +121,77 @@ public class BridgeHealth {
* Get the maximum health for an entity (LivingEntity).
* @param entity
* @return
* @throws RuntimeException, in case of an AbstractMethodError without success on recovery attempts.
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static double getMaxHealth(final LivingEntity entity){
try{
return entity.getMaxHealth();
}
catch(AbstractMethodError e){
catch(IncompatibleClassChangeError e){
return getDoubleOrInt(entity, "getMaxHealth", e);
}
}
/**
* Get the last damage for an entity (LivingEntity).
* @param entity
* @return
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static double getLastDamage(final LivingEntity entity){
try{
return entity.getLastDamage();
}
catch(IncompatibleClassChangeError e){
return getDoubleOrInt(entity, "getLastDamage", e);
}
}
/**
* Set the health for an entity (LivingEntity).
* @param entity
* @param health
* @return
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static void setHealth(final LivingEntity entity, final double health){
try{
entity.setHealth(health);
}
catch(IncompatibleClassChangeError e){
invokeVoid(entity, "setHealth", (int) Math.round(health), e);
}
}
@SuppressWarnings("deprecation")
public static EntityDamageEvent getEntityDamageEvent(final Entity entity, final DamageCause damageCause, final double damage){
try{
return new EntityDamageEvent(entity, damageCause, damage);
}
catch(IncompatibleClassChangeError e){
return new EntityDamageEvent(entity, damageCause, (int) Math.round(damage));
}
}
/**
* Intended for faster compatibility methods for defined scenarios. Transforms any exception to a RuntimeException.
* @param obj
* @param methodName
* @param value
*/
public static void invokeVoid(final Object obj, final String methodName, final int value, final Throwable reason){
if (reason != null){
final String tag = obj.getClass().getName() + "." + methodName;
if (failures.add(tag)){
// New entry.
LogUtil.logWarning("[NoCheatPlus] API incompatibility detected: " + tag);
}
}
try {
obj.getClass().getMethod(methodName, int.class).invoke(obj, value);
} catch (Throwable t) {
throw new RuntimeException("Could not invoke " + methodName + " with one argument (int) on: " + obj.getClass().getName(), reason);
}
}
}

View File

@ -96,7 +96,7 @@ public interface MCAccess {
public void setInvulnerableTicks(Player player, int ticks);
public void dealFallDamage(Player player, int damage);
public void dealFallDamage(Player player, double damage);
/**
* This may well be removed, if possible to check with Bukkit.