Remove old compatibility workaround (skipnext).

This commit is contained in:
asofold 2012-10-27 21:56:56 +02:00
parent 20065d0baf
commit 12f8d3036e
2 changed files with 8 additions and 34 deletions

View File

@ -79,8 +79,6 @@ public class FightData extends ACheckData {
public double reachVL; public double reachVL;
public double speedVL; public double speedVL;
public boolean skipNext;
public long damageTakenTick; public long damageTakenTick;
// Shared // Shared

View File

@ -62,43 +62,22 @@ public class FightListener implements Listener {
/** The speed check. */ /** The speed check. */
private final Speed speed = new Speed(); private final Speed speed = new Speed();
/**
* There is an unofficial agreement that if a plugin wants an attack to not get checked by NoCheatPlus, it either
* has to use a damage type different from ENTITY_ATTACK or fire an event with damage type CUSTOM and damage 0
* directly before the to-be-ignored event.
*
* @param event
* the event
*/
private void handleCustomDamage(final EntityDamageByEntityEvent event) {
if (event.getDamager() instanceof Player)
// Skip the next damage event, because it is with high probability something from the Heroes plugin.
FightData.getData((Player) event.getDamager()).skipNext = true;
}
/** /**
* A player attacked something with DamageCause ENTITY_ATTACK. That's most likely what we want to really check. * A player attacked something with DamageCause ENTITY_ATTACK. That's most likely what we want to really check.
* *
* @param event * @param event
* The EntityDamageByEntityEvent * The EntityDamageByEntityEvent
* @return
*/ */
private void handleNormalDamage(final EntityDamageByEntityEvent event) { private boolean handleNormalDamage(final Player player, final Entity cbEntity) {
final Player player = (Player) event.getDamager();
final FightConfig cc = FightConfig.getConfig(player); final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player); final FightData data = FightData.getData(player);
// For some reason we decided to skip this event anyway.
if (data.skipNext) {
data.skipNext = false;
return;
}
boolean cancelled = false; boolean cancelled = false;
final String worldName = player.getWorld().getName(); final String worldName = player.getWorld().getName();
// Check for self hit exploits (mind that projectiles should be excluded) // Check for self hit exploits (mind that projectiles should be excluded)
final Entity cbEntity = event.getEntity();
if (cbEntity instanceof Player){ if (cbEntity instanceof Player){
final Player damagedPlayer = (Player) cbEntity; final Player damagedPlayer = (Player) cbEntity;
if (selfHit.isEnabled(player) && selfHit.check(player, damagedPlayer, data, cc)) if (selfHit.isEnabled(player) && selfHit.check(player, damagedPlayer, data, cc))
@ -162,11 +141,8 @@ public class FightListener implements Listener {
if (!cancelled && player.isBlocking() && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_BLOCKING)) if (!cancelled && player.isBlocking() && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_BLOCKING))
cancelled = true; cancelled = true;
// One of the checks requested the event to be cancelled, so do it.
if (cancelled)
event.setCancelled(cancelled);
data.lastWorld = worldName; data.lastWorld = worldName;
return cancelled;
} }
/** /**
@ -191,15 +167,15 @@ public class FightListener implements Listener {
final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; final EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
final Entity damaged = e.getEntity(); final Entity damaged = e.getEntity();
if (damaged instanceof Player){ if (damaged instanceof Player){
// TODO: check once more when to set this (!) in terms of order.
FightData.getData((Player) damaged).damageTakenTick = TickTask.getTick(); FightData.getData((Player) damaged).damageTakenTick = TickTask.getTick();
} }
final Entity damager = e.getDamager();
if (e.getDamager() instanceof Player){ if (damager instanceof Player){
final Player player = (Player) damager;
if (e.getCause() == DamageCause.ENTITY_ATTACK){ if (e.getCause() == DamageCause.ENTITY_ATTACK){
handleNormalDamage(e); if (handleNormalDamage(player, damaged)) e.setCancelled(true);
} }
else if (e.getCause() == DamageCause.CUSTOM)
handleCustomDamage(e);
} }
} }
} }