mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-01 05:18:00 +01:00
Handle statistic data independant of checks specific data, fix
instanteat check
This commit is contained in:
parent
df8cd92a8c
commit
2fafc0a75d
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>cc.co.evenprime.bukkit</groupId>
|
||||
<artifactId>NoCheat</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<version>3.2.2</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>NoCheat</name>
|
||||
<properties>
|
||||
|
@ -1,13 +1,8 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* Every class that is extending this has to implement an empty Constructor()
|
||||
*
|
||||
*/
|
||||
public interface DataItem {
|
||||
|
||||
public abstract void collectData(Map<String, Object> map);
|
||||
}
|
||||
public interface DataItem {}
|
||||
|
@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
@ -170,9 +169,7 @@ public class NoCheat extends JavaPlugin implements Listener {
|
||||
*/
|
||||
public Map<String, Object> getPlayerData(String playerName) {
|
||||
|
||||
Map<String, Object> map = new TreeMap<String, Object>();
|
||||
|
||||
players.getPlayerData(playerName, map);
|
||||
Map<String, Object> map = players.getPlayerData(playerName);
|
||||
|
||||
map.put("nocheat.version", this.getDescription().getVersion());
|
||||
|
||||
|
@ -16,6 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.types.LogAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.types.SpecialAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public abstract class Check {
|
||||
|
||||
@ -66,6 +67,10 @@ public abstract class Check {
|
||||
return special;
|
||||
}
|
||||
|
||||
protected void incrementStatistics(NoCheatPlayer player, Id id, double vl) {
|
||||
player.getDataStore().getStatistics().increment(id, vl);
|
||||
}
|
||||
|
||||
private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) {
|
||||
|
||||
if(!cc.logging.active)
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import java.util.Map;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
@ -11,14 +10,8 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
public class BlockBreakData implements DataItem {
|
||||
|
||||
public double reachVL = 0.0D;
|
||||
public double reachTotalVL = 0.0D;
|
||||
public int reachFailed = 0;
|
||||
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 long directionLastViolationTime = 0;
|
||||
public final SimpleLocation instaBrokenBlockLocation = new SimpleLocation();
|
||||
@ -27,14 +20,4 @@ public class BlockBreakData implements DataItem {
|
||||
public double reachDistance;
|
||||
public boolean armswung = true;
|
||||
public final SimpleLocation lastDamagedBlock = new SimpleLocation();
|
||||
|
||||
@Override
|
||||
public void collectData(Map<String, Object> map) {
|
||||
map.put("blockbreak.reach.vl", (int) reachTotalVL);
|
||||
map.put("blockbreak.direction.vl", (int) directionTotalVL);
|
||||
map.put("blockbreak.noswing.vl", (int) noswingTotalVL);
|
||||
map.put("blockbreak.reach.failed", reachFailed);
|
||||
map.put("blockbreak.direction.failed", directionFailed);
|
||||
map.put("blockbreak.noswing.failed", noswingFailed);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* The DirectionCheck will find out if a player tried to interact with something
|
||||
@ -42,8 +43,7 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
off /= 10;
|
||||
}
|
||||
data.directionVL += off;
|
||||
data.directionTotalVL += off;
|
||||
data.directionFailed++;
|
||||
incrementStatistics(player, Id.BB_DIRECTION, off);
|
||||
|
||||
cancel = executeActions(player, ccblockbreak.directionActions.getActions(data.directionVL));
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class NoswingCheck extends BlockBreakCheck {
|
||||
|
||||
@ -23,8 +23,7 @@ public class NoswingCheck extends BlockBreakCheck {
|
||||
data.noswingVL *= 0.90D;
|
||||
} else {
|
||||
data.noswingVL += 1;
|
||||
data.noswingTotalVL += 1;
|
||||
data.noswingFailed++;
|
||||
incrementStatistics(player, Id.BB_NOSWING, 1);
|
||||
|
||||
cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL));
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* The reach check will find out if a player interacts with something that's too
|
||||
@ -32,8 +33,7 @@ public class ReachCheck extends BlockBreakCheck {
|
||||
|
||||
// Increment violation counter
|
||||
data.reachVL += distance;
|
||||
data.reachTotalVL += distance;
|
||||
data.reachFailed++;
|
||||
incrementStatistics(player, Id.BB_REACH, distance);
|
||||
data.reachDistance = distance;
|
||||
|
||||
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
import java.util.Map;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
@ -9,30 +8,12 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
*/
|
||||
public class BlockPlaceData implements DataItem {
|
||||
|
||||
public double reachVL = 0.0D;
|
||||
public double reachTotalVL = 0.0D;
|
||||
public int reachFailed = 0;
|
||||
public double directionVL = 0.0D;
|
||||
public double directionTotalVL = 0.0D;
|
||||
public int directionFailed = 0;
|
||||
public double reachVL = 0.0D;
|
||||
public double directionVL = 0.0D;
|
||||
|
||||
public long directionLastViolationTime = 0;
|
||||
public long directionLastViolationTime = 0;
|
||||
|
||||
public final SimpleLocation blockPlacedAgainst = new SimpleLocation();
|
||||
public final SimpleLocation blockPlaced = new SimpleLocation();
|
||||
public double reachdistance;
|
||||
|
||||
public void clearCriticalData() {
|
||||
blockPlacedAgainst.reset();
|
||||
blockPlaced.reset();
|
||||
directionLastViolationTime = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectData(Map<String, Object> map) {
|
||||
map.put("blockplace.reach.vl", (int) reachTotalVL);
|
||||
map.put("blockplace.direction.vl", (int) directionTotalVL);
|
||||
map.put("blockplace.reach.failed", reachFailed);
|
||||
map.put("blockplace.direction.failed", directionFailed);
|
||||
}
|
||||
public final SimpleLocation blockPlacedAgainst = new SimpleLocation();
|
||||
public final SimpleLocation blockPlaced = new SimpleLocation();
|
||||
public double reachdistance;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
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.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class DirectionCheck extends BlockPlaceCheck {
|
||||
|
||||
@ -59,8 +59,7 @@ public class DirectionCheck extends BlockPlaceCheck {
|
||||
// Player failed the check
|
||||
// Increment violation counter
|
||||
data.directionVL += off;
|
||||
data.directionTotalVL += off;
|
||||
data.directionFailed++;
|
||||
incrementStatistics(player, Id.BP_DIRECTION, off);
|
||||
|
||||
// Prepare some event-specific values for logging and custom actions
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
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.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* The reach check will find out if a player interacts with something that's too
|
||||
@ -33,8 +33,7 @@ public class ReachCheck extends BlockPlaceCheck {
|
||||
|
||||
// Increment violation counter
|
||||
data.reachVL += distance;
|
||||
data.reachTotalVL += distance;
|
||||
data.reachFailed++;
|
||||
incrementStatistics(player, Id.BP_REACH, distance);
|
||||
data.reachdistance = distance;
|
||||
|
||||
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.chat;
|
||||
|
||||
import java.util.Map;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
|
||||
/**
|
||||
@ -9,22 +8,10 @@ import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
public class ChatData implements DataItem {
|
||||
|
||||
public int spamVL;
|
||||
public int spamTotalVL;
|
||||
public int spamFailed;
|
||||
public int colorVL;
|
||||
public int colorTotalVL;
|
||||
public int colorFailed;
|
||||
|
||||
public int messageCount = 0;
|
||||
public int commandCount = 0;
|
||||
public long spamLastTime = 0;
|
||||
public String message = "";
|
||||
|
||||
@Override
|
||||
public void collectData(Map<String, Object> map) {
|
||||
map.put("chat.spam.vl", (int) spamTotalVL);
|
||||
map.put("chat.color.vl", (int) colorTotalVL);
|
||||
map.put("chat.spam.failed", spamFailed);
|
||||
map.put("chat.color.failed", colorFailed);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class ColorCheck extends ChatCheck {
|
||||
|
||||
@ -17,8 +18,7 @@ public class ColorCheck extends ChatCheck {
|
||||
if(data.message.matches(".*\247.*")) {
|
||||
|
||||
data.colorVL += 1;
|
||||
data.colorTotalVL += 1;
|
||||
data.colorFailed++;
|
||||
incrementStatistics(player, Id.CHAT_COLOR, 1);
|
||||
|
||||
boolean filter = executeActions(player, cc.colorActions.getActions(data.colorVL));
|
||||
|
||||
|
@ -5,6 +5,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class SpamCheck extends ChatCheck {
|
||||
|
||||
@ -44,8 +45,7 @@ public class SpamCheck extends ChatCheck {
|
||||
|
||||
data.spamVL = Math.max(0, data.messageCount - cc.spamLimit);
|
||||
data.spamVL += Math.max(0, data.commandCount - cc.commandLimit);
|
||||
data.spamTotalVL++;
|
||||
data.spamFailed++;
|
||||
incrementStatistics(player, Id.CHAT_SPAM, 1);
|
||||
|
||||
cancel = executeActions(player, cc.spamActions.getActions(data.spamVL));
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
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;
|
||||
@ -11,6 +10,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class DirectionCheck extends FightCheck {
|
||||
|
||||
@ -51,8 +51,7 @@ public class DirectionCheck extends FightCheck {
|
||||
if(!plugin.skipCheck()) {
|
||||
double sqrt = Math.sqrt(off);
|
||||
data.directionVL += sqrt;
|
||||
data.directionTotalVL += sqrt;
|
||||
data.directionFailed++;
|
||||
incrementStatistics(player, Id.FI_DIRECTION, sqrt);
|
||||
}
|
||||
|
||||
cancel = executeActions(player, cc.directionActions.getActions(data.directionVL));
|
||||
|
@ -1,23 +1,14 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
||||
|
||||
import java.util.Map;
|
||||
import net.minecraft.server.Entity;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
|
||||
public class FightData implements DataItem {
|
||||
|
||||
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 int speedVL;
|
||||
public int speedTotalVL;
|
||||
public int speedFailed;
|
||||
|
||||
public long directionLastViolationTime;
|
||||
public long reachLastViolationTime;
|
||||
@ -28,19 +19,4 @@ public class FightData implements DataItem {
|
||||
|
||||
public long speedTime;
|
||||
public int speedAttackCount;
|
||||
|
||||
@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.speed.vl", (int) speedTotalVL);
|
||||
|
||||
|
||||
map.put("fight.direction.failed", (int) directionFailed);
|
||||
map.put("fight.noswing.failed", (int) noswingFailed);
|
||||
map.put("fight.reach.failed", (int) reachFailed);
|
||||
map.put("fight.speed.failed", (int) speedFailed);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class NoswingCheck extends FightCheck {
|
||||
|
||||
@ -23,8 +23,7 @@ public class NoswingCheck extends FightCheck {
|
||||
data.noswingVL *= 0.90D;
|
||||
} else {
|
||||
data.noswingVL += 1;
|
||||
data.noswingTotalVL += 1;
|
||||
data.noswingFailed++;
|
||||
incrementStatistics(player, Id.FI_NOSWING, 1);
|
||||
|
||||
cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL));
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class ReachCheck extends FightCheck {
|
||||
|
||||
@ -49,8 +50,7 @@ public class ReachCheck extends FightCheck {
|
||||
if(!plugin.skipCheck()) {
|
||||
double sqrt = Math.sqrt(off);
|
||||
data.reachVL += sqrt;
|
||||
data.reachTotalVL += sqrt;
|
||||
data.reachFailed++;
|
||||
incrementStatistics(player, Id.FI_REACH, sqrt);
|
||||
}
|
||||
|
||||
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
|
||||
|
@ -5,6 +5,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class SpeedCheck extends FightCheck {
|
||||
|
||||
@ -29,8 +30,7 @@ public class SpeedCheck extends FightCheck {
|
||||
if(data.speedAttackCount > cc.speedAttackLimit) {
|
||||
if(!plugin.skipCheck()) {
|
||||
data.speedVL += 1;
|
||||
data.speedTotalVL += 1;
|
||||
data.speedFailed++;
|
||||
incrementStatistics(player, Id.FI_SPEED, 1);
|
||||
}
|
||||
|
||||
cancel = executeActions(player, cc.speedActions.getActions(data.speedVL));
|
||||
|
@ -5,6 +5,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class DropCheck extends InventoryCheck {
|
||||
|
||||
@ -32,8 +33,7 @@ public class DropCheck extends InventoryCheck {
|
||||
if(data.dropCount > cc.dropLimit) {
|
||||
|
||||
data.dropVL = data.dropCount - cc.dropLimit;
|
||||
data.dropTotalVL++;
|
||||
data.dropFailed++;
|
||||
incrementStatistics(player, Id.INV_DROP, 1);
|
||||
|
||||
cancel = executeActions(player, cc.dropActions.getActions(data.dropVL));
|
||||
}
|
||||
|
@ -6,11 +6,12 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class InstantBowCheck extends InventoryCheck {
|
||||
|
||||
public InstantBowCheck(NoCheat plugin) {
|
||||
super(plugin, "fight.instantbow", Permissions.INVENTORY_INSTANTBOW);
|
||||
super(plugin, "inventory.instantbow", Permissions.INVENTORY_INSTANTBOW);
|
||||
}
|
||||
|
||||
public boolean check(NoCheatPlayer player, EntityShootBowEvent event, InventoryData data, InventoryConfig cc) {
|
||||
@ -31,8 +32,7 @@ public class InstantBowCheck extends InventoryCheck {
|
||||
// Seems fishy, increase violation level
|
||||
int vl = ((int) (expectedTimeWhenStringDrawn - time)) / 100;
|
||||
data.instantBowVL += vl;
|
||||
data.instantBowTotalVL += vl;
|
||||
data.instantBowFailed++;
|
||||
incrementStatistics(player, Id.INV_BOW, vl);
|
||||
cancelled = executeActions(player, cc.bowActions.getActions(data.instantBowVL));
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
public class InstantEatCheck extends InventoryCheck {
|
||||
|
||||
@ -34,8 +35,7 @@ public class InstantEatCheck extends InventoryCheck {
|
||||
// Seems fishy, increase violation level
|
||||
int vl = ((int) (expectedTimeWhenEatingFinished - time)) / 100;
|
||||
data.instantEatVL += vl;
|
||||
data.instantEatTotalVL += vl;
|
||||
data.instantEatFailed++;
|
||||
incrementStatistics(player, Id.INV_EAT, vl);
|
||||
cancelled = executeActions(player, cc.eatActions.getActions(data.instantEatVL));
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ public class InstantEatCheck extends InventoryCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", getData(player.getDataStore()).instantEatVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).instantEatVL);
|
||||
else if(wildcard == ParameterName.FOOD)
|
||||
return getData(player.getDataStore()).foodMaterial.toString();
|
||||
else
|
||||
|
@ -78,10 +78,10 @@ public class InventoryCheckListener implements Listener, EventManager {
|
||||
} else if(CheckUtil.isFood(event.getItem())) {
|
||||
// Remember food Material, because we don't have that info in the other event
|
||||
data.foodMaterial = event.getItem().getType();
|
||||
data.lastFoodInteractTime = System.currentTimeMillis();
|
||||
data.lastEatInteractTime = System.currentTimeMillis();
|
||||
} else {
|
||||
data.lastBowInteractTime = 0;
|
||||
data.lastFoodInteractTime = 0;
|
||||
data.lastEatInteractTime = 0;
|
||||
data.foodMaterial = null;
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,18 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.inventory;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
|
||||
public class InventoryData implements DataItem {
|
||||
|
||||
public int dropVL;
|
||||
public double dropTotalVL;
|
||||
public int dropFailed;
|
||||
public long dropLastTime;
|
||||
public int dropCount;
|
||||
|
||||
public int instantBowVL;
|
||||
public int instantBowTotalVL;
|
||||
public int instantBowFailed;
|
||||
public long lastBowInteractTime;
|
||||
|
||||
public double instantEatVL;
|
||||
public int instantEatTotalVL;
|
||||
public int instantEatFailed;
|
||||
|
||||
public long lastBowInteractTime;
|
||||
public int lastEatInteractTime;
|
||||
public long lastEatInteractTime;
|
||||
public Material foodMaterial;
|
||||
public long lastFoodInteractTime;
|
||||
public int newFoodLevel;
|
||||
|
||||
@Override
|
||||
public void collectData(Map<String, Object> map) {
|
||||
map.put("inventory.drop.vl", (int) dropTotalVL);
|
||||
map.put("inventory.drop.failed", (int) dropFailed);
|
||||
|
||||
map.put("inventory.instantbow.vl", (int) instantBowTotalVL);
|
||||
map.put("inventory.instantbow.failed", (int) instantBowFailed);
|
||||
|
||||
map.put("inventory.instanteat.vl", (int) instantEatTotalVL);
|
||||
map.put("inventory.instanteat.failed", (int) instantEatFailed);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ 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.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* A check designed for people that are allowed to fly. The complement to
|
||||
@ -98,13 +99,11 @@ public class FlyingCheck extends MovingCheck {
|
||||
// Increment violation counter
|
||||
data.runflyVL += result;
|
||||
if(resultHoriz > 0) {
|
||||
data.runflyRunningTotalVL += resultHoriz;
|
||||
data.runflyRunningFailed++;
|
||||
incrementStatistics(player, Id.MOV_RUNNING, resultHoriz);
|
||||
}
|
||||
|
||||
if(resultVert > 0) {
|
||||
data.runflyFlyingTotalVL += resultVert;
|
||||
data.runflyFlyingFailed++;
|
||||
incrementStatistics(player, Id.MOV_FLYING, resultVert);
|
||||
}
|
||||
|
||||
boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(data.runflyVL));
|
||||
|
@ -6,6 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* The morePacketsCheck (previously called SpeedhackCheck) will try to identify
|
||||
@ -51,8 +52,7 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
if(data.morePacketsBuffer < 0) {
|
||||
|
||||
data.morePacketsVL = -data.morePacketsBuffer;
|
||||
data.morePacketsTotalVL++;
|
||||
data.morePacketsFailed++;
|
||||
incrementStatistics(player, Id.MOV_MOREPACKETS, 1);
|
||||
|
||||
data.packets = -data.morePacketsBuffer;
|
||||
|
||||
@ -64,7 +64,7 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
|
||||
if(data.morePacketsLastTime + 1000 < time) {
|
||||
// More than 1 second elapsed, but how many?
|
||||
double seconds = ((double)(time - data.morePacketsLastTime)) / 1000D;
|
||||
double seconds = ((double) (time - data.morePacketsLastTime)) / 1000D;
|
||||
|
||||
// For each second, fill the buffer
|
||||
data.morePacketsBuffer += packetsPerTimeframe * seconds;
|
||||
@ -84,7 +84,7 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
|
||||
// Set the new "last" time
|
||||
data.morePacketsLastTime = time;
|
||||
|
||||
|
||||
// Set the new "setback" location
|
||||
if(newToLocation == null) {
|
||||
data.morePacketsSetbackPoint.set(data.from);
|
||||
|
@ -1,8 +1,8 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
import java.util.Map;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* Player specific data for the moving check group
|
||||
@ -10,26 +10,8 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
public class MovingData implements DataItem {
|
||||
|
||||
public double runflyVL;
|
||||
|
||||
public double runflyRunningTotalVL;
|
||||
public int runflyRunningFailed;
|
||||
|
||||
public double runflyFlyingTotalVL;
|
||||
public int runflyFlyingFailed;
|
||||
|
||||
public double runflySneakingTotalVL;
|
||||
public int runflySneakingFailed;
|
||||
|
||||
public double runflySwimmingTotalVL;
|
||||
public int runflySwimmingFailed;
|
||||
|
||||
public double nofallVL;
|
||||
public double nofallTotalVL;
|
||||
public int nofallFailed;
|
||||
|
||||
public double morePacketsVL;
|
||||
public double morePacketsTotalVL;
|
||||
public int morePacketsFailed;
|
||||
|
||||
public int jumpPhase;
|
||||
public double lastJumpAmplifier;
|
||||
@ -62,7 +44,7 @@ public class MovingData implements DataItem {
|
||||
public boolean fromOnOrInGround;
|
||||
public boolean toOnOrInGround;
|
||||
|
||||
public String checknamesuffix = "";
|
||||
public Id statisticCategory = Id.MOV_RUNNING;
|
||||
|
||||
public int packets;
|
||||
|
||||
@ -77,21 +59,4 @@ public class MovingData implements DataItem {
|
||||
public void clearMorePacketsData() {
|
||||
morePacketsSetbackPoint.reset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collectData(Map<String, Object> map) {
|
||||
map.put("moving.running.vl", (int) runflyRunningTotalVL);
|
||||
map.put("moving.flying.vl", (int) runflyFlyingTotalVL);
|
||||
map.put("moving.sneaking.vl", (int) runflySneakingTotalVL);
|
||||
map.put("moving.swimming.vl", (int) runflySwimmingTotalVL);
|
||||
map.put("moving.nofall.vl", (int) nofallTotalVL);
|
||||
map.put("moving.morepackets.vl", (int) morePacketsTotalVL);
|
||||
|
||||
map.put("moving.running.failed", runflyRunningFailed);
|
||||
map.put("moving.flying.failed", runflyFlyingFailed);
|
||||
map.put("moving.sneaking.failed", runflySneakingFailed);
|
||||
map.put("moving.swimming.failed", runflySwimmingFailed);
|
||||
map.put("moving.nofall.failed", nofallFailed);
|
||||
map.put("moving.morepackets.failed", morePacketsFailed);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* A check to see if people cheat by tricking the server to not deal them
|
||||
@ -41,8 +42,7 @@ public class NoFallCheck extends MovingCheck {
|
||||
if(cc.nofallaggressive && data.fromOnOrInGround && data.toOnOrInGround && data.from.y <= data.to.y && player.getPlayer().getFallDistance() > 3.0F) {
|
||||
data.fallDistance = player.getPlayer().getFallDistance();
|
||||
data.nofallVL += data.fallDistance;
|
||||
data.nofallTotalVL += data.fallDistance;
|
||||
data.nofallFailed++;
|
||||
incrementStatistics(player, Id.MOV_NOFALL, data.fallDistance);
|
||||
final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallVL));
|
||||
if(cancel) {
|
||||
player.dealFallDamage();
|
||||
@ -64,8 +64,7 @@ public class NoFallCheck extends MovingCheck {
|
||||
|
||||
if(difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) {
|
||||
data.nofallVL += difference;
|
||||
data.nofallTotalVL += difference;
|
||||
data.nofallFailed++;
|
||||
incrementStatistics(player, Id.MOV_NOFALL, difference);
|
||||
|
||||
final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallVL));
|
||||
|
||||
|
@ -9,6 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.Statistics.Id;
|
||||
|
||||
/**
|
||||
* The counterpart to the FlyingCheck. People that are not allowed to fly
|
||||
@ -76,19 +77,7 @@ public class RunningCheck extends MovingCheck {
|
||||
// Increment violation counter
|
||||
data.runflyVL += result;
|
||||
|
||||
if(data.checknamesuffix.equals("sneaking")) {
|
||||
data.runflySneakingTotalVL += result;
|
||||
data.runflySneakingFailed++;
|
||||
} else if(data.checknamesuffix.equals("swimming")) {
|
||||
data.runflySwimmingTotalVL += result;
|
||||
data.runflySwimmingFailed++;
|
||||
} else if(data.checknamesuffix.equals("vertical")) {
|
||||
data.runflyFlyingTotalVL += result;
|
||||
data.runflyFlyingFailed++;
|
||||
} else {
|
||||
data.runflyRunningTotalVL += result;
|
||||
data.runflyRunningFailed++;
|
||||
}
|
||||
incrementStatistics(player, data.statisticCategory, result);
|
||||
|
||||
boolean cancel = executeActions(player, cc.actions.getActions(data.runflyVL));
|
||||
|
||||
@ -143,7 +132,7 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
double limit = 0.0D;
|
||||
|
||||
String suffix = null;
|
||||
Id statisticsCategory = null;
|
||||
|
||||
// Player on ice?
|
||||
Block b = player.getPlayer().getLocation().getBlock();
|
||||
@ -155,16 +144,16 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
if(cc.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVING_SNEAKING)) {
|
||||
limit = cc.sneakingSpeedLimit;
|
||||
suffix = "sneaking";
|
||||
statisticsCategory = Id.MOV_SNEAKING;
|
||||
} else if(isSwimming && !player.hasPermission(Permissions.MOVING_SWIMMING)) {
|
||||
limit = cc.swimmingSpeedLimit;
|
||||
suffix = "swimming";
|
||||
statisticsCategory = Id.MOV_SWIMMING;
|
||||
} else if(!sprinting) {
|
||||
limit = cc.walkingSpeedLimit;
|
||||
suffix = "walking";
|
||||
statisticsCategory = Id.MOV_RUNNING;
|
||||
} else {
|
||||
limit = cc.sprintingSpeedLimit;
|
||||
suffix = "sprinting";
|
||||
statisticsCategory = Id.MOV_RUNNING;
|
||||
}
|
||||
|
||||
if(data.onIce > 0) {
|
||||
@ -204,7 +193,7 @@ public class RunningCheck extends MovingCheck {
|
||||
}
|
||||
|
||||
if(distanceAboveLimit > 0) {
|
||||
data.checknamesuffix = suffix;
|
||||
data.statisticCategory = statisticsCategory;
|
||||
}
|
||||
|
||||
return distanceAboveLimit;
|
||||
@ -235,7 +224,7 @@ public class RunningCheck extends MovingCheck {
|
||||
distanceAboveLimit = data.to.y - data.runflySetBackPoint.y - limit;
|
||||
|
||||
if(distanceAboveLimit > 0) {
|
||||
data.checknamesuffix = "vertical";
|
||||
data.statisticCategory = Id.MOV_FLYING;
|
||||
}
|
||||
|
||||
if(toOnGround || fromOnGround) {
|
||||
@ -254,7 +243,7 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
if(wildcard == ParameterName.CHECK)
|
||||
// Workaround for something until I find a better way to do it
|
||||
return getName() + "." + getData(player.getDataStore()).checknamesuffix;
|
||||
return getData(player.getDataStore()).statisticCategory.toString();
|
||||
else if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).runflyVL);
|
||||
else
|
||||
|
@ -6,9 +6,10 @@ import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
|
||||
public class DataStore {
|
||||
|
||||
private final Map<String, DataItem> dataMap = new HashMap<String, DataItem>();
|
||||
private final Map<String, DataItem> dataMap = new HashMap<String, DataItem>();
|
||||
private final Statistics statistics = new Statistics();
|
||||
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends DataItem>T get(String id) {
|
||||
@ -19,12 +20,15 @@ public class DataStore {
|
||||
dataMap.put(id, data);
|
||||
}
|
||||
|
||||
public void collectData(Map<String, Object> map) {
|
||||
for(DataItem data : dataMap.values()) {
|
||||
data.collectData(map);
|
||||
}
|
||||
|
||||
public Map<String, Object> collectData() {
|
||||
Map<String, Object> map = statistics.get();
|
||||
map.put("nocheat.starttime", timestamp);
|
||||
map.put("nocheat.endtime", System.currentTimeMillis());
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
public Statistics getStatistics() {
|
||||
return statistics;
|
||||
}
|
||||
}
|
||||
|
@ -59,14 +59,15 @@ public class PlayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void getPlayerData(String playerName, Map<String, Object> map) {
|
||||
public Map<String, Object> getPlayerData(String playerName) {
|
||||
|
||||
NoCheatPlayer player = this.players.get(playerName.toLowerCase());
|
||||
|
||||
if(player != null) {
|
||||
player.getDataStore().collectData(map);
|
||||
|
||||
return player.getDataStore().collectData();
|
||||
}
|
||||
|
||||
return new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
}
|
||||
|
71
src/cc/co/evenprime/bukkit/nocheat/data/Statistics.java
Normal file
71
src/cc/co/evenprime/bukkit/nocheat/data/Statistics.java
Normal file
@ -0,0 +1,71 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Statistics {
|
||||
|
||||
public enum Id {
|
||||
|
||||
BB_DIRECTION("blockbreak.direction"), BB_NOSWING("blockbreak.noswing"),
|
||||
BB_REACH("blockbreak.reach"), BP_DIRECTION("blockplace.direction"),
|
||||
BP_REACH("blockplace.reach"), CHAT_COLOR("chat.color"),
|
||||
CHAT_SPAM("chat.spam"), FI_DIRECTION("fight.direction"),
|
||||
FI_NOSWING("fight.noswing"), FI_REACH("fight.reach"),
|
||||
FI_SPEED("fight.speed"), INV_DROP("inventory.drop"),
|
||||
INV_BOW("inventory.instantbow"), INV_EAT("inventory.instanteat"),
|
||||
MOV_RUNNING("moving.running"), MOV_FLYING("moving.flying"),
|
||||
MOV_MOREPACKETS("moving.morepackets"), MOV_NOFALL("moving.nofall"),
|
||||
MOV_SNEAKING("moving.sneaking"), MOV_SWIMMING("moving.swimming");
|
||||
|
||||
private final String name;
|
||||
|
||||
private Id(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private final Map<Id, Double> statisticVLs = new HashMap<Id, Double>(Id.values().length);
|
||||
private final Map<Id, Integer> statisticFails = new HashMap<Id, Integer>(Id.values().length);
|
||||
|
||||
public Statistics() {
|
||||
// Initialize statistic values
|
||||
for(Id id : Id.values()) {
|
||||
statisticVLs.put(id, 0D);
|
||||
statisticFails.put(id, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void increment(Id id, double vl) {
|
||||
Double stored = statisticVLs.get(id);
|
||||
if(stored == null)
|
||||
stored = 0D;
|
||||
statisticVLs.put(id, stored + vl);
|
||||
|
||||
Integer failed = statisticFails.get(id);
|
||||
if(failed == null)
|
||||
failed = 0;
|
||||
statisticFails.put(id, failed + 1);
|
||||
}
|
||||
|
||||
public Map<String, Object> get() {
|
||||
Map<String, Object> map = new TreeMap<String, Object>();
|
||||
|
||||
for(Entry<Id, Double> entry : statisticVLs.entrySet()) {
|
||||
map.put(entry.getKey().toString() + ".vl", entry.getValue().intValue());
|
||||
}
|
||||
|
||||
for(Entry<Id, Integer> entry : statisticFails.entrySet()) {
|
||||
map.put(entry.getKey().toString() + ".failed", entry.getValue());
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user