mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-11-07 03:02:11 +01:00
[Development] NoSwing check added for BlockPlace events and some more
fixes.
This commit is contained in:
parent
ad6af2bc14
commit
28ae0a2bef
@ -21,12 +21,12 @@ package fr.neatmonster.nocheatplus.actions;
|
||||
* Some wildcards that are used in commands and log messages.
|
||||
*/
|
||||
public enum ParameterName {
|
||||
ATTACKS_LIMIT("attackslimit"),
|
||||
CHECK("check"),
|
||||
DISTANCE("distance"),
|
||||
FALL_DISTANCE("falldistance"),
|
||||
FOOD("food"),
|
||||
IP("ip"),
|
||||
LIMIT("limit"),
|
||||
LOCATION_FROM("locationfrom"),
|
||||
LOCATION_TO("locationto"),
|
||||
PACKETS("packets"),
|
||||
|
@ -67,6 +67,9 @@ public class BlockPlaceConfig {
|
||||
public final long fastPlaceInterval;
|
||||
public final ActionList fastPlaceActions;
|
||||
|
||||
public final boolean noSwingCheck;
|
||||
public final ActionList noSwingActions;
|
||||
|
||||
public final boolean reachCheck;
|
||||
public final ActionList reachActions;
|
||||
|
||||
@ -89,6 +92,9 @@ public class BlockPlaceConfig {
|
||||
fastPlaceInterval = data.getLong(ConfPaths.BLOCKPLACE_FASTPLACE_INTERVAL);
|
||||
fastPlaceActions = data.getActionList(ConfPaths.BLOCKPLACE_FASTPLACE_ACTIONS, Permissions.BLOCKPLACE_FASTPLACE);
|
||||
|
||||
noSwingCheck = data.getBoolean(ConfPaths.BLOCKPLACE_NOSWING_CHECK);
|
||||
noSwingActions = data.getActionList(ConfPaths.BLOCKPLACE_NOSWING_ACTIONS, Permissions.BLOCKPLACE_NOSWING);
|
||||
|
||||
reachCheck = data.getBoolean(ConfPaths.BLOCKPLACE_REACH_CHECK);
|
||||
reachActions = data.getActionList(ConfPaths.BLOCKPLACE_REACH_ACTIONS, Permissions.BLOCKPLACE_REACH);
|
||||
|
||||
|
@ -46,6 +46,7 @@ public class BlockPlaceData {
|
||||
// Violation levels.
|
||||
public double directionVL;
|
||||
public double fastPlaceVL;
|
||||
public double noSwingVL;
|
||||
public double reachVL;
|
||||
public double speedVL;
|
||||
|
||||
@ -53,6 +54,9 @@ public class BlockPlaceData {
|
||||
public long fastPlaceLastTime;
|
||||
public boolean fastPlaceLastRefused;
|
||||
|
||||
// Data of the no swing check.
|
||||
public boolean noSwingArmSwung;
|
||||
|
||||
// Data of the reach check.
|
||||
public double reachDistance;
|
||||
|
||||
|
@ -9,6 +9,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.ProjectileLaunchEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
/*
|
||||
@ -36,6 +37,7 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
public class BlockPlaceListener implements Listener {
|
||||
private final Direction direction = new Direction();
|
||||
private final FastPlace fastPlace = new FastPlace();
|
||||
private final NoSwing noSwing = new NoSwing();
|
||||
private final Reach reach = new Reach();
|
||||
private final Speed speed = new Speed();
|
||||
|
||||
@ -65,22 +67,49 @@ public class BlockPlaceListener implements Listener {
|
||||
boolean cancelled = false;
|
||||
|
||||
// First, the fast place check.
|
||||
if (fastPlace.isEnabled(player))
|
||||
cancelled = fastPlace.check(player, block);
|
||||
if (fastPlace.isEnabled(player) && fastPlace.check(player, block))
|
||||
cancelled = true;
|
||||
|
||||
// Second, the reach check.
|
||||
if (!cancelled && reach.isEnabled(player))
|
||||
cancelled = reach.check(player, block.getLocation());
|
||||
// Second, the no swing check.
|
||||
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player))
|
||||
cancelled = true;
|
||||
|
||||
// Third, the direction check.
|
||||
if (!cancelled && direction.isEnabled(player))
|
||||
cancelled = direction.check(player, block.getLocation(), event.getBlockAgainst().getLocation());
|
||||
// Third, the reach check.
|
||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation()))
|
||||
cancelled = true;
|
||||
|
||||
// Fourth, the direction check.
|
||||
if (!cancelled && direction.isEnabled(player)
|
||||
&& direction.check(player, block.getLocation(), event.getBlockAgainst().getLocation()))
|
||||
cancelled = true;
|
||||
|
||||
// If one of the checks requested to cancel the event, do so.
|
||||
if (cancelled)
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
|
||||
/**
|
||||
* We listen to PlayerAnimation events because it is (currently) equivalent to "player swings arm" and we want to
|
||||
* check if he did that between block breaks.
|
||||
*
|
||||
* @param event
|
||||
* the event
|
||||
*/
|
||||
@EventHandler(
|
||||
priority = EventPriority.MONITOR)
|
||||
public void onPlayerAnimation(final PlayerAnimationEvent event) {
|
||||
/*
|
||||
* ____ _ _ _ _ _
|
||||
* | _ \| | __ _ _ _ ___ _ __ / \ _ __ (_)_ __ ___ __ _| |_(_) ___ _ __
|
||||
* | |_) | |/ _` | | | |/ _ \ '__| / _ \ | '_ \| | '_ ` _ \ / _` | __| |/ _ \| '_ \
|
||||
* | __/| | (_| | |_| | __/ | / ___ \| | | | | | | | | | (_| | |_| | (_) | | | |
|
||||
* |_| |_|\__,_|\__, |\___|_| /_/ \_\_| |_|_|_| |_| |_|\__,_|\__|_|\___/|_| |_|
|
||||
* |___/
|
||||
*/
|
||||
// Just set a flag to true when the arm was swung.
|
||||
BlockPlaceData.getData(event.getPlayer()).noSwingArmSwung = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* We listener to PlayerInteract events to prevent players from spamming the server with monster eggs.
|
||||
*/
|
||||
|
@ -1,6 +1,7 @@
|
||||
package fr.neatmonster.nocheatplus.checks.fight;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
@ -52,6 +53,11 @@ public class Knockback extends Check {
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
// If the item has the knockback enchantment, do not check.
|
||||
if (player.getItemInHand().containsEnchantment(Enchantment.KNOCKBACK)
|
||||
|| player.getItemInHand().containsEnchantment(Enchantment.ARROW_KNOCKBACK))
|
||||
return false;
|
||||
|
||||
// How long ago has the player started sprinting?
|
||||
if (data.knockbackSprintTime > 0L
|
||||
&& System.currentTimeMillis() - data.knockbackSprintTime < cc.knockbackInterval) {
|
||||
|
@ -88,7 +88,7 @@ public class Speed extends Check {
|
||||
public String getParameter(final ParameterName wildcard, final Player player) {
|
||||
if (wildcard == ParameterName.VIOLATIONS)
|
||||
return String.valueOf(Math.round(FightData.getData(player).speedVL));
|
||||
else if (wildcard == ParameterName.ATTACKS_LIMIT)
|
||||
else if (wildcard == ParameterName.LIMIT)
|
||||
return String.valueOf(Math.round(FightConfig.getConfig(player).speedLimit));
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
|
@ -3,7 +3,6 @@ package fr.neatmonster.nocheatplus.checks.moving;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -75,8 +74,6 @@ public class NoFall extends Check {
|
||||
if (cc.noFallAggressive && (from.isInLiquid() || from.isOnGround() || from.isOnLadder())
|
||||
&& (to.isInLiquid() || to.isOnGround() || to.isOnLadder()) && from.getY() <= to.getY()
|
||||
&& player.getFallDistance() > 3F) {
|
||||
// Bukkit.broadcastMessage(ChatColor.RED + "Problem with the no fall check!"); // TODO
|
||||
|
||||
data.noFallDistance = player.getFallDistance();
|
||||
|
||||
// Increment violation level.
|
||||
@ -105,8 +102,6 @@ public class NoFall extends Check {
|
||||
// We want to know if the fallDistance recorded by the game is smaller than the fall distance recorded by the
|
||||
// plugin.
|
||||
if (difference > 1F && (to.isInWater() || to.isOnGround() || to.isOnLadder()) && data.noFallDistance > 2F) {
|
||||
Bukkit.broadcastMessage(ChatColor.RED + "Problem with the no fall check!"); // TODO
|
||||
|
||||
// Increment violation level.
|
||||
data.noFallVL += difference;
|
||||
|
||||
|
@ -281,9 +281,6 @@ public class SurvivalFly extends Check {
|
||||
|
||||
// Did the player move in unexpected ways?
|
||||
if (result > 0D) {
|
||||
// Bukkit.broadcastMessage(ChatColor.RED + player.getName() + ": problem with the survival fly check!"); //
|
||||
// TODO
|
||||
|
||||
// Increment violation counter.
|
||||
data.survivalFlyVL += result;
|
||||
|
||||
|
@ -89,6 +89,10 @@ public abstract class ConfPaths {
|
||||
public static final String BLOCKPLACE_FASTPLACE_INTERVAL = BLOCKPLACE_FASTPLACE + "interval";
|
||||
public static final String BLOCKPLACE_FASTPLACE_ACTIONS = BLOCKPLACE_FASTPLACE + "actions";
|
||||
|
||||
private static final String BLOCKPLACE_NOSWING = BLOCKPLACE + "noswing.";
|
||||
public static final String BLOCKPLACE_NOSWING_CHECK = BLOCKPLACE_NOSWING + "active";
|
||||
public static final String BLOCKPLACE_NOSWING_ACTIONS = BLOCKPLACE_NOSWING + "actions";
|
||||
|
||||
private static final String BLOCKPLACE_REACH = BLOCKPLACE + "reach.";
|
||||
public static final String BLOCKPLACE_REACH_CHECK = BLOCKPLACE_REACH + "active";
|
||||
public static final String BLOCKPLACE_REACH_ACTIONS = BLOCKPLACE_REACH + "actions";
|
||||
|
@ -88,6 +88,9 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.BLOCKPLACE_REACH_CHECK, true);
|
||||
set(ConfPaths.BLOCKPLACE_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel");
|
||||
|
||||
set(ConfPaths.BLOCKPLACE_NOSWING_CHECK, true);
|
||||
set(ConfPaths.BLOCKPLACE_NOSWING_ACTIONS, "log:noswing:3:2:if cancel");
|
||||
|
||||
set(ConfPaths.BLOCKPLACE_SPEED_CHECK, true);
|
||||
set(ConfPaths.BLOCKPLACE_SPEED_INTERVAL, 45L);
|
||||
set(ConfPaths.BLOCKPLACE_SPEED_ACTIONS,
|
||||
@ -302,7 +305,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 + ".fspeed", start + "tried to attack more than [attackslimit] times per second" + end);
|
||||
set(ConfPaths.STRINGS + ".fspeed", start + "tried to attack more than [limit] times per second" + end);
|
||||
set(ConfPaths.STRINGS + ".godmode", start + "avoided taking damage or lagging" + end);
|
||||
set(ConfPaths.STRINGS + ".instantbow", start + "fires bow to fast" + end);
|
||||
set(ConfPaths.STRINGS + ".instanteat", start + "eats food [food] too fast" + end);
|
||||
|
@ -87,7 +87,8 @@ public class Permissions {
|
||||
*/
|
||||
private static final String BLOCKPLACE = CHECKS + ".blockplace";
|
||||
public static final String BLOCKPLACE_DIRECTION = BLOCKPLACE + ".direction";
|
||||
public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + "fastplace";
|
||||
public static final String BLOCKPLACE_FASTPLACE = BLOCKPLACE + ".fastplace";
|
||||
public static final String BLOCKPLACE_NOSWING = BLOCKPLACE + ".noswing";
|
||||
public static final String BLOCKPLACE_REACH = BLOCKPLACE + ".reach";
|
||||
public static final String BLOCKPLACE_SPEED = BLOCKPLACE + ".speed";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user