From 3b226dea6db22d18d53e16a2bdad12b4ad64e4a5 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 23 Nov 2012 16:16:05 +0100 Subject: [PATCH] Make bed-leave an extra check. --- .../nocheatplus/checks/CheckType.java | 1 + .../nocheatplus/checks/combined/BedLeave.java | 43 +++++++++++++++++++ .../checks/combined/CombinedConfig.java | 12 ++++++ .../checks/combined/CombinedData.java | 4 ++ .../checks/moving/MovingListener.java | 18 ++++++-- .../checks/moving/SurvivalFly.java | 34 --------------- .../nocheatplus/config/ConfPaths.java | 4 ++ .../nocheatplus/config/DefaultConfig.java | 12 +++++- .../nocheatplus/permissions/Permissions.java | 1 + 9 files changed, 89 insertions(+), 40 deletions(-) create mode 100644 src/fr/neatmonster/nocheatplus/checks/combined/BedLeave.java diff --git a/src/fr/neatmonster/nocheatplus/checks/CheckType.java b/src/fr/neatmonster/nocheatplus/checks/CheckType.java index 335acae2..139489de 100644 --- a/src/fr/neatmonster/nocheatplus/checks/CheckType.java +++ b/src/fr/neatmonster/nocheatplus/checks/CheckType.java @@ -68,6 +68,7 @@ public enum CheckType { COMBINED(CombinedConfig.factory, CombinedData.factory, Permissions.COMBINED), + COMBINED_BEDLEAVE(COMBINED, Permissions.COMBINED_BEDLEAVE), COMBINED_IMPROBABLE(COMBINED, Permissions.COMBINED_IMPROBABLE), FIGHT(FightConfig.factory, FightData.factory, Permissions.FIGHT), diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/BedLeave.java b/src/fr/neatmonster/nocheatplus/checks/combined/BedLeave.java new file mode 100644 index 00000000..f6f85832 --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/checks/combined/BedLeave.java @@ -0,0 +1,43 @@ +package fr.neatmonster.nocheatplus.checks.combined; + +import org.bukkit.entity.Player; + +import fr.neatmonster.nocheatplus.checks.Check; +import fr.neatmonster.nocheatplus.checks.CheckType; + +public class BedLeave extends Check { + + public BedLeave() { + super(CheckType.COMBINED_BEDLEAVE); + } + + /** + * Checks a player. + * + * @param player + * the player + * @return Location to teleport to if it is a violation. + */ + public boolean checkBed(final Player player) { + final CombinedData data = CombinedData.getData(player); + + boolean cancel = false; + // Check if the player had been in bed at all. + if (!data.wasInBed) { + // Violation ... + data.bedLeaveVL += 1D; + + // TODO: add tag + + // And return if we need to do something or not. + if (executeActions(player, data.bedLeaveVL, 1D, CombinedConfig.getConfig(player).bedLeaveActions)){ + cancel = true; + } + } else{ + // He has, everything is alright. + data.wasInBed = false; + } + return cancel; + } + +} diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java index e6de7847..97498bd2 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedConfig.java @@ -43,7 +43,13 @@ public class CombinedConfig extends ACheckConfig { } return cc; } + + + // Bedleave check. + public final boolean bedLeaveCheck; + public final ActionList bedLeaveActions; + // Improbable check /** Do mind that this flag is not used by all components. */ public final boolean improbableCheck; public final float improbableLevel; @@ -67,6 +73,10 @@ public class CombinedConfig extends ACheckConfig { public CombinedConfig(final ConfigFile config) { super(config, ConfPaths.COMBINED); + + bedLeaveCheck = config.getBoolean(ConfPaths.COMBINED_BEDLEAVE_CHECK, false); + bedLeaveActions = config.getOptimizedActionList(ConfPaths.COMBINED_BEDLEAVE_ACTIONS, Permissions.COMBINED_BEDLEAVE); + improbableCheck = config.getBoolean(ConfPaths.COMBINED_IMPROBABLE_CHECK, false); improbableLevel = (float) config.getDouble(ConfPaths.COMBINED_IMPROBABLE_LEVEL, 300); improbableActions = config.getOptimizedActionList(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, Permissions.COMBINED_IMPROBABLE); @@ -119,6 +129,8 @@ public class CombinedConfig extends ACheckConfig { switch(checkType){ case COMBINED_IMPROBABLE: return improbableCheck; + case COMBINED_BEDLEAVE: + return bedLeaveCheck; } return false; } diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java index 89a7174e..bac2e050 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedData.java @@ -51,6 +51,7 @@ public class CombinedData extends ACheckData { } // VLs + public double bedLeaveVL = 0; public double improbableVL = 0; // Invulnerable management: @@ -65,6 +66,9 @@ public class CombinedData extends ACheckData { // General penalty time (used for fighting mainly, set by yawrate check). public long timeFreeze = 0; + // Bedleave check + public boolean wasInBed = false; + // Improbable check public final ActionFrequency improbableCount = new ActionFrequency(20, 3000); diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index c45e1ec3..0504baa9 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -37,6 +37,7 @@ import org.bukkit.util.Vector; import fr.neatmonster.nocheatplus.NoCheatPlus; import fr.neatmonster.nocheatplus.checks.CheckListener; import fr.neatmonster.nocheatplus.checks.CheckType; +import fr.neatmonster.nocheatplus.checks.combined.BedLeave; import fr.neatmonster.nocheatplus.checks.combined.Combined; import fr.neatmonster.nocheatplus.checks.combined.CombinedData; import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; @@ -111,6 +112,9 @@ public class MovingListener extends CheckListener{ /** The Passable (simple no-clip) check.*/ private final Passable passable = new Passable(); + /** Combined check but handled here (subject to change!) */ + private final BedLeave bedLeave = new BedLeave(); + /** * Unused instances.
* TODO: Not sure this is needed by contract, might be better due to cascading events in case of actions. @@ -211,13 +215,19 @@ public class MovingListener extends CheckListener{ * |___/ */ final Player player = event.getPlayer(); - final MovingData data = MovingData.getData(player); - final MovingConfig cc = MovingConfig.getConfig(player); - if (shouldCheckSurvivalFly(player, data, cc)) { + if (bedLeave.isEnabled(player) && bedLeave.checkBed(player)) { // Check if the player has to be reset. - final Location target = survivalFly.checkBed(player, data); // To cancel the event, we teleport the player. + final Location loc = player.getLocation(); + final MovingData data = MovingData.getData(player); + Location target = data.setBack; + if (target == null){ + // TODO: Add something to guess the best set back location (possibly data.guessSetBack(Location)). + target = loc; + } + target.setPitch(loc.getPitch()); + target.setYaw(loc.getYaw()); if (target != null){ if (noFall.isEnabled(player)){ // Check if to deal damage. diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java index 4de5e1c7..be9ea43b 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/SurvivalFly.java @@ -64,40 +64,6 @@ public class SurvivalFly extends Check { super(CheckType.MOVING_SURVIVALFLY); } - /** - * Checks a player. - * - * @param player - * the player - * @return Location to teleport to if it is a violation. - */ - public Location checkBed(final Player player, final MovingData data) { - Location newTo = null; - // Check if the player had been in bed at all. - if (!data.sfWasInBed) { - // Violation ... - data.survivalFlyVL += 100D; - - // TODO: add tag - - // And return if we need to do something or not. - if (executeActions(player, data.survivalFlyVL, 100D, MovingConfig.getConfig(player).survivalFlyActions)){ - final Location loc = player.getLocation(); - newTo = data.setBack; - if (newTo == null){ - // TODO: Add something to guess the best set back location (possibly data.guessSetBack(Location)). - newTo = loc; - } - newTo.setPitch(loc.getPitch()); - newTo.setYaw(loc.getYaw()); - } - } else{ - // He has, everything is alright. - data.sfWasInBed = false; - } - return newTo; - } - /** * Checks a player. * diff --git a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java index 8b2c07c0..14a0d3f4 100644 --- a/src/fr/neatmonster/nocheatplus/config/ConfPaths.java +++ b/src/fr/neatmonster/nocheatplus/config/ConfPaths.java @@ -299,6 +299,10 @@ public abstract class ConfPaths { */ public static final String COMBINED = CHECKS + "combined."; + private static final String COMBINED_BEDLEAVE = COMBINED + "bedleave."; + public static final String COMBINED_BEDLEAVE_CHECK = COMBINED_BEDLEAVE + "active"; + public static final String COMBINED_BEDLEAVE_ACTIONS = COMBINED_BEDLEAVE + "actions"; + private static final String COMBINED_IMPROBABLE = COMBINED + "improbable."; public static final String COMBINED_IMPROBABLE_CHECK = COMBINED_IMPROBABLE + "active"; public static final String COMBINED_IMPROBABLE_LEVEL = COMBINED_IMPROBABLE + "level"; diff --git a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java index 03ad3249..e36785f7 100644 --- a/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java +++ b/src/fr/neatmonster/nocheatplus/config/DefaultConfig.java @@ -21,7 +21,10 @@ import org.bukkit.Material; */ public class DefaultConfig extends ConfigFile { - /** NCP build needed for this config. */ + /** + * NCP build needed for this config. + * (Should only increment with changing or removing paths.) + */ public static final int buildNumber = 256; /** @@ -234,12 +237,15 @@ public class DefaultConfig extends ConfigFile { /* * Combined ! */ + + set(ConfPaths.COMBINED_BEDLEAVE_CHECK, true); + set(ConfPaths.COMBINED_BEDLEAVE_ACTIONS, "cancel log:bedleave:0:5:if vl>2 cancel log:bedleave:0:5:if cmd:kickbedleave"); + set(ConfPaths.COMBINED_IMPROBABLE_CHECK , true); set(ConfPaths.COMBINED_IMPROBABLE_LEVEL, 300); // set(ConfPaths.COMBINED_IMPROBABLE_FASTBREAK_CHECK, false); set(ConfPaths.COMBINED_IMPROBABLE_ACTIONS, "cancel log:improbable:2:8:if"); - set(ConfPaths.COMBINED_INVULNERABLE_CHECK, true); set(ConfPaths.COMBINED_INVULNERABLE_TRIGGERS_ALWAYS, false); set(ConfPaths.COMBINED_INVULNERABLE_TRIGGERS_FALLDISTANCE, true); @@ -393,6 +399,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.STRINGS + ".ban-ip", "ban-ip [ip]"); set(ConfPaths.STRINGS + ".bbfrequency", start + "tried to break too many blocks within time frame" + end); set(ConfPaths.STRINGS + ".bdirection", start + "tried to interact with a block out of his line of sight" + end); + set(ConfPaths.STRINGS + ".bedleave", start + "sends bed leave packets (was not in bed)" + end); set(ConfPaths.STRINGS + ".bpspeed", start + "tried to throw projectiles too quickly" + end); set(ConfPaths.STRINGS + ".breach", start + "tried to interact with a block over distance [reachdistance] block(s)" + end); @@ -420,6 +427,7 @@ public class DefaultConfig extends ConfigFile { set(ConfPaths.STRINGS + ".instantbow", start + "fires bow too fast" + end); set(ConfPaths.STRINGS + ".instanteat", start + "eats food [food] too fast" + end); set(ConfPaths.STRINGS + ".kick", "kick [player]"); + set(ConfPaths.STRINGS + ".kickbedleave", "ncp delay ncp kick [player] Go find a bed!"); set(ConfPaths.STRINGS + ".kickcaptcha", "ncp kick [player] Enter the captcha!"); set(ConfPaths.STRINGS + ".kickchat1", "ncp tempkick [player] 1 You're still not allowed to spam!"); set(ConfPaths.STRINGS + ".kickchat5", "ncp tempkick [player] 5 You're not intended to spam!"); diff --git a/src/fr/neatmonster/nocheatplus/permissions/Permissions.java b/src/fr/neatmonster/nocheatplus/permissions/Permissions.java index fffa18d5..11d2a8c8 100644 --- a/src/fr/neatmonster/nocheatplus/permissions/Permissions.java +++ b/src/fr/neatmonster/nocheatplus/permissions/Permissions.java @@ -119,6 +119,7 @@ public class Permissions { * Combined ! */ public static final String COMBINED = CHECKS + ".combined"; + public static final String COMBINED_BEDLEAVE = COMBINED + ".bedleave"; public static final String COMBINED_IMPROBABLE = COMBINED + ".improbable"; /*