More cleanup for health API changes.

This commit is contained in:
asofold 2013-07-15 12:31:37 +02:00
parent 489c60f07f
commit f17378b3e0
8 changed files with 39 additions and 18 deletions

View File

@ -12,7 +12,6 @@ import org.bukkit.entity.ComplexLivingEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.potion.PotionEffectType;
@ -122,18 +121,19 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
return player.getNoDamageTicks();
}
@SuppressWarnings("deprecation")
@Override
public void setInvulnerableTicks(final Player player, final int ticks) {
// TODO: Ahhh...
player.setLastDamageCause(new EntityDamageEvent(player, DamageCause.CUSTOM, 500));
// TODO: Not really.
player.setLastDamageCause(BridgeHealth.getEntityDamageEvent(player, DamageCause.CUSTOM, 500.0));
player.setNoDamageTicks(ticks);
}
@Override
public void dealFallDamage(final Player player, final double damage) {
// TODO: account for armor, other.
player.damage((int) Math.round(damage));
// TODO: Document in knowledge base.
// TODO: Account for armor, other.
// TODO: use setLastDamageCause here ?
BridgeHealth.damage(player, damage);
}
@Override
@ -150,8 +150,9 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
@Override
public void setDead(final Player player, final int deathTicks) {
// TODO: Test / kick ? ...
player.setHealth(0);
player.damage(1);
BridgeHealth.setHealth(player, 0.0);
// TODO: Might try stuff like setNoDamageTicks.
BridgeHealth.damage(player, 1.0);
}
@Override
@ -201,6 +202,7 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
return mat.hasGravity();
}
catch(Throwable t){
// Backwards compatibility.
switch(mat){
case SAND:
case GRAVEL:

View File

@ -126,7 +126,7 @@ public class MCAccessCB2794 implements MCAccess{
@Override
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage);
}
@Override
@ -137,7 +137,7 @@ public class MCAccessCB2794 implements MCAccess{
@Override
public boolean shouldBeZombie(final Player player) {
final net.minecraft.server.v1_6_R1.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ;
return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ;
}
@Override

View File

@ -127,7 +127,7 @@ public class MCAccessCBDev implements MCAccess{
@Override
public void dealFallDamage(final Player player, final double damage) {
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (int) Math.round(damage));
((CraftPlayer) player).getHandle().damageEntity(DamageSource.FALL, (float) damage);
}
@Override
@ -138,7 +138,7 @@ public class MCAccessCBDev implements MCAccess{
@Override
public boolean shouldBeZombie(final Player player) {
final net.minecraft.server.v1_6_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
return !mcPlayer.dead && mcPlayer.getHealth() <= 0 ;
return !mcPlayer.dead && mcPlayer.getHealth() <= 0.0f ;
}
@Override

View File

@ -153,8 +153,9 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
}
}
if (damage <= 4 && tick == data.damageTakenByEntityTick && data.thornsId != Integer.MIN_VALUE && data.thornsId == damaged.getEntityId()){
if (damage <= 4.0 && tick == data.damageTakenByEntityTick && data.thornsId != Integer.MIN_VALUE && data.thornsId == damaged.getEntityId()){
// Don't handle further, but do respect selfhit/canceldead.
// TODO: Remove soon.
data.thornsId = Integer.MIN_VALUE;
return cancelled;
}

View File

@ -80,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 > BridgeHealth.getLastDamage(player)|| damage == 0){
if (delta <= 0 || data.lastNoDamageTicks <= player.getMaximumNoDamageTicks() / 2 || dTick > data.lastNoDamageTicks || damage > BridgeHealth.getLastDamage(player)|| damage == 0.0){
// Not resetting acc.
legit = set = true;
}
@ -182,7 +182,7 @@ 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 (BridgeHealth.getHealth(player) <= 0 && player.isDead()){
if (BridgeHealth.getHealth(player) <= 0.0 && player.isDead()){
try {
// Schedule a task to be executed in roughly 1.5 seconds.
// TODO: Get plugin otherwise !?

View File

@ -1217,7 +1217,7 @@ public class MovingListener extends CheckListener implements TickListener, IRemo
System.out.println(player.getName() + " damage(FALL): " + damage + " / dist=" + player.getFallDistance() + " nf=" + data.noFallFallDistance + " yDiff=" + yDiff);
}
// Fall-back check.
final double maxD = NoFall.getDamage(Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance))) + (allowReset ? 0 : 3);
final double maxD = NoFall.getDamage(Math.max(yDiff, Math.max(data.noFallFallDistance, fallDistance))) + (allowReset ? 0.0 : 3.0);
if (maxD > damage){
// TODO: respect dealDamage ?
BridgeHealth.setDamage(event, maxD);

View File

@ -165,6 +165,21 @@ public class BridgeHealth {
}
}
/**
* Damage an entity (LivingEntity).
* @param entity
* @param damage
* @throws RuntimeException, in case of an IncompatibleClassChangeError without success on recovery attempts.
*/
public static void damage(final LivingEntity entity, final double damage){
try{
entity.damage(damage);
}
catch(IncompatibleClassChangeError e){
invokeVoid(entity, "damage", (int) Math.round(damage), e);
}
}
@SuppressWarnings("deprecation")
public static EntityDamageEvent getEntityDamageEvent(final Entity entity, final DamageCause damageCause, final double damage){
try{

View File

@ -113,9 +113,12 @@ public interface MCAccess {
public boolean shouldBeZombie(Player player);
/**
* Set flag + death ticks.
* Ensure the player is really taken out: Set flag + death ticks.
*
* TODO: Check if still necessary + make knowledge-base entries for what to check.
*
* @param player
* @param i
* @param deathTicks
*/
public void setDead(Player player, int deathTicks);