mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-02-11 09:11:26 +01:00
Added self-hit check.
This commit is contained in:
parent
5419b3ceff
commit
ac9b6473fc
@ -65,6 +65,7 @@ public enum CheckType {
|
||||
FIGHT_KNOCKBACK(FIGHT, Permissions.FIGHT_KNOCKBACK),
|
||||
FIGHT_NOSWING(FIGHT, Permissions.FIGHT_NOSWING),
|
||||
FIGHT_REACH(FIGHT, Permissions.FIGHT_REACH),
|
||||
FIGHT_SELFHIT(FIGHT, Permissions.FIGHT_SELFHIT),
|
||||
FIGHT_SPEED(FIGHT, Permissions.FIGHT_SPEED),
|
||||
|
||||
INVENTORY(InventoryConfig.factory, InventoryData.factory),
|
||||
|
@ -91,6 +91,9 @@ public class FightConfig implements CheckConfig {
|
||||
public final boolean reachCheck;
|
||||
public final long reachPenalty;
|
||||
public final ActionList reachActions;
|
||||
|
||||
public final boolean selfHitCheck;
|
||||
public final ActionList selfHitActions;
|
||||
|
||||
public final boolean speedCheck;
|
||||
public final int speedLimit;
|
||||
@ -133,6 +136,9 @@ public class FightConfig implements CheckConfig {
|
||||
reachPenalty = data.getLong(ConfPaths.FIGHT_REACH_PENALTY);
|
||||
reachActions = data.getActionList(ConfPaths.FIGHT_REACH_ACTIONS, Permissions.FIGHT_REACH);
|
||||
|
||||
selfHitCheck = data.getBoolean(ConfPaths.FIGHT_SELFHIT_CHECK);
|
||||
selfHitActions = data.getActionList(ConfPaths.FIGHT_SELFHIT_ACTIONS, Permissions.FIGHT_SELFHIT);
|
||||
|
||||
speedCheck = data.getBoolean(ConfPaths.FIGHT_SPEED_CHECK);
|
||||
speedLimit = data.getInt(ConfPaths.FIGHT_SPEED_LIMIT);
|
||||
speedActions = data.getActionList(ConfPaths.FIGHT_SPEED_ACTIONS, Permissions.FIGHT_SPEED);
|
||||
@ -162,6 +168,8 @@ public class FightConfig implements CheckConfig {
|
||||
return reachCheck;
|
||||
case FIGHT_SPEED:
|
||||
return speedCheck;
|
||||
case FIGHT_SELFHIT:
|
||||
return selfHitCheck;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.CheckData;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckDataFactory;
|
||||
import fr.neatmonster.nocheatplus.utilities.ActionFrequency;
|
||||
|
||||
/*
|
||||
* MM""""""""`M oo dP dP M""""""'YMM dP
|
||||
@ -85,6 +86,9 @@ public class FightData implements CheckData {
|
||||
|
||||
// Data of the reach check.
|
||||
public long reachLastViolationTime;
|
||||
|
||||
// Data of the SelfHit check.
|
||||
public ActionFrequency selfHitVL = new ActionFrequency(6, 5000);
|
||||
|
||||
// Data of the speed check.
|
||||
public int speedAttacks;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.neatmonster.nocheatplus.checks.fight;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -56,6 +57,9 @@ public class FightListener implements Listener {
|
||||
|
||||
/** The reach check. */
|
||||
private final Reach reach = new Reach();
|
||||
|
||||
/** The self hit check */
|
||||
private final SelfHit selfHit = new SelfHit();
|
||||
|
||||
/** The speed check. */
|
||||
private final Speed speed = new Speed();
|
||||
@ -82,7 +86,7 @@ public class FightListener implements Listener {
|
||||
*/
|
||||
private void handleNormalDamage(final EntityDamageByEntityEvent event) {
|
||||
final Player player = (Player) event.getDamager();
|
||||
FightConfig.getConfig(player);
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
// For some reason we decided to skip this event anyway.
|
||||
@ -92,12 +96,19 @@ public class FightListener implements Listener {
|
||||
}
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
// Check for self hit exploits (mind that projectiles should be excluded)
|
||||
final Entity cbEntity = event.getEntity();
|
||||
if (cbEntity instanceof Player){
|
||||
if (selfHit.isEnabled(player) && selfHit.check(player, cbEntity, data, cc))
|
||||
cancelled = true;
|
||||
}
|
||||
|
||||
// Get the attacked entity.
|
||||
final net.minecraft.server.Entity damaged = ((CraftEntity) event.getEntity()).getHandle();
|
||||
final net.minecraft.server.Entity damaged = ((CraftEntity) cbEntity).getHandle();
|
||||
|
||||
// Run through the main checks.
|
||||
if (angle.isEnabled(player) && angle.check(player))
|
||||
if (!cancelled && angle.isEnabled(player) && angle.check(player))
|
||||
cancelled = true;
|
||||
|
||||
if (!cancelled && critical.isEnabled(player) && critical.check(player))
|
||||
|
27
src/fr/neatmonster/nocheatplus/checks/fight/SelfHit.java
Normal file
27
src/fr/neatmonster/nocheatplus/checks/fight/SelfHit.java
Normal file
@ -0,0 +1,27 @@
|
||||
package fr.neatmonster.nocheatplus.checks.fight;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
public class SelfHit extends Check {
|
||||
|
||||
public SelfHit() {
|
||||
super(CheckType.FIGHT_SELFHIT);
|
||||
}
|
||||
|
||||
public boolean check(final Player damager, final Entity damaged, final FightData data, final FightConfig cc){
|
||||
if (!damager.getName().equals(((Player) damaged).getName())) return false;
|
||||
|
||||
boolean cancel = false;
|
||||
// Treat self hitting as instant violation.
|
||||
data.selfHitVL.add(System.currentTimeMillis(), 1.0f);
|
||||
// NOTE: This lets VL decrease slightly over 30 seconds, one could also use a number, but this is more tolerant.
|
||||
cancel = executeActions(damager, data.selfHitVL.getScore(0.99f), 1.0f, cc.selfHitActions);
|
||||
|
||||
return cancel;
|
||||
}
|
||||
|
||||
}
|
@ -294,6 +294,11 @@ public abstract class ConfPaths {
|
||||
public static final String FIGHT_REACH_CHECK = FIGHT_REACH + "active";
|
||||
public static final String FIGHT_REACH_PENALTY = FIGHT_REACH + "penalty";
|
||||
public static final String FIGHT_REACH_ACTIONS = FIGHT_REACH + "actions";
|
||||
|
||||
public static final String FIGHT_SELFHIT = FIGHT + "selfhit.";
|
||||
public static final String FIGHT_SELFHIT_CHECK = FIGHT_SELFHIT + "check";
|
||||
public static final String FIGHT_SELFHIT_ACTIONS = FIGHT_SELFHIT + "actions";
|
||||
|
||||
|
||||
private static final String FIGHT_SPEED = FIGHT + "speed.";
|
||||
public static final String FIGHT_SPEED_CHECK = FIGHT_SPEED + "active";
|
||||
@ -383,5 +388,5 @@ public abstract class ConfPaths {
|
||||
* "8",P"
|
||||
*/
|
||||
public static final String STRINGS = "strings";
|
||||
|
||||
|
||||
}
|
||||
|
@ -244,6 +244,9 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.FIGHT_REACH_CHECK, true);
|
||||
set(ConfPaths.FIGHT_REACH_PENALTY, 500);
|
||||
set(ConfPaths.FIGHT_REACH_ACTIONS, "cancel vl>10 log:freach:2:5:if cancel");
|
||||
|
||||
set(ConfPaths.FIGHT_SELFHIT_CHECK, true);
|
||||
set(ConfPaths.FIGHT_SELFHIT_ACTIONS, "log:fselfhit:2:5:if cancel vl>10 log:fselfhit:0:5:if cancel cmd:kickselfhit");
|
||||
|
||||
set(ConfPaths.FIGHT_SPEED_CHECK, true);
|
||||
set(ConfPaths.FIGHT_SPEED_LIMIT, 15);
|
||||
@ -339,6 +342,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".flylong", start
|
||||
+ "tried to move from [locationfrom] to [locationto] over a distance of [distance] block(s)" + end);
|
||||
set(ConfPaths.STRINGS + ".freach", start + "tried to attack entity out of reach" + end);
|
||||
set(ConfPaths.STRINGS + ".fselfhit", start + "tried to self-hit" + end);
|
||||
set(ConfPaths.STRINGS + ".fspeed", start + "tried to attack more than [limit] times per second" + end);
|
||||
set(ConfPaths.STRINGS + ".globalchat", start + "potentially annoying chat" + end);
|
||||
set(ConfPaths.STRINGS + ".godmode", start + "avoided taking damage or lagging" + end);
|
||||
@ -349,6 +353,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".kicknopwnage", "ncp kick [player] You're not allowed to spam this server!");
|
||||
set(ConfPaths.STRINGS + ".kickcaptcha", "ncp kick [player] Enter the captcha!");
|
||||
set(ConfPaths.STRINGS + ".kickglchat", "ncp kick [player] Too many chat messages, take a break.");
|
||||
set(ConfPaths.STRINGS + ".kickselfhit", "ncp kick [player] That must be exhausting!");
|
||||
set(ConfPaths.STRINGS + ".knockback", start + "tried to do a knockback but wasn't technically sprinting" + end);
|
||||
set(ConfPaths.STRINGS + ".morepackets", start + "sent [packets] more packet(s) than expected" + end);
|
||||
set(ConfPaths.STRINGS + ".nofall", start + "tried to avoid fall damage for ~[falldistance] block(s)" + end);
|
||||
|
@ -104,6 +104,7 @@ public class Permissions {
|
||||
public static final String FIGHT_KNOCKBACK = FIGHT + ".knockback";
|
||||
public static final String FIGHT_NOSWING = FIGHT + ".noswing";
|
||||
public static final String FIGHT_REACH = FIGHT + ".reach";
|
||||
public static final String FIGHT_SELFHIT = FIGHT + ".selfhit";
|
||||
public static final String FIGHT_SPEED = FIGHT + ".speed";
|
||||
|
||||
/*
|
||||
@ -178,4 +179,5 @@ public class Permissions {
|
||||
public static final String ZOMBE_FLY = ZOMBE + ".fly";
|
||||
public static final String ZOMBE_NOCLIP = ZOMBE + ".noclip";
|
||||
public static final String ZOMBE_CHEAT = ZOMBE + ".cheat";
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user