mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-02 22:07:50 +01:00
Ignore attack event that comes after an "DamageType.CUSTOM" events
Ignore EnderDragons and giants in "fight.direction" check
This commit is contained in:
parent
614db88d54
commit
66c93513bd
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>cc.co.evenprime.bukkit</groupId>
|
<groupId>cc.co.evenprime.bukkit</groupId>
|
||||||
<artifactId>NoCheat</artifactId>
|
<artifactId>NoCheat</artifactId>
|
||||||
<version>2.21a</version>
|
<version>2.21b</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>NoCheat</name>
|
<name>NoCheat</name>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -3,6 +3,9 @@ package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import net.minecraft.server.Entity;
|
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.NoCheat;
|
||||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||||
import cc.co.evenprime.bukkit.nocheat.actions.types.ParameterName;
|
import cc.co.evenprime.bukkit.nocheat.actions.types.ParameterName;
|
||||||
@ -27,6 +30,12 @@ public class DirectionCheck extends FightCheck {
|
|||||||
// Get the width of the damagee
|
// Get the width of the damagee
|
||||||
Entity entity = data.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;
|
final float width = entity.length > entity.width ? entity.length : entity.width;
|
||||||
|
|
||||||
// height = 2.0D as minecraft doesn't store the height of entities,
|
// height = 2.0D as minecraft doesn't store the height of entities,
|
||||||
|
@ -270,19 +270,12 @@ public abstract class EventManagerImpl implements EventManager {
|
|||||||
if(!(event instanceof EntityDamageByEntityEvent))
|
if(!(event instanceof EntityDamageByEntityEvent))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/**
|
// Only handle if attack done by a projectile
|
||||||
* Only interested in PROJECTILE and ENTITY_ATTACK
|
if(event.getCause() == DamageCause.PROJECTILE) {
|
||||||
*/
|
|
||||||
if(event.getCause() != DamageCause.PROJECTILE && event.getCause() != DamageCause.ENTITY_ATTACK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
|
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
|
||||||
|
|
||||||
if(event2.getCause() == DamageCause.PROJECTILE) {
|
// And only if the shooter was a player
|
||||||
|
|
||||||
// Only handle if attack done by a player indirectly with a
|
|
||||||
// projectile
|
|
||||||
if(!((event2.getDamager() instanceof Projectile) && ((Projectile) event2.getDamager()).getShooter() instanceof Player)) {
|
if(!((event2.getDamager() instanceof Projectile) && ((Projectile) event2.getDamager()).getShooter() instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -290,15 +283,18 @@ public abstract class EventManagerImpl implements EventManager {
|
|||||||
/** Only now measure time and dispatch event */
|
/** Only now measure time and dispatch event */
|
||||||
if(measureTime != null && measureTime.isEnabled()) {
|
if(measureTime != null && measureTime.isEnabled()) {
|
||||||
final long startTime = System.nanoTime();
|
final long startTime = System.nanoTime();
|
||||||
m.handleProjectileDamageByEntityEvent(event2, priority);
|
m.handleProjectileDamageByPlayerEvent(event2, priority);
|
||||||
measureTime.addTime(System.nanoTime() - startTime);
|
measureTime.addTime(System.nanoTime() - startTime);
|
||||||
} else {
|
} else {
|
||||||
m.handleProjectileDamageByEntityEvent(event2, priority);
|
m.handleProjectileDamageByPlayerEvent(event2, priority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Only handle if attack done by a player directly
|
// Only handle if attack done directly
|
||||||
else if(event2.getCause() == DamageCause.ENTITY_ATTACK) {
|
else if(event.getCause() == DamageCause.ENTITY_ATTACK) {
|
||||||
|
|
||||||
|
final EntityDamageByEntityEvent event2 = (EntityDamageByEntityEvent) event;
|
||||||
|
|
||||||
|
// And only if done by a player
|
||||||
if(!(event2.getDamager() instanceof Player)) {
|
if(!(event2.getDamager() instanceof Player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -306,10 +302,29 @@ public abstract class EventManagerImpl implements EventManager {
|
|||||||
/** Only now measure time and dispatch event */
|
/** Only now measure time and dispatch event */
|
||||||
if(measureTime != null && measureTime.isEnabled()) {
|
if(measureTime != null && measureTime.isEnabled()) {
|
||||||
final long startTime = System.nanoTime();
|
final long startTime = System.nanoTime();
|
||||||
m.handleEntityAttackDamageByEntityEvent(event2, priority);
|
m.handleEntityAttackDamageByPlayerEvent(event2, priority);
|
||||||
measureTime.addTime(System.nanoTime() - startTime);
|
measureTime.addTime(System.nanoTime() - startTime);
|
||||||
} else {
|
} 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);
|
handleEvent(event, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handleProjectileDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
|
protected void handleProjectileDamageByPlayerEvent(final EntityDamageByEntityEvent event, final Priority priority) {
|
||||||
handleEvent(event, 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);
|
handleEvent(event, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void handlePlayerToggleSprintEvent(PlayerToggleSprintEvent event, Priority priority) {
|
protected void handlePlayerToggleSprintEvent(PlayerToggleSprintEvent event, Priority priority) {
|
||||||
handleEvent(event, priority);
|
handleEvent(event, priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleCustomDamageByPlayerEvent(EntityDamageByEntityEvent event, Priority priority) {
|
||||||
|
handleEvent(event, priority);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class FightEventManager extends EventManagerImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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();
|
final Player damager = (Player) event.getDamager();
|
||||||
|
|
||||||
@ -54,14 +54,15 @@ public class FightEventManager extends EventManagerImpl {
|
|||||||
|
|
||||||
final FightData data = player.getData().fight;
|
final FightData data = player.getData().fight;
|
||||||
|
|
||||||
|
// For some reason we decided to skip this event anyway
|
||||||
if(data.skipNext) {
|
if(data.skipNext) {
|
||||||
data.skipNext = false;
|
data.skipNext = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are still interested in this event type
|
|
||||||
boolean cancelled = false;
|
boolean cancelled = false;
|
||||||
|
|
||||||
|
// Get the attacked entity
|
||||||
data.damagee = ((CraftEntity) event.getEntity()).getHandle();
|
data.damagee = ((CraftEntity) event.getEntity()).getHandle();
|
||||||
|
|
||||||
for(FightCheck check : checks) {
|
for(FightCheck check : checks) {
|
||||||
@ -78,19 +79,33 @@ public class FightEventManager extends EventManagerImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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 Player damager = (Player) ((Projectile) event.getDamager()).getShooter();
|
||||||
final NoCheatPlayer player = plugin.getPlayer(damager);
|
final NoCheatPlayer player = plugin.getPlayer(damager);
|
||||||
|
|
||||||
final FightData data = player.getData().fight;
|
final FightData data = player.getData().fight;
|
||||||
|
|
||||||
// Skip the next damage event, because it is with high probability
|
// Skip the next damage event, because it is the same as this one
|
||||||
// the same as this one
|
// just mislabelled as a "direct" attack from one player onto another
|
||||||
data.skipNext = true;
|
data.skipNext = true;
|
||||||
|
|
||||||
return;
|
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
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user