Refactoring, code cleanup, moved executionHistories to "data"

This commit is contained in:
Evenprime 2011-10-14 18:44:56 +02:00
parent 0b04b7d43f
commit a0024d0737
39 changed files with 199 additions and 211 deletions

View File

@ -12,6 +12,7 @@ import org.bukkit.permissions.Permission;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
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;
@ -46,6 +47,7 @@ public class NoCheat extends JavaPlugin {
private LogManager log;
private DataManager data;
private PerformanceManager performance;
private ActionManager action;
private final List<EventManager> eventManagers = new LinkedList<EventManager>();
@ -89,6 +91,9 @@ public class NoCheat extends JavaPlugin {
// Then set up the performance counters
this.performance = new PerformanceManager();
// Then set up the Action Manager
this.action = new ActionManager(this);
// Then set up the event listeners
eventManagers.add(new PlayerMoveEventManager(this));
eventManagers.add(new PlayerTeleportEventManager(this));
@ -114,7 +119,7 @@ public class NoCheat extends JavaPlugin {
lastIngamesecondDuration = 1000;
lastIngamesecondTime = time;
ingameseconds++;
// Check if some data is outdated now and let it be removed
getDataManager().cleanDataMap();
}
@ -144,6 +149,10 @@ public class NoCheat extends JavaPlugin {
return performance;
}
public ActionManager getActionManager() {
return action;
}
public int getIngameSeconds() {
return ingameseconds;
}

View File

@ -1,17 +1,15 @@
package cc.co.evenprime.bukkit.nocheat.actions;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.history.ActionHistory;
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction;
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.LogData;
/**
@ -21,34 +19,32 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
* @author Evenprime
*
*/
public class ActionExecutor {
public class ActionManager {
private final Map<Player, ActionHistory> actionHistory = new HashMap<Player, ActionHistory>();
private final NoCheat plugin;
private final NoCheat plugin;
public ActionExecutor(NoCheat plugin) {
public ActionManager(NoCheat plugin) {
this.plugin = plugin;
}
public boolean executeActions(Player player, ActionList actions, int violationLevel, LogData data, ConfigurationCache cc) {
public boolean executeActions(Player player, ActionList actions, int violationLevel, LogData data, ActionData history, ConfigurationCache cc) {
boolean special = false;
// Always set this here "by hand"
data.violationLevel = violationLevel;
long time = System.currentTimeMillis() / 1000;
final long time = System.currentTimeMillis() / 1000;
for(Action ac : actions.getActions(violationLevel)) {
if(getHistory(player).executeAction(ac, time)) {
if(history.executeAction(ac, time)) {
if(ac instanceof LogAction) {
LogAction l = (LogAction) ac;
plugin.getLogManager().log(l.level, l.getMessage(data), cc);
executeLogAction((LogAction) ac, data, cc);
} else if(ac instanceof SpecialAction) {
special = true;
} else if(ac instanceof ConsolecommandAction) {
executeConsoleCommand(((ConsolecommandAction) ac).getCommand(data));
executeConsoleCommand((ConsolecommandAction) ac, data);
}
}
}
@ -56,19 +52,12 @@ public class ActionExecutor {
return special;
}
private ActionHistory getHistory(Player player) {
ActionHistory history = actionHistory.get(player);
if(history == null) {
history = new ActionHistory();
actionHistory.put(player, history);
}
return history;
private void executeLogAction(LogAction l, LogData data, ConfigurationCache cc) {
plugin.getLogManager().log(l.level, l.getMessage(data), cc);
}
private void executeConsoleCommand(String command) {
private void executeConsoleCommand(ConsolecommandAction action, LogData data) {
String command = action.getCommand(data);
try {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
} catch(Exception e) {

View File

@ -12,13 +12,13 @@ import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
public class LogAction extends ActionWithParameters {
public final LogLevel level;
public LogAction(String name, int delay, int repeat, LogLevel level, String message) {
super(name, delay, repeat, message);
this.level = level;
}
public String getMessage(LogData ldata) {
return super.getMessage(ldata);
}

View File

@ -11,9 +11,9 @@ 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 checks
* need to be executed and in which order. It will also precalculate some values
* that are needed by multiple checks.
* The main Check class for blockbreak event checking. It will decide which
* checks need to be executed and in which order. It will also precalculate
* some values that are needed by multiple checks.
*
* @author Evenprime
*

View File

@ -1,11 +1,10 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.block.Block;
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.actions.ActionExecutor;
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;
@ -19,12 +18,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
*/
public class DirectionCheck {
private final ActionExecutor action;
private final NoCheat plugin;
private final NoCheat plugin;
public DirectionCheck(NoCheat plugin) {
this.plugin = plugin;
this.action = new ActionExecutor(plugin);
}
public boolean check(Player player, double factor, double x1, double y1, double z1, Block brokenBlock, BlockBreakData data, ConfigurationCache cc) {
@ -33,9 +30,9 @@ public class DirectionCheck {
if(!cc.blockbreak.checkinstabreakblocks && brokenBlock.getLocation().equals(data.instaBrokeBlockLocation)) {
return false;
}
boolean cancel = false;
Vector direction = player.getEyeLocation().getDirection();
final double x2 = x1 + 2;
final double y2 = y1 + 2;
@ -50,10 +47,10 @@ public class DirectionCheck {
data.directionViolationLevel += 1;
// Prepare some event-specific values for logging and custom actions
LogData ldata = plugin.getDataManager().getData( player).log;
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "blockbreak.direction";
cancel = action.executeActions(player, cc.blockbreak.directionActions, (int) data.directionViolationLevel, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.directionActions, (int) data.directionViolationLevel, ldata, data.history, cc);
}
return cancel;

View File

@ -4,7 +4,6 @@ import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -18,12 +17,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
*/
public class ReachCheck {
private final NoCheat plugin;
private final ActionExecutor action;
private final NoCheat plugin;
public ReachCheck(NoCheat plugin) {
this.plugin = plugin;
this.action = new ActionExecutor(plugin);
}
public boolean check(Player player, double distance, BlockBreakData data, ConfigurationCache cc) {
@ -41,7 +38,7 @@ public class ReachCheck {
ldata.check = "blockbreak.reach";
ldata.reachdistance = distance;
cancel = action.executeActions(player, cc.blockbreak.reachActions, (int) data.reachViolationLevel, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockbreak.reachActions, (int) data.reachViolationLevel, ldata, data.history, cc);
} else {
data.reachViolationLevel *= 0.9D;
}

View File

@ -15,11 +15,11 @@ import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
*/
public class BlockPlaceCheck {
private final ReachCheck reachCheck;
private final ReachCheck reachCheck;
private final OnLiquidCheck onLiquidCheck;
public BlockPlaceCheck(NoCheat plugin) {
reachCheck = new ReachCheck(plugin);
onLiquidCheck = new OnLiquidCheck(plugin);
}
@ -35,7 +35,7 @@ public class BlockPlaceCheck {
if(!cancel && reach) {
cancel = reachCheck.check(player, blockPlaced, blockPlacedAgainst, data, cc);
}
if(!cancel && onliquid) {
cancel = onLiquidCheck.check(player, blockPlaced, blockPlacedAgainst, data, cc);
}

View File

@ -6,7 +6,6 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -18,12 +17,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
*/
public class OnLiquidCheck {
private final NoCheat plugin;
private final ActionExecutor action;
private final NoCheat plugin;
public OnLiquidCheck(NoCheat plugin) {
this.plugin = plugin;
action = new ActionExecutor(plugin);
}
public boolean check(Player player, Block blockPlaced, Block blockPlacedAgainst, BlockPlaceData data, ConfigurationCache cc) {
@ -43,7 +40,7 @@ public class OnLiquidCheck {
ldata.placed = blockPlaced;
ldata.placedAgainst = blockPlacedAgainst;
cancel = action.executeActions(player, cc.blockplace.onliquidActions, (int) data.onliquidViolationLevel, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockplace.onliquidActions, (int) data.onliquidViolationLevel, ldata, data.history, cc);
}
data.onliquidViolationLevel *= 0.95D; // Reduce level over time

View File

@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -20,12 +19,10 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
*/
public class ReachCheck {
private final NoCheat plugin;
private final ActionExecutor action;
private final NoCheat plugin;
public ReachCheck(NoCheat plugin) {
this.plugin = plugin;
this.action = new ActionExecutor(plugin);
}
public boolean check(Player player, Block blockPlaced, Block placedAgainstBlock, BlockPlaceData data, ConfigurationCache cc) {
@ -51,7 +48,7 @@ public class ReachCheck {
ldata.check = "blockplace.reach";
ldata.reachdistance = distance;
cancel = action.executeActions(player, cc.blockplace.reachActions, (int) data.reachViolationLevel, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.blockplace.reachActions, (int) data.reachViolationLevel, ldata, data.history, cc);
} else {
data.reachViolationLevel *= 0.9D;
}

View File

@ -3,7 +3,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.chat;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -16,13 +15,11 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
*/
public class ChatCheck {
private final ActionExecutor action;
private final NoCheat plugin;
private final NoCheat plugin;
public ChatCheck(NoCheat plugin) {
this.plugin = plugin;
action = new ActionExecutor(plugin);
}
public boolean check(Player player, String message, ChatData data, ConfigurationCache cc) {
@ -51,7 +48,7 @@ public class ChatCheck {
ldata.check = "chat.spam";
ldata.text = message;
cancel = action.executeActions(player, cc.chat.spamActions, data.messageCount - cc.chat.spamLimit, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.chat.spamActions, data.messageCount - cc.chat.spamLimit, ldata, data.history, cc);
}
}

View File

@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -19,13 +18,11 @@ import cc.co.evenprime.bukkit.nocheat.data.LogData;
*/
public class FightCheck {
private final ActionExecutor action;
private final NoCheat plugin;
private final NoCheat plugin;
public FightCheck(NoCheat plugin) {
this.plugin = plugin;
action = new ActionExecutor(plugin);
}
public boolean check(Player player, Entity damagee, FightData data, ConfigurationCache cc) {
@ -35,7 +32,7 @@ public class FightCheck {
boolean directionCheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
long time = System.currentTimeMillis();
if(directionCheck) {
Location eyes = player.getEyeLocation();
@ -50,7 +47,8 @@ public class FightCheck {
final double p = width / 2 + cc.fight.directionPrecision;
final double h = height / 2 + cc.fight.directionPrecision;
// TODO: Move this into a seperate class to recycle it throughout NoCheat
// 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;
@ -77,7 +75,7 @@ public class FightCheck {
LogData ldata = plugin.getDataManager().getData(player).log;
ldata.check = "fight.direction";
cancel = action.executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.fight.directionActions, (int) data.violationLevel, ldata, data.history, cc);
if(cancel) {
// Needed to calculate penalty times

View File

@ -6,7 +6,6 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -21,14 +20,12 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
*/
public class FlyingCheck {
private final NoCheat plugin;
private final ActionExecutor action;
private final NoCheat plugin;
private static final double creativeSpeed = 0.60D;
private static final double creativeSpeed = 0.60D;
public FlyingCheck(NoCheat plugin) {
this.plugin = plugin;
this.action = new ActionExecutor(plugin);
}
public Location check(Player player, Location from, Location to, ConfigurationCache cc, MovingData data) {
@ -88,7 +85,7 @@ public class FlyingCheck {
ldata.toLocation = to;
ldata.check = "flying/toofast";
boolean cancel = action.executeActions(player, cc.moving.flyingActions, (int) data.runflyViolationLevel, ldata, cc);
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.flyingActions, (int) data.runflyViolationLevel, ldata, data.history, cc);
// Was one of the actions a cancel? Then really do it
if(cancel) {

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -23,14 +22,11 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
*/
public class MorePacketsCheck {
private final ActionExecutor action;
private final static int packetsPerTimeframe = 22;
private final static int bufferLimit = 30;
private final NoCheat plugin;
private final static int packetsPerTimeframe = 22;
private final static int bufferLimit = 30;
private final NoCheat plugin;
public MorePacketsCheck(NoCheat plugin) {
this.action = new ActionExecutor(plugin);
this.plugin = plugin;
}
@ -128,7 +124,7 @@ public class MorePacketsCheck {
ldata.check = "moving/morepackets";
boolean cancel = false;
cancel = action.executeActions(player, cc.moving.morePacketsActions, (int) data.morePacketsViolationLevel, ldata, cc);
cancel = plugin.getActionManager().executeActions(player, cc.moving.morePacketsActions, (int) data.morePacketsViolationLevel, ldata, data.history, cc);
// Only do the cancel if the player didn't change worlds
// inbetween

View File

@ -15,20 +15,20 @@ import org.bukkit.World;
*/
public class MovingEventHelper {
private final static double magic = 0.45D;
private final static double magic2 = 0.55D;
private final static double magic = 0.45D;
private final static double magic2 = 0.55D;
// Block types that may need to be treated specially
private static final int NONSOLID = 1; // 0x00000001
private static final int SOLID = 2; // 0x00000010
private static final int LIQUID = 4 | NONSOLID; // 0x00000101
private static final int LADDER = 8 | NONSOLID | SOLID; // 0x00001011
private static final int FENCE = 16 | SOLID; // 0x00010000
private static final int INGROUND = 128;
private static final int ONGROUND = 256;
private static final int NONSOLID = 1; // 0x00000001
private static final int SOLID = 2; // 0x00000010
private static final int LIQUID = 4 | NONSOLID; // 0x00000101
private static final int LADDER = 8 | NONSOLID | SOLID; // 0x00001011
private static final int FENCE = 16 | SOLID; // 0x00010000
private static final int INGROUND = 128;
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];
public final int types[] = new int[256];
public MovingEventHelper() {
// Find and define properties of all blocks

View File

@ -4,7 +4,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.actions.ActionExecutor;
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;
@ -18,12 +17,10 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
*/
public class NoFallCheck {
private final ActionExecutor action;
private final NoCheat plugin;
private final NoCheat plugin;
public NoFallCheck(NoCheat plugin) {
this.plugin = plugin;
this.action = new ActionExecutor(plugin);
}
/**
@ -41,59 +38,63 @@ public class NoFallCheck {
data.fallDistance = 0F;
}
// If we increased fall height before for no good reason, reduce now by the same amount
// 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);
}
data.lastAddedFallDistance = 0;
// We want to know if the fallDistance recorded by the game is smaller
// than the fall distance recorded by the plugin
// than the fall distance recorded by the plugin
float difference = data.fallDistance - player.getFallDistance();
if(difference > 1.0F && toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallViolationLevel += difference;
// Prepare some event-specific values for logging and custom actions
// 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";
ldata.check = "moving/nofall";
boolean cancel = action.executeActions(player, cc.moving.nofallActions, (int) data.nofallViolationLevel, ldata, cc);
// If "cancelled", the fall damage gets dealt in a way that's visible to other plugins
if(cancel) {
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.nofallActions, (int) data.nofallViolationLevel, ldata, data.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);
player.setFallDistance(totalDistance);
}
data.fallDistance = 0F;
}
// Increase the fall distance that is recorded by the plugin, AND set the fall distance of the player
// to whatever he would get with this move event. This modifies Minecrafts fall damage calculation
// slightly, but that's still better than ignoring players that try to use "teleports" or "stepdown"
// to avoid falldamage. It is only added for big height differences anyway, as to avoid to much deviation
// Increase the fall distance that is recorded by the plugin, AND set
// the fall distance of the player
// to whatever he would get with this move event. This modifies
// Minecrafts fall damage calculation
// slightly, but that's still better than ignoring players that try to
// use "teleports" or "stepdown"
// to avoid falldamage. It is only added for big height differences
// anyway, as to avoid to much deviation
// from the original Minecraft feeling.
if(oldY > newY) {
float dist = (float) (oldY - newY);
data.fallDistance += dist;
if(dist > 1.0F) {
data.lastAddedFallDistance = dist;
player.setFallDistance(player.getFallDistance() + dist);
}
else {
} else {
data.lastAddedFallDistance = 0.0F;
}
}
else {
} else {
data.lastAddedFallDistance = 0.0F;
}
// Reduce falldamage violation level
data.nofallViolationLevel *= 0.99D;
}

View File

@ -1,11 +1,10 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
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.actions.ActionExecutor;
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;
@ -22,20 +21,18 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
*/
public class RunningCheck {
private final static double maxBonus = 1D;
private final static double maxBonus = 1D;
// How many move events can a player have in air before he is expected to
// lose altitude (or eventually land somewhere)
private final static int jumpingLimit = 6;
private final static int jumpingLimit = 6;
private final ActionExecutor action;
private final NoCheat plugin;
private final NoCheat plugin;
private final NoFallCheck noFallCheck;
private final NoFallCheck noFallCheck;
public RunningCheck(NoCheat plugin, NoFallCheck noFallCheck) {
this.plugin = plugin;
this.action = new ActionExecutor(plugin);
this.noFallCheck = noFallCheck;
}
@ -86,7 +83,7 @@ public class RunningCheck {
else if(resultVert > 0)
ldata.check = "runfly/vertical";
boolean cancel = action.executeActions(player, cc.moving.actions, (int) data.runflyViolationLevel, ldata, cc);
boolean cancel = plugin.getActionManager().executeActions(player, cc.moving.actions, (int) data.runflyViolationLevel, ldata, data.history, cc);
// Was one of the actions a cancel? Then do it
if(cancel) {

View File

@ -3,8 +3,9 @@ package cc.co.evenprime.bukkit.nocheat.config;
import java.util.HashMap;
import java.util.Map;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.OptionNode.DataType;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode;
import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode.DataType;
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
/**
@ -100,8 +101,6 @@ public abstract class Configuration {
public static final OptionNode FIGHT_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", FIGHT_DIRECTION, DataType.INTEGER);
public final static OptionNode FIGHT_DIRECTION_ACTIONS = new OptionNode("actions", FIGHT_DIRECTION, DataType.ACTIONLIST);
private final Map<OptionNode, Object> values;
private final Configuration defaults;

View File

@ -16,6 +16,7 @@ import java.util.logging.LogRecord;
import java.util.logging.Logger;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper;
/**
* Central location for everything that's described in the configuration file(s)

View File

@ -5,7 +5,8 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper;
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
/**

View File

@ -3,6 +3,8 @@ package cc.co.evenprime.bukkit.nocheat.config;
import java.util.HashMap;
import java.util.Map;
import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode;
/**
* Textual explainations of options, will be displayed in the gui tool and the
* descriptions.txt file.

View File

@ -12,6 +12,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction;
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.util.ActionMapper;
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
public class FlatFileAction {

View File

@ -8,8 +8,10 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper;
import cc.co.evenprime.bukkit.nocheat.config.util.OptionNode;
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
public class FlatFileConfiguration extends Configuration {

View File

@ -1,7 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
/**
* Configurations specific for the "BlockBreak" checks

View File

@ -1,7 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
/**
*

View File

@ -1,7 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
public class CCChat {

View File

@ -1,7 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
public class CCFight {

View File

@ -1,7 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.config.cache;
import cc.co.evenprime.bukkit.nocheat.actions.ActionList;
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
/**
* Configurations specific for the Move Checks. Every world gets one of these

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat.actions;
package cc.co.evenprime.bukkit.nocheat.config.util;
import java.util.ArrayList;
import java.util.Collections;
@ -18,11 +18,11 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
public class ActionList {
public ActionList() {}
private final static Action[] emptyArray = new Action[0];
private final Map<Integer, Action[]> actions = new HashMap<Integer, Action[]>();
private final List<Integer> tresholds = new ArrayList<Integer>();
private final static Action[] emptyArray = new Action[0];
private final Map<Integer, Action[]> actions = new HashMap<Integer, Action[]>();
private final List<Integer> tresholds = new ArrayList<Integer>();
/**
* Add an entry to this actionList. The list will be sorted by tresholds
@ -52,7 +52,7 @@ public class ActionList {
public Action[] getActions(Integer vl) {
Integer result = null;
for(Integer treshold : tresholds) {
if(treshold <= vl) {
result = treshold;

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat.config;
package cc.co.evenprime.bukkit.nocheat.config.util;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat.config;
package cc.co.evenprime.bukkit.nocheat.config.util;
import java.util.LinkedList;
import java.util.List;

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat.actions.history;
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.HashMap;
import java.util.Map;
@ -11,7 +11,7 @@ import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
* @author Evenprime
*
*/
public class ActionHistory {
public class ActionData {
private static class ExecutionHistoryEntry {
@ -34,7 +34,7 @@ public class ActionHistory {
clearTimes(lastClearedTime + 1, time - lastClearedTime);
lastClearedTime = time + 1;
}
executionTimes[(int) (time % executionTimes.length)]++;
totalEntries++;
}
@ -60,11 +60,11 @@ public class ActionHistory {
if(j == executionTimes.length) {
j = 0;
}
totalEntries -= executionTimes[j];
executionTimes[j] = 0;
j++;
j++;
}
}
@ -83,9 +83,11 @@ public class ActionHistory {
// Store data between Events
// time + action + action-counter
private final Map<Action, ExecutionHistoryEntry> executionHistory = new HashMap<Action, ExecutionHistoryEntry>();
private final Map<Action, ExecutionHistoryEntry> executionHistory;
public ActionHistory() {}
public ActionData() {
executionHistory = new HashMap<Action, ExecutionHistoryEntry>();
}
/**
* Returns true, if the action should be executed, because all time
@ -111,8 +113,8 @@ public class ActionHistory {
entry.addCounter(time);
if(entry.getCounter() > action.delay) {
// Execute action?
if(entry.getLastExecution() <= time - action.repeat) {
// Execute action?
if(entry.getLastExecution() <= time - action.repeat) {
// Execute action!
entry.setLastExecution(time);
return true;

View File

@ -2,21 +2,19 @@ package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.entity.Player;
public class BaseData {
public class BaseData extends Data {
public final BlockBreakData blockbreak;
public final BlockPlaceData blockplace;
public final ChatData chat;
public final LogData log;
public final MovingData moving;
public final FightData fight;
private final Data[] data;
private long removalTime;
public final ChatData chat;
public final LogData log;
public final MovingData moving;
public final FightData fight;
private final Data[] data;
private long removalTime;
public BaseData() {
this.blockbreak = new BlockBreakData();
this.blockplace = new BlockPlaceData();
@ -24,10 +22,11 @@ public class BaseData {
this.log = new LogData();
this.moving = new MovingData();
this.fight = new FightData();
this.removalTime = 0;
data = new Data[] { this.blockbreak, this.blockplace, this.chat, this.log, this.moving, this.fight };
data = new Data[] {this.blockbreak, this.blockplace, this.chat,
this.log, this.moving, this.fight};
}
public void clearCriticalData() {
@ -41,17 +40,17 @@ public class BaseData {
d.initialize(player);
}
}
public void markForRemoval(boolean removal) {
if(removal) {
// 1 minute in the future
this.removalTime = System.currentTimeMillis() + 60000;
}
else {
} else {
this.removalTime = 0;
}
}
public boolean shouldBeRemoved() {
public boolean shouldBeRemoved() {
return removalTime != 0 && removalTime < System.currentTimeMillis();
}
}

View File

@ -2,6 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.data;
import org.bukkit.Location;
/**
* Playerspecific data for the blockbreak check group
*
@ -10,9 +11,10 @@ import org.bukkit.Location;
*/
public class BlockBreakData extends Data {
public double reachViolationLevel = 0.0D;
public double directionViolationLevel = 0.0D;
public double reachViolationLevel = 0.0D;
public double directionViolationLevel = 0.0D;
public Location instaBrokeBlockLocation = null;
public Location instaBrokeBlockLocation = null;
public final ActionData history = new ActionData();
}

View File

@ -1,5 +1,6 @@
package cc.co.evenprime.bukkit.nocheat.data;
/**
*
* @author Evenprime
@ -7,6 +8,7 @@ package cc.co.evenprime.bukkit.nocheat.data;
*/
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 ActionData history = new ActionData();
}

View File

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

View File

@ -7,15 +7,15 @@ 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

@ -1,9 +1,9 @@
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 ActionData history = new ActionData();
}

View File

@ -22,7 +22,7 @@ public class LogData extends Data {
public void initialize(Player player) {
this.player = player;
check = "";
toLocation = player.getLocation();
this.check = "";
this.toLocation = player.getLocation();
}
}

View File

@ -3,38 +3,41 @@ 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();
@Override
public void initialize(Player player) {