New Checks fight.reach and fight.speed

This commit is contained in:
Evenprime 2012-01-31 17:51:29 +01:00
parent 22a82b8beb
commit 11827a89df
10 changed files with 226 additions and 11 deletions

View File

@ -78,6 +78,10 @@ permissions:
description: Allow a player to attack players and monster even if they are not in his field of view
nocheat.checks.fight.noswing:
description: Allow a player to fight without swinging their arm
nocheat.checks.fight.reach:
description: Allow a player to fight over bigger distances than usual
nocheat.checks.fight.speed:
description: Allow a player to attack faster than usual
nocheat.checks.inventory:
description: Allow the player to bypass all inventory checks
children:

View File

@ -17,11 +17,17 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import cc.co.evenprime.bukkit.nocheat.checks.WorkaroundsListener;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.BlockPlaceCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.checks.chat.ChatCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.chat.ChatData;
import cc.co.evenprime.bukkit.nocheat.checks.fight.FightCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.fight.FightData;
import cc.co.evenprime.bukkit.nocheat.checks.inventory.InventoryCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.inventory.InventoryData;
import cc.co.evenprime.bukkit.nocheat.checks.moving.MovingCheckListener;
import cc.co.evenprime.bukkit.nocheat.checks.moving.MovingData;
import cc.co.evenprime.bukkit.nocheat.command.CommandHandler;
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager;
@ -89,6 +95,13 @@ public class NoCheat extends JavaPlugin implements Listener {
eventManagers.add(new FightCheckListener(this));
eventManagers.add(new InventoryCheckListener(this));
new MovingData();
new BlockBreakData();
new BlockPlaceData();
new ChatData();
new FightData();
new InventoryData();
// Then set up a task to monitor server lag
if(lagMeasureTask == null) {
lagMeasureTask = new LagMeasureTask(this);

View File

@ -26,8 +26,10 @@ public class FightCheckListener implements Listener, EventManager {
public FightCheckListener(NoCheat plugin) {
this.checks = new ArrayList<FightCheck>(3);
this.checks.add(new SpeedCheck(plugin));
this.checks.add(new NoswingCheck(plugin));
this.checks.add(new DirectionCheck(plugin));
this.checks.add(new ReachCheck(plugin));
this.plugin = plugin;
}
@ -114,6 +116,10 @@ public class FightCheckListener implements Listener, EventManager {
s.add("fight.direction");
if(f.check && f.noswingCheck)
s.add("fight.noswing");
if(f.check && f.reachCheck)
s.add("fight.reach");
if(f.check && f.speedCheck)
s.add("fight.speed");
return s;
}
}

View File

@ -14,6 +14,13 @@ public class FightConfig implements ConfigItem {
public final long directionPenaltyTime;
public final boolean noswingCheck;
public final ActionList noswingActions;
public final boolean reachCheck;
public final double reachLimit;
public final long reachPenaltyTime;
public final ActionList reachActions;
public final int speedAttackLimit;
public final ActionList speedActions;
public final boolean speedCheck;
public FightConfig(NoCheatConfiguration data) {
@ -23,7 +30,14 @@ public class FightConfig implements ConfigItem {
directionActions = data.getActionList(ConfPaths.FIGHT_DIRECTION_ACTIONS);
noswingCheck = data.getBoolean(ConfPaths.FIGHT_NOSWING_CHECK);
noswingActions = data.getActionList(ConfPaths.FIGHT_NOSWING_ACTIONS);
reachCheck = data.getBoolean(ConfPaths.FIGHT_REACH_CHECK);
reachLimit = ((double) (data.getInt(ConfPaths.FIGHT_REACH_LIMIT))) / 100D;
reachPenaltyTime = data.getInt(ConfPaths.FIGHT_REACH_PENALTYTIME);
reachActions = data.getActionList(ConfPaths.FIGHT_REACH_ACTIONS);
speedCheck = data.getBoolean(ConfPaths.FIGHT_SPEED_CHECK);
speedActions = data.getActionList(ConfPaths.FIGHT_SPEED_ACTIONS);
speedAttackLimit = data.getInt(ConfPaths.FIGHT_SPEED_ATTACKLIMIT);
check = directionCheck || noswingCheck;
check = directionCheck || noswingCheck || reachCheck || speedCheck;
}
}

View File

@ -6,25 +6,37 @@ import cc.co.evenprime.bukkit.nocheat.DataItem;
public class FightData implements DataItem {
public double directionVL = 0.0D;
public double directionTotalVL = 0.0D;
public int directionFailed = 0;
public double noswingVL = 0.0D;
public double noswingTotalVL = 0.0D;
public int noswingFailed = 0;
public double directionVL;
public double directionTotalVL;
public int directionFailed;
public double noswingVL;
public double noswingTotalVL;
public int noswingFailed;
public double reachVL;
public double reachTotalVL;
public int reachFailed;
public long directionLastViolationTime = 0;
public long directionLastViolationTime;
public long reachLastViolationTime;
public Entity damagee;
public boolean armswung = true;
public boolean skipNext = false;
public Entity damagee;
public boolean armswung = true;
public boolean skipNext = false;
public long speedTime;
public int speedAttackCount;
public int speedVL;
public int speedTotalVL;
public int speedFailed;
@Override
public void collectData(Map<String, Object> map) {
map.put("fight.direction.vl", (int) directionTotalVL);
map.put("fight.noswing.vl", (int) noswingTotalVL);
map.put("fight.reach.vl", (int) reachTotalVL);
map.put("fight.direction.failed", directionFailed);
map.put("fight.noswing.failed", noswingFailed);
map.put("fight.reach.failed", (int) reachFailed);
}
@Override

View File

@ -0,0 +1,88 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import java.util.Locale;
import net.minecraft.server.Entity;
import net.minecraft.server.EntityComplex;
import net.minecraft.server.EntityComplexPart;
import net.minecraft.server.EntityGiantZombie;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
public class ReachCheck extends FightCheck {
public ReachCheck(NoCheat plugin) {
super(plugin, "fight.reach", Permissions.FIGHT_REACH);
}
public boolean check(NoCheatPlayer player, FightData data, FightConfig cc) {
boolean cancel = false;
final long time = System.currentTimeMillis();
// Get the width of the damagee
Entity entity = data.damagee;
// Safeguard, if entity is Giant or Ender Dragon, this check will fail
// due to giant and hard to define hitboxes
if(entity instanceof EntityComplex || entity instanceof EntityComplexPart || entity instanceof EntityGiantZombie) {
return false;
}
// height = 2.0D as minecraft doesn't store the height of entities,
// and that should be enough. Because entityLocations are always set
// to center bottom of the hitbox, increase "y" location by 1/2
// height to get the "center" of the hitbox
final double off = CheckUtil.reachCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, cc.reachLimit);
if(off < 0.1D) {
// Player did probably nothing wrong
// reduce violation counter
data.reachVL *= 0.80D;
} else {
// Player failed the check
// Increment violation counter
if(!plugin.skipCheck()) {
double sqrt = Math.sqrt(off);
data.reachVL += sqrt;
data.reachTotalVL += sqrt;
data.reachFailed++;
}
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
if(cancel) {
// Needed to calculate penalty times
data.reachLastViolationTime = time;
}
}
// If the player is still in penalty time, cancel the event anyway
if(data.reachLastViolationTime + cc.reachPenaltyTime > time) {
if(data.reachLastViolationTime > time) {
System.out.println("Nocheat noted that your time ran backwards for " + (data.reachLastViolationTime - time) + " ms");
// Security check for server time changed situations
data.reachLastViolationTime = 0;
}
return true;
}
return cancel;
}
@Override
public boolean isEnabled(FightConfig cc) {
return cc.reachCheck;
}
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).reachVL);
else
return super.getParameter(wildcard, player);
}
}

View File

@ -0,0 +1,54 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
public class SpeedCheck extends FightCheck {
public SpeedCheck(NoCheat plugin) {
super(plugin, "fight.speed", Permissions.FIGHT_SPEED);
}
public boolean check(NoCheatPlayer player, FightData data, FightConfig cc) {
boolean cancel = false;
final long time = System.currentTimeMillis();
if(data.speedTime + 1000 <= time) {
data.speedTime = time;
data.speedAttackCount = 0;
data.speedVL = 0;
}
data.speedAttackCount++;
if(data.speedAttackCount > cc.speedAttackLimit) {
if(!plugin.skipCheck()) {
data.speedVL += 1;
data.speedTotalVL += 1;
data.speedFailed++;
}
cancel = executeActions(player, cc.speedActions.getActions(data.speedVL));
}
return cancel;
}
@Override
public boolean isEnabled(FightConfig cc) {
return cc.speedCheck;
}
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
if(wildcard == ParameterName.VIOLATIONS)
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).speedVL);
else
return super.getParameter(wildcard, player);
}
}

View File

@ -98,6 +98,17 @@ public abstract class ConfPaths {
public final static String FIGHT_NOSWING_CHECK = FIGHT_NOSWING + "active";
public final static String FIGHT_NOSWING_ACTIONS = FIGHT_NOSWING + "actions";
private final static String FIGHT_REACH = FIGHT + "reach.";
public static final String FIGHT_REACH_CHECK = FIGHT_REACH + "active";
public static final String FIGHT_REACH_LIMIT = FIGHT_REACH + "distance";
public static final String FIGHT_REACH_PENALTYTIME = FIGHT_REACH + "penaltytime";
public static final String FIGHT_REACH_ACTIONS = FIGHT_REACH + "actions";
private final static String FIGHT_SPEED = FIGHT + "speed.";
public final static String FIGHT_SPEED_CHECK = FIGHT_SPEED + "active";
public final static String FIGHT_SPEED_ATTACKLIMIT = FIGHT_SPEED + "attacklimit";
public final static String FIGHT_SPEED_ACTIONS = FIGHT_SPEED + "actions";
public final static String STRINGS = "strings";
}

View File

@ -89,6 +89,15 @@ public class DefaultConfiguration extends NoCheatConfiguration {
set(ConfPaths.FIGHT_NOSWING_CHECK, true);
set(ConfPaths.FIGHT_NOSWING_ACTIONS, "log:fnoswing:0:5:cif cancel");
set(ConfPaths.FIGHT_REACH_CHECK, true);
set(ConfPaths.FIGHT_REACH_LIMIT, 400);
set(ConfPaths.FIGHT_REACH_PENALTYTIME, 500);
set(ConfPaths.FIGHT_REACH_ACTIONS, "log:freach:0:5:if cancel");
set(ConfPaths.FIGHT_SPEED_CHECK, true);
set(ConfPaths.FIGHT_SPEED_ATTACKLIMIT, 7);
set(ConfPaths.FIGHT_SPEED_ACTIONS, "log:fspeed:0:5:if cancel");
set(ConfPaths.STRINGS + ".drop", "[player] failed [check]: Tried to drop more items than allowed. VL [violations]");
set(ConfPaths.STRINGS + ".moveshort", "[player] failed [check]. VL [violations]");
set(ConfPaths.STRINGS + ".movelong", "[player] in [world] at [location] moving to [locationto] over distance [movedistance] failed check [check]. Total violation level so far [violations]");
@ -102,6 +111,8 @@ public class DefaultConfiguration extends NoCheatConfiguration {
set(ConfPaths.STRINGS + ".color", "[player] failed [check]: Sent colored chat message '[text]'. VL [violations]");
set(ConfPaths.STRINGS + ".spam", "[player] failed [check]: Last sent message '[text]'. VL [violations]");
set(ConfPaths.STRINGS + ".fdirection", "[player] failed [check]: tried to interact with a block out of line of sight. VL [violations]");
set(ConfPaths.STRINGS + ".freach", "[player] failed [check]: tried to attack entity out of reach. VL [violations]");
set(ConfPaths.STRINGS + ".fspeed", "[player] failed [check]: tried to attack too fast. VL [violations]");
set(ConfPaths.STRINGS + ".fnoswing", "[player] failed [check]: Didn't swing arm. VL [violations]");
set(ConfPaths.STRINGS + ".kick", "kick [player]");

View File

@ -33,6 +33,8 @@ public class Permissions {
public static final String FIGHT = CHECKS + ".fight";
public static final String FIGHT_DIRECTION = FIGHT + ".direction";
public static final String FIGHT_NOSWING = FIGHT + ".noswing";
public static final String FIGHT_REACH = FIGHT + ".reach";
public static final String FIGHT_SPEED = FIGHT + ".speed";
public final static String ADMIN_CHATLOG = ADMIN + ".chatlog";
public static final String ADMIN_COMMANDS = ADMIN + ".commands";