mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-26 02:17:42 +01:00
More cleanup for health API changes.
This commit is contained in:
parent
489c60f07f
commit
f17378b3e0
@ -12,7 +12,6 @@ import org.bukkit.entity.ComplexLivingEntity;
|
|||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@ -122,18 +121,19 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||||||
return player.getNoDamageTicks();
|
return player.getNoDamageTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public void setInvulnerableTicks(final Player player, final int ticks) {
|
public void setInvulnerableTicks(final Player player, final int ticks) {
|
||||||
// TODO: Ahhh...
|
// TODO: Not really.
|
||||||
player.setLastDamageCause(new EntityDamageEvent(player, DamageCause.CUSTOM, 500));
|
player.setLastDamageCause(BridgeHealth.getEntityDamageEvent(player, DamageCause.CUSTOM, 500.0));
|
||||||
player.setNoDamageTicks(ticks);
|
player.setNoDamageTicks(ticks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dealFallDamage(final Player player, final double damage) {
|
public void dealFallDamage(final Player player, final double damage) {
|
||||||
// TODO: account for armor, other.
|
// TODO: Document in knowledge base.
|
||||||
player.damage((int) Math.round(damage));
|
// TODO: Account for armor, other.
|
||||||
|
// TODO: use setLastDamageCause here ?
|
||||||
|
BridgeHealth.damage(player, damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -150,8 +150,9 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||||||
@Override
|
@Override
|
||||||
public void setDead(final Player player, final int deathTicks) {
|
public void setDead(final Player player, final int deathTicks) {
|
||||||
// TODO: Test / kick ? ...
|
// TODO: Test / kick ? ...
|
||||||
player.setHealth(0);
|
BridgeHealth.setHealth(player, 0.0);
|
||||||
player.damage(1);
|
// TODO: Might try stuff like setNoDamageTicks.
|
||||||
|
BridgeHealth.damage(player, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -201,6 +202,7 @@ public class MCAccessBukkit implements MCAccess, BlockPropertiesSetup{
|
|||||||
return mat.hasGravity();
|
return mat.hasGravity();
|
||||||
}
|
}
|
||||||
catch(Throwable t){
|
catch(Throwable t){
|
||||||
|
// Backwards compatibility.
|
||||||
switch(mat){
|
switch(mat){
|
||||||
case SAND:
|
case SAND:
|
||||||
case GRAVEL:
|
case GRAVEL:
|
||||||
|
@ -126,7 +126,7 @@ public class MCAccessCB2794 implements MCAccess{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dealFallDamage(final Player player, final double damage) {
|
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
|
@Override
|
||||||
@ -137,7 +137,7 @@ public class MCAccessCB2794 implements MCAccess{
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldBeZombie(final Player player) {
|
public boolean shouldBeZombie(final Player player) {
|
||||||
final net.minecraft.server.v1_6_R1.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
|
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
|
@Override
|
||||||
|
@ -127,7 +127,7 @@ public class MCAccessCBDev implements MCAccess{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dealFallDamage(final Player player, final double damage) {
|
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
|
@Override
|
||||||
@ -138,7 +138,7 @@ public class MCAccessCBDev implements MCAccess{
|
|||||||
@Override
|
@Override
|
||||||
public boolean shouldBeZombie(final Player player) {
|
public boolean shouldBeZombie(final Player player) {
|
||||||
final net.minecraft.server.v1_6_R2.EntityPlayer mcPlayer = ((CraftPlayer) player).getHandle();
|
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
|
@Override
|
||||||
|
@ -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.
|
// Don't handle further, but do respect selfhit/canceldead.
|
||||||
|
// TODO: Remove soon.
|
||||||
data.thornsId = Integer.MIN_VALUE;
|
data.thornsId = Integer.MIN_VALUE;
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public class GodMode extends Check {
|
|||||||
|
|
||||||
// Check if reduced more than expected or new/count down fully.
|
// Check if reduced more than expected or new/count down fully.
|
||||||
// TODO: Mostly workarounds.
|
// 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.
|
// Not resetting acc.
|
||||||
legit = set = true;
|
legit = set = true;
|
||||||
}
|
}
|
||||||
@ -182,7 +182,7 @@ public class GodMode extends Check {
|
|||||||
public void death(final Player player) {
|
public void death(final Player player) {
|
||||||
// TODO: Is this still relevant ?
|
// TODO: Is this still relevant ?
|
||||||
// First check if the player is really dead (e.g. another plugin could have just fired an artificial event).
|
// 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 {
|
try {
|
||||||
// Schedule a task to be executed in roughly 1.5 seconds.
|
// Schedule a task to be executed in roughly 1.5 seconds.
|
||||||
// TODO: Get plugin otherwise !?
|
// TODO: Get plugin otherwise !?
|
||||||
|
@ -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);
|
System.out.println(player.getName() + " damage(FALL): " + damage + " / dist=" + player.getFallDistance() + " nf=" + data.noFallFallDistance + " yDiff=" + yDiff);
|
||||||
}
|
}
|
||||||
// Fall-back check.
|
// 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){
|
if (maxD > damage){
|
||||||
// TODO: respect dealDamage ?
|
// TODO: respect dealDamage ?
|
||||||
BridgeHealth.setDamage(event, maxD);
|
BridgeHealth.setDamage(event, maxD);
|
||||||
|
@ -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")
|
@SuppressWarnings("deprecation")
|
||||||
public static EntityDamageEvent getEntityDamageEvent(final Entity entity, final DamageCause damageCause, final double damage){
|
public static EntityDamageEvent getEntityDamageEvent(final Entity entity, final DamageCause damageCause, final double damage){
|
||||||
try{
|
try{
|
||||||
|
@ -113,9 +113,12 @@ public interface MCAccess {
|
|||||||
public boolean shouldBeZombie(Player player);
|
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 player
|
||||||
* @param i
|
* @param deathTicks
|
||||||
*/
|
*/
|
||||||
public void setDead(Player player, int deathTicks);
|
public void setDead(Player player, int deathTicks);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user