Further configuration options for the fight.direction check

This commit is contained in:
Evenprime 2011-10-14 15:19:13 +02:00
parent 37e9f2ff62
commit 9a7bffcc1f
5 changed files with 50 additions and 23 deletions

View File

@ -13,12 +13,14 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
/**
* Check various things related to fighting players/entities
*
*/
public class FightCheck {
private final ActionExecutor action;
private final NoCheat plugin;
private final static float precision = 0.75F;
public FightCheck(NoCheat plugin) {
@ -32,39 +34,39 @@ public class FightCheck {
boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
if(data.directionLastViolationTime + 300 > System.currentTimeMillis()) {
return true;
}
long time = System.currentTimeMillis();
if(directionCheck) {
Location eyes = player.getEyeLocation();
// Get the width of the damagee
net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle();
float width = entity.length > entity.width ? entity.length : entity.width;
double height = 2.0D; // Minecraft server doesn't store the height of entities :(
final double p = width/2 + precision;
final double h = height/2 + precision;
float width = entity.length > entity.width ? entity.length : entity.width;
double height = 2.0D; // Minecraft server doesn't store the height
// of entities :(
final double p = width / 2 + cc.fight.directionPrecision;
final double h = height / 2 + cc.fight.directionPrecision;
// TODO: Move this into a seperate class to recycle it throughout NoCheat
final double x1 = ((double) damagee.getLocation().getX()) - eyes.getX() - p;
final double y1 = ((double) damagee.getLocation().getY()) - eyes.getY() - precision;
final double y1 = ((double) damagee.getLocation().getY()) - eyes.getY() - cc.fight.directionPrecision;
final double z1 = ((double) damagee.getLocation().getZ()) - eyes.getZ() - p;
double factor = new Vector(x1 + p, y1 + h, z1 + p).length();
Vector direction = player.getEyeLocation().getDirection();
final double x2 = x1 + 2*p;
final double y2 = y1 + 2*h;
final double z2 = z1 + 2*p;
final double x2 = x1 + 2 * p;
final double y2 = y1 + 2 * h;
final double z2 = z1 + 2 * p;
if(factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 && factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
// Player did nothing wrong
// reduce violation counter
data.violationLevel *= 0.9D;
data.violationLevel *= 0.95D;
} else {
// Player failed the check
// Increment violation counter
@ -76,9 +78,19 @@ public class FightCheck {
ldata.check = "fight.direction";
cancel = action.executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, cc);
if(cancel) {
// Needed to calculate penalty times
data.directionLastViolationTime = time;
}
}
}
// If the player is still in penalty time, cancel the event anyway
if(data.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) {
return true;
}
return cancel;
}
}

View File

@ -96,8 +96,12 @@ public abstract class Configuration {
private final static OptionNode FIGHT_DIRECTION = new OptionNode("direction", FIGHT, DataType.PARENT);
public final static OptionNode FIGHT_DIRECTION_CHECK = new OptionNode("check", FIGHT_DIRECTION, DataType.BOOLEAN);
public static final OptionNode FIGHT_DIRECTION_PRECISION = new OptionNode("precision", FIGHT_DIRECTION, DataType.INTEGER);
public static final OptionNode FIGHT_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", FIGHT_DIRECTION, DataType.INTEGER);
public final static OptionNode FIGHT_DIRECTION_ACTIONS = new OptionNode("actions", FIGHT_DIRECTION, DataType.ACTIONLIST);
private final Map<OptionNode, Object> values;
private final Configuration defaults;

View File

@ -141,6 +141,8 @@ public class DefaultConfiguration extends Configuration {
setValue(FIGHT_CHECK, true);
setValue(FIGHT_DIRECTION_CHECK, true);
setValue(FIGHT_DIRECTION_PRECISION, 75);
setValue(FIGHT_DIRECTION_PENALTYTIME, 400);
ActionList directionActionList = new ActionList();
directionActionList.setActions(0, action.getActions("fightDirectionLog fightCancel".split(" ")));
@ -226,7 +228,7 @@ public class DefaultConfiguration extends Configuration {
w(w, "log onliquidLog 2 1 med NC: [player] failed [check]: tried to place a [blocktype] block at [placelocation] against block at [placeagainst].");
w(w, "log spamLog 0 4 med NC: [player] failed [check]: Last sent message \"[text]\".");
w(w, "log nofallLog 0 1 med NC: [player] failed [check]: tried to avoid fall damage for ~[falldistance] blocks.");
w(w, "log fightDirectionLog 3 5 med NC: [player] failed [check]: tried to attack out of sight entity.");
w(w, "log fightDirectionLog 3 5 med NC: [player] failed [check]: tried to attack out of sight entity. Total violation level so far [violations]");
w(w, "");
w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event.");
w(w, "# - They start with the word 'special'");

View File

@ -76,6 +76,11 @@ public class Explainations {
set(Configuration.CHAT_SPAM_LIMIT, "How many messages per timeframe may the player send without it counting as spamming?");
set(Configuration.CHAT_SPAM_ACTIONS, "What should be done if a player is trying to spam the chat.\nUnit is number of chat messages above the limit you declared above.");
set(Configuration.FIGHT_CHECK, "If true, do various checks on Events related to fighting.");
set(Configuration.FIGHT_DIRECTION_CHECK, "If true, check if a player is really looking at enemies that he attacks.");
set(Configuration.FIGHT_DIRECTION_PRECISION, "Set how precise the check should be. If you experience the check to be too zealous, increase this value. \nIf you want to make it tighter, reduce this value. Default is 75.");
set(Configuration.FIGHT_DIRECTION_PENALTYTIME, "If a player fails the check, he will be unable to attack for this amount of time (in milliseconds), default is 500.");
set(Configuration.FIGHT_DIRECTION_ACTIONS, "What should be done if a player attacks entities that are not in his field of view.\nUnit is number of attacks on entities out of view.");
}
private static void set(OptionNode id, String text) {

View File

@ -3,16 +3,20 @@ package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
public class CCFight {
public final boolean check;
public final boolean directionCheck;
public final boolean check;
public final boolean directionCheck;
public final double directionPrecision;
public final ActionList directionActions;
public final long directionPenaltyTime;
public CCFight(Configuration data) {
check = data.getBoolean(Configuration.FIGHT_CHECK);
directionCheck = data.getBoolean(Configuration.FIGHT_DIRECTION_CHECK);
directionPrecision = ((double) (data.getInteger(Configuration.FIGHT_DIRECTION_PRECISION))) / 100D;
directionPenaltyTime = data.getInteger(Configuration.FIGHT_DIRECTION_PENALTYTIME);
directionActions = data.getActionList(Configuration.FIGHT_DIRECTION_ACTIONS);
}
}