mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-04 23:07:44 +01:00
[Development] Removed BlockInteractNoSwing check. Some little tweaking.
If only it could be the last commmit... /bed
This commit is contained in:
parent
e783dfbe7c
commit
58f4f838f9
@ -40,7 +40,6 @@ public enum CheckType {
|
||||
|
||||
BLOCKINTERACT(BlockInteractConfig.class, BlockInteractData.class),
|
||||
BLOCKINTERACT_DIRECTION(BLOCKINTERACT, "direction", Permissions.BLOCKINTERACT_DIRECTION),
|
||||
BLOCKINTERACT_NOSWING(BLOCKINTERACT, "noSwing", Permissions.BLOCKINTERACT_NOSWING),
|
||||
BLOCKINTERACT_REACH(BLOCKINTERACT, "reach", Permissions.BLOCKINTERACT_REACH),
|
||||
|
||||
BLOCKPLACE(BlockPlaceConfig.class, BlockPlaceData.class),
|
||||
|
@ -46,7 +46,6 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
BlockBreakConfig.getConfig(player);
|
||||
final BlockBreakData data = BlockBreakData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -62,9 +62,6 @@ public class BlockInteractConfig {
|
||||
public final boolean directionCheck;
|
||||
public final ActionList directionActions;
|
||||
|
||||
public final boolean noSwingCheck;
|
||||
public final ActionList noSwingActions;
|
||||
|
||||
public final boolean reachCheck;
|
||||
public final ActionList reachActions;
|
||||
|
||||
@ -79,9 +76,6 @@ public class BlockInteractConfig {
|
||||
directionActions = data.getActionList(ConfPaths.BLOCKINTERACT_DIRECTION_ACTIONS,
|
||||
Permissions.BLOCKINTERACT_DIRECTION);
|
||||
|
||||
noSwingCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_NOSWING_CHECK);
|
||||
noSwingActions = data.getActionList(ConfPaths.BLOCKINTERACT_NOSWING_ACTIONS, Permissions.BLOCKINTERACT_NOSWING);
|
||||
|
||||
reachCheck = data.getBoolean(ConfPaths.BLOCKINTERACT_REACH_CHECK);
|
||||
reachActions = data.getActionList(ConfPaths.BLOCKINTERACT_REACH_ACTIONS, Permissions.BLOCKINTERACT_REACH);
|
||||
}
|
||||
|
@ -44,14 +44,9 @@ public class BlockInteractData {
|
||||
}
|
||||
|
||||
// Violation levels.
|
||||
public double directionVL;
|
||||
public double noSwingVL;
|
||||
public double reachVL;
|
||||
|
||||
// Data of the no swing check.
|
||||
public boolean noSwingArmSwung;
|
||||
public long noSwingLastTime;
|
||||
public double directionVL;
|
||||
public double reachVL;
|
||||
|
||||
// Data of the reach check.
|
||||
public double reachDistance;
|
||||
public double reachDistance;
|
||||
}
|
||||
|
@ -1,15 +1,11 @@
|
||||
package fr.neatmonster.nocheatplus.checks.blockinteract;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
|
||||
/*
|
||||
@ -35,37 +31,8 @@ import org.bukkit.event.player.PlayerInteractEvent;
|
||||
* @see BlockInteractEvent
|
||||
*/
|
||||
public class BlockInteractListener implements Listener {
|
||||
private final Direction direction = new Direction();
|
||||
private final NoSwing noSwing = new NoSwing();
|
||||
private final Reach reach = new Reach();
|
||||
|
||||
private final Material[] materials = new Material[] {Material.BED_BLOCK, Material.BURNING_FURNACE,
|
||||
Material.BREWING_STAND, Material.CAKE_BLOCK, Material.CAULDRON, Material.CHEST, Material.DIODE_BLOCK_OFF,
|
||||
Material.DIODE_BLOCK_ON, Material.DISPENSER, Material.DRAGON_EGG, Material.ENCHANTMENT_TABLE,
|
||||
Material.ENDER_CHEST, Material.FENCE_GATE, Material.FURNACE, Material.IRON_DOOR_BLOCK, Material.LEVER,
|
||||
Material.NOTE_BLOCK, Material.STONE_BUTTON, Material.TRAP_DOOR, Material.WOODEN_DOOR, Material.WORKBENCH};
|
||||
|
||||
/**
|
||||
* We listen to PlayerAnimation events because it is (currently) equivalent to "player swings arm" and we want to
|
||||
* check if he did that between interactions with blocks.
|
||||
*
|
||||
* @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.
|
||||
BlockInteractData.getData(event.getPlayer()).noSwingArmSwung = true;
|
||||
}
|
||||
private final Direction direction = new Direction();
|
||||
private final Reach reach = new Reach();
|
||||
|
||||
/**
|
||||
* We listen to PlayerInteractEvent events for obvious reasons.
|
||||
@ -94,19 +61,11 @@ public class BlockInteractListener implements Listener {
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
// First the no swing check.
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK
|
||||
|| Arrays.asList(materials).contains(event.getClickedBlock().getType())) {
|
||||
if (noSwing.isEnabled(player) && noSwing.check(player))
|
||||
cancelled = true;
|
||||
} else
|
||||
BlockInteractData.getData(player).noSwingArmSwung = false;
|
||||
|
||||
// Second the reach check.
|
||||
// First the reach check.
|
||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, block.getLocation()))
|
||||
cancelled = true;
|
||||
|
||||
// Third the direction check
|
||||
// Second the direction check
|
||||
if (!cancelled && direction.isEnabled(player) && direction.check(player, block.getLocation()))
|
||||
cancelled = true;
|
||||
|
||||
|
@ -39,7 +39,6 @@ public class Direction extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
BlockInteractConfig.getConfig(player);
|
||||
final BlockInteractData data = BlockInteractData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -1,64 +0,0 @@
|
||||
package fr.neatmonster.nocheatplus.checks.blockinteract;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckType;
|
||||
|
||||
/*
|
||||
* 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 block breaks, this is what gets checked here.
|
||||
*/
|
||||
public class NoSwing extends Check {
|
||||
|
||||
/**
|
||||
* Instantiates a new no swing check.
|
||||
*/
|
||||
public NoSwing() {
|
||||
super(CheckType.BLOCKINTERACT_NOSWING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a player.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
BlockInteractConfig.getConfig(player);
|
||||
final BlockInteractData data = BlockInteractData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
if (System.currentTimeMillis() - data.noSwingLastTime > 3L)
|
||||
// Did he swing his arm before?
|
||||
if (data.noSwingArmSwung) {
|
||||
// "Consume" the flag.
|
||||
data.noSwingArmSwung = false;
|
||||
// Reward with lowering of the violation level.
|
||||
data.noSwingVL *= 0.9D;
|
||||
} else {
|
||||
// He failed, increase violation level.
|
||||
data.noSwingVL += 1D;
|
||||
|
||||
// Execute whatever actions are associated with this check and the violation level and find out if we
|
||||
// should cancel the event.
|
||||
cancel = executeActions(player);
|
||||
}
|
||||
|
||||
data.noSwingLastTime = System.currentTimeMillis();
|
||||
|
||||
return cancel;
|
||||
|
||||
}
|
||||
}
|
@ -46,7 +46,6 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
BlockInteractConfig.getConfig(player);
|
||||
final BlockInteractData data = BlockInteractData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -39,7 +39,6 @@ public class Direction extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location placed, final Location against) {
|
||||
BlockPlaceConfig.getConfig(player);
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -35,7 +35,6 @@ public class NoSwing extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
BlockPlaceConfig.getConfig(player);
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -46,7 +46,6 @@ public class Reach extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Location location) {
|
||||
BlockPlaceConfig.getConfig(player);
|
||||
final BlockPlaceData data = BlockPlaceData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -36,7 +36,6 @@ public class Color extends Check {
|
||||
* @return the string
|
||||
*/
|
||||
public String check(final Player player, final String message) {
|
||||
ChatConfig.getConfig(player);
|
||||
final ChatData data = ChatData.getData(player);
|
||||
|
||||
// If the message contains colors...
|
||||
|
@ -39,7 +39,6 @@ public class GodMode extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -34,7 +34,6 @@ public class InstantHeal extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -35,7 +35,6 @@ public class NoSwing extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -36,7 +36,6 @@ public class InstantBow extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final float force) {
|
||||
InventoryConfig.getConfig(player);
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -37,7 +37,6 @@ public class InstantEat extends Check {
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final int level) {
|
||||
InventoryConfig.getConfig(player);
|
||||
final InventoryData data = InventoryData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
@ -58,7 +58,6 @@ public class MorePackets extends Check {
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final PlayerLocation from, final PlayerLocation to) {
|
||||
MovingConfig.getConfig(player);
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
Location newTo = null;
|
||||
|
@ -57,7 +57,6 @@ public class MorePacketsVehicle extends Check {
|
||||
* @return the location
|
||||
*/
|
||||
public Location check(final Player player, final Location from, final Location to) {
|
||||
MovingConfig.getConfig(player);
|
||||
final MovingData data = MovingData.getData(player);
|
||||
|
||||
Location newTo = null;
|
||||
|
@ -42,7 +42,7 @@ public class SurvivalFly extends Check {
|
||||
private static final double COBWEB_ASCEND = 0.02D + MARGIN;
|
||||
|
||||
/** The vertical speed limit when descending into web. */
|
||||
private static final double COBWEB_DESCEND = 0.062D + MARGIN;
|
||||
private static final double COBWEB_DESCEND = 0.09D + MARGIN;
|
||||
|
||||
/** The horizontal speed limit when moving into web. */
|
||||
private static final double COBWEB_MOVE = 0.11D;
|
||||
|
@ -84,10 +84,6 @@ public abstract class ConfPaths {
|
||||
public static final String BLOCKINTERACT_DIRECTION_CHECK = BLOCKINTERACT_DIRECTION + "active";
|
||||
public static final String BLOCKINTERACT_DIRECTION_ACTIONS = BLOCKINTERACT_DIRECTION + "actions";
|
||||
|
||||
private static final String BLOCKINTERACT_NOSWING = BLOCKINTERACT + "noswing.";
|
||||
public static final String BLOCKINTERACT_NOSWING_CHECK = BLOCKINTERACT_NOSWING + "active";
|
||||
public static final String BLOCKINTERACT_NOSWING_ACTIONS = BLOCKINTERACT_NOSWING + "actions";
|
||||
|
||||
private static final String BLOCKINTERACT_REACH = BLOCKINTERACT + "reach.";
|
||||
public static final String BLOCKINTERACT_REACH_CHECK = BLOCKINTERACT_REACH + "active";
|
||||
public static final String BLOCKINTERACT_REACH_ACTIONS = BLOCKINTERACT_REACH + "actions";
|
||||
|
@ -81,9 +81,6 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.BLOCKINTERACT_DIRECTION_CHECK, true);
|
||||
set(ConfPaths.BLOCKINTERACT_DIRECTION_ACTIONS, "cancel vl>10 log:bdirection:0:3:if cancel");
|
||||
|
||||
set(ConfPaths.BLOCKINTERACT_NOSWING_CHECK, true);
|
||||
set(ConfPaths.BLOCKINTERACT_NOSWING_ACTIONS, "log:noswing:3:2:if cancel");
|
||||
|
||||
set(ConfPaths.BLOCKINTERACT_REACH_CHECK, true);
|
||||
set(ConfPaths.BLOCKINTERACT_REACH_ACTIONS, "cancel vl>5 log:breach:0:2:if cancel");
|
||||
|
||||
|
@ -87,7 +87,6 @@ public class Permissions {
|
||||
*/
|
||||
private static final String BLOCKINTERACT = CHECKS + ".blockinteract";
|
||||
public static final String BLOCKINTERACT_DIRECTION = BLOCKINTERACT + ".direction";
|
||||
public static final String BLOCKINTERACT_NOSWING = BLOCKINTERACT + ".noswing";
|
||||
public static final String BLOCKINTERACT_REACH = BLOCKINTERACT + ".reach";
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user