mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-02 00:29:59 +01:00
[Development] NoSwing!
This commit is contained in:
parent
c1b2fed6ca
commit
2a44f8df43
@ -74,6 +74,9 @@ public class FightConfig {
|
||||
public final long knockbackInterval;
|
||||
public final ActionList knockbackActions;
|
||||
|
||||
public final boolean noSwingCheck;
|
||||
public final ActionList noSwingActions;
|
||||
|
||||
/**
|
||||
* Instantiates a new fight configuration.
|
||||
*
|
||||
@ -103,5 +106,8 @@ public class FightConfig {
|
||||
knockbackCheck = data.getBoolean(ConfPaths.FIGHT_KNOCKBACK_CHECK);
|
||||
knockbackInterval = data.getLong(ConfPaths.FIGHT_KNOCKBACK_INTERVAL);
|
||||
knockbackActions = data.getActionList(ConfPaths.FIGHT_KNOCKBACK_ACTIONS, Permissions.FIGHT_KNOCKBACK);
|
||||
|
||||
noSwingCheck = data.getBoolean(ConfPaths.FIGHT_NOSWING_CHECK);
|
||||
noSwingActions = data.getActionList(ConfPaths.FIGHT_NOSWING_ACTIONS, Permissions.FIGHT_NOSWING);
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ public class FightData {
|
||||
public double godModeVL;
|
||||
public double instantHealVL;
|
||||
public double knockbackVL;
|
||||
public double noSwingVL;
|
||||
|
||||
// Data of the angle check.
|
||||
public TreeMap<Long, Location> angleHits = new TreeMap<Long, Location>();
|
||||
@ -64,4 +65,7 @@ public class FightData {
|
||||
// Data of the knockback check.
|
||||
public long knockbackSprintTime;
|
||||
|
||||
// Data of the no swing check.
|
||||
public boolean noSwingArmSwung;
|
||||
|
||||
}
|
||||
|
96
src/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java
Normal file
96
src/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java
Normal file
@ -0,0 +1,96 @@
|
||||
package fr.neatmonster.nocheatplus.checks.fight;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckEvent;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
|
||||
/*
|
||||
* M"""""""`YM MP""""""`MM oo
|
||||
* M mmmm. M M mmmmm..M
|
||||
* M MMMMM M .d8888b. M. `YM dP dP dP dP 88d888b. .d8888b.
|
||||
* M MMMMM M 88' `88 MMMMMMM. M 88 88 88 88 88' `88 88' `88
|
||||
* M MMMMM M 88. .88 M. .MMM' M 88.88b.88' 88 88 88 88. .88
|
||||
* * M MMMMM M `88888P' Mb. .dM 8888P Y8P dP dP dP `8888P88
|
||||
* MMMMMMMMMMM MMMMMMMMMMM .88
|
||||
* d8888P
|
||||
*/
|
||||
/**
|
||||
* We require that the player moves his arm between attacks, this is basically what gets checked here.
|
||||
*/
|
||||
public class NoSwing extends Check {
|
||||
|
||||
/**
|
||||
* The event triggered by this check.
|
||||
*/
|
||||
public class NoSwingEvent extends CheckEvent {
|
||||
|
||||
/**
|
||||
* Instantiates a new no swing event.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
*/
|
||||
public NoSwingEvent(final Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a player.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
// Did he swing his arm before?
|
||||
if (data.noSwingArmSwung) {
|
||||
|
||||
// Yes, reward him with reduction of his violation level.
|
||||
data.noSwingArmSwung = false;
|
||||
data.noSwingVL *= 0.9D;
|
||||
} else {
|
||||
|
||||
// No, increase his violation level.
|
||||
data.noSwingVL += 1D;
|
||||
|
||||
// Dispatch a no swing event (API).
|
||||
final NoSwingEvent e = new NoSwingEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
|
||||
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
||||
// cancel the event.
|
||||
cancel = !e.isCancelled() && executeActions(player, cc.noSwingActions, data.noSwingVL);
|
||||
}
|
||||
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
|
||||
*/
|
||||
@Override
|
||||
public String getParameter(final ParameterName wildcard, final Player player) {
|
||||
if (wildcard == ParameterName.VIOLATIONS)
|
||||
return String.valueOf(Math.round(FightData.getData(player).noSwingVL));
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isEnabled(final Player player) {
|
||||
return !player.hasPermission(Permissions.FIGHT_NOSWING) && FightConfig.getConfig(player).noSwingCheck;
|
||||
}
|
||||
}
|
@ -226,6 +226,10 @@ public abstract class ConfPaths {
|
||||
public static final String FIGHT_KNOCKBACK_INTERVAL = FIGHT_KNOCKBACK + "interval";
|
||||
public static final String FIGHT_KNOCKBACK_ACTIONS = FIGHT_KNOCKBACK + "actions";
|
||||
|
||||
private static final String FIGHT_NOSWING = FIGHT + "noswing.";
|
||||
public static final String FIGHT_NOSWING_CHECK = FIGHT_NOSWING + "active";
|
||||
public static final String FIGHT_NOSWING_ACTIONS = FIGHT_NOSWING + "actions";
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
* d8b d8b e88 88e Y8b Y888P " 888 8e e88 888
|
||||
|
@ -65,7 +65,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.BLOCKBREAK_FASTBREAK_ACTIONS, "cancel vl>100 log:fastbreak:3:5:cif cancel");
|
||||
|
||||
set(ConfPaths.BLOCKBREAK_NOSWING_CHECK, true);
|
||||
set(ConfPaths.BLOCKBREAK_NOSWING_ACTIONS, "log:bbnoswing:3:2:if cancel");
|
||||
set(ConfPaths.BLOCKBREAK_NOSWING_ACTIONS, "log:noswing:3:2:if cancel");
|
||||
|
||||
set(ConfPaths.BLOCKBREAK_REACH_CHECK, true);
|
||||
set(ConfPaths.BLOCKBREAK_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel");
|
||||
@ -201,6 +201,9 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.FIGHT_KNOCKBACK_INTERVAL, 50L);
|
||||
set(ConfPaths.FIGHT_KNOCKBACK_ACTIONS, "cancel vl>50 log:knockback:0:5:cif cancel");
|
||||
|
||||
set(ConfPaths.FIGHT_NOSWING_CHECK, true);
|
||||
set(ConfPaths.FIGHT_NOSWING_ACTIONS, "log:noswing:0:5:cif cancel");
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
* d8b d8b e88 88e Y8b Y888P " 888 8e e88 888
|
||||
@ -258,7 +261,6 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".angle", start + "tried to hit multiple entities at the same time" + end);
|
||||
set(ConfPaths.STRINGS + ".ban", "ban [player]");
|
||||
set(ConfPaths.STRINGS + ".ban-ip", "ban-ip [ip]");
|
||||
set(ConfPaths.STRINGS + ".bbnoswing", start + "didn't swing arm" + end);
|
||||
set(ConfPaths.STRINGS + ".bdirection", start + "tried to interact with a block out of his line of sight" + end);
|
||||
set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end);
|
||||
set(ConfPaths.STRINGS + ".breach", start
|
||||
@ -277,6 +279,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
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);
|
||||
set(ConfPaths.STRINGS + ".nopwnage", start + "acted like a spambot (IP: [ip])" + end);
|
||||
set(ConfPaths.STRINGS + ".noswing", start + "didn't swing arm" + end);
|
||||
|
||||
// Update internal factory based on all the new entries to the "actions" section.
|
||||
regenerateActionLists();
|
||||
|
@ -119,6 +119,7 @@ public class Permissions {
|
||||
public static final String FIGHT_GODMODE = FIGHT + ".godmode";
|
||||
public static final String FIGHT_INSTANTHEAL = FIGHT + ".instantheal";
|
||||
public static final String FIGHT_KNOCKBACK = FIGHT + ".knockback";
|
||||
public static final String FIGHT_NOSWING = FIGHT + ".noswing";
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
|
Loading…
Reference in New Issue
Block a user