Some refactoring to lessen class dependencies, reduce number of

parameters and duplicate code
This commit is contained in:
Evenprime 2011-10-16 19:57:05 +02:00
parent 14642564b6
commit 2c27063b75
32 changed files with 429 additions and 474 deletions

View File

@ -16,6 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.ActionManager;
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager;
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.DataManager;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager;
@ -121,7 +122,7 @@ public class NoCheat extends JavaPlugin {
ingameseconds++;
// Check if some data is outdated now and let it be removed
getDataManager().cleanDataMap();
data.cleanDataMap();
}
}, 0, 20);
}
@ -141,8 +142,20 @@ public class NoCheat extends JavaPlugin {
return log;
}
public DataManager getDataManager() {
return data;
public BaseData getPlayerData(Player player) {
return data.getData(player);
}
public void clearCriticalPlayerData(Player player) {
data.clearCriticalData(player);
}
public void playerLeft(Player player) {
data.queueForRemoval(player);
}
public void playerJoined(Player player) {
data.unqueueForRemoval(player);
}
public PerformanceManager getPerformanceManager() {
@ -254,7 +267,7 @@ public class NoCheat extends JavaPlugin {
this.conf.cleanup();
this.conf = new ConfigurationManager(this.getDataFolder().getPath());
this.data.resetAllCriticalData();
this.data.clearCriticalData();
sender.sendMessage("[NoCheat] Configuration reloaded");

View File

@ -9,7 +9,8 @@ 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.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
import cc.co.evenprime.bukkit.nocheat.data.ActionData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
/**
@ -27,12 +28,13 @@ public class ActionManager {
this.plugin = plugin;
}
public boolean executeActions(Player player, ActionList actions, int violationLevel, LogData data, ActionData history, ConfigurationCache cc) {
public boolean executeActions(Player player, ActionList actions, int violationLevel, ExecutionHistory history, ConfigurationCache cc) {
boolean special = false;
BaseData data = plugin.getPlayerData(player);
// Always set this here "by hand"
data.violationLevel = violationLevel;
data.log.violationLevel = violationLevel;
final long time = System.currentTimeMillis() / 1000;
@ -40,11 +42,11 @@ public class ActionManager {
if(history.executeAction(ac, time)) {
if(ac instanceof LogAction) {
executeLogAction((LogAction) ac, data, cc);
executeLogAction((LogAction) ac, data.log, cc);
} else if(ac instanceof SpecialAction) {
special = true;
} else if(ac instanceof ConsolecommandAction) {
executeConsoleCommand((ConsolecommandAction) ac, data);
executeConsoleCommand((ConsolecommandAction) ac, data.log);
}
}
}
@ -61,7 +63,6 @@ public class ActionManager {
try {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
} catch(Exception e) {
// TODO: Better error handling
System.out.println("[NoCheat] failed to execute the command '" + command + "', please check if everything is setup correct. ");
e.printStackTrace();
}

View File

@ -1,19 +1,64 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
package cc.co.evenprime.bukkit.nocheat.checks;
import net.minecraft.server.Block;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
/**
* A collection of methods that help to categorize blocks and find out if a
* player at a specific location can be considered "standing" or "swimming".
* Some stuff that's used by different checks
*
* @author Evenprime
*
*/
public class MovingEventHelper {
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) {
// Eye location of the player
Location eyes = player.getEyeLocation();
double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
// View direction of the player
Vector direction = player.getEyeLocation().getDirection();
final double x = ((double) targetX) - eyes.getX();
final double y = ((double) targetY) - eyes.getY();
final double z = ((double) targetZ) - eyes.getZ();
final double xPrediction = factor * direction.getX();
final double yPrediction = factor * direction.getY();
final double zPrediction = factor * direction.getZ();
double off = 0.0D;
off += Math.max(Math.abs(x - xPrediction) - (targetWidth / 2 + precision), 0.0D);
off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2 + precision), 0.0D);
off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2 + precision), 0.0D);
if(off > 1) {
off = Math.sqrt(off);
}
return off;
}
public static double reachCheck(Player player, double targetX, double targetY, double targetZ, double limit) {
Location eyes = player.getEyeLocation();
double distance = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
return Math.max(distance - limit, 0.0D);
}
private final static double magic = 0.45D;
private final static double magic2 = 0.55D;
@ -28,9 +73,10 @@ public class MovingEventHelper {
private static final int ONGROUND = 256;
// Until I can think of a better way to determine if a block is solid or
// not, this is what I'll do
public final int types[] = new int[256];
private static final int types[];
public MovingEventHelper() {
static {
types = new int[256];
// Find and define properties of all blocks
for(int i = 0; i < types.length; i++) {
@ -73,7 +119,7 @@ public class MovingEventHelper {
* The precise location that was used for calculation of "values"
* @return
*/
public int isLocationOnGround(final World world, final double x, final double y, final double z, boolean waterElevatorsAllowed) {
public static int isLocationOnGround(final World world, final double x, final double y, final double z, boolean waterElevatorsAllowed) {
final int lowerX = lowerBorder(x);
final int upperX = upperBorder(x);
@ -120,7 +166,7 @@ public class MovingEventHelper {
* @param z
* @return
*/
private final int canStand(World world, int x, int y, int z) {
private static final int canStand(World world, int x, int y, int z) {
int standingIn = types[world.getBlockTypeIdAt(x, y, z)];
int headIn = types[world.getBlockTypeIdAt(x, y + 1, z)];
@ -151,27 +197,27 @@ public class MovingEventHelper {
return result;
}
public final boolean isSolid(int value) {
public static final boolean isSolid(int value) {
return (value & SOLID) == SOLID;
}
public final boolean isLiquid(int value) {
public static final boolean isLiquid(int value) {
return (value & LIQUID) == LIQUID;
}
private final boolean isNonSolid(int value) {
private static final boolean isNonSolid(int value) {
return((value & NONSOLID) == NONSOLID);
}
private final boolean isLadder(int value) {
private static final boolean isLadder(int value) {
return((value & LADDER) == LADDER);
}
public boolean isOnGround(int fromType) {
public static boolean isOnGround(int fromType) {
return isLadder(fromType) || (fromType & ONGROUND) == ONGROUND;
}
public boolean isInGround(int fromType) {
public static boolean isInGround(int fromType) {
return isLadder(fromType) || isLiquid(fromType) || (fromType & INGROUND) == INGROUND;
}
@ -182,7 +228,7 @@ public class MovingEventHelper {
* @param d1
* @return
*/
private final int lowerBorder(double d1) {
private static final int lowerBorder(double d1) {
double floor = Math.floor(d1);
double d4 = floor + magic;
@ -202,7 +248,7 @@ public class MovingEventHelper {
* @param d1
* @return
*/
private final int upperBorder(double d1) {
private static final int upperBorder(double d1) {
double floor = Math.floor(d1);
double d4 = floor + magic2;
@ -215,4 +261,8 @@ public class MovingEventHelper {
return (int) (floor - d4);
}
public static int getType(int typeId) {
return types[typeId];
}
}

View File

@ -1,14 +1,11 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
/**
* The main Check class for blockbreak event checking. It will decide which
@ -29,7 +26,7 @@ public class BlockBreakCheck {
this.directionCheck = new DirectionCheck(plugin);
}
public boolean check(final Player player, final Block brokenBlock, final BlockBreakData data, final ConfigurationCache cc) {
public boolean check(final Player player, final Block brokenBlock, final ConfigurationCache cc) {
boolean cancel = false;
@ -38,20 +35,13 @@ public class BlockBreakCheck {
boolean direction = cc.blockbreak.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION);
if((reach || direction) && brokenBlock != null) {
Location eyes = player.getEyeLocation();
final double x1 = ((double) brokenBlock.getX()) - eyes.getX() - 0.5;
final double y1 = ((double) brokenBlock.getY()) - eyes.getY() - 0.5;
final double z1 = ((double) brokenBlock.getZ()) - eyes.getZ() - 0.5;
double factor = new Vector(x1 + 1, y1 + 1, z1 + 1).length();
if(reach) {
cancel = reachCheck.check(player, factor, data, cc);
cancel = reachCheck.check(player, brokenBlock, cc);
}
if(!cancel && direction) {
cancel = directionCheck.check(player, factor, x1, y1, z1, brokenBlock, data, cc);
cancel = directionCheck.check(player, brokenBlock, cc);
}
}
return cancel;

View File

@ -2,12 +2,11 @@ package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The DirectionCheck will find out if a player tried to interact with something
@ -24,33 +23,32 @@ public class DirectionCheck {
this.plugin = plugin;
}
public boolean check(Player player, double factor, double x1, double y1, double z1, Block brokenBlock, BlockBreakData data, ConfigurationCache cc) {
public boolean check(Player player, Block brokenBlock, ConfigurationCache cc) {
BaseData data = plugin.getPlayerData(player);
// If the block is instabreak and we don't check instabreak, return
if(!cc.blockbreak.checkinstabreakblocks && brokenBlock.getLocation().equals(data.instaBrokeBlockLocation)) {
if(!cc.blockbreak.checkinstabreakblocks && brokenBlock.getLocation().equals(data.blockbreak.instaBrokeBlockLocation)) {
return false;
}
boolean cancel = false;
double off = CheckUtil.directionCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, 1D, 1D, 0.5D);
Vector direction = player.getEyeLocation().getDirection();
final double x2 = x1 + 2;
final double y2 = y1 + 2;
final double z2 = z1 + 2;
if(factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 && factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
if(off < 0.1D) {
// Player did nothing wrong
// reduce violation counter
data.directionViolationLevel *= 0.9D;
data.blockbreak.directionViolationLevel *= 0.9D;
} else {
// Player failed the check
// Increment violation counter
data.directionViolationLevel += 1;
data.blockbreak.directionViolationLevel += off;
// Prepare some event-specific values for logging and custom actions
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "blockbreak.direction";
data.log.check = "blockbreak.direction";
cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.directionActions, (int) data.directionViolationLevel, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.directionActions, (int) data.blockbreak.directionViolationLevel, data.blockbreak.history, cc);
}
return cancel;

View File

@ -1,12 +1,13 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.GameMode;
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.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The reach check will find out if a player interacts with something that's too
@ -23,24 +24,27 @@ public class ReachCheck {
this.plugin = plugin;
}
public boolean check(Player player, double distance, BlockBreakData data, ConfigurationCache cc) {
public boolean check(Player player, Block brokenBlock, ConfigurationCache cc) {
boolean cancel = false;
double limit = player.getGameMode() == GameMode.CREATIVE ? cc.blockbreak.reachDistance + 2 : cc.blockbreak.reachDistance;
if(distance > limit) {
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.getPlayerData(player);
if(distance > 0D) {
// Player failed the check
// Increment violation counter
data.reachViolationLevel += 1;
data.blockbreak.reachViolationLevel += distance;
// Setup data for logging
data.log.check = "blockbreak.reach";
data.log.reachdistance = distance;
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "blockbreak.reach";
ldata.reachdistance = distance;
cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.reachActions, (int) data.reachViolationLevel, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.reachActions, (int) data.blockbreak.reachViolationLevel, data.blockbreak.history, cc);
} else {
data.reachViolationLevel *= 0.9D;
data.blockbreak.reachViolationLevel *= 0.9D;
}
return cancel;

View File

@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
/**
*
@ -24,7 +23,7 @@ public class BlockPlaceCheck {
onLiquidCheck = new OnLiquidCheck(plugin);
}
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, BlockPlaceData data, ConfigurationCache cc) {
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, ConfigurationCache cc) {
boolean cancel = false;
@ -33,11 +32,11 @@ public class BlockPlaceCheck {
final boolean reach = cc.blockplace.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH);
if(!cancel && reach) {
cancel = reachCheck.check(player, blockPlaced, blockPlacedAgainst, data, cc);
cancel = reachCheck.check(player, blockPlaced, blockPlacedAgainst, cc);
}
if(!cancel && onliquid) {
cancel = onLiquidCheck.check(player, blockPlaced, blockPlacedAgainst, data, cc);
cancel = onLiquidCheck.check(player, blockPlaced, blockPlacedAgainst, cc);
}
return cancel;

View File

@ -1,14 +1,13 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
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.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
*
@ -23,33 +22,36 @@ public class OnLiquidCheck {
this.plugin = plugin;
}
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, BlockPlaceData data, ConfigurationCache cc) {
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, ConfigurationCache cc) {
boolean cancel = false;
if(blockPlaced == null || blockPlaced.isEmpty()) {
BaseData data = plugin.getPlayerData(player);
if(blockPlaced == null || blockPlaced.isEmpty() || (blockPlacedAgainst != null && isSolid(blockPlacedAgainst.getTypeId()))) {
// all ok
} else if(blockPlacedAgainst != null && isSolid(blockPlacedAgainst)) {
// all ok
} else if(isSolid(blockPlaced.getRelative(BlockFace.DOWN)) || isSolid(blockPlaced.getRelative(BlockFace.WEST)) || isSolid(blockPlaced.getRelative(BlockFace.EAST)) || isSolid(blockPlaced.getRelative(BlockFace.NORTH)) || isSolid(blockPlaced.getRelative(BlockFace.SOUTH)) || isSolid(blockPlaced.getRelative(BlockFace.UP))) {
} else if(nextToSolid(blockPlaced.getWorld(), blockPlaced.getX(), blockPlaced.getY(), blockPlaced.getZ())) {
// all ok
} else {
data.onliquidViolationLevel += 1;
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "blockplace.onliquid";
ldata.placed = blockPlaced;
ldata.placedAgainst = blockPlacedAgainst;
data.blockplace.onliquidViolationLevel += 1;
data.log.check = "blockplace.onliquid";
data.log.placed = blockPlaced;
data.log.placedAgainst = blockPlacedAgainst;
cancel = plugin.getActionManager().executeActions(player, cc.blockplace.onliquidActions, (int) data.onliquidViolationLevel, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockplace.onliquidActions, (int) data.blockplace.onliquidViolationLevel, data.blockplace.history, cc);
}
data.onliquidViolationLevel *= 0.95D; // Reduce level over time
data.blockplace.onliquidViolationLevel *= 0.95D; // Reduce level over
// time
return cancel;
}
private boolean isSolid(Block block) {
Material m = block.getType();
return !(m == Material.AIR) || (m == Material.WATER) || (m == Material.STATIONARY_WATER) || (m == Material.LAVA) || (m == Material.STATIONARY_LAVA);
private boolean nextToSolid(World world, int x, int y, int z) {
return isSolid(world.getBlockTypeIdAt(x, y - 1, z)) || isSolid(world.getBlockTypeIdAt(x - 1, y, z)) || isSolid(world.getBlockTypeIdAt(x + 1, y, z)) || isSolid(world.getBlockTypeIdAt(x, y, z + 1)) || isSolid(world.getBlockTypeIdAt(x, y, z - 1)) || isSolid(world.getBlockTypeIdAt(x, y + 1, z));
}
private boolean isSolid(int id) {
return !((id == Material.AIR.getId()) || (id == Material.WATER.getId()) || (id == Material.STATIONARY_WATER.getId()) || (id == Material.LAVA.getId()) || (id == Material.STATIONARY_LAVA.getId()));
}
}

View File

@ -1,14 +1,12 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The reach check will find out if a player interacts with something that's too
@ -25,32 +23,27 @@ public class ReachCheck {
this.plugin = plugin;
}
public boolean check(Player player, Block blockPlaced, Block placedAgainstBlock, BlockPlaceData data, ConfigurationCache cc) {
public boolean check(Player player, Block blockPlaced, Block placedAgainstBlock, ConfigurationCache cc) {
boolean cancel = false;
Location eyes = player.getEyeLocation();
double distance = CheckUtil.reachCheck(player, placedAgainstBlock.getX() + 0.5D, placedAgainstBlock.getY() + 0.5D, placedAgainstBlock.getZ() + 0.5D, cc.blockplace.reachDistance);
final double x1 = ((double) placedAgainstBlock.getX()) - eyes.getX();
final double y1 = ((double) placedAgainstBlock.getY()) - eyes.getY();
final double z1 = ((double) placedAgainstBlock.getZ()) - eyes.getZ();
BaseData data = plugin.getPlayerData(player);
double distance = new Vector(x1 + 0.5, y1 + +0.5, z1 + +0.5).length();
if(distance > cc.blockplace.reachDistance) {
if(distance > 0D) {
// Player failed the check
// Increment violation counter
data.reachViolationLevel += 1;
data.blockplace.reachViolationLevel += distance;
// Prepare some event-specific values for logging and custom actions
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "blockplace.reach";
ldata.reachdistance = distance;
data.log.check = "blockplace.reach";
data.log.reachdistance = distance;
cancel = plugin.getActionManager().executeActions(player, cc.blockplace.reachActions, (int) data.reachViolationLevel, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockplace.reachActions, (int) data.blockplace.reachViolationLevel, data.blockplace.history, cc);
} else {
data.reachViolationLevel *= 0.9D;
data.blockplace.reachViolationLevel *= 0.9D;
}
return cancel;

View File

@ -5,8 +5,7 @@ import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
*
@ -22,7 +21,7 @@ public class ChatCheck {
this.plugin = plugin;
}
public boolean check(Player player, String message, ChatData data, ConfigurationCache cc) {
public boolean check(Player player, String message, ConfigurationCache cc) {
boolean cancel = false;
@ -32,23 +31,24 @@ public class ChatCheck {
int time = plugin.getIngameSeconds();
if(data.spamLasttime + cc.chat.spamTimeframe <= time) {
data.spamLasttime = time;
data.messageCount = 0;
BaseData data = plugin.getPlayerData(player);
if(data.chat.spamLasttime + cc.chat.spamTimeframe <= time) {
data.chat.spamLasttime = time;
data.chat.messageCount = 0;
}
data.messageCount++;
data.chat.messageCount++;
if(data.messageCount > cc.chat.spamLimit) {
if(data.chat.messageCount > cc.chat.spamLimit) {
// Prepare some event-specific values for logging and custom
// actions
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "chat.spam";
ldata.text = message;
data.log.check = "chat.spam";
data.log.text = message;
cancel = plugin.getActionManager().executeActions(player, cc.chat.spamActions, data.messageCount - cc.chat.spamLimit, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.chat.spamActions, data.chat.messageCount - cc.chat.spamLimit, data.chat.history, cc);
}
}

View File

@ -1,16 +1,14 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import org.bukkit.Location;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
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.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* Check various things related to fighting players/entities
@ -25,7 +23,7 @@ public class FightCheck {
this.plugin = plugin;
}
public boolean check(Player player, Entity damagee, FightData data, ConfigurationCache cc) {
public boolean check(Player player, Entity damagee, ConfigurationCache cc) {
boolean cancel = false;
@ -35,73 +33,46 @@ public class FightCheck {
if(directionCheck) {
Location eyes = player.getEyeLocation();
// Get the width of the damagee
net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle();
float width = entity.length > entity.width ? entity.length : entity.width;
double height = 2.0D; // Minecraft server doesn't store the height
// of entities :(
final double p = width / 2 + cc.fight.directionPrecision;
final double h = height / 2 + cc.fight.directionPrecision;
// height = 2.0D as minecraft doesn't store the height of entities,
// and that should be enough. Because entityLocations are always set
// to center bottom of the hitbox, increase "y" location by 1/2
// 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);
// TODO: Move this into a seperate class to recycle it throughout
// NoCheat
final double x1 = ((double) damagee.getLocation().getX()) - eyes.getX() - p;
final double y1 = ((double) damagee.getLocation().getY()) - eyes.getY() - cc.fight.directionPrecision;
final double z1 = ((double) damagee.getLocation().getZ()) - eyes.getZ() - p;
double factor = new Vector(x1 + p, y1 + h, z1 + p).length();
Vector direction = player.getEyeLocation().getDirection();
final double x2 = x1 + 2 * p;
final double y2 = y1 + 2 * h;
final double z2 = z1 + 2 * p;
final double xPrediction = factor * direction.getX();
final double yPrediction = factor * direction.getY();
final double zPrediction = factor * direction.getZ();
double off = 0.0D;
off += Math.max(x1 - xPrediction, 0.0D);
off += Math.max(y1 - yPrediction, 0.0D);
off += Math.max(z1 - zPrediction, 0.0D);
off += Math.max(xPrediction - x2, 0.0D);
off += Math.max(yPrediction - y2, 0.0D);
off += Math.max(zPrediction - z2, 0.0D);
BaseData data = plugin.getPlayerData(player);
if(off < 0.1D) {
// Player did probably nothing wrong
// reduce violation counter
data.violationLevel *= 0.80D;
data.fight.violationLevel *= 0.80D;
} else {
// Player failed the check
// Increment violation counter
if(!plugin.skipCheck()) {
data.violationLevel += Math.sqrt(off);
data.fight.violationLevel += Math.sqrt(off);
}
// Prepare some event-specific values for logging and custom
// actions
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "fight.direction";
data.log.check = "fight.direction";
cancel = plugin.getActionManager().executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.fight.directionActions, (int) data.fight.violationLevel, data.fight.history, cc);
if(cancel) {
// Needed to calculate penalty times
data.directionLastViolationTime = time;
data.fight.directionLastViolationTime = time;
}
}
}
// If the player is still in penalty time, cancel the event anyway
if(data.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) {
return true;
// If the player is still in penalty time, cancel the event anyway
if(data.fight.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) {
return true;
}
}
return cancel;

View File

@ -7,8 +7,7 @@ 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.LogData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* A check designed for people that are allowed to fly. The complement to
@ -28,10 +27,12 @@ public class FlyingCheck {
this.plugin = plugin;
}
public Location check(Player player, Location from, Location to, ConfigurationCache cc, MovingData data) {
public Location check(Player player, Location from, Location to, ConfigurationCache cc) {
if(data.runflySetBackPoint == null) {
data.runflySetBackPoint = player.getLocation().clone();
BaseData data = plugin.getPlayerData(player);
if(data.moving.runflySetBackPoint == null) {
data.moving.runflySetBackPoint = player.getLocation().clone();
}
final double yDistance = to.getY() - from.getY();
@ -48,7 +49,7 @@ public class FlyingCheck {
// horizontal
final double speedLimitHorizontal = player.getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, cc.moving.flyingSpeedLimitHorizontal) : cc.moving.flyingSpeedLimitHorizontal;
result += Math.max(0.0D, horizontalDistance - data.horizFreedom - speedLimitHorizontal);
result += Math.max(0.0D, horizontalDistance - data.moving.horizFreedom - speedLimitHorizontal);
boolean sprinting = true;
@ -58,47 +59,44 @@ public class FlyingCheck {
e.printStackTrace();
}
data.bunnyhopdelay--;
data.moving.bunnyhopdelay--;
// Did he go too far?
if(result > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem
if(data.bunnyhopdelay <= 0 && result < 0.4D) {
data.bunnyhopdelay = 3;
if(data.moving.bunnyhopdelay <= 0 && result < 0.4D) {
data.moving.bunnyhopdelay = 3;
result = 0;
}
}
// super simple, just check distance compared to max distance
result += Math.max(0.0D, yDistance - data.vertFreedom - cc.moving.flyingSpeedLimitVertical);
result += Math.max(0.0D, yDistance - data.moving.vertFreedom - cc.moving.flyingSpeedLimitVertical);
result = result * 100;
if(result > 0) {
// Increment violation counter
data.runflyViolationLevel += result;
data.moving.runflyViolationLevel += result;
// Prepare some event-specific values for logging and custom actions
LogData ldata = plugin.getDataManager().getData(player).log;
data.log.toLocation = to;
data.log.check = "flying/toofast";
ldata.toLocation = to;
ldata.check = "flying/toofast";
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.flyingActions, (int) data.runflyViolationLevel, ldata, data.history, cc);
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.flyingActions, (int) data.moving.runflyViolationLevel, data.moving.history, cc);
// Was one of the actions a cancel? Then really do it
if(cancel) {
newToLocation = data.runflySetBackPoint;
newToLocation = data.moving.runflySetBackPoint;
}
}
// Slowly reduce the level with each event
data.runflyViolationLevel *= 0.97;
data.moving.runflyViolationLevel *= 0.97;
// Some other cleanup 'n' stuff
if(newToLocation == null) {
data.runflySetBackPoint = to.clone();
data.moving.runflySetBackPoint = to.clone();
}
return newToLocation;

View File

@ -5,8 +5,7 @@ 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.LogData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The morePacketsCheck (previously called SpeedhackCheck) will try to identify
@ -84,66 +83,67 @@ public class MorePacketsCheck {
* 8. reset packetCounter, wait for next 20 ticks to pass by.
*
*/
public Location check(Player player, ConfigurationCache cc, MovingData data) {
public Location check(Player player, ConfigurationCache cc) {
Location newToLocation = null;
data.morePacketsCounter++;
if(data.morePacketsSetbackPoint == null) {
data.morePacketsSetbackPoint = player.getLocation();
BaseData data = plugin.getPlayerData(player);
data.moving.morePacketsCounter++;
if(data.moving.morePacketsSetbackPoint == null) {
data.moving.morePacketsSetbackPoint = player.getLocation();
}
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.lastElapsedIngameSeconds) {
if(ingameSeconds != data.moving.lastElapsedIngameSeconds) {
int limit = (int) ((packetsPerTimeframe * plugin.getIngameSecondDuration()) / 1000L);
int difference = limit - data.morePacketsCounter;
int difference = limit - data.moving.morePacketsCounter;
data.morePacketsBuffer = data.morePacketsBuffer + difference;
if(data.morePacketsBuffer > bufferLimit)
data.morePacketsBuffer = bufferLimit;
data.moving.morePacketsBuffer = data.moving.morePacketsBuffer + difference;
if(data.moving.morePacketsBuffer > bufferLimit)
data.moving.morePacketsBuffer = bufferLimit;
// Are we over the 22 event limit for that time frame now? (limit
// increases with time)
int packetsAboveLimit = (int) -data.morePacketsBuffer;
int packetsAboveLimit = (int) -data.moving.morePacketsBuffer;
if(data.morePacketsBuffer < 0)
data.morePacketsBuffer = 0;
if(data.moving.morePacketsBuffer < 0)
data.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.morePacketsViolationLevel += packetsAboveLimit;
data.moving.morePacketsViolationLevel += packetsAboveLimit;
LogData ldata = plugin.getDataManager().getData(player).log;
// Packets above limit
ldata.packets = data.morePacketsCounter - limit;
ldata.check = "moving/morepackets";
data.log.packets = data.moving.morePacketsCounter - limit;
data.log.check = "moving/morepackets";
boolean cancel = false;
cancel = plugin.getActionManager().executeActions(player, cc.moving.morePacketsActions, (int) data.morePacketsViolationLevel, ldata, data.history, cc);
cancel = plugin.getActionManager().executeActions(player, cc.moving.morePacketsActions, (int) data.moving.morePacketsViolationLevel, data.moving.history, cc);
// Only do the cancel if the player didn't change worlds
// inbetween
if(cancel && player.getWorld().equals(data.morePacketsSetbackPoint.getWorld())) {
newToLocation = data.morePacketsSetbackPoint;
if(cancel && player.getWorld().equals(data.moving.morePacketsSetbackPoint.getWorld())) {
newToLocation = data.moving.morePacketsSetbackPoint;
}
}
// No new setbackLocation was chosen
if(newToLocation == null) {
data.morePacketsSetbackPoint = player.getLocation();
data.moving.morePacketsSetbackPoint = player.getLocation();
}
if(data.morePacketsViolationLevel > 0)
if(data.moving.morePacketsViolationLevel > 0)
// Shrink the "over limit" value by 20 % every second
data.morePacketsViolationLevel *= 0.8;
data.moving.morePacketsViolationLevel *= 0.8;
data.morePacketsCounter = 0; // Count from zero again
data.lastElapsedIngameSeconds = ingameSeconds;
data.moving.morePacketsCounter = 0; // Count from zero again
data.moving.lastElapsedIngameSeconds = ingameSeconds;
}
return newToLocation;

View File

@ -5,8 +5,7 @@ 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.LogData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* A check to see if people cheat by tricking the server to not deal them
@ -27,49 +26,50 @@ 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, final MovingData data) {
public void check(final Player player, final Location from, final boolean fromOnOrInGround, final Location to, final boolean toOnOrInGround, final ConfigurationCache cc) {
double oldY = from.getY();
double newY = to.getY();
BaseData data = plugin.getPlayerData(player);
// This check is pretty much always a step behind for technical reasons.
if(fromOnOrInGround) {
// Start with zero fall distance
data.fallDistance = 0F;
data.moving.fallDistance = 0F;
}
// If we increased fall height before for no good reason, reduce now by
// the same amount
if(player.getFallDistance() > data.lastAddedFallDistance) {
player.setFallDistance(player.getFallDistance() - data.lastAddedFallDistance);
if(player.getFallDistance() > data.moving.lastAddedFallDistance) {
player.setFallDistance(player.getFallDistance() - data.moving.lastAddedFallDistance);
}
data.lastAddedFallDistance = 0;
data.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.fallDistance - player.getFallDistance();
float difference = data.moving.fallDistance - player.getFallDistance();
if(difference > 1.0F && toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallViolationLevel += difference;
if(difference > 1.0F && toOnOrInGround && data.moving.fallDistance > 2.0F) {
data.moving.nofallViolationLevel += difference;
// Prepare some event-specific values for logging and custom actions
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.falldistance = data.fallDistance;
ldata.check = "moving/nofall";
data.log.falldistance = data.moving.fallDistance;
data.log.check = "moving/nofall";
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.nofallActions, (int) data.nofallViolationLevel, ldata, data.history, cc);
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.nofallActions, (int) data.moving.nofallViolationLevel, data.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.fallDistance + difference * (cc.moving.nofallMultiplier - 1.0F);
float totalDistance = data.moving.fallDistance + difference * (cc.moving.nofallMultiplier - 1.0F);
player.setFallDistance(totalDistance);
}
data.fallDistance = 0F;
data.moving.fallDistance = 0F;
}
// Increase the fall distance that is recorded by the plugin, AND set
@ -83,19 +83,19 @@ public class NoFallCheck {
// from the original Minecraft feeling.
if(oldY > newY) {
float dist = (float) (oldY - newY);
data.fallDistance += dist;
data.moving.fallDistance += dist;
if(dist > 1.0F) {
data.lastAddedFallDistance = dist;
data.moving.lastAddedFallDistance = dist;
player.setFallDistance(player.getFallDistance() + dist);
} else {
data.lastAddedFallDistance = 0.0F;
data.moving.lastAddedFallDistance = 0.0F;
}
} else {
data.lastAddedFallDistance = 0.0F;
data.moving.lastAddedFallDistance = 0.0F;
}
// Reduce falldamage violation level
data.nofallViolationLevel *= 0.99D;
data.moving.nofallViolationLevel *= 0.99D;
}
}

View File

@ -6,9 +6,10 @@ 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.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The main Check class for Move event checking. It will decide which checks
@ -20,15 +21,15 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
*/
public class RunFlyCheck {
private final FlyingCheck flyingCheck;
private final RunningCheck runningCheck;
private final NoFallCheck noFallCheck;
private final MorePacketsCheck morePacketsCheck;
private final FlyingCheck flyingCheck;
private final RunningCheck runningCheck;
private final NoFallCheck noFallCheck;
private final MorePacketsCheck morePacketsCheck;
private final MovingEventHelper helper;
private final NoCheat plugin;
public RunFlyCheck(NoCheat plugin) {
this.helper = new MovingEventHelper();
this.plugin = plugin;
this.flyingCheck = new FlyingCheck(plugin);
this.noFallCheck = new NoFallCheck(plugin);
@ -42,7 +43,7 @@ public class RunFlyCheck {
* @param event
* @return
*/
public Location check(final Player player, final Location from, final Location to, final MovingData data, final ConfigurationCache cc) {
public Location check(final Player player, final Location from, final Location to, final ConfigurationCache cc) {
// Players in vehicles are of no interest
if(player.isInsideVehicle())
@ -53,19 +54,21 @@ public class RunFlyCheck {
*/
Location newToLocation = null;
BaseData data = plugin.getPlayerData(player);
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
if(data.horizVelocityCounter > 0) {
data.horizVelocityCounter--;
if(data.moving.horizVelocityCounter > 0) {
data.moving.horizVelocityCounter--;
} else {
data.horizFreedom *= 0.90;
data.moving.horizFreedom *= 0.90;
}
if(data.vertVelocityCounter > 0) {
data.vertVelocityCounter--;
data.vertFreedom += data.vertVelocity;
data.vertVelocity *= 0.90;
if(data.moving.vertVelocityCounter > 0) {
data.moving.vertVelocityCounter--;
data.moving.vertFreedom += data.moving.vertVelocity;
data.moving.vertVelocity *= 0.90;
} else {
data.vertFreedom = 0;
data.moving.vertFreedom = 0;
}
/************* DECIDE WHICH CHECKS NEED TO BE RUN *************/
@ -77,33 +80,31 @@ public class RunFlyCheck {
// If the player is not allowed to fly and not allowed to run
if(runflyCheck) {
if(flyAllowed) {
newToLocation = flyingCheck.check(player, from, to, cc, data);
}
else {
newToLocation = runningCheck.check(player, from, to, helper, cc, data);
newToLocation = flyingCheck.check(player, from, to, cc);
} else {
newToLocation = runningCheck.check(player, from, to, cc);
}
}
/********* EXECUTE THE MOREPACKETS CHECK ********************/
if(newToLocation == null && morepacketsCheck) {
newToLocation = morePacketsCheck.check(player, cc, data);
newToLocation = morePacketsCheck.check(player, cc);
}
return newToLocation;
}
/**
* This is a workaround for people placing blocks below them causing false positives
* This is a workaround for people placing blocks below them causing false
* positives
* with the move check(s).
*
* @param player
* @param data
* @param blockPlaced
*/
public void blockPlaced(Player player, MovingData data, Block blockPlaced) {
public void blockPlaced(Player player, Block blockPlaced) {
if(blockPlaced == null || data.runflySetBackPoint == null) {
BaseData data = plugin.getPlayerData(player);
if(blockPlaced == null || data.moving.runflySetBackPoint == null) {
return;
}
@ -112,11 +113,11 @@ public class RunFlyCheck {
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) {
int type = helper.types[blockPlaced.getTypeId()];
if(helper.isSolid(type) || helper.isLiquid(type)) {
if(lblock.getBlockY() + 1 >= data.runflySetBackPoint.getY()) {
data.runflySetBackPoint.setY(lblock.getBlockY() + 1);
data.jumpPhase = 0;
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);
data.moving.jumpPhase = 0;
}
}
}

View File

@ -5,10 +5,10 @@ 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.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* The counterpart to the FlyingCheck. People that are not allowed to fly
@ -36,70 +36,71 @@ public class RunningCheck {
this.noFallCheck = noFallCheck;
}
public Location check(final Player player, final Location from, final Location to, final MovingEventHelper helper, final ConfigurationCache cc, final MovingData data) {
public Location check(final Player player, final Location from, final Location to, final ConfigurationCache cc) {
// Calculate some distances
final double xDistance = to.getX() - from.getX();
final double zDistance = to.getZ() - from.getZ();
final double horizontalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
if(data.runflySetBackPoint == null) {
data.runflySetBackPoint = from.clone();
BaseData data = plugin.getPlayerData(player);
if(data.moving.runflySetBackPoint == null) {
data.moving.runflySetBackPoint = from.clone();
}
// To know if a player "is on ground" is useful
final int fromType = helper.isLocationOnGround(from.getWorld(), from.getX(), from.getY(), from.getZ(), false);
final int toType = helper.isLocationOnGround(to.getWorld(), to.getX(), to.getY(), to.getZ(), false);
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 boolean fromOnGround = helper.isOnGround(fromType);
final boolean fromInGround = helper.isInGround(fromType);
final boolean toOnGround = helper.isOnGround(toType);
final boolean toInGround = helper.isInGround(toType);
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;
double resultHoriz = Math.max(0.0D, checkHorizontal(player, helper.isLiquid(fromType) && helper.isLiquid(toType), horizontalDistance, cc, data));
double resultVert = Math.max(0.0D, checkVertical(from, fromOnGround, to, toOnGround, cc, data));
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));
double result = (resultHoriz + resultVert) * 100;
data.jumpPhase++;
data.moving.jumpPhase++;
// Slowly reduce the level with each event
data.runflyViolationLevel *= 0.97;
data.moving.runflyViolationLevel *= 0.97;
if(result > 0) {
// Increment violation counter
data.runflyViolationLevel += result;
data.moving.runflyViolationLevel += result;
// Prepare some event-specific values for logging and custom actions
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.toLocation = to;
data.log.toLocation = to;
if(resultHoriz > 0 && resultVert > 0)
ldata.check = "runfly/both";
data.log.check = "runfly/both";
else if(resultHoriz > 0)
ldata.check = "runfly/horizontal";
data.log.check = "runfly/horizontal";
else if(resultVert > 0)
ldata.check = "runfly/vertical";
data.log.check = "runfly/vertical";
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.actions, (int) data.runflyViolationLevel, ldata, data.history, cc);
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.actions, (int) data.moving.runflyViolationLevel, data.moving.history, cc);
// Was one of the actions a cancel? Then do it
if(cancel) {
newToLocation = data.runflySetBackPoint;
newToLocation = data.moving.runflySetBackPoint;
}
} else {
if((toInGround && from.getY() >= to.getY()) || helper.isLiquid(toType)) {
data.runflySetBackPoint = to.clone();
data.runflySetBackPoint.setY(Math.ceil(data.runflySetBackPoint.getY()));
data.jumpPhase = 0;
} else if(toOnGround && (from.getY() >= to.getY() || data.runflySetBackPoint.getY() <= Math.floor(to.getY()))) {
data.runflySetBackPoint = to.clone();
data.runflySetBackPoint.setY(Math.floor(data.runflySetBackPoint.getY()));
data.jumpPhase = 0;
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;
} else if(fromOnGround || fromInGround || toOnGround || toInGround) {
data.jumpPhase = 0;
data.moving.jumpPhase = 0;
}
}
@ -107,7 +108,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, data);
noFallCheck.check(player, from, fromOnGround || fromInGround, to, toOnGround || toInGround, cc);
}
return newToLocation;
@ -116,14 +117,8 @@ public class RunningCheck {
/**
* Calculate how much the player failed this check
*
* @param isSneaking
* @param isSwimming
* @param totalDistance
* @param cc
* @param data
* @return
*/
private double checkHorizontal(final Player player, final boolean isSwimming, final double totalDistance, final ConfigurationCache cc, final MovingData data) {
private double checkHorizontal(final Player player, final boolean isSwimming, final double totalDistance, final ConfigurationCache cc) {
// How much further did the player move than expected??
double distanceAboveLimit = 0.0D;
@ -135,41 +130,43 @@ public class RunningCheck {
e.printStackTrace();
}
BaseData data = plugin.getPlayerData(player);
if(cc.moving.sneakingCheck && player.isSneaking() && !player.hasPermission(Permissions.MOVE_SNEAK)) {
distanceAboveLimit = totalDistance - cc.moving.sneakingSpeedLimit - data.horizFreedom;
distanceAboveLimit = totalDistance - cc.moving.sneakingSpeedLimit - data.moving.horizFreedom;
} else if(cc.moving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVE_SWIM)) {
distanceAboveLimit = totalDistance - cc.moving.swimmingSpeedLimit - data.horizFreedom;
distanceAboveLimit = totalDistance - cc.moving.swimmingSpeedLimit - data.moving.horizFreedom;
} else if(!sprinting) {
distanceAboveLimit = totalDistance - cc.moving.walkingSpeedLimit - data.horizFreedom;
distanceAboveLimit = totalDistance - cc.moving.walkingSpeedLimit - data.moving.horizFreedom;
} else {
distanceAboveLimit = totalDistance - cc.moving.sprintingSpeedLimit - data.horizFreedom;
distanceAboveLimit = totalDistance - cc.moving.sprintingSpeedLimit - data.moving.horizFreedom;
}
data.bunnyhopdelay--;
data.moving.bunnyhopdelay--;
// Did he go too far?
if(distanceAboveLimit > 0 && sprinting) {
// Try to treat it as a the "bunnyhop" problem
if(data.bunnyhopdelay <= 0 && distanceAboveLimit > 0.05D && distanceAboveLimit < 0.4D) {
data.bunnyhopdelay = 3;
if(data.moving.bunnyhopdelay <= 0 && distanceAboveLimit > 0.05D && distanceAboveLimit < 0.4D) {
data.moving.bunnyhopdelay = 3;
distanceAboveLimit = 0;
}
}
if(distanceAboveLimit > 0) {
// Try to consume the "buffer"
distanceAboveLimit -= data.horizontalBuffer;
data.horizontalBuffer = 0;
distanceAboveLimit -= data.moving.horizontalBuffer;
data.moving.horizontalBuffer = 0;
// Put back the "overconsumed" buffer
if(distanceAboveLimit < 0) {
data.horizontalBuffer = -distanceAboveLimit;
data.moving.horizontalBuffer = -distanceAboveLimit;
}
}
// He was within limits, give the difference as buffer
else {
data.horizontalBuffer = Math.min(maxBonus, data.horizontalBuffer - distanceAboveLimit);
data.moving.horizontalBuffer = Math.min(maxBonus, data.moving.horizontalBuffer - distanceAboveLimit);
}
return distanceAboveLimit;
@ -179,19 +176,21 @@ public class RunningCheck {
* Calculate if and how much the player "failed" this check.
*
*/
private double checkVertical(final Location from, final boolean fromOnGround, final Location to, final boolean toOnGround, final ConfigurationCache cc, final MovingData data) {
private double checkVertical(final Player player, final Location from, final boolean fromOnGround, final Location to, final boolean toOnGround, final ConfigurationCache cc) {
// How much higher did the player move than expected??
double distanceAboveLimit = 0.0D;
final double toY = to.getY();
double limit = data.vertFreedom + cc.moving.jumpheight;
BaseData data = plugin.getPlayerData(player);
if(data.jumpPhase > jumpingLimit) {
limit -= (data.jumpPhase - jumpingLimit) * 0.15D;
double limit = data.moving.vertFreedom + cc.moving.jumpheight;
if(data.moving.jumpPhase > jumpingLimit) {
limit -= (data.moving.jumpPhase - jumpingLimit) * 0.15D;
}
distanceAboveLimit = toY - data.runflySetBackPoint.getY() - limit;
distanceAboveLimit = toY - data.moving.runflySetBackPoint.getY() - limit;
return distanceAboveLimit;

View File

@ -121,10 +121,13 @@ public class ConfigurationManager {
File globalConfigFile = getGlobalConfigFile(rootConfigFolder);
root = new FlatFileConfiguration(defaultConfig, true, globalConfigFile);
try {
root.load(action);
} catch(Exception e) {
if(globalConfigFile.exists()) {
try {
root.load(action);
} catch(Exception e) {
e.printStackTrace();
}
}
try {
@ -156,6 +159,7 @@ public class ConfigurationManager {
} catch(IOException e) {
System.out.println("NoCheat: Couldn't load world-specific config for " + worldEntry.getKey());
e.printStackTrace();
}
}
}
@ -222,9 +226,7 @@ public class ConfigurationManager {
l.addHandler(fh);
} catch(SecurityException e) {
e.printStackTrace();
} catch(IOException e) {
} catch(Exception e) {
e.printStackTrace();
}
}

View File

@ -15,6 +15,6 @@ public class BlockBreakData extends Data {
public double directionViolationLevel = 0.0D;
public Location instaBrokeBlockLocation = null;
public final ActionData history = new ActionData();
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -10,5 +10,5 @@ public class BlockPlaceData extends Data {
public double onliquidViolationLevel = 0.0D;
public double reachViolationLevel = 0.0D;
public final ActionData history = new ActionData();
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -10,6 +10,6 @@ public class ChatData extends Data {
public int messageCount = 0;
public int spamLasttime = 0;
public final ActionData history = new ActionData();
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -47,7 +47,7 @@ public class DataManager {
* Reset data that may cause problems after e.g. changing the config
*
*/
public void resetAllCriticalData() {
public void clearCriticalData() {
for(BaseData b : this.map.values()) {
b.clearCriticalData();
}
@ -79,17 +79,26 @@ public class DataManager {
*
*/
public void cleanDataMap() {
List<Player> removals = new ArrayList<Player>();
try {
List<Player> removals = new ArrayList<Player>();
for(Entry<Player, BaseData> p : this.map.entrySet()) {
if(p.getValue().shouldBeRemoved()) {
removals.add(p.getKey());
for(Entry<Player, BaseData> p : this.map.entrySet()) {
if(p.getValue().shouldBeRemoved()) {
removals.add(p.getKey());
}
}
}
for(Player p : removals) {
this.map.remove(p);
for(Player p : removals) {
this.map.remove(p);
}
} catch(Exception e) {
// Ignore problems, as they really don't matter much
}
}
public void clearCriticalData(Player player) {
BaseData data = this.map.get(player);
data.clearCriticalData();
}
}

View File

@ -11,7 +11,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
* @author Evenprime
*
*/
public class ActionData {
public class ExecutionHistory {
private static class ExecutionHistoryEntry {
@ -85,7 +85,7 @@ public class ActionData {
// time + action + action-counter
private final Map<Action, ExecutionHistoryEntry> executionHistory;
public ActionData() {
public ExecutionHistory() {
executionHistory = new HashMap<Action, ExecutionHistoryEntry>();
}

View File

@ -4,6 +4,6 @@ public class FightData extends Data {
public double violationLevel = 0;
public long directionLastViolationTime = 0;
public final ActionData history = new ActionData();
public final ExecutionHistory history = new ExecutionHistory();
}

View File

@ -3,41 +3,40 @@ 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 Location runflySetBackPoint;
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;
public Location morePacketsSetbackPoint;
public double morePacketsViolationLevel;
public Location teleportTo;
public Location teleportTo;
public int lastElapsedIngameSeconds;
public int lastElapsedIngameSeconds;
public final ActionData history = new ActionData();
public final ExecutionHistory history = new ExecutionHistory();
@Override
public void initialize(Player player) {

View File

@ -16,7 +16,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -34,7 +34,6 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
private final Performance blockBreakPerformance;
private final Performance blockDamagePerformance;
public BlockBreakEventManager(NoCheat plugin) {
this.plugin = plugin;
@ -70,10 +69,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
boolean cancel = false;
// Get the player-specific stored data that applies here
final BlockBreakData data = plugin.getDataManager().getData(player).blockbreak;
cancel = blockBreakCheck.check(player, event.getBlock(), data, cc);
cancel = blockBreakCheck.check(player, event.getBlock(), cc);
if(cancel) {
event.setCancelled(true);
@ -92,22 +88,22 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
if(!event.isCancelled() && !event.getInstaBreak()) {
return;
}
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = blockDamagePerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
final Player player = event.getPlayer();
// Get the player-specific stored data that applies here
final BlockBreakData data = plugin.getDataManager().getData(player).blockbreak;
final BaseData data = plugin.getPlayerData(player);
// Remember this location. We ignore block breaks in the block-break
// direction check that are insta-breaks
data.instaBrokeBlockLocation = event.getBlock().getLocation();
data.blockbreak.instaBrokeBlockLocation = event.getBlock().getLocation();
// store performance time
if(performanceCheck)
blockDamagePerformance.addTime(System.nanoTime() - nanoTimeStart);
@ -123,15 +119,4 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
return s;
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();
if(!(cc.blockbreak.check && cc.blockbreak.directionCheck))
s.add("blockbreak.direction");
if(!(cc.blockbreak.check && cc.blockbreak.reachCheck))
s.add("blockbreak.reach");
return s;
}
}

View File

@ -57,7 +57,7 @@ public class BlockPlaceEventManager extends BlockListener implements EventManage
final Player player = event.getPlayer();
// Get the player-specific stored data that applies here
movingCheck.blockPlaced(player, plugin.getDataManager().getData(player).moving, event.getBlockPlaced());
movingCheck.blockPlaced(player, event.getBlockPlaced());
}
}, Priority.Monitor, plugin);
@ -83,7 +83,7 @@ public class BlockPlaceEventManager extends BlockListener implements EventManage
// Find out if checks need to be done for that player
if(cc.blockplace.check && !player.hasPermission(Permissions.BLOCKPLACE)) {
cancel = blockPlaceCheck.check(player, event.getBlockPlaced(), event.getBlockAgainst(), plugin.getDataManager().getData(player).blockplace, cc);
cancel = blockPlaceCheck.check(player, event.getBlockPlaced(), event.getBlockAgainst(), cc);
}
if(cancel) {
@ -105,15 +105,4 @@ public class BlockPlaceEventManager extends BlockListener implements EventManage
return s;
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();
if(!(cc.blockplace.check && cc.blockplace.onliquidCheck))
s.add("blockplace.onliquid");
if(!(cc.blockplace.check && cc.blockplace.reachCheck))
s.add("blockplace.reach");
return s;
}
}

View File

@ -71,7 +71,7 @@ public class EntityDamageEventManager extends EntityListener implements EventMan
boolean cancel = false;
cancel = fightCheck.check(player, damagee, plugin.getDataManager().getData(player).fight, cc);
cancel = fightCheck.check(player, damagee, cc);
if(cancel) {
event.setCancelled(true);
@ -83,7 +83,6 @@ public class EntityDamageEventManager extends EntityListener implements EventMan
fightPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
public List<String> getActiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();
@ -91,12 +90,4 @@ public class EntityDamageEventManager extends EntityListener implements EventMan
s.add("fight.direction");
return s;
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();
if(!(cc.fight.check && cc.fight.directionCheck))
s.add("fight.direction");
return s;
}
}

View File

@ -8,6 +8,4 @@ public interface EventManager {
public List<String> getActiveChecks(ConfigurationCache cc);
public List<String> getInactiveChecks(ConfigurationCache cc);
}

View File

@ -65,7 +65,7 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
boolean cancel = false;
cancel = chatCheck.check(player, event.getMessage(), plugin.getDataManager().getData(player).chat, cc);
cancel = chatCheck.check(player, event.getMessage(), cc);
if(cancel) {
event.setCancelled(true);
@ -91,13 +91,4 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
s.add("chat.spam");
return s;
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();
if(!(cc.chat.check && cc.chat.spamCheck))
s.add("chat.spam");
return s;
}
}

View File

@ -18,7 +18,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
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.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -74,9 +74,6 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
// Find out if checks need to be done for that player
if(cc.moving.check && !player.hasPermission(Permissions.MOVE)) {
// Get the player-specific stored data that applies here
final MovingData data = plugin.getDataManager().getData(player).moving;
// 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)
@ -88,7 +85,7 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
Location newTo = null;
// Currently only one check here.
newTo = movingCheck.check(player, from, to, data, cc);
newTo = movingCheck.check(player, from, to, cc);
// Did the check(s) decide we need a new "to"-location?
if(newTo != null) {
@ -96,7 +93,11 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
// viewing direction of "event.getTo()"
Location l = new Location(newTo.getWorld(), newTo.getX(), newTo.getY(), newTo.getZ(), to.getYaw(), to.getPitch());
event.setTo(l);
data.teleportTo = l;
// Get the player-specific stored data that applies here
final BaseData data = plugin.getPlayerData(player);
data.moving.teleportTo = l;
}
}
@ -119,22 +120,22 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
Player player = event.getPlayer();
MovingData mdata = plugin.getDataManager().getData(player).moving;
BaseData data = plugin.getPlayerData(player);
Vector v = event.getVelocity();
double newVal = v.getY();
if(newVal >= 0.0D) {
mdata.vertVelocity += newVal;
mdata.vertFreedom += mdata.vertVelocity;
data.moving.vertVelocity += newVal;
data.moving.vertFreedom += data.moving.vertVelocity;
}
mdata.vertVelocityCounter = 50;
data.moving.vertVelocityCounter = 50;
newVal = Math.sqrt(Math.pow(v.getX(), 2) + Math.pow(v.getZ(), 2));
if(newVal > 0.0D) {
mdata.horizFreedom += newVal;
mdata.horizVelocityCounter = 30;
data.moving.horizFreedom += newVal;
data.moving.horizVelocityCounter = 30;
}
// store performance time
@ -160,23 +161,4 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
return s;
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();
if(!(cc.moving.check && cc.moving.runflyCheck && !cc.moving.allowFlying))
s.add("moving.runfly");
if(!(cc.moving.check && cc.moving.runflyCheck && cc.moving.allowFlying))
s.add("moving.flying");
if(!(cc.moving.check && cc.moving.runflyCheck && !cc.moving.allowFlying && cc.moving.swimmingCheck))
s.add("moving.swimming");
if(!(cc.moving.check && cc.moving.runflyCheck && !cc.moving.allowFlying && cc.moving.sneakingCheck))
s.add("moving.sneaking");
if(!(cc.moving.check && cc.moving.runflyCheck && !cc.moving.allowFlying && cc.moving.nofallCheck))
s.add("moving.nofall");
if(!(cc.moving.check && cc.moving.morePacketsCheck))
s.add("moving.morepackets");
return s;
}
}

View File

@ -17,38 +17,32 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
public class PlayerQuitEventManager extends PlayerListener implements EventManager {
private final NoCheat plugin;
public PlayerQuitEventManager(NoCheat plugin) {
this.plugin = plugin;
PluginManager pm = Bukkit.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_QUIT, this, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_JOIN, this, Priority.Monitor, plugin);
}
@Override
public void onPlayerQuit(PlayerQuitEvent event) {
// Get rid of the critical data that's stored for player immediately
plugin.getDataManager().getData(event.getPlayer()).clearCriticalData();
plugin.clearCriticalPlayerData(event.getPlayer());
// But only after a certain time, get rid of the rest of the data
plugin.getDataManager().queueForRemoval(event.getPlayer());
plugin.playerLeft(event.getPlayer());
}
@Override
public void onPlayerJoin(PlayerJoinEvent event) {
// A player came back early, so make sure that his data gets recycled
plugin.getDataManager().unqueueForRemoval(event.getPlayer());
plugin.playerJoined(event.getPlayer());
}
public List<String> getActiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
}

View File

@ -17,7 +17,7 @@ import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/**
* Only place that listens to Player-teleport related events and dispatches them
@ -52,9 +52,9 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
return;
}
final MovingData data = plugin.getDataManager().getData(event.getPlayer()).moving;
final BaseData data = plugin.getPlayerData(event.getPlayer());
if(data.teleportTo != null && data.teleportTo.equals(event.getTo())) {
if(data.moving.teleportTo != null && data.moving.teleportTo.equals(event.getTo())) {
event.setCancelled(false);
}
}
@ -91,14 +91,10 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
private void handleTeleportation(Player player, Location newLocation) {
plugin.getDataManager().getData(player).clearCriticalData();
plugin.clearCriticalPlayerData(player);
}
public List<String> getActiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
public List<String> getInactiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
}