Ignore attack event that comes after an "DamageType.CUSTOM" events

Ignore EnderDragons and giants in "fight.direction" check
This commit is contained in:
Evenprime 2011-12-15 16:34:11 +01:00
parent 614db88d54
commit 66c93513bd
4 changed files with 68 additions and 25 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cc.co.evenprime.bukkit</groupId>
<artifactId>NoCheat</artifactId>
<version>2.21a</version>
<version>2.21b</version>
<packaging>jar</packaging>
<name>NoCheat</name>
<properties>

View File

@ -3,6 +3,9 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight;
import java.util.Locale;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityComplex;
import net.minecraft.server.EntityComplexPart;
import net.minecraft.server.EntityGiantZombie;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ParameterName;
@ -27,6 +30,12 @@ public class DirectionCheck extends FightCheck {
// Get the width of the damagee
Entity entity = data.damagee;
// Safeguard, if entity is Giant or Ender Dragon, this check will fail
// due to giant and hard to define hitboxes
if(entity instanceof EntityComplex || entity instanceof EntityComplexPart || entity instanceof EntityGiantZombie) {
return false;
}
final float width = entity.length > entity.width ? entity.length : entity.width;
// height = 2.0D as minecraft doesn't store the height of entities,

View File

@ -270,19 +270,12 @@ public abstract class EventManagerImpl implements EventManager {
if(!(event instanceof EntityDamageByEntityEvent))
return;
/**
* Only interested in PROJECTILE and ENTITY_ATTACK
*/
if(event.getCause() != DamageCause.PROJECTILE && event.getCause() != DamageCause.ENTITY_ATTACK) {
return;
}
// Only handle if attack done by a projectile
if(event.getCause() == DamageCause.PROJECTILE) {
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
if(event2.getCause() == DamageCause.PROJECTILE) {
// Only handle if attack done by a player indirectly with a
// projectile
// And only if the shooter was a player
if(!((event2.getDamager() instanceof Projectile) && ((Projectile) event2.getDamager()).getShooter() instanceof Player)) {
return;
}
@ -290,15 +283,18 @@ public abstract class EventManagerImpl implements EventManager {
/** Only now measure time and dispatch event */
if(measureTime != null && measureTime.isEnabled()) {
final long startTime = System.nanoTime();
m.handleProjectileDamageByEntityEvent(event2, priority);
m.handleProjectileDamageByPlayerEvent(event2, priority);
measureTime.addTime(System.nanoTime() - startTime);
} else {
m.handleProjectileDamageByEntityEvent(event2, priority);
m.handleProjectileDamageByPlayerEvent(event2, priority);
}
}
// Only handle if attack done by a player directly
else if(event2.getCause() == DamageCause.ENTITY_ATTACK) {
// Only handle if attack done directly
else if(event.getCause() == DamageCause.ENTITY_ATTACK) {
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
// And only if done by a player
if(!(event2.getDamager() instanceof Player)) {
return;
}
@ -306,10 +302,29 @@ public abstract class EventManagerImpl implements EventManager {
/** Only now measure time and dispatch event */
if(measureTime != null && measureTime.isEnabled()) {
final long startTime = System.nanoTime();
m.handleEntityAttackDamageByEntityEvent(event2, priority);
m.handleEntityAttackDamageByPlayerEvent(event2, priority);
measureTime.addTime(System.nanoTime() - startTime);
} else {
m.handleEntityAttackDamageByEntityEvent(event2, priority);
m.handleEntityAttackDamageByPlayerEvent(event2, priority);
}
}
// Only handle if attack done by "custom"
else if(event.getCause() == DamageCause.CUSTOM) {
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
// And only if done by a player
if(!(event2.getDamager() instanceof Player)) {
return;
}
/** Only now measure time and dispatch event */
if(measureTime != null && measureTime.isEnabled()) {
final long startTime = System.nanoTime();
m.handleCustomDamageByPlayerEvent(event2, priority);
measureTime.addTime(System.nanoTime() - startTime);
} else {
m.handleCustomDamageByPlayerEvent(event2, priority);
}
}
}
@ -408,15 +423,19 @@ public abstract class EventManagerImpl implements EventManager {
handleEvent(event, priority);
}
protected void handleProjectileDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
protected void handleProjectileDamageByPlayerEvent(final EntityDamageByEntityEvent event, final Priority priority) {
handleEvent(event, priority);
}
protected void handleEntityAttackDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
protected void handleEntityAttackDamageByPlayerEvent(final EntityDamageByEntityEvent event, final Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerToggleSprintEvent(PlayerToggleSprintEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handleCustomDamageByPlayerEvent(EntityDamageByEntityEvent event, Priority priority) {
handleEvent(event, priority);
}
}

View File

@ -41,7 +41,7 @@ public class FightEventManager extends EventManagerImpl {
}
@Override
protected void handleEntityAttackDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
protected void handleEntityAttackDamageByPlayerEvent(final EntityDamageByEntityEvent event, final Priority priority) {
final Player damager = (Player) event.getDamager();
@ -54,14 +54,15 @@ public class FightEventManager extends EventManagerImpl {
final FightData data = player.getData().fight;
// For some reason we decided to skip this event anyway
if(data.skipNext) {
data.skipNext = false;
return;
}
// We are still interested in this event type
boolean cancelled = false;
// Get the attacked entity
data.damagee = ((CraftEntity) event.getEntity()).getHandle();
for(FightCheck check : checks) {
@ -78,19 +79,33 @@ public class FightEventManager extends EventManagerImpl {
}
@Override
protected void handleProjectileDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
protected void handleProjectileDamageByPlayerEvent(final EntityDamageByEntityEvent event, final Priority priority) {
final Player damager = (Player) ((Projectile) event.getDamager()).getShooter();
final NoCheatPlayer player = plugin.getPlayer(damager);
final FightData data = player.getData().fight;
// Skip the next damage event, because it is with high probability
// the same as this one
// Skip the next damage event, because it is the same as this one
// just mislabelled as a "direct" attack from one player onto another
data.skipNext = true;
return;
}
@Override
protected void handleCustomDamageByPlayerEvent(final EntityDamageByEntityEvent event, final Priority priority) {
final Player damager = (Player) event.getDamager();
final NoCheatPlayer player = plugin.getPlayer(damager);
final FightData data = player.getData().fight;
// Skip the next damage event, because it is with high probability
// something from the Heroes plugin
data.skipNext = true;
return;
}
@Override