Lots of minor optimizations to avoid creation of new objects if not

necessary and stop referencing bukkit objects beyond the scope of
events.
This commit is contained in:
Evenprime 2011-10-21 20:14:21 +02:00
parent 0225c73a51
commit 0687d6c78c
38 changed files with 487 additions and 404 deletions

View File

@ -129,23 +129,23 @@ public class NoCheat extends JavaPlugin {
log.log(level, message, cc);
}
public BaseData getData(Player player) {
return data.getData(player);
public BaseData getData(String playerName) {
return data.getData(playerName);
}
public void clearCriticalData(Player player) {
data.clearCriticalData(player);
public void clearCriticalData(String playerName) {
data.clearCriticalData(playerName);
}
public void playerLeft(Player player) {
public void playerLeft(String playerName) {
// Get rid of the critical data that's stored for player immediately
clearCriticalData(player);
clearCriticalData(playerName);
data.queueForRemoval(player);
data.queueForRemoval(playerName);
}
public void playerJoined(Player player) {
data.unqueueForRemoval(player);
public void playerJoined(String playerName) {
data.unqueueForRemoval(playerName);
}
public Performance getPerformance(Type type) {

View File

@ -30,7 +30,7 @@ public class ActionManager {
boolean special = false;
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
// Always set this here "by hand"
data.log.violationLevel = violationLevel;

View File

@ -3,10 +3,13 @@ package cc.co.evenprime.bukkit.nocheat.actions.types;
import java.util.ArrayList;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
public abstract class ActionWithParameters extends Action {
@ -99,29 +102,44 @@ public abstract class ActionWithParameters extends Action {
// only equal
switch (wildcard) {
case PLAYER:
return data.player.getName();
return data.playerName;
case CHECK:
return data.check;
case LOCATION:
Location l = data.player.getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
case WORLD:
return data.player.getWorld().getName();
case LOCATION: {
Player player = Bukkit.getPlayer(data.playerName);
if(player != null) {
Location l = player.getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
}
return "unknown";
}
case WORLD: {
Player player = Bukkit.getPlayer(data.playerName);
if(player != null) {
return player.getWorld().getName();
}
return "unknown";
}
case VIOLATIONS:
return String.format(Locale.US, "%d", data.violationLevel);
case MOVEDISTANCE:
Location l2 = data.player.getLocation();
Location t = data.toLocation;
if(t != null) {
return String.format(Locale.US, "%.2f,%.2f,%.2f", t.getX() - l2.getX(), t.getY() - l2.getY(), t.getZ() - l2.getZ());
} else {
return "null";
case MOVEDISTANCE: {
Player player = Bukkit.getPlayer(data.playerName);
if(player != null) {
Location l = player.getLocation();
PreciseLocation t = data.toLocation;
if(t.isSet()) {
return String.format(Locale.US, "%.2f,%.2f,%.2f", t.x - l.getX(), t.y - l.getY(), t.z - l.getZ());
} else {
return "null";
}
}
return "unknown";
}
case REACHDISTANCE:
return String.format(Locale.US, "%.2f", data.reachdistance);
@ -129,8 +147,12 @@ public abstract class ActionWithParameters extends Action {
return String.format(Locale.US, "%.2f", data.falldistance);
case LOCATION_TO:
Location to = data.toLocation;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.getX(), to.getY(), to.getZ());
PreciseLocation to = data.toLocation;
if(to.isSet()) {
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
} else {
return "unknown";
}
case PACKETS:
return String.valueOf(data.packets);

View File

@ -9,11 +9,11 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
/**
* Some stuff that's used by different checks
*
* @author Evenprime
*
*/
public class CheckUtil {
@ -21,7 +21,7 @@ public class CheckUtil {
* Check if a player looks at a target of a specific size, with a specific
* precision value (roughly)
*/
public static double directionCheck(Player player, double targetX, double targetY, double targetZ, double targetWidth, double targetHeight, double precision) {
public static final double directionCheck(Player player, double targetX, double targetY, double targetZ, double targetWidth, double targetHeight, double precision) {
// Eye location of the player
Location eyes = player.getEyeLocation();
@ -52,7 +52,7 @@ public class CheckUtil {
return off;
}
public static double reachCheck(Player player, double targetX, double targetY, double targetZ, double limit) {
public static final double reachCheck(Player player, double targetX, double targetY, double targetZ, double limit) {
Location eyes = player.getEyeLocation();
@ -108,10 +108,11 @@ public class CheckUtil {
types[Material.TRAP_DOOR.getId()] |= SOLID | NONSOLID;
}
public static boolean isSprinting(Player player) {
public static final boolean isSprinting(final Player player) {
return !(player instanceof CraftPlayer) || (player.isSprinting() && player.getFoodLevel() > 5);
}
/**
* Check if certain coordinates are considered "on ground"
*
@ -124,13 +125,13 @@ public class CheckUtil {
* The precise location that was used for calculation of "values"
* @return
*/
public static int isLocationOnGround(final World world, final double x, final double y, final double z, boolean waterElevatorsAllowed) {
public static final int isLocationOnGround(final World world, final PreciseLocation location) {
final int lowerX = lowerBorder(x);
final int upperX = upperBorder(x);
final int Y = (int) Math.floor(y);
final int lowerZ = lowerBorder(z);
final int upperZ = upperBorder(z);
final int lowerX = lowerBorder(location.x);
final int upperX = upperBorder(location.x);
final int Y = (int) Math.floor(location.y);
final int lowerZ = lowerBorder(location.z);
final int upperZ = upperBorder(location.z);
// Check the four borders of the players hitbox for something he could
// be standing on
@ -145,20 +146,11 @@ public class CheckUtil {
if(!isInGround(result)) {
// Original location: X, Z (allow standing in walls this time)
if(isSolid(types[world.getBlockTypeIdAt(Location.locToBlock(x), Location.locToBlock(y), Location.locToBlock(z))])) {
if(isSolid(types[world.getBlockTypeIdAt(Location.locToBlock(location.x), Location.locToBlock(location.y), Location.locToBlock(location.z))])) {
result |= INGROUND;
}
}
// Water elevators - optional "feature"
if(waterElevatorsAllowed && result == 0) {
result = types[world.getBlockTypeIdAt(lowerX + 1, Y + 1, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX, Y + 1, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX + 1, Y + 1, lowerZ)];
if((result & LIQUID) != 0) {
return INGROUND | ONGROUND; // WaterElevators don't really count
// as "water"
}
}
return result;
}
@ -171,10 +163,10 @@ public class CheckUtil {
* @param z
* @return
*/
private static final int canStand(World world, int x, int y, int z) {
private static final int canStand(final World world, final int x, final int y, final int z) {
int standingIn = types[world.getBlockTypeIdAt(x, y, z)];
int headIn = types[world.getBlockTypeIdAt(x, y + 1, z)];
final int standingIn = types[world.getBlockTypeIdAt(x, y, z)];
final int headIn = types[world.getBlockTypeIdAt(x, y + 1, z)];
int result = 0;
@ -187,7 +179,7 @@ public class CheckUtil {
return LADDER;
}
int standingOn = types[world.getBlockTypeIdAt(x, y - 1, z)];
final int standingOn = types[world.getBlockTypeIdAt(x, y - 1, z)];
// Player standing with his feet in a (half) block?
if((isSolid(standingIn) || standingOn == FENCE) && isNonSolid(headIn) && standingIn != FENCE) {
@ -202,27 +194,27 @@ public class CheckUtil {
return result;
}
public static final boolean isSolid(int value) {
public static final boolean isSolid(final int value) {
return (value & SOLID) == SOLID;
}
public static final boolean isLiquid(int value) {
public static final boolean isLiquid(final int value) {
return (value & LIQUID) == LIQUID;
}
private static final boolean isNonSolid(int value) {
private static final boolean isNonSolid(final int value) {
return((value & NONSOLID) == NONSOLID);
}
private static final boolean isLadder(int value) {
private static final boolean isLadder(final int value) {
return((value & LADDER) == LADDER);
}
public static boolean isOnGround(int fromType) {
public static final boolean isOnGround(final int fromType) {
return isLadder(fromType) || (fromType & ONGROUND) == ONGROUND;
}
public static boolean isInGround(int fromType) {
public static final boolean isInGround(final int fromType) {
return isLadder(fromType) || isLiquid(fromType) || (fromType & INGROUND) == INGROUND;
}
@ -233,17 +225,14 @@ public class CheckUtil {
* @param d1
* @return
*/
private static final int lowerBorder(double d1) {
private static final int lowerBorder(final double d1) {
double floor = Math.floor(d1);
double d4 = floor + magic;
final double floor = Math.floor(d1);
if(d4 <= d1)
d4 = 0;
if(floor + magic <= d1)
return (int) (floor);
else
d4 = 1;
return (int) (floor - d4);
return (int) (floor - 1);
}
/**
@ -253,20 +242,17 @@ public class CheckUtil {
* @param d1
* @return
*/
private static final int upperBorder(double d1) {
private static final int upperBorder(final double d1) {
double floor = Math.floor(d1);
double d4 = floor + magic2;
final double floor = Math.floor(d1);
if(d4 < d1)
d4 = -1;
if(floor + magic2 < d1)
return (int) (floor + 1);
else
d4 = 0;
return (int) (floor - d4);
return (int) floor;
}
public static int getType(int typeId) {
public static int getType(final int typeId) {
return types[typeId];
}

View File

@ -23,10 +23,10 @@ public class DirectionCheck {
public boolean check(Player player, Block brokenBlock, ConfigurationCache cc) {
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
// If the block is instabreak and we don't check instabreak, return
if(!cc.blockbreak.checkinstabreakblocks && brokenBlock.getLocation().equals(data.blockbreak.instaBrokeBlockLocation)) {
if(!cc.blockbreak.checkinstabreakblocks && data.blockbreak.instaBrokeBlockLocation.equals(brokenBlock)) {
return false;
}
@ -63,5 +63,4 @@ public class DirectionCheck {
return cancel;
}
}

View File

@ -30,7 +30,7 @@ public class ReachCheck {
double distance = CheckUtil.reachCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, player.getGameMode() == GameMode.CREATIVE ? cc.blockbreak.reachDistance + 2 : cc.blockbreak.reachDistance);
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
if(distance > 0D) {
// Player failed the check

View File

@ -0,0 +1,32 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The noswingcheck will only identify if an action happened without a preceding "swing"
*
*/
public class NoSwingCheck {
private final NoCheat plugin;
public NoSwingCheck(NoCheat plugin) {
this.plugin = plugin;
}
public boolean check(Player player, ConfigurationCache cc) {
boolean cancel = false;
BaseData data = plugin.getData(player.getName());
return cancel;
}
}

View File

@ -26,7 +26,7 @@ public class OnLiquidCheck {
boolean cancel = false;
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
if(blockPlaced == null || blockPlaced.isEmpty() || (blockPlacedAgainst != null && isSolid(blockPlacedAgainst.getTypeId()))) {
// all ok

View File

@ -29,7 +29,7 @@ public class ReachCheck {
double distance = CheckUtil.reachCheck(player, placedAgainstBlock.getX() + 0.5D, placedAgainstBlock.getY() + 0.5D, placedAgainstBlock.getZ() + 0.5D, cc.blockplace.reachDistance);
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
if(distance > 0D) {
// Player failed the check

View File

@ -37,7 +37,7 @@ public class ChatCheck {
int time = plugin.getIngameSeconds();
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
if(data.chat.spamLasttime + cc.chat.spamTimeframe <= time) {
data.chat.spamLasttime = time;

View File

@ -44,7 +44,7 @@ public class FightCheck {
// height to get the "center" of the hitbox
double off = CheckUtil.directionCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, width, 2.0D, cc.fight.directionPrecision);
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
if(off < 0.1D) {
// Player did probably nothing wrong

View File

@ -4,14 +4,16 @@ import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
/**
* A check designed for people that are allowed to fly. The complement to
@ -29,77 +31,82 @@ public class FlyingCheck {
this.plugin = plugin;
}
public Location check(Player player, Location from, Location to, ConfigurationCache cc) {
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
BaseData data = plugin.getData(player);
final MovingData moving = data.moving;
final PreciseLocation to = moving.to;
final PreciseLocation from = moving.from;
final PreciseLocation setBack = moving.runflySetBackPoint;
if(data.moving.runflySetBackPoint == null) {
data.moving.runflySetBackPoint = player.getLocation().clone();
final CCMoving ccmoving = cc.moving;
if(!setBack.isSet()) {
setBack.set(from);
}
final double yDistance = to.getY() - from.getY();
final double yDistance = to.y - from.y;
// Calculate some distances
final double xDistance = to.getX() - from.getX();
final double zDistance = to.getZ() - from.getZ();
final double xDistance = to.x - from.x;
final double zDistance = to.z - from.z;
final double horizontalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
double result = 0;
Location newToLocation = null;
PreciseLocation newToLocation = null;
// In case of creative gamemode, give at least 0.60 speed limit
// horizontal
double speedLimitHorizontal = player.getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, cc.moving.flyingSpeedLimitHorizontal) : cc.moving.flyingSpeedLimitHorizontal;
double speedLimitHorizontal = player.getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
EntityPlayer p = ((CraftPlayer) player).getHandle();
if(p.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
// Taken directly from Minecraft code, should work
speedLimitHorizontal *= 1.0F + 0.2F * (float) (p.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
}
result += Math.max(0.0D, horizontalDistance - data.moving.horizFreedom - speedLimitHorizontal);
result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal);
boolean sprinting = CheckUtil.isSprinting(player);
data.moving.bunnyhopdelay--;
moving.bunnyhopdelay--;
// Did he go too far?
if(result > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem
if(data.moving.bunnyhopdelay <= 0 && result < 0.4D) {
data.moving.bunnyhopdelay = 3;
if(moving.bunnyhopdelay <= 0 && result < 0.4D) {
moving.bunnyhopdelay = 3;
result = 0;
}
}
// super simple, just check distance compared to max distance
result += Math.max(0.0D, yDistance - data.moving.vertFreedom - cc.moving.flyingSpeedLimitVertical);
result += Math.max(0.0D, yDistance - moving.vertFreedom - ccmoving.flyingSpeedLimitVertical);
result = result * 100;
if(result > 0) {
// Increment violation counter
data.moving.runflyViolationLevel += result;
moving.runflyViolationLevel += result;
data.log.toLocation = to;
data.log.toLocation.set(to);
data.log.check = "flying/toofast";
boolean cancel = plugin.execute(player, cc.moving.flyingActions, (int) data.moving.runflyViolationLevel, data.moving.history, cc);
boolean cancel = plugin.execute(player, ccmoving.flyingActions, (int) moving.runflyViolationLevel, moving.history, cc);
// Was one of the actions a cancel? Then really do it
if(cancel) {
newToLocation = data.moving.runflySetBackPoint;
newToLocation = setBack;
}
}
// Slowly reduce the level with each event
data.moving.runflyViolationLevel *= 0.97;
moving.runflyViolationLevel *= 0.97;
// Some other cleanup 'n' stuff
if(newToLocation == null) {
data.moving.runflySetBackPoint = to.clone();
setBack.set(to);
}
return newToLocation;

View File

@ -1,11 +1,12 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
/**
* The morePacketsCheck (previously called SpeedhackCheck) will try to identify
@ -81,67 +82,63 @@ public class MorePacketsCheck {
* 8. reset packetCounter, wait for next 20 ticks to pass by.
*
*/
public Location check(Player player, ConfigurationCache cc) {
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
Location newToLocation = null;
PreciseLocation newToLocation = null;
BaseData data = plugin.getData(player);
final MovingData moving = data.moving;
data.moving.morePacketsCounter++;
if(data.moving.morePacketsSetbackPoint == null) {
data.moving.morePacketsSetbackPoint = player.getLocation();
moving.morePacketsCounter++;
if(!moving.morePacketsSetbackPoint.isSet()) {
moving.morePacketsSetbackPoint.set(moving.from);
}
int ingameSeconds = plugin.getIngameSeconds();
// Is at least a second gone by and has the server at least processed 20
// ticks since last time
if(ingameSeconds != data.moving.lastElapsedIngameSeconds) {
if(ingameSeconds != moving.lastElapsedIngameSeconds) {
int limit = (int) ((packetsPerTimeframe * plugin.getIngameSecondDuration()) / 1000L);
int difference = limit - data.moving.morePacketsCounter;
int difference = limit - moving.morePacketsCounter;
data.moving.morePacketsBuffer += difference;
if(data.moving.morePacketsBuffer > bufferLimit)
data.moving.morePacketsBuffer = bufferLimit;
moving.morePacketsBuffer += difference;
if(moving.morePacketsBuffer > bufferLimit)
moving.morePacketsBuffer = bufferLimit;
// Are we over the 22 event limit for that time frame now? (limit
// increases with time)
int packetsAboveLimit = (int) -data.moving.morePacketsBuffer;
int packetsAboveLimit = (int) -moving.morePacketsBuffer;
if(data.moving.morePacketsBuffer < 0)
data.moving.morePacketsBuffer = 0;
if(moving.morePacketsBuffer < 0)
moving.morePacketsBuffer = 0;
// Should we react? Only if the check doesn't get skipped and we
// went over the limit
if(!plugin.skipCheck() && packetsAboveLimit > 0) {
data.moving.morePacketsViolationLevel += packetsAboveLimit;
moving.morePacketsViolationLevel += packetsAboveLimit;
// Packets above limit
data.log.packets = data.moving.morePacketsCounter - limit;
data.log.packets = moving.morePacketsCounter - limit;
data.log.check = "moving/morepackets";
boolean cancel = false;
cancel = plugin.execute(player, cc.moving.morePacketsActions, (int) data.moving.morePacketsViolationLevel, data.moving.history, cc);
final boolean cancel = plugin.execute(player, cc.moving.morePacketsActions, (int) moving.morePacketsViolationLevel, moving.history, cc);
// Only do the cancel if the player didn't change worlds
// inbetween
if(cancel && player.getWorld().equals(data.moving.morePacketsSetbackPoint.getWorld())) {
newToLocation = data.moving.morePacketsSetbackPoint;
}
if(cancel)
newToLocation = moving.morePacketsSetbackPoint;
}
// No new setbackLocation was chosen
if(newToLocation == null) {
data.moving.morePacketsSetbackPoint = player.getLocation();
moving.morePacketsSetbackPoint.set(player.getLocation());
}
if(data.moving.morePacketsViolationLevel > 0)
if(moving.morePacketsViolationLevel > 0)
// Shrink the "over limit" value by 20 % every second
data.moving.morePacketsViolationLevel *= 0.8;
moving.morePacketsViolationLevel *= 0.8;
data.moving.morePacketsCounter = 0; // Count from zero again
data.moving.lastElapsedIngameSeconds = ingameSeconds;
moving.morePacketsCounter = 0; // Count from zero again
moving.lastElapsedIngameSeconds = ingameSeconds;
}
return newToLocation;

View File

@ -1,18 +1,16 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
/**
* A check to see if people cheat by tricking the server to not deal them
* fall damage.
*
* @author Evenprime
*
*/
public class NoFallCheck {
@ -26,45 +24,42 @@ public class NoFallCheck {
* Calculate if and how much the player "failed" this check.
*
*/
public void check(final Player player, final Location from, final boolean fromOnOrInGround, final Location to, final boolean toOnOrInGround, final ConfigurationCache cc) {
public void check(final Player player, final BaseData data, final boolean fromOnOrInGround, final boolean toOnOrInGround, final ConfigurationCache cc) {
double oldY = from.getY();
double newY = to.getY();
BaseData data = plugin.getData(player);
final MovingData moving = data.moving;
// This check is pretty much always a step behind for technical reasons.
if(fromOnOrInGround) {
// Start with zero fall distance
data.moving.fallDistance = 0F;
moving.fallDistance = 0F;
}
// If we increased fall height before for no good reason, reduce now by
// the same amount
if(player.getFallDistance() > data.moving.lastAddedFallDistance) {
player.setFallDistance(player.getFallDistance() - data.moving.lastAddedFallDistance);
if(player.getFallDistance() > moving.lastAddedFallDistance) {
player.setFallDistance(player.getFallDistance() - moving.lastAddedFallDistance);
}
data.moving.lastAddedFallDistance = 0;
moving.lastAddedFallDistance = 0;
// We want to know if the fallDistance recorded by the game is smaller
// than the fall distance recorded by the plugin
float difference = data.moving.fallDistance - player.getFallDistance();
final float difference = moving.fallDistance - player.getFallDistance();
if(difference > 1.0F && toOnOrInGround && data.moving.fallDistance > 2.0F) {
data.moving.nofallViolationLevel += difference;
if(difference > 1.0F && toOnOrInGround && moving.fallDistance > 2.0F) {
moving.nofallViolationLevel += difference;
// Prepare some event-specific values for logging and custom actions
data.log.falldistance = data.moving.fallDistance;
data.log.falldistance = moving.fallDistance;
data.log.check = "moving/nofall";
boolean cancel = plugin.execute(player, cc.moving.nofallActions, (int) data.moving.nofallViolationLevel, data.moving.history, cc);
final boolean cancel = plugin.execute(player, cc.moving.nofallActions, (int) moving.nofallViolationLevel, moving.history, cc);
// If "cancelled", the fall damage gets dealt in a way that's
// visible to other plugins
if(cancel) {
// Increase the fall distance a bit :)
float totalDistance = data.moving.fallDistance + difference * (cc.moving.nofallMultiplier - 1.0F);
final float totalDistance = moving.fallDistance + difference * (cc.moving.nofallMultiplier - 1.0F);
player.setFallDistance(totalDistance);
}
@ -81,21 +76,25 @@ public class NoFallCheck {
// to avoid falldamage. It is only added for big height differences
// anyway, as to avoid to much deviation
// from the original Minecraft feeling.
final double oldY = moving.from.y;
final double newY = moving.to.y;
if(oldY > newY) {
float dist = (float) (oldY - newY);
data.moving.fallDistance += dist;
final float dist = (float) (oldY - newY);
moving.fallDistance += dist;
if(dist > 1.0F) {
data.moving.lastAddedFallDistance = dist;
moving.lastAddedFallDistance = dist;
player.setFallDistance(player.getFallDistance() + dist);
} else {
data.moving.lastAddedFallDistance = 0.0F;
moving.lastAddedFallDistance = 0.0F;
}
} else {
data.moving.lastAddedFallDistance = 0.0F;
moving.lastAddedFallDistance = 0.0F;
}
// Reduce falldamage violation level
data.moving.nofallViolationLevel *= 0.99D;
moving.nofallViolationLevel *= 0.99D;
}
}

View File

@ -1,15 +1,18 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
/**
* The main Check class for Move event checking. It will decide which checks
@ -43,7 +46,7 @@ public class RunFlyCheck {
* @param event
* @return
*/
public Location check(final Player player, final Location from, final Location to, final ConfigurationCache cc) {
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
// Players in vehicles are of no interest
if(player.isInsideVehicle())
@ -52,47 +55,49 @@ public class RunFlyCheck {
/**
* If not null, this will be used as the new target location
*/
Location newToLocation = null;
PreciseLocation newTo = null;
BaseData data = plugin.getData(player);
final MovingData moving = data.moving;
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
if(data.moving.horizVelocityCounter > 0) {
data.moving.horizVelocityCounter--;
if(moving.horizVelocityCounter > 0) {
moving.horizVelocityCounter--;
} else {
data.moving.horizFreedom *= 0.90;
moving.horizFreedom *= 0.90;
}
if(data.moving.vertVelocityCounter > 0) {
data.moving.vertVelocityCounter--;
data.moving.vertFreedom += data.moving.vertVelocity;
data.moving.vertVelocity *= 0.90;
if(moving.vertVelocityCounter > 0) {
moving.vertVelocityCounter--;
moving.vertFreedom += moving.vertVelocity;
moving.vertVelocity *= 0.90;
} else {
data.moving.vertFreedom = 0;
moving.vertFreedom = 0;
}
final CCMoving ccmoving = cc.moving;
/************* DECIDE WHICH CHECKS NEED TO BE RUN *************/
final boolean runflyCheck = cc.moving.runflyCheck && !player.hasPermission(Permissions.MOVE_RUNFLY);
final boolean flyAllowed = cc.moving.allowFlying || player.hasPermission(Permissions.MOVE_FLY) || (player.getGameMode() == GameMode.CREATIVE && cc.moving.identifyCreativeMode);
final boolean morepacketsCheck = cc.moving.morePacketsCheck && !player.hasPermission(Permissions.MOVE_MOREPACKETS);
final boolean runflyCheck = ccmoving.runflyCheck && !player.hasPermission(Permissions.MOVE_RUNFLY);
final boolean flyAllowed = ccmoving.allowFlying || player.hasPermission(Permissions.MOVE_FLY) || (player.getGameMode() == GameMode.CREATIVE && ccmoving.identifyCreativeMode);
final boolean morepacketsCheck = ccmoving.morePacketsCheck && !player.hasPermission(Permissions.MOVE_MOREPACKETS);
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
// If the player is not allowed to fly and not allowed to run
if(runflyCheck) {
if(flyAllowed) {
newToLocation = flyingCheck.check(player, from, to, cc);
newTo = flyingCheck.check(player, data, cc);
} else {
newToLocation = runningCheck.check(player, from, to, cc);
newTo = runningCheck.check(player, data, cc);
}
}
/********* EXECUTE THE MOREPACKETS CHECK ********************/
if(newToLocation == null && morepacketsCheck) {
newToLocation = morePacketsCheck.check(player, cc);
if(newTo == null && morepacketsCheck) {
newTo = morePacketsCheck.check(player, data, cc);
}
return newToLocation;
return newTo;
}
/**
@ -102,21 +107,23 @@ public class RunFlyCheck {
*/
public void blockPlaced(Player player, Block blockPlaced) {
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(player.getName());
if(blockPlaced == null || data.moving.runflySetBackPoint == null) {
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
return;
}
Location lblock = blockPlaced.getLocation();
Location lplayer = player.getLocation();
SimpleLocation lblock = new SimpleLocation();
lblock.setLocation(blockPlaced);
SimpleLocation lplayer = new SimpleLocation();
lplayer.setLocation(player.getLocation());
if(Math.abs(lplayer.getBlockX() - lblock.getBlockX()) <= 1 && Math.abs(lplayer.getBlockZ() - lblock.getBlockZ()) <= 1 && lplayer.getBlockY() - lblock.getBlockY() >= 0 && lplayer.getBlockY() - lblock.getBlockY() <= 2) {
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
int type = CheckUtil.getType(blockPlaced.getTypeId());
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
if(lblock.getBlockY() + 1 >= data.moving.runflySetBackPoint.getY()) {
data.moving.runflySetBackPoint.setY(lblock.getBlockY() + 1);
if(lblock.y + 1 >= data.moving.runflySetBackPoint.y) {
data.moving.runflySetBackPoint.y = (lblock.y + 1);
data.moving.jumpPhase = 0;
}
}

View File

@ -3,15 +3,17 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
/**
* The counterpart to the FlyingCheck. People that are not allowed to fly
@ -37,73 +39,77 @@ public class RunningCheck {
this.noFallCheck = noFallCheck;
}
public Location check(final Player player, final Location from, final Location to, final ConfigurationCache cc) {
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
// Some shortcuts:
final MovingData moving = data.moving;
final PreciseLocation to = moving.to;
final PreciseLocation from = moving.from;
final PreciseLocation setBack = moving.runflySetBackPoint;
final CCMoving ccmoving = cc.moving;
// Calculate some distances
final double xDistance = to.getX() - from.getX();
final double zDistance = to.getZ() - from.getZ();
final double xDistance = to.x - from.x;
final double zDistance = to.z - from.z;
final double horizontalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
BaseData data = plugin.getData(player);
if(data.moving.runflySetBackPoint == null) {
data.moving.runflySetBackPoint = from.clone();
if(!setBack.isSet()) {
setBack.set(from);
}
// To know if a player "is on ground" is useful
final int fromType = CheckUtil.isLocationOnGround(from.getWorld(), from.getX(), from.getY(), from.getZ(), false);
final int toType = CheckUtil.isLocationOnGround(to.getWorld(), to.getX(), to.getY(), to.getZ(), false);
final int fromType = CheckUtil.isLocationOnGround(player.getWorld(), from);
final int toType = CheckUtil.isLocationOnGround(player.getWorld(), to);
final boolean fromOnGround = CheckUtil.isOnGround(fromType);
final boolean fromInGround = CheckUtil.isInGround(fromType);
final boolean toOnGround = CheckUtil.isOnGround(toType);
final boolean toInGround = CheckUtil.isInGround(toType);
Location newToLocation = null;
PreciseLocation newToLocation = null;
double resultHoriz = Math.max(0.0D, checkHorizontal(player, CheckUtil.isLiquid(fromType) && CheckUtil.isLiquid(toType), horizontalDistance, cc));
double resultVert = Math.max(0.0D, checkVertical(player, from, fromOnGround, to, toOnGround, cc));
final double resultHoriz = Math.max(0.0D, checkHorizontal(player, data, CheckUtil.isLiquid(fromType) && CheckUtil.isLiquid(toType), horizontalDistance, ccmoving));
final double resultVert = Math.max(0.0D, checkVertical(moving, fromOnGround, toOnGround, ccmoving));
double result = (resultHoriz + resultVert) * 100;
final double result = (resultHoriz + resultVert) * 100;
data.moving.jumpPhase++;
moving.jumpPhase++;
// Slowly reduce the level with each event
data.moving.runflyViolationLevel *= 0.97;
moving.runflyViolationLevel *= 0.97;
if(result > 0) {
// Increment violation counter
data.moving.runflyViolationLevel += result;
moving.runflyViolationLevel += result;
// Prepare some event-specific values for logging and custom actions
data.log.toLocation = to;
data.log.toLocation.set(to);
if(resultHoriz > 0 && resultVert > 0)
data.log.check = "runfly/both";
else if(resultHoriz > 0) {
// We already set the correct value for this
// data.log.check = "runfly/something"
}
else if(resultVert > 0)
} else if(resultVert > 0)
data.log.check = "runfly/vertical";
boolean cancel = plugin.execute(player, cc.moving.actions, (int) data.moving.runflyViolationLevel, data.moving.history, cc);
boolean cancel = plugin.execute(player, cc.moving.actions, (int) moving.runflyViolationLevel, moving.history, cc);
// Was one of the actions a cancel? Then do it
if(cancel) {
newToLocation = data.moving.runflySetBackPoint;
newToLocation = setBack;
}
} else {
if((toInGround && from.getY() >= to.getY()) || CheckUtil.isLiquid(toType)) {
data.moving.runflySetBackPoint = to.clone();
data.moving.runflySetBackPoint.setY(Math.ceil(data.moving.runflySetBackPoint.getY()));
data.moving.jumpPhase = 0;
} else if(toOnGround && (from.getY() >= to.getY() || data.moving.runflySetBackPoint.getY() <= Math.floor(to.getY()))) {
data.moving.runflySetBackPoint = to.clone();
data.moving.runflySetBackPoint.setY(Math.floor(data.moving.runflySetBackPoint.getY()));
data.moving.jumpPhase = 0;
if((toInGround && from.y >= to.y) || CheckUtil.isLiquid(toType)) {
setBack.set(to);
setBack.y = Math.ceil(setBack.y);
moving.jumpPhase = 0;
} else if(toOnGround && (from.y >= to.y || setBack.y <= Math.floor(to.y))) {
setBack.set(to);
setBack.y = Math.floor(setBack.y);
moving.jumpPhase = 0;
} else if(fromOnGround || fromInGround || toOnGround || toInGround) {
data.moving.jumpPhase = 0;
moving.jumpPhase = 0;
}
}
@ -111,7 +117,7 @@ public class RunningCheck {
final boolean checkNoFall = cc.moving.nofallCheck && !player.hasPermission(Permissions.MOVE_NOFALL);
if(checkNoFall && newToLocation == null) {
noFallCheck.check(player, from, fromOnGround || fromInGround, to, toOnGround || toInGround, cc);
noFallCheck.check(player, data, fromOnGround || fromInGround, toOnGround || toInGround, cc);
}
return newToLocation;
@ -121,71 +127,73 @@ public class RunningCheck {
* Calculate how much the player failed this check
*
*/
private double checkHorizontal(final Player player, final boolean isSwimming, final double totalDistance, final ConfigurationCache cc) {
private double checkHorizontal(final Player player, final BaseData data, final boolean isSwimming, final double totalDistance, final CCMoving ccmoving) {
// How much further did the player move than expected??
double distanceAboveLimit = 0.0D;
final boolean sprinting = CheckUtil.isSprinting(player);
BaseData data = plugin.getData(player);
double limit = 0.0D;
EntityPlayer p = ((CraftPlayer) player).getHandle();
final EntityPlayer p = ((CraftPlayer) player).getHandle();
final MovingData moving = data.moving;
if(cc.moving.sneakingCheck && player.isSneaking() && !player.hasPermission(Permissions.MOVE_SNEAK)) {
limit = cc.moving.sneakingSpeedLimit;
if(ccmoving.sneakingCheck && player.isSneaking() && !player.hasPermission(Permissions.MOVE_SNEAK)) {
limit = ccmoving.sneakingSpeedLimit;
data.log.check = "runfly/sneak";
} else if(cc.moving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVE_SWIM)) {
limit = cc.moving.swimmingSpeedLimit;
} else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVE_SWIM)) {
limit = ccmoving.swimmingSpeedLimit;
data.log.check = "runfly/swim";
} else if(!sprinting) {
limit = cc.moving.walkingSpeedLimit;
limit = ccmoving.walkingSpeedLimit;
data.log.check = "runfly/walk";
} else {
limit = cc.moving.sprintingSpeedLimit;
limit = ccmoving.sprintingSpeedLimit;
data.log.check = "runfly/sprint";
}
if(p.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
// Taken directly from Minecraft code, should work
limit *= 1.0F + 0.2F * (float) (p.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
limit *= 1.0F + 0.2F * (float) (p.getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier() + 1);
}
// Ignore slowdowns for now
/*if(p.hasEffect(MobEffectList.SLOWER_MOVEMENT)) {
limit *= 1.0F - 0.15F * (float) (p.getEffect(MobEffectList.SLOWER_MOVEMENT).getAmplifier() + 1);
}*/
distanceAboveLimit = totalDistance - limit - data.moving.horizFreedom;
data.moving.bunnyhopdelay--;
// Ignore slowdowns for now
/*
* if(p.hasEffect(MobEffectList.SLOWER_MOVEMENT)) {
* limit *= 1.0F - 0.15F * (float)
* (p.getEffect(MobEffectList.SLOWER_MOVEMENT).getAmplifier() + 1);
* }
*/
distanceAboveLimit = totalDistance - limit - moving.horizFreedom;
moving.bunnyhopdelay--;
// Did he go too far?
if(distanceAboveLimit > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem
if(data.moving.bunnyhopdelay <= 0 && distanceAboveLimit > 0.05D && distanceAboveLimit < 0.4D) {
data.moving.bunnyhopdelay = 3;
if(moving.bunnyhopdelay <= 0 && distanceAboveLimit > 0.05D && distanceAboveLimit < 0.4D) {
moving.bunnyhopdelay = 3;
distanceAboveLimit = 0;
}
}
if(distanceAboveLimit > 0) {
// Try to consume the "buffer"
distanceAboveLimit -= data.moving.horizontalBuffer;
data.moving.horizontalBuffer = 0;
distanceAboveLimit -= moving.horizontalBuffer;
moving.horizontalBuffer = 0;
// Put back the "overconsumed" buffer
if(distanceAboveLimit < 0) {
data.moving.horizontalBuffer = -distanceAboveLimit;
moving.horizontalBuffer = -distanceAboveLimit;
}
}
// He was within limits, give the difference as buffer
else {
data.moving.horizontalBuffer = Math.min(maxBonus, data.moving.horizontalBuffer - distanceAboveLimit);
moving.horizontalBuffer = Math.min(maxBonus, moving.horizontalBuffer - distanceAboveLimit);
}
return distanceAboveLimit;
@ -195,21 +203,17 @@ public class RunningCheck {
* Calculate if and how much the player "failed" this check.
*
*/
private double checkVertical(final Player player, final Location from, final boolean fromOnGround, final Location to, final boolean toOnGround, final ConfigurationCache cc) {
private double checkVertical(final MovingData moving, final boolean fromOnGround, final boolean toOnGround, final CCMoving ccmoving) {
// How much higher did the player move than expected??
double distanceAboveLimit = 0.0D;
final double toY = to.getY();
double limit = moving.vertFreedom + ccmoving.jumpheight;
BaseData data = plugin.getData(player);
double limit = data.moving.vertFreedom + cc.moving.jumpheight;
if(data.moving.jumpPhase > jumpingLimit) {
limit -= (data.moving.jumpPhase - jumpingLimit) * 0.15D;
if(moving.jumpPhase > jumpingLimit) {
limit -= (moving.jumpPhase - jumpingLimit) * 0.15D;
}
distanceAboveLimit = toY - data.moving.runflySetBackPoint.getY() - limit;
distanceAboveLimit = moving.to.y - moving.runflySetBackPoint.y - limit;
return distanceAboveLimit;

View File

@ -4,8 +4,6 @@ import cc.co.evenprime.bukkit.nocheat.config.Configuration;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
/**
*
* @author Evenprime
*
*/
public class CCBlockPlace {

View File

@ -7,8 +7,6 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
* Configurations specific for the Move Checks. Every world gets one of these
* assigned to it.
*
* @author Evenprime
*
*/
public class CCMoving {

View File

@ -8,10 +8,8 @@ import cc.co.evenprime.bukkit.nocheat.config.Configuration;
* A class to keep all configurables of the plugin associated with
* a world, everything unmodifiable for security/performance
*
* @author Evenprime
*
*/
public class ConfigurationCache {
public class ConfigurationCache {
public final CCMoving moving;
public final CCLogging logging;

View File

@ -1,7 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.entity.Player;
public class BaseData extends Data {
public final BlockBreakData blockbreak;
@ -35,12 +33,6 @@ public class BaseData extends Data {
}
}
public void initialize(Player player) {
for(Data d : data) {
d.initialize(player);
}
}
public void markForRemoval(boolean removal) {
if(removal) {
// 1 minute in the future

View File

@ -1,7 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location;
/**
* Playerspecific data for the blockbreak check group
*
@ -12,7 +10,8 @@ public class BlockBreakData extends Data {
public double directionViolationLevel = 0.0D;
public long directionLastViolationTime = 0;
public Location instaBrokeBlockLocation = null;
public final SimpleLocation instaBrokeBlockLocation = new SimpleLocation();
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -1,14 +1,11 @@
package cc.co.evenprime.bukkit.nocheat.data;
/**
*
* @author Evenprime
*
*/
public class BlockPlaceData extends Data {
public double onliquidViolationLevel = 0.0D;
public double reachViolationLevel = 0.0D;
public double onliquidViolationLevel = 0.0D;
public double reachViolationLevel = 0.0D;
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -1,15 +1,12 @@
package cc.co.evenprime.bukkit.nocheat.data;
/**
*
* @author Evenprime
*
*/
public class ChatData extends Data {
public int messageCount = 0;
public int spamLasttime = 0;
public int messageCount = 0;
public int spamLasttime = 0;
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -1,20 +1,12 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.entity.Player;
/**
*
* Every class that is extending this has to implement an empty Constructor()
*
* @author Evenprime
*
*/
public abstract class Data {
public void initialize(Player player) {
}
public void clearCriticalData() {
}

View File

@ -6,8 +6,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.entity.Player;
/**
* Provide secure access to player-specific data objects for various checks or
* check groups.
@ -15,19 +13,21 @@ import org.bukkit.entity.Player;
public class DataManager {
// Store data between Events
private final Map<Player, BaseData> map;
private final Map<String, BaseData> map;
private final List<String> removals;
public DataManager() {
this.map = new HashMap<Player, BaseData>();
this.map = new HashMap<String, BaseData>();
this.removals = new ArrayList<String>(5);
}
/**
* Get a data object of the specified class. If none is stored yet, create
* one.
*/
public BaseData getData(Player player) {
public BaseData getData(String playerName) {
BaseData data = this.map.get(player);
BaseData data = this.map.get(playerName);
// intentionally not thread-safe, because bukkit events are handled
// in sequence anyway, so zero chance of two events of the same
@ -36,8 +36,8 @@ public class DataManager {
// losing data of one instance doesn't really hurt at all
if(data == null) {
data = new BaseData();
data.initialize(player);
this.map.put(player, data);
data.log.playerName = playerName;
this.map.put(playerName, data);
}
return data;
@ -58,16 +58,16 @@ public class DataManager {
* before)
*
*/
public void queueForRemoval(Player player) {
BaseData data = this.map.get(player);
public void queueForRemoval(String playerName) {
BaseData data = this.map.get(playerName);
if(data != null) {
data.markForRemoval(true);
}
}
public void unqueueForRemoval(Player player) {
BaseData data = this.map.get(player);
public void unqueueForRemoval(String playerName) {
BaseData data = this.map.get(playerName);
if(data != null) {
data.markForRemoval(false);
@ -80,24 +80,25 @@ public class DataManager {
*/
public void cleanDataMap() {
try {
List<Player> removals = new ArrayList<Player>();
for(Entry<Player, BaseData> p : this.map.entrySet()) {
for(Entry<String, BaseData> p : this.map.entrySet()) {
if(p.getValue().shouldBeRemoved()) {
removals.add(p.getKey());
}
}
for(Player p : removals) {
for(String p : removals) {
this.map.remove(p);
}
removals.clear();
} catch(Exception e) {
// Ignore problems, as they really don't matter much
}
}
public void clearCriticalData(Player player) {
BaseData data = this.map.get(player);
public void clearCriticalData(String playerName) {
BaseData data = this.map.get(playerName);
if(data != null) {
data.clearCriticalData();
}

View File

@ -8,8 +8,6 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
/**
* Store amount of action executions for last 60 seconds
*
* @author Evenprime
*
*/
public class ExecutionHistory {

View File

@ -2,8 +2,8 @@ package cc.co.evenprime.bukkit.nocheat.data;
public class FightData extends Data {
public double violationLevel = 0;
public long directionLastViolationTime = 0;
public double violationLevel = 0;
public long directionLastViolationTime = 0;
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -1,28 +1,21 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
/**
* Everything that could be relevant for logging or consolecommand actions
*/
public class LogData extends Data {
public Player player;
public String check;
public int violationLevel;
public Location toLocation;
public int packets;
public String text;
public Block placed;
public Block placedAgainst;
public double reachdistance;
public float falldistance;
public String check;
public int violationLevel;
public final PreciseLocation toLocation = new PreciseLocation();
public int packets;
public String text;
public Block placed;
public Block placedAgainst;
public double reachdistance;
public float falldistance;
public String playerName;
public void initialize(Player player) {
this.player = player;
this.check = "";
this.toLocation = player.getLocation();
}
}

View File

@ -1,60 +1,53 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location;
import org.bukkit.entity.Player;
/**
* Player specific data for the moving check group
*/
public class MovingData extends Data {
public int jumpPhase;
public int jumpPhase;
public Location runflySetBackPoint;
public final PreciseLocation runflySetBackPoint = new PreciseLocation();
public double runflyViolationLevel;
public double runflyViolationLevel;
public double vertFreedom;
public double vertVelocity;
public int vertVelocityCounter;
public double horizFreedom;
public int horizVelocityCounter;
public double vertFreedom;
public double vertVelocity;
public int vertVelocityCounter;
public double horizFreedom;
public int horizVelocityCounter;
public double nofallViolationLevel;
public float fallDistance;
public float lastAddedFallDistance;
public double nofallViolationLevel;
public float fallDistance;
public float lastAddedFallDistance;
public double horizontalBuffer;
public int bunnyhopdelay;
public double horizontalBuffer;
public int bunnyhopdelay;
public int morePacketsCounter;
public int morePacketsBuffer;
public Location morePacketsSetbackPoint;
public double morePacketsViolationLevel;
public int morePacketsCounter;
public int morePacketsBuffer = 50;
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
public double morePacketsViolationLevel;
public Location teleportTo;
public final PreciseLocation teleportTo = new PreciseLocation();
public int lastElapsedIngameSeconds;
public int lastElapsedIngameSeconds;
public final ExecutionHistory history = new ExecutionHistory();
public final ExecutionHistory history = new ExecutionHistory();
@Override
public void initialize(Player player) {
runflySetBackPoint = player.getLocation();
morePacketsBuffer = 50;
morePacketsSetbackPoint = player.getLocation();
}
public final PreciseLocation from = new PreciseLocation();
public final PreciseLocation to = new PreciseLocation();
@Override
public void clearCriticalData() {
teleportTo = null;
teleportTo.reset();
jumpPhase = 0;
runflySetBackPoint = null;
runflySetBackPoint.reset();
fallDistance = 0;
lastAddedFallDistance = 0;
bunnyhopdelay = 0;
morePacketsBuffer = 50;
morePacketsSetbackPoint = null;
morePacketsSetbackPoint.reset();
lastElapsedIngameSeconds = 0;
morePacketsCounter = 0;
}

View File

@ -0,0 +1,39 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location;
public class PreciseLocation {
public double x;
public double y;
public double z;
public PreciseLocation() {
reset();
}
public void set(Location location) {
x = location.getX();
y = location.getY();
z = location.getZ();
}
public void set(PreciseLocation location) {
x = location.x;
y = location.y;
z = location.z;
}
public boolean isSet() {
return x != Double.MAX_VALUE;
}
public void reset() {
x = Double.MAX_VALUE;
y = Double.MAX_VALUE;
z = Double.MAX_VALUE;
}
public boolean equals(Location location) {
return location.getX() == x && location.getY() == y && location.getZ() == z;
}
}

View File

@ -0,0 +1,47 @@
package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location;
import org.bukkit.block.Block;
/**
* To avoid constantly creating and referencing "Location" objects, which
* in turn reference a whole lot of other unnecessary stuff, rather use
* our own "Location" object which is easily reusable.
*
*/
public class SimpleLocation {
public int x;
public int y;
public int z;
public SimpleLocation() {
reset();
}
public boolean equals(Block block) {
return block.getX() == x && block.getY() == y && block.getZ() == z;
}
public void setLocation(Block block) {
x = block.getX();
y = block.getY();
z = block.getZ();
}
public void setLocation(Location location) {
x = location.getBlockX();
y = location.getBlockY();
z = location.getBlockZ();
}
public boolean isSet() {
return x != Integer.MAX_VALUE;
}
public void reset() {
x = Integer.MAX_VALUE;
y = Integer.MAX_VALUE;
z = Integer.MAX_VALUE;
}
}

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
@ -39,7 +38,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
this.blockBreakPerformance = plugin.getPerformance(Type.BLOCKBREAK);
this.blockDamagePerformance = plugin.getPerformance(Type.BLOCKDAMAGE);
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.Monitor, plugin);
@ -94,13 +93,12 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
if(performanceCheck)
nanoTimeStart = System.nanoTime();
final Player player = event.getPlayer();
// Get the player-specific stored data that applies here
final BaseData data = plugin.getData(player);
final BaseData data = plugin.getData(event.getPlayer().getName());
// Remember this location. We ignore block breaks in the block-break
// direction check that are insta-breaks
data.blockbreak.instaBrokeBlockLocation = event.getBlock().getLocation();
data.blockbreak.instaBrokeBlockLocation.setLocation(event.getBlock());
// store performance time
if(performanceCheck)

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
@ -41,7 +40,7 @@ public class BlockPlaceEventManager extends BlockListener implements EventManage
this.blockPlacePerformance = p.getPerformance(Type.BLOCKPLACE);
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Lowest, plugin);

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -34,7 +33,7 @@ public class EntityDamageEventManager extends EntityListener implements EventMan
this.fightPerformance = plugin.getPerformance(Type.FIGHT);
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Lowest, plugin);
}

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
@ -35,7 +34,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
this.chatPerformance = plugin.getPerformance(Type.CHAT);
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this, Priority.Lowest, plugin);

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
@ -19,6 +18,8 @@ import cc.co.evenprime.bukkit.nocheat.checks.moving.RunFlyCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -45,14 +46,14 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
this.movePerformance = plugin.getPerformance(Type.MOVING);
this.velocityPerformance = plugin.getPerformance(Type.VELOCITY);
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_VELOCITY, this, Priority.Monitor, plugin);
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
public void onPlayerMove(final PlayerMoveEvent event) {
// Cancelled events are ignored
if(event.isCancelled())
@ -75,27 +76,25 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
// Get some data that's needed from this event, to avoid passing the
// event itself on to the checks (and risk to
// accidentally modifying the event there)
final Location from = event.getFrom();
final BaseData data = plugin.getData(player.getName());
final MovingData moving = data.moving;
final Location to = event.getTo();
moving.from.set(event.getFrom());
moving.to.set(to);
// This variable will have the modified data of the event (new
// "to"-location)
Location newTo = null;
// Currently only one check here.
newTo = movingCheck.check(player, from, to, cc);
final PreciseLocation newTo = movingCheck.check(player, data, cc);
// Did the check(s) decide we need a new "to"-location?
if(newTo != null) {
// Compose a new location based on coordinates of "newTo" and
// viewing direction of "event.getTo()"
Location l = new Location(newTo.getWorld(), newTo.getX(), newTo.getY(), newTo.getZ(), to.getYaw(), to.getPitch());
event.setTo(l);
event.setTo(new Location(player.getWorld(), newTo.x, newTo.y, newTo.z, to.getYaw(), to.getPitch()));
// Get the player-specific stored data that applies here
final BaseData data = plugin.getData(player);
data.moving.teleportTo = l;
data.moving.teleportTo.set(newTo);
}
}
@ -116,9 +115,7 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
if(performanceCheck)
nanoTimeStart = System.nanoTime();
Player player = event.getPlayer();
BaseData data = plugin.getData(player);
BaseData data = plugin.getData(event.getPlayer().getName());
Vector v = event.getVelocity();

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerJoinEvent;
@ -21,7 +20,7 @@ public class PlayerQuitEventManager extends PlayerListener implements EventManag
public PlayerQuitEventManager(NoCheat plugin) {
this.plugin = plugin;
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_QUIT, this, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_JOIN, this, Priority.Monitor, plugin);
@ -30,13 +29,13 @@ public class PlayerQuitEventManager extends PlayerListener implements EventManag
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
// But only after a certain time, get rid of the rest of the data
plugin.playerLeft(event.getPlayer());
plugin.playerLeft(event.getPlayer().getName());
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
// A player came back early, so make sure that his data gets recycled
plugin.playerJoined(event.getPlayer());
plugin.playerJoined(event.getPlayer().getName());
}
public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -3,9 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.events;
import java.util.Collections;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerListener;
@ -32,7 +29,7 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
this.plugin = p;
PluginManager pm = Bukkit.getServer().getPluginManager();
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_TELEPORT, this, Priority.Monitor, plugin);
@ -50,9 +47,9 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
return;
}
final BaseData data = plugin.getData(event.getPlayer());
final BaseData data = plugin.getData(event.getPlayer().getName());
if(data.moving.teleportTo != null && data.moving.teleportTo.equals(event.getTo())) {
if(data.moving.teleportTo.isSet() && data.moving.teleportTo.equals(event.getTo())) {
event.setCancelled(false);
}
}
@ -64,18 +61,18 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
if(event.isCancelled())
return;
handleTeleportation(event.getPlayer(), event.getTo());
handleTeleportation(event.getPlayer().getName());
}
public void onPlayerPortal(PlayerPortalEvent event) {
if(event.isCancelled())
return;
handleTeleportation(event.getPlayer(), event.getTo());
handleTeleportation(event.getPlayer().getName());
}
public void onPlayerRespawn(PlayerRespawnEvent event) {
handleTeleportation(event.getPlayer(), event.getRespawnLocation());
handleTeleportation(event.getPlayer().getName());
}
// Workaround for buggy Playermove cancelling
@ -84,12 +81,12 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
return;
}
handleTeleportation(event.getPlayer(), event.getFrom());
handleTeleportation(event.getPlayer().getName());
}
private void handleTeleportation(Player player, Location newLocation) {
private void handleTeleportation(String playerName) {
plugin.clearCriticalData(player);
plugin.clearCriticalData(playerName);
}
public List<String> getActiveChecks(ConfigurationCache cc) {