Make bed-leave an extra check.

This commit is contained in:
asofold 2012-11-23 16:16:05 +01:00
parent b0a56ef743
commit 3b226dea6d
9 changed files with 89 additions and 40 deletions

View File

@ -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),

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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);

View File

@ -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.<br>
* 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.

View File

@ -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.
*

View File

@ -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";

View File

@ -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!");

View File

@ -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";
/*