mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-06 20:18:00 +02:00
Further configuration options for the fight.direction check
This commit is contained in:
parent
37e9f2ff62
commit
9a7bffcc1f
@ -13,13 +13,15 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
|||||||
import cc.co.evenprime.bukkit.nocheat.data.FightData;
|
import cc.co.evenprime.bukkit.nocheat.data.FightData;
|
||||||
import cc.co.evenprime.bukkit.nocheat.data.LogData;
|
import cc.co.evenprime.bukkit.nocheat.data.LogData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check various things related to fighting players/entities
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class FightCheck {
|
public class FightCheck {
|
||||||
|
|
||||||
private final ActionExecutor action;
|
private final ActionExecutor action;
|
||||||
private final NoCheat plugin;
|
private final NoCheat plugin;
|
||||||
|
|
||||||
private final static float precision = 0.75F;
|
|
||||||
|
|
||||||
public FightCheck(NoCheat plugin) {
|
public FightCheck(NoCheat plugin) {
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -32,9 +34,7 @@ public class FightCheck {
|
|||||||
|
|
||||||
boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
|
boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
|
||||||
|
|
||||||
if(data.directionLastViolationTime + 300 > System.currentTimeMillis()) {
|
long time = System.currentTimeMillis();
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(directionCheck) {
|
if(directionCheck) {
|
||||||
|
|
||||||
@ -44,13 +44,15 @@ public class FightCheck {
|
|||||||
net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle();
|
net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle();
|
||||||
|
|
||||||
float width = entity.length > entity.width ? entity.length : entity.width;
|
float width = entity.length > entity.width ? entity.length : entity.width;
|
||||||
double height = 2.0D; // Minecraft server doesn't store the height of entities :(
|
double height = 2.0D; // Minecraft server doesn't store the height
|
||||||
|
// of entities :(
|
||||||
|
|
||||||
final double p = width/2 + precision;
|
final double p = width / 2 + cc.fight.directionPrecision;
|
||||||
final double h = height/2 + precision;
|
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 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;
|
final double z1 = ((double) damagee.getLocation().getZ()) - eyes.getZ() - p;
|
||||||
|
|
||||||
double factor = new Vector(x1 + p, y1 + h, z1 + p).length();
|
double factor = new Vector(x1 + p, y1 + h, z1 + p).length();
|
||||||
@ -64,7 +66,7 @@ public class FightCheck {
|
|||||||
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) {
|
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
|
// Player did nothing wrong
|
||||||
// reduce violation counter
|
// reduce violation counter
|
||||||
data.violationLevel *= 0.9D;
|
data.violationLevel *= 0.95D;
|
||||||
} else {
|
} else {
|
||||||
// Player failed the check
|
// Player failed the check
|
||||||
// Increment violation counter
|
// Increment violation counter
|
||||||
@ -76,8 +78,18 @@ public class FightCheck {
|
|||||||
ldata.check = "fight.direction";
|
ldata.check = "fight.direction";
|
||||||
|
|
||||||
cancel = action.executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, cc);
|
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;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
@ -96,8 +96,12 @@ public abstract class Configuration {
|
|||||||
|
|
||||||
private final static OptionNode FIGHT_DIRECTION = new OptionNode("direction", FIGHT, DataType.PARENT);
|
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 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);
|
public final static OptionNode FIGHT_DIRECTION_ACTIONS = new OptionNode("actions", FIGHT_DIRECTION, DataType.ACTIONLIST);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final Map<OptionNode, Object> values;
|
private final Map<OptionNode, Object> values;
|
||||||
private final Configuration defaults;
|
private final Configuration defaults;
|
||||||
|
|
||||||
|
@ -141,6 +141,8 @@ public class DefaultConfiguration extends Configuration {
|
|||||||
setValue(FIGHT_CHECK, true);
|
setValue(FIGHT_CHECK, true);
|
||||||
|
|
||||||
setValue(FIGHT_DIRECTION_CHECK, true);
|
setValue(FIGHT_DIRECTION_CHECK, true);
|
||||||
|
setValue(FIGHT_DIRECTION_PRECISION, 75);
|
||||||
|
setValue(FIGHT_DIRECTION_PENALTYTIME, 400);
|
||||||
|
|
||||||
ActionList directionActionList = new ActionList();
|
ActionList directionActionList = new ActionList();
|
||||||
directionActionList.setActions(0, action.getActions("fightDirectionLog fightCancel".split(" ")));
|
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 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 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 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, "");
|
||||||
w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event.");
|
w(w, "# SPECIAL Actions: They will do something check dependant, usually cancel an event.");
|
||||||
w(w, "# - They start with the word 'special'");
|
w(w, "# - They start with the word 'special'");
|
||||||
|
@ -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_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.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) {
|
private static void set(OptionNode id, String text) {
|
||||||
|
@ -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.actions.ActionList;
|
||||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||||
|
|
||||||
|
|
||||||
public class CCFight {
|
public class CCFight {
|
||||||
|
|
||||||
public final boolean check;
|
public final boolean check;
|
||||||
public final boolean directionCheck;
|
public final boolean directionCheck;
|
||||||
|
public final double directionPrecision;
|
||||||
public final ActionList directionActions;
|
public final ActionList directionActions;
|
||||||
|
public final long directionPenaltyTime;
|
||||||
|
|
||||||
public CCFight(Configuration data) {
|
public CCFight(Configuration data) {
|
||||||
|
|
||||||
check = data.getBoolean(Configuration.FIGHT_CHECK);
|
check = data.getBoolean(Configuration.FIGHT_CHECK);
|
||||||
directionCheck = data.getBoolean(Configuration.FIGHT_DIRECTION_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);
|
directionActions = data.getActionList(Configuration.FIGHT_DIRECTION_ACTIONS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user