Make NoCheat identify new MC 1.0.1 versions. First attempt at a data

collection interface for other plugins.
This commit is contained in:
Evenprime 2011-12-02 16:14:12 +01:00
parent 1dd6ccb786
commit b5390cbd91
25 changed files with 213 additions and 59 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cc.co.evenprime.bukkit</groupId>
<artifactId>NoCheat</artifactId>
<version>2.19</version>
<version>2.19a</version>
<packaging>jar</packaging>
<name>NoCheat</name>
<properties>

View File

@ -2,6 +2,8 @@ package cc.co.evenprime.bukkit.nocheat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -60,7 +62,7 @@ public class NoCheat extends JavaPlugin {
private MCVersion mcVersion = MCVersion.Unknown;
public enum MCVersion {
MC100, MC181, Unknown
MC100, MC181, Unknown, MC101
}
public NoCheat() {
@ -100,6 +102,8 @@ public class NoCheat extends JavaPlugin {
// find out Minecraft version
if(Bukkit.getVersion().contains("MC: 1.0.0")) {
this.mcVersion = MCVersion.MC100;
} else if(Bukkit.getVersion().contains("MC: 1.0.1")) {
this.mcVersion = MCVersion.MC101;
} else if(Bukkit.getVersion().contains("MC: 1.8.1")) {
this.mcVersion = MCVersion.MC181;
} else {
@ -134,7 +138,7 @@ public class NoCheat extends JavaPlugin {
// Then print a list of active checks per world
ActiveCheckPrinter.printActiveChecks(this, eventManagers);
if(mcVersion == MCVersion.MC100 && this.conf.getConfigurationCacheForWorld(null).emergencyfix) {
if((mcVersion == MCVersion.MC100 || mcVersion == MCVersion.MC101) && this.conf.getConfigurationCacheForWorld(null).emergencyfix) {
// Tell the server admin that we are activating a workaround
log.logToConsole(LogLevel.LOW, "[NoCheat] Activating emergency bugfix for broken player death handling of minecraft.");
@ -231,7 +235,27 @@ public class NoCheat extends JavaPlugin {
*/
public void cleanDataMap() {
players.cleanDataMap();
}
/**
* An interface method usable by other plugins to collect information about
* a player. It will include the plugin version, two timestamps (beginning
* and end of data collection for that player), and various data from
* checks)
*
* @param playerName
* a player name
* @return A newly created map of identifiers and corresponding values
*/
public Map<String, Object> getPlayerData(String playerName) {
Map<String, Object> map = new TreeMap<String, Object>();
players.getPlayerData(playerName, map);
map.put("nocheat.version", this.getDescription().getVersion());
return map;
}
public NoCheatPlayer getPlayer(Player player) {

View File

@ -23,10 +23,10 @@ public class DirectionCheck extends BlockBreakCheck {
super(plugin, "blockbreak.direction", Permissions.BLOCKBREAK_DIRECTION);
}
public boolean check(final NoCheatPlayer player, final BlockBreakData blockbreak, final CCBlockBreak ccblockbreak) {
public boolean check(final NoCheatPlayer player, final BlockBreakData data, final CCBlockBreak ccblockbreak) {
final SimpleLocation brokenBlock = blockbreak.brokenBlockLocation;
final boolean isInstaBreak = blockbreak.instaBrokenBlockLocation.equals(brokenBlock);
final SimpleLocation brokenBlock = data.brokenBlockLocation;
final boolean isInstaBreak = data.instaBrokenBlockLocation.equals(brokenBlock);
// If the block is instabreak and we don't check instabreak, return
if(isInstaBreak && !ccblockbreak.checkinstabreakblocks) {
@ -42,7 +42,7 @@ public class DirectionCheck extends BlockBreakCheck {
if(off < 0.1D) {
// Player did nothing wrong
// reduce violation counter
blockbreak.directionVL *= 0.9D;
data.directionVL *= 0.9D;
} else {
// Player failed the check
// Increment violation counter
@ -51,21 +51,23 @@ public class DirectionCheck extends BlockBreakCheck {
// hard on people failing them
off /= 10;
}
blockbreak.directionVL += off;
data.directionVL += off;
data.directionTotalVL += off;
data.directionFailed++;
cancel = executeActions(player, ccblockbreak.directionActions.getActions(blockbreak.directionVL));
cancel = executeActions(player, ccblockbreak.directionActions.getActions(data.directionVL));
if(cancel) {
// Needed to calculate penalty times
blockbreak.directionLastViolationTime = time;
data.directionLastViolationTime = time;
}
}
// If the player is still in penalty time, cancel the event anyway
if(blockbreak.directionLastViolationTime + ccblockbreak.directionPenaltyTime > time) {
if(blockbreak.directionLastViolationTime > time) {
System.out.println("Nocheat noted that your time ran backwards for " + (blockbreak.directionLastViolationTime - time) + " ms");
blockbreak.directionLastViolationTime = 0;
if(data.directionLastViolationTime + ccblockbreak.directionPenaltyTime > time) {
if(data.directionLastViolationTime > time) {
System.out.println("Nocheat noted that your time ran backwards for " + (data.directionLastViolationTime - time) + " ms");
data.directionLastViolationTime = 0;
}
return true;
}

View File

@ -26,6 +26,8 @@ public class NoswingCheck extends BlockBreakCheck {
data.noswingVL *= 0.90D;
} else {
data.noswingVL += 1;
data.noswingTotalVL += 1;
data.noswingFailed++;
cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL));
}

View File

@ -36,6 +36,8 @@ public class ReachCheck extends BlockBreakCheck {
// Increment violation counter
data.reachVL += distance;
data.reachTotalVL += distance;
data.reachFailed++;
data.reachDistance = distance;
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));

View File

@ -62,6 +62,8 @@ public class DirectionCheck extends BlockPlaceCheck {
// Player failed the check
// Increment violation counter
data.directionVL += off;
data.directionTotalVL += off;
data.directionFailed++;
// Prepare some event-specific values for logging and custom actions

View File

@ -36,6 +36,8 @@ public class ReachCheck extends BlockPlaceCheck {
// Increment violation counter
data.reachVL += distance;
data.reachTotalVL += distance;
data.reachFailed++;
data.reachdistance = distance;
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));

View File

@ -19,10 +19,13 @@ public class EmptyCheck extends ChatCheck {
public boolean check(NoCheatPlayer player, ChatData data, CCChat cc) {
boolean cancel = false;
if(data.message.trim().length() == 0) {
data.emptyVL += 1;
data.emptyTotalVL += 1;
data.emptyFailed++;
cancel = executeActions(player, cc.emptyActions.getActions(data.emptyVL));
}

View File

@ -39,6 +39,9 @@ public class SpamCheck extends ChatCheck {
if(data.messageCount > cc.spamLimit) {
data.spamVL = data.messageCount - cc.spamLimit;
data.spamTotalVL++;
data.spamFailed++;
cancel = executeActions(player, cc.spamActions.getActions(data.spamVL));
}

View File

@ -43,7 +43,10 @@ public class DirectionCheck extends FightCheck {
// Player failed the check
// Increment violation counter
if(!plugin.skipCheck()) {
data.directionVL += Math.sqrt(off);
double sqrt = Math.sqrt(off);
data.directionVL += sqrt;
data.directionTotalVL += sqrt;
data.directionFailed++;
}
cancel = executeActions(player, cc.directionActions.getActions(data.directionVL));

View File

@ -26,6 +26,8 @@ public class NoswingCheck extends FightCheck {
data.noswingVL *= 0.90D;
} else {
data.noswingVL += 1;
data.noswingTotalVL += 1;
data.noswingFailed++;
cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL));
}

View File

@ -24,6 +24,9 @@ public class SelfhitCheck extends FightCheck {
// Player failed the check obviously
data.selfhitVL += 1;
data.selfhitTotalVL += 1;
data.selfhitFailed++;
cancel = executeActions(player, cc.selfhitActions.getActions(data.selfhitVL));
} else {
data.selfhitVL *= 0.99D;

View File

@ -24,11 +24,11 @@ public class FlyingCheck extends MovingCheck {
private static final double creativeSpeed = 0.60D;
public PreciseLocation check(NoCheatPlayer player, MovingData moving, CCMoving ccmoving) {
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving ccmoving) {
final PreciseLocation setBack = moving.runflySetBackPoint;
final PreciseLocation from = moving.from;
final PreciseLocation to = moving.to;
final PreciseLocation setBack = data.runflySetBackPoint;
final PreciseLocation from = data.from;
final PreciseLocation to = data.to;
if(!setBack.isSet()) {
setBack.set(from);
@ -50,32 +50,34 @@ public class FlyingCheck extends MovingCheck {
speedLimitHorizontal *= player.getSpeedAmplifier();
result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal);
result += Math.max(0.0D, horizontalDistance - data.horizFreedom - speedLimitHorizontal);
boolean sprinting = player.isSprinting();
moving.bunnyhopdelay--;
data.bunnyhopdelay--;
// Did he go too far?
if(result > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem
if(moving.bunnyhopdelay <= 0 && result < 0.4D) {
moving.bunnyhopdelay = 3;
if(data.bunnyhopdelay <= 0 && result < 0.4D) {
data.bunnyhopdelay = 3;
result = 0;
}
}
// super simple, just check distance compared to max distance
result += Math.max(0.0D, yDistance - moving.vertFreedom - ccmoving.flyingSpeedLimitVertical);
result += Math.max(0.0D, yDistance - data.vertFreedom - ccmoving.flyingSpeedLimitVertical);
result = result * 100;
if(result > 0) {
// Increment violation counter
moving.runflyVL += result;
data.runflyVL += result;
data.runflyTotalVL += result;
data.runflyFailed++;
boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(moving.runflyVL));
boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(data.runflyVL));
// Was one of the actions a cancel? Then really do it
if(cancel) {
@ -84,7 +86,7 @@ public class FlyingCheck extends MovingCheck {
}
// Slowly reduce the level with each event
moving.runflyVL *= 0.97;
data.runflyVL *= 0.97;
// Some other cleanup 'n' stuff
if(newToLocation == null) {

View File

@ -74,6 +74,8 @@ public class MorePacketsCheck extends MovingCheck {
// went over the limit
if(!plugin.skipCheck() && packetsAboveLimit > 0) {
data.morePacketsVL += packetsAboveLimit;
data.morePacketsTotalVL += packetsAboveLimit;
data.morePacketsFailed++;
data.packets = packetsAboveLimit;

View File

@ -48,6 +48,8 @@ public class NoFallCheck extends MovingCheck {
if(difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallVL += difference;
data.nofallTotalVL += difference;
data.nofallFailed++;
final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallVL));

View File

@ -77,6 +77,8 @@ public class RunningCheck extends MovingCheck {
// Increment violation counter
data.runflyVL += result;
data.runflyTotalVL += result;
data.runflyFailed++;
boolean cancel = executeActions(player, cc.actions.getActions(data.runflyVL));

View File

@ -1,5 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
public class BaseData extends Data {
public final BlockBreakData blockbreak;
@ -7,20 +9,22 @@ public class BaseData extends Data {
public final ChatData chat;
public final MovingData moving;
public final FightData fight;
public final TimedData timed;
private final Data[] data; // for convenience
private final long timestamp;
public BaseData() {
this.blockbreak = new BlockBreakData();
this.blockplace = new BlockPlaceData();
this.chat = new ChatData();
this.moving = new MovingData();
this.fight = new FightData();
this.timed = new TimedData();
data = new Data[] {this.blockbreak, this.blockplace, this.chat,
this.moving, this.fight, this.timed};
this.moving, this.fight};
this.timestamp = System.currentTimeMillis();
}
@ -30,4 +34,12 @@ public class BaseData extends Data {
}
}
public void collectData(Map<String, Object> map) {
for(Data d : data) {
d.collectData(map);
}
map.put("nocheat.starttime", timestamp);
map.put("nocheat.endtime", System.currentTimeMillis());
}
}

View File

@ -1,5 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
/**
* Playerspecific data for the blockbreak check group
*
@ -7,14 +9,21 @@ package cc.co.evenprime.bukkit.nocheat.data;
public class BlockBreakData extends Data {
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();
public final SimpleLocation brokenBlockLocation = new SimpleLocation();
public final ExecutionHistory history = new ExecutionHistory();
public double noswingVL = 0.0D;
public double reachDistance;
public boolean armswung = true;
@ -25,4 +34,14 @@ public class BlockBreakData extends Data {
directionLastViolationTime = 0;
armswung = true;
}
@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);
}
}

View File

@ -1,13 +1,20 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
/**
*
*/
public class BlockPlaceData extends Data {
public double reachVL = 0.0D;
public final ExecutionHistory history = new ExecutionHistory();
public double reachTotalVL = 0.0D;
public int reachFailed = 0;
public double directionVL = 0.0D;
public double directionTotalVL = 0.0D;
public int directionFailed = 0;
public final ExecutionHistory history = new ExecutionHistory();
public long directionLastViolationTime = 0;
public final SimpleLocation blockPlacedAgainst = new SimpleLocation();
@ -19,4 +26,12 @@ public class BlockPlaceData extends Data {
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);
}
}

View File

@ -1,14 +1,29 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
/**
*
*/
public class ChatData extends Data {
public int spamVL;
public int spamTotalVL;
public int spamFailed;
public int emptyVL;
public int emptyTotalVL;
public int emptyFailed;
public int messageCount = 0;
public int spamLasttime = 0;
public final ExecutionHistory history = new ExecutionHistory();
public String message = "";
public int spamVL;
public int emptyVL;
@Override
public void collectData(Map<String, Object> map) {
map.put("chat.spam.vl", (int) spamTotalVL);
map.put("chat.empty.vl", (int) emptyTotalVL);
map.put("chat.spam.failed", spamFailed);
map.put("chat.empty.failed", emptyFailed);
}
}

View File

@ -1,5 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
/**
*
* Every class that is extending this has to implement an empty Constructor()
@ -10,4 +12,6 @@ public abstract class Data {
public void clearCriticalData() {
}
public abstract void collectData(Map<String, Object> map);
}

View File

@ -1,15 +1,34 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
import net.minecraft.server.Entity;
public class FightData extends Data {
public double directionVL = 0;
public double directionVL = 0.0D;
public double directionTotalVL = 0.0D;
public int directionFailed = 0;
public double selfhitVL = 0.0D;
public double selfhitTotalVL = 0.0D;
public int selfhitFailed = 0;
public double noswingVL = 0.0D;
public double noswingTotalVL = 0.0D;
public int noswingFailed = 0;
public long directionLastViolationTime = 0;
public final ExecutionHistory history = new ExecutionHistory();
public double selfhitVL = 0;
public double noswingVL = 0.0D;
public Entity damagee;
public boolean armswung = true;
@Override
public void collectData(Map<String, Object> map) {
map.put("fight.direction.vl", (int)directionTotalVL);
map.put("fight.selfhit.vl", (int)selfhitTotalVL);
map.put("fight.noswing.vl", (int)noswingTotalVL);
map.put("fight.direction.failed", directionFailed);
map.put("fight.selfhit.failed", selfhitFailed);
map.put("fight.noswing.failed", noswingFailed);
}
}

View File

@ -1,23 +1,34 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.Map;
/**
* Player specific data for the moving check group
*/
public class MovingData extends Data {
public double runflyVL;
public double runflyTotalVL;
public int runflyFailed;
public double nofallVL;
public double nofallTotalVL;
public int nofallFailed;
public double morePacketsVL;
public double morePacketsTotalVL;
public int morePacketsFailed;
public int jumpPhase;
public final PreciseLocation runflySetBackPoint = new PreciseLocation();
public double runflyVL;
public double vertFreedom;
public double vertVelocity;
public int vertVelocityCounter;
public double horizFreedom;
public int horizVelocityCounter;
public double nofallVL;
public float fallDistance;
public float lastAddedFallDistance;
@ -29,7 +40,6 @@ public class MovingData extends Data {
public int packets;
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
public double morePacketsVL;
public final PreciseLocation teleportTo = new PreciseLocation();
@ -58,4 +68,14 @@ public class MovingData extends Data {
lastElapsedIngameSeconds = 0;
morePacketsCounter = 0;
}
@Override
public void collectData(Map<String, Object> map) {
map.put("moving.runfly.vl", (int) runflyTotalVL);
map.put("moving.nofall.vl", (int) nofallTotalVL);
map.put("moving.morepackets.vl", (int) morePacketsTotalVL);
map.put("moving.runfly.failed", runflyFailed);
map.put("moving.nofall.failed", nofallFailed);
map.put("moving.morepackets.failed", morePacketsFailed);
}
}

View File

@ -78,4 +78,15 @@ public class PlayerManager {
}
}
public void getPlayerData(String playerName, Map<String, Object> map) {
NoCheatPlayer player = this.players.get(playerName);
if(player != null) {
BaseData data = player.getData();
data.collectData(map);
}
}
}

View File

@ -1,17 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.data;
public class TimedData extends Data {
public int ticksLived;
public int ticksBehind;
public double godmodeVL;
public final ExecutionHistory history = new ExecutionHistory(); ;
public TimedData() {}
@Override
public void clearCriticalData() {
ticksBehind = 0;
ticksLived = 0;
}
}