Massive rewrite part 1: Inheritance between checks, less entanglement

between
components, introduce "NoCheatPlayer" class for easier access to data
and configuration
This commit is contained in:
Evenprime 2011-11-06 21:08:22 +01:00
parent f04be42eb2
commit ae8cacb97b
59 changed files with 1595 additions and 1340 deletions

View File

@ -10,14 +10,10 @@ import org.bukkit.entity.Player;
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.command.CommandHandler;
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager;
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.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.DataManager;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
import cc.co.evenprime.bukkit.nocheat.data.PlayerManager;
import cc.co.evenprime.bukkit.nocheat.debug.ActiveCheckPrinter;
import cc.co.evenprime.bukkit.nocheat.debug.LagMeasureTask;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
@ -26,7 +22,7 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager;
import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager;
import cc.co.evenprime.bukkit.nocheat.events.EntityDamageEventManager;
import cc.co.evenprime.bukkit.nocheat.events.FightEventManager;
import cc.co.evenprime.bukkit.nocheat.events.EventManager;
import cc.co.evenprime.bukkit.nocheat.events.PlayerChatEventManager;
import cc.co.evenprime.bukkit.nocheat.events.PlayerMoveEventManager;
@ -47,9 +43,8 @@ public class NoCheat extends JavaPlugin {
private ConfigurationManager conf;
private LogManager log;
private DataManager data;
private PlayerManager players;
private PerformanceManager performance;
private ActionManager action;
private List<EventManager> eventManagers;
@ -94,7 +89,7 @@ public class NoCheat extends JavaPlugin {
log.logToConsole(LogLevel.LOW, "[NoCheat] This version is for CB #1337. It may break at any time and for any other version.");
// Then set up in memory per player data storage
this.data = new DataManager();
this.players = new PlayerManager(this);
// Then read the configuration files
this.conf = new ConfigurationManager(this.getDataFolder().getPath());
@ -102,9 +97,6 @@ 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);
eventManagers = new ArrayList<EventManager>(8); // Big enough
// Then set up the event listeners
eventManagers.add(new PlayerMoveEventManager(this));
@ -112,7 +104,7 @@ public class NoCheat extends JavaPlugin {
eventManagers.add(new PlayerChatEventManager(this));
eventManagers.add(new BlockBreakEventManager(this));
eventManagers.add(new BlockPlaceEventManager(this));
eventManagers.add(new EntityDamageEventManager(this));
eventManagers.add(new FightEventManager(this));
eventManagers.add(new SwingEventManager(this));
TimedEventManager m = new TimedEventManager(this);
taskId = m.taskId; // There's a bukkit task, remember its id
@ -132,7 +124,7 @@ public class NoCheat extends JavaPlugin {
}
public ConfigurationCache getConfig(Player player) {
return getConfig(player.getWorld());
return conf.getConfigurationCacheForWorld(player.getWorld().getName());
}
public ConfigurationCache getConfig(World world) {
@ -143,12 +135,8 @@ public class NoCheat extends JavaPlugin {
log.log(level, message, cc);
}
public BaseData getData(String playerName) {
return data.getData(playerName);
}
public void clearCriticalData(String playerName) {
data.clearCriticalData(playerName);
players.clearCriticalData(playerName);
}
public Performance getPerformance(Type type) {
@ -178,13 +166,6 @@ public class NoCheat extends JavaPlugin {
return 1000L;
}
public boolean execute(Player player, ActionList actions, int violationLevel, ExecutionHistory history, ConfigurationCache cc) {
if(action != null) {
return action.executeActions(player, actions, violationLevel, history, cc);
}
return false;
}
public void logToConsole(LogLevel low, String message) {
if(log != null) {
log.logToConsole(low, message);
@ -194,8 +175,8 @@ public class NoCheat extends JavaPlugin {
public void reloadConfiguration() {
conf.cleanup();
this.conf = new ConfigurationManager(this.getDataFolder().getPath());
data.cleanDataMap();
data.clearCriticalData();
players.cleanDataMap();
players.clearCriticalData();
}
/**
@ -204,7 +185,12 @@ public class NoCheat extends JavaPlugin {
*
*/
public void cleanDataMap() {
data.cleanDataMap();
players.cleanDataMap();
}
public NoCheatPlayer getPlayer(String playerName) {
return players.getPlayer(playerName);
}
}

View File

@ -0,0 +1,21 @@
package cc.co.evenprime.bukkit.nocheat;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
public interface NoCheatPlayer {
public boolean hasPermission(String permission);
public String getName();
public Player getPlayer();
public BaseData getData();
public ConfigurationCache getConfiguration();
}

View File

@ -1,67 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.actions;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
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.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
/**
* Will trace the history of action executions to decide if an action 'really'
* gets executed.
*
*/
public class ActionManager {
private final NoCheat plugin;
public ActionManager(NoCheat plugin) {
this.plugin = plugin;
}
public boolean executeActions(final Player player, final ActionList actions, final int violationLevel, final ExecutionHistory history, final ConfigurationCache cc) {
boolean special = false;
final BaseData data = plugin.getData(player.getName());
// Always set this here "by hand"
data.log.violationLevel = violationLevel;
final long time = System.currentTimeMillis() / 1000;
for(Action ac : actions.getActions(violationLevel)) {
if(history.executeAction(ac, time)) {
if(ac instanceof LogAction) {
executeLogAction((LogAction) ac, data, cc);
} else if(ac instanceof SpecialAction) {
special = true;
} else if(ac instanceof ConsolecommandAction) {
executeConsoleCommand((ConsolecommandAction) ac, data);
}
}
}
return special;
}
private void executeLogAction(LogAction l, BaseData data, ConfigurationCache cc) {
plugin.log(l.level, cc.logging.prefix + l.getLogMessage(data), cc);
}
private void executeConsoleCommand(ConsolecommandAction action, BaseData data) {
String command = action.getCommand(data);
try {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
} catch(Exception e) {
System.out.println("[NoCheat] failed to execute the command '" + command + "', please check if everything is setup correct. ");
e.printStackTrace();
}
}
}

View File

@ -1,21 +1,13 @@
package cc.co.evenprime.bukkit.nocheat.actions.types;
import java.util.ArrayList;
import java.util.Locale;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.LogData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.Check;
public abstract class ActionWithParameters extends Action {
private enum WildCard {
public enum WildCard {
PLAYER("player"), LOCATION("location"), WORLD("world"), VIOLATIONS("violations"), MOVEDISTANCE("movedistance"), REACHDISTANCE("reachdistance"), FALLDISTANCE("falldistance"), LOCATION_TO("locationto"), CHECK("check"), PACKETS("packets"), TEXT("text"), PLACE_LOCATION("placelocation"), PLACE_AGAINST("placeagainst"), BLOCK_TYPE("blocktype");
private final String s;
@ -84,7 +76,9 @@ public abstract class ActionWithParameters extends Action {
* @param data
* @return
*/
protected String getMessage(final BaseData data) {
protected String getMessage(NoCheatPlayer player, Check check) {
StringBuilder log = new StringBuilder(100); // Should be big enough most
// of the time
@ -92,107 +86,10 @@ public abstract class ActionWithParameters extends Action {
if(part instanceof String) {
log.append((String) part);
} else {
log.append(getParameter((WildCard) part, data));
log.append(check.getParameter((WildCard) part, player));
}
}
return log.toString();
}
private String getParameter(WildCard wildcard, BaseData bdata) {
// The == is correct here, as these really are identical objects, not
// only equal
final LogData data = bdata.log;
switch (wildcard) {
case PLAYER:
return data.playerName;
case CHECK:
return data.check;
case LOCATION: {
Player player = Bukkit.getPlayer(data.playerName);
if(player != null) {
Location l = player.getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
}
return "unknown";
}
case WORLD: {
Player player = Bukkit.getPlayer(data.playerName);
if(player != null) {
return player.getWorld().getName();
}
return "unknown";
}
case VIOLATIONS:
return String.format(Locale.US, "%d", data.violationLevel);
case MOVEDISTANCE: {
Player player = Bukkit.getPlayer(data.playerName);
if(player != null) {
Location l = player.getLocation();
PreciseLocation t = data.toLocation;
if(t.isSet()) {
return String.format(Locale.US, "%.2f,%.2f,%.2f", t.x - l.getX(), t.y - l.getY(), t.z - l.getZ());
} else {
return "null";
}
}
return "unknown";
}
case REACHDISTANCE:
return String.format(Locale.US, "%.2f", data.reachdistance);
case FALLDISTANCE:
return String.format(Locale.US, "%.2f", data.falldistance);
case LOCATION_TO:
PreciseLocation to = data.toLocation;
if(to.isSet()) {
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
} else {
return "unknown";
}
case PACKETS:
return String.valueOf(data.packets);
case TEXT:
return data.text;
case PLACE_LOCATION: {
SimpleLocation l = bdata.blockplace.blockPlaced;
if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
} else {
return "null";
}
}
case PLACE_AGAINST: {
SimpleLocation l = bdata.blockplace.blockPlacedAgainst;
if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
} else {
return "null";
}
}
case BLOCK_TYPE: {
Material type = bdata.blockplace.placedType;
if(type == null) {
return "null";
}
return type.toString();
}
default:
return "Evenprime was lazy and forgot to define " + wildcard + ".";
}
}
}

View File

@ -1,6 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.actions.types;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.Check;
/**
* Execute a command by imitating an admin typing the command directly into the
@ -14,8 +15,8 @@ public class ConsolecommandAction extends ActionWithParameters {
}
public String getCommand(BaseData data) {
public String getCommand(NoCheatPlayer player, Check check) {
return super.getMessage(data);
return super.getMessage(player, check);
}
}

View File

@ -1,6 +1,7 @@
package cc.co.evenprime.bukkit.nocheat.actions.types;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.Check;
import cc.co.evenprime.bukkit.nocheat.log.Colors;
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
@ -19,7 +20,7 @@ public class LogAction extends ActionWithParameters {
this.level = level;
}
public String getLogMessage(final BaseData data) {
return super.getMessage(data);
public String getLogMessage(NoCheatPlayer player, Check check) {
return super.getMessage(player, check);
}
}

View File

@ -0,0 +1,23 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
public abstract class BlockBreakCheck extends Check {
public BlockBreakCheck(NoCheat plugin, String name, String permission) {
super(plugin, name, permission);
}
public abstract boolean check(NoCheatPlayer player, BlockBreakData data, CCBlockBreak cc);
public abstract boolean isEnabled(CCBlockBreak cc);
@Override
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
return player.getData().blockbreak.history;
}
}

View File

@ -0,0 +1,66 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import java.util.Locale;
import org.bukkit.Material;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
/**
*
*/
public abstract class BlockPlaceCheck extends Check {
public BlockPlaceCheck(NoCheat plugin, String name, String permission) {
super(plugin, name, permission);
}
public abstract boolean check(NoCheatPlayer player, BlockPlaceData data, CCBlockPlace cc);
public abstract boolean isEnabled(CCBlockPlace cc);
@Override
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
return player.getData().blockplace.history;
}
@Override
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case PLACE_LOCATION: {
SimpleLocation l = player.getData().blockplace.blockPlaced;
if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
} else {
return "null";
}
}
case PLACE_AGAINST: {
SimpleLocation l = player.getData().blockplace.blockPlacedAgainst;
if(l.isSet()) {
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
} else {
return "null";
}
}
case BLOCK_TYPE: {
Material type = player.getData().blockplace.placedType;
if(type == null) {
return "null";
}
return type.toString();
}
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -0,0 +1,38 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
public abstract class ChatCheck extends Check {
public ChatCheck(NoCheat plugin, String name, String permission) {
super(plugin, name, permission);
}
public abstract boolean check(NoCheatPlayer player, ChatData data, CCChat cc);
public abstract boolean isEnabled(CCChat cc);
@Override
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
return player.getData().chat.history;
}
@Override
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case TEXT: {
return player.getData().chat.message;
}
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -0,0 +1,99 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import java.util.Locale;
import org.bukkit.Location;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.Action;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
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.data.ExecutionHistory;
public abstract class Check {
private final String name;
private final String permission;
protected final NoCheat plugin;
public Check(NoCheat plugin, String name, String permission) {
this.plugin = plugin;
this.name = name;
this.permission = permission;
}
public final String getName() {
return name;
}
public final String getPermission() {
return permission;
}
protected final boolean executeActions(NoCheatPlayer player, Action[] actions) {
boolean special = false;
final long time = System.currentTimeMillis() / 1000;
final ConfigurationCache cc = player.getConfiguration();
for(Action ac : actions) {
if(getHistory(player).executeAction(ac, time)) {
if(ac instanceof LogAction) {
executeLogAction((LogAction) ac, this, player, cc);
} else if(ac instanceof SpecialAction) {
special = true;
} else if(ac instanceof ConsolecommandAction) {
executeConsoleCommand((ConsolecommandAction) ac, this, player, cc);
}
}
}
return special;
}
protected abstract ExecutionHistory getHistory(NoCheatPlayer player);
private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCache cc) {
plugin.log(l.level, cc.logging.prefix + l.getLogMessage(player, check), cc);
}
private final void executeConsoleCommand(ConsolecommandAction action, Check check, NoCheatPlayer player, ConfigurationCache cc) {
String command = action.getCommand(player, check);
try {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), command);
} catch(Exception e) {
System.out.println("[NoCheat] failed to execute the command '" + command + "', please check if everything is setup correct. ");
e.printStackTrace();
}
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case PLAYER:
return player.getName();
case CHECK:
return getName();
case LOCATION: {
Location l = player.getPlayer().getLocation();
return String.format(Locale.US, "%.2f,%.2f,%.2f", l.getX(), l.getY(), l.getZ());
}
case WORLD: {
return player.getPlayer().getWorld().getName();
}
default:
return "Evenprime was lazy and forgot to define " + wildcard + ".";
}
}
}

View File

@ -9,6 +9,7 @@ import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
/**
@ -21,15 +22,15 @@ public class CheckUtil {
* Check if a player looks at a target of a specific size, with a specific
* precision value (roughly)
*/
public static final double directionCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision) {
public static final double directionCheck(final NoCheatPlayer player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision) {
// Eye location of the player
final Location eyes = player.getEyeLocation();
final Location eyes = player.getPlayer().getEyeLocation();
final 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
final Vector direction = player.getEyeLocation().getDirection();
final Vector direction = eyes.getDirection();
final double x = ((double) targetX) - eyes.getX();
final double y = ((double) targetY) - eyes.getY();
@ -52,9 +53,9 @@ public class CheckUtil {
return off;
}
public static final double reachCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double limit) {
public static final double reachCheck(final NoCheatPlayer player, final double targetX, final double targetY, final double targetZ, final double limit) {
final Location eyes = player.getEyeLocation();
final Location eyes = player.getPlayer().getEyeLocation();
final double distance = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));

View File

@ -0,0 +1,27 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
/**
* Check various things related to fighting players/entities
*
*/
public abstract class FightCheck extends Check {
public FightCheck(NoCheat plugin, String name, String permission) {
super(plugin, name, permission);
}
public abstract boolean check(NoCheatPlayer player, FightData data, CCFight cc);
public abstract boolean isEnabled(CCFight cc);
@Override
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
return player.getData().fight.history;
}
}

View File

@ -0,0 +1,58 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
public abstract class MovingCheck extends Check {
public MovingCheck(NoCheat plugin, String name, String permission) {
super(plugin, name, permission);
}
/**
* Return a new destination location or null
*
* @param event
* @return
*/
public abstract PreciseLocation check(final NoCheatPlayer player, MovingData data, CCMoving cc);
public abstract boolean isEnabled(CCMoving moving);
@Override
protected ExecutionHistory getHistory(NoCheatPlayer player) {
return player.getData().moving.history;
}
@Override
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case LOCATION: {
PreciseLocation from = player.getData().moving.from;
return String.format(Locale.US, "%.2f,%.2f,%.2f", from.x, from.y, from.z);
}
case MOVEDISTANCE: {
PreciseLocation from = player.getData().moving.from;
PreciseLocation to = player.getData().moving.to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x - from.x, to.y - from.y, to.z - from.z);
}
case LOCATION_TO:
PreciseLocation to = player.getData().moving.to;
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -0,0 +1,24 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCTimed;
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
import cc.co.evenprime.bukkit.nocheat.data.TimedData;
public abstract class TimedCheck extends Check {
public TimedCheck(NoCheat plugin, String name, String permission) {
super(plugin, name, permission);
}
public abstract boolean check(final NoCheatPlayer player, TimedData data, CCTimed cc);
public abstract boolean isEnabled(CCTimed cc);
@Override
protected ExecutionHistory getHistory(NoCheatPlayer player) {
// TODO Auto-generated method stub
return player.getData().timed.history;
}
}

View File

@ -1,58 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.block.Block;
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.BaseData;
/**
* 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.
*
*/
public class BlockBreakCheck {
private final ReachCheck reachCheck;
private final DirectionCheck directionCheck;
private final NoswingCheck noswingCheck;
private final NoCheat plugin;
public BlockBreakCheck(NoCheat plugin) {
this.plugin = plugin;
this.reachCheck = new ReachCheck(plugin);
this.directionCheck = new DirectionCheck(plugin);
this.noswingCheck = new NoswingCheck(plugin);
}
public boolean check(final Player player, final Block brokenBlock, final ConfigurationCache cc) {
boolean cancel = false;
// Reach check only if not in creative mode!
final boolean reach = cc.blockbreak.reachCheck && !player.hasPermission(Permissions.BLOCKBREAK_REACH);
final boolean direction = cc.blockbreak.directionCheck && !player.hasPermission(Permissions.BLOCKBREAK_DIRECTION);
final boolean noswing = cc.blockbreak.noswingCheck && !player.hasPermission(Permissions.BLOCKBREAK_NOSWING);
if((noswing || reach || direction) && brokenBlock != null) {
final BaseData data = plugin.getData(player.getName());
if(noswing) {
cancel = noswingCheck.check(player, data, cc);
}
if(!cancel && reach) {
cancel = reachCheck.check(player, data, brokenBlock, cc);
}
if(!cancel && direction) {
cancel = directionCheck.check(player, data, brokenBlock, cc);
}
}
return cancel;
}
}

View File

@ -1,35 +1,33 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
/**
* The DirectionCheck will find out if a player tried to interact with something
* that's not in his field of view.
*
*/
public class DirectionCheck {
private final NoCheat plugin;
public class DirectionCheck extends BlockBreakCheck {
public DirectionCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "blockbreak.direction", Permissions.BLOCKBREAK_DIRECTION);
}
public boolean check(final Player player, final BaseData data, final Block brokenBlock, final ConfigurationCache cc) {
public boolean check(final NoCheatPlayer player, final BlockBreakData blockbreak, final CCBlockBreak ccblockbreak) {
final BlockBreakData blockbreak = data.blockbreak;
final CCBlockBreak ccblockbreak = cc.blockbreak;
final SimpleLocation brokenBlock = blockbreak.brokenBlockLocation;
final boolean isInstaBreak = blockbreak.instaBrokeBlockLocation.equals(brokenBlock);
// If the block is instabreak and we don't check instabreak, return
if(isInstaBreak && !ccblockbreak.checkinstabreakblocks) {
return false;
@ -37,7 +35,7 @@ public class DirectionCheck {
boolean cancel = false;
double off = CheckUtil.directionCheck(player, brokenBlock.getX() + 0.5D, brokenBlock.getY() + 0.5D, brokenBlock.getZ() + 0.5D, 1D, 1D, ccblockbreak.directionPrecision);
double off = CheckUtil.directionCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D, brokenBlock.z + 0.5D, 1D, 1D, ccblockbreak.directionPrecision);
final long time = System.currentTimeMillis();
@ -49,15 +47,13 @@ public class DirectionCheck {
// Player failed the check
// Increment violation counter
if(isInstaBreak) {
// Instabreak block failures are very common, so don't be as hard on people failing them
// Instabreak block failures are very common, so don't be as
// hard on people failing them
off /= 10;
}
blockbreak.directionViolationLevel += off;
// Prepare some event-specific values for logging and custom actions
data.log.check = "blockbreak.direction";
cancel = plugin.execute(player, ccblockbreak.directionActions, (int) blockbreak.directionViolationLevel, blockbreak.history, cc);
cancel = executeActions(player, ccblockbreak.directionActions.getActions(blockbreak.directionViolationLevel));
if(cancel) {
// Needed to calculate penalty times
@ -66,10 +62,27 @@ public class DirectionCheck {
}
// If the player is still in penalty time, cancel the event anyway
if(blockbreak.directionLastViolationTime + ccblockbreak.directionPenaltyTime >= time) {
if(blockbreak.directionLastViolationTime + ccblockbreak.directionPenaltyTime > time) {
return true;
}
return cancel;
}
public boolean isEnabled(CCBlockBreak cc) {
return cc.directionCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.directionViolationLevel);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,36 +1,56 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
public class NoswingCheck {
private final NoCheat plugin;
public class NoswingCheck extends BlockBreakCheck {
public NoswingCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "blockbreak.noswing", Permissions.BLOCKBREAK_NOSWING);
}
public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, BlockBreakData data, CCBlockBreak cc) {
boolean cancel = false;
// did he swing his arm before?
if(data.armswung) {
data.armswung = false;
data.blockbreak.noswingVL *= 0.90D;
} else {
data.blockbreak.noswingVL += 1;
// Prepare some event-specific values for logging and custom
// actions
data.log.check = "blockbreak.noswing";
BaseData d = player.getData();
cancel = plugin.execute(player, cc.blockbreak.noswingActions, (int) data.blockbreak.noswingVL, data.blockbreak.history, cc);
// did he swing his arm before?
if(d.armswung) {
d.armswung = false;
data.noswingVL *= 0.90D;
} else {
data.noswingVL += 1;
cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL));
}
return cancel;
}
public boolean isEnabled(CCBlockBreak cc) {
return cc.noswingCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.noswingVL);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,52 +1,69 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
import java.util.Locale;
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.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
/**
* The reach check will find out if a player interacts with something that's too
* far away
*
*/
public class ReachCheck {
private final NoCheat plugin;
public class ReachCheck extends BlockBreakCheck {
public ReachCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "blockbreak.reach", Permissions.BLOCKBREAK_REACH);
}
public boolean check(final Player player, final BaseData data, final Block brokenBlock, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, BlockBreakData data, CCBlockBreak cc) {
boolean cancel = false;
final BlockBreakData blockbreak = data.blockbreak;
final SimpleLocation brokenBlock = data.brokenBlockLocation;
final 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);
final double distance = CheckUtil.reachCheck(player, brokenBlock.x + 0.5D, brokenBlock.y + 0.5D, brokenBlock.z + 0.5D, player.getPlayer().getGameMode() == GameMode.CREATIVE ? cc.reachDistance + 2 : cc.reachDistance);
if(distance > 0D) {
// Player failed the check
// Increment violation counter
blockbreak.reachViolationLevel += distance;
data.reachVL += distance;
data.reachDistance = distance;
// Setup data for logging
data.log.check = "blockbreak.reach";
data.log.reachdistance = distance;
cancel = plugin.execute(player, cc.blockbreak.reachActions, (int) blockbreak.reachViolationLevel, blockbreak.history, cc);
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
} else {
blockbreak.reachViolationLevel *= 0.9D;
data.reachVL *= 0.9D;
}
return cancel;
}
public boolean isEnabled(CCBlockBreak cc) {
return cc.reachCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.reachVL);
case REACHDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,54 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.block.Block;
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.BaseData;
/**
*
*/
public class BlockPlaceCheck {
private final ReachCheck reachCheck;
private final DirectionCheck directionCheck;
private final NoCheat plugin;
public BlockPlaceCheck(NoCheat plugin) {
this.plugin = plugin;
reachCheck = new ReachCheck(plugin);
directionCheck = new DirectionCheck(plugin);
}
public boolean check(final Player player, final Block blockPlaced, final Block blockPlacedAgainst, final ConfigurationCache cc) {
boolean cancel = false;
// Which checks are going to be executed?
final boolean reach = cc.blockplace.reachCheck && !player.hasPermission(Permissions.BLOCKPLACE_REACH);
final boolean direction = cc.blockplace.directionCheck && !player.hasPermission(Permissions.BLOCKPLACE_DIRECTION);
final BaseData data = plugin.getData(player.getName());
if(blockPlaced != null && blockPlacedAgainst != null) {
data.blockplace.blockPlaced.set(blockPlaced);
data.blockplace.blockPlacedAgainst.set(blockPlacedAgainst);
data.blockplace.placedType = blockPlaced.getType();
if(!cancel && direction) {
cancel = directionCheck.check(player, data, cc);
}
if(!cancel && reach) {
cancel = reachCheck.check(player, data, cc);
}
}
return cancel;
}
}

View File

@ -1,35 +1,32 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.BlockPlaceCheck;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
public class DirectionCheck {
private final NoCheat plugin;
public class DirectionCheck extends BlockPlaceCheck {
public DirectionCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "blockplace.direction", Permissions.BLOCKPLACE_DIRECTION);
}
public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, BlockPlaceData data, CCBlockPlace cc) {
boolean cancel = false;
final CCBlockPlace ccblockplace = cc.blockplace;
final BlockPlaceData blockplace = data.blockplace;
final SimpleLocation blockPlaced = blockplace.blockPlaced;
final SimpleLocation blockPlacedAgainst = blockplace.blockPlacedAgainst;
final SimpleLocation blockPlaced = data.blockPlaced;
final SimpleLocation blockPlacedAgainst = data.blockPlacedAgainst;
// First check if the crosshair matches (roughly) the clicked block
double off = CheckUtil.directionCheck(player, blockPlacedAgainst.x + 0.5D, blockPlacedAgainst.y + 0.5D, blockPlacedAgainst.z + 0.5D, 1D, 1D, ccblockplace.directionPrecision);
double off = CheckUtil.directionCheck(player, blockPlacedAgainst.x + 0.5D, blockPlacedAgainst.y + 0.5D, blockPlacedAgainst.z + 0.5D, 1D, 1D, cc.directionPrecision);
// now check if the player is looking at the block from the correct side
@ -38,17 +35,17 @@ public class DirectionCheck {
// Find out against which face the player tried to build, and if he
// stood on the correct side
if(blockPlaced.x > blockPlacedAgainst.x) {
off2 = blockPlacedAgainst.x + 0.5D - player.getEyeLocation().getX();
off2 = blockPlacedAgainst.x + 0.5D - player.getPlayer().getEyeLocation().getX();
} else if(blockPlaced.x < blockPlacedAgainst.x) {
off2 = -(blockPlacedAgainst.x + 0.5D - player.getEyeLocation().getX());
off2 = -(blockPlacedAgainst.x + 0.5D - player.getPlayer().getEyeLocation().getX());
} else if(blockPlaced.y > blockPlacedAgainst.y) {
off2 = blockPlacedAgainst.y + 0.5D - player.getEyeLocation().getY();
off2 = blockPlacedAgainst.y + 0.5D - player.getPlayer().getEyeLocation().getY();
} else if(blockPlaced.y < blockPlacedAgainst.y) {
off2 = -(blockPlacedAgainst.y + 0.5D - player.getEyeLocation().getY());
off2 = -(blockPlacedAgainst.y + 0.5D - player.getPlayer().getEyeLocation().getY());
} else if(blockPlaced.z > blockPlacedAgainst.z) {
off2 = blockPlacedAgainst.z + 0.5D - player.getEyeLocation().getZ();
off2 = blockPlacedAgainst.z + 0.5D - player.getPlayer().getEyeLocation().getZ();
} else if(blockPlaced.z < blockPlacedAgainst.z) {
off2 = -(blockPlacedAgainst.z + 0.5D - player.getEyeLocation().getZ());
off2 = -(blockPlacedAgainst.z + 0.5D - player.getPlayer().getEyeLocation().getZ());
}
if(off2 > 0.0D) {
@ -60,28 +57,44 @@ public class DirectionCheck {
if(off < 0.1D) {
// Player did nothing wrong
// reduce violation counter
blockplace.directionViolationLevel *= 0.9D;
data.directionViolationLevel *= 0.9D;
} else {
// Player failed the check
// Increment violation counter
blockplace.directionViolationLevel += off;
data.directionViolationLevel += off;
// Prepare some event-specific values for logging and custom actions
data.log.check = "blockplace.direction";
cancel = plugin.execute(player, ccblockplace.directionActions, (int) blockplace.directionViolationLevel, blockplace.history, cc);
cancel = executeActions(player, cc.directionActions.getActions(data.directionViolationLevel));
if(cancel) {
// Needed to calculate penalty times
blockplace.directionLastViolationTime = time;
data.directionLastViolationTime = time;
}
}
// If the player is still in penalty time, cancel the event anyway
if(blockplace.directionLastViolationTime + ccblockplace.directionPenaltyTime >= time) {
if(data.directionLastViolationTime + cc.directionPenaltyTime > time) {
return true;
}
return cancel;
}
@Override
public boolean isEnabled(CCBlockPlace cc) {
return cc.directionCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockplace.directionViolationLevel);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,11 +1,14 @@
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.BlockPlaceCheck;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
@ -14,39 +17,52 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
* far away
*
*/
public class ReachCheck {
private final NoCheat plugin;
public class ReachCheck extends BlockPlaceCheck {
public ReachCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "blockplace.reach", Permissions.BLOCKPLACE_REACH);
}
public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, BlockPlaceData data, CCBlockPlace cc) {
boolean cancel = false;
final SimpleLocation placedAgainstBlock = data.blockplace.blockPlacedAgainst;
final double distance = CheckUtil.reachCheck(player, placedAgainstBlock.x + 0.5D, placedAgainstBlock.y + 0.5D, placedAgainstBlock.z + 0.5D, cc.blockplace.reachDistance);
final SimpleLocation placedAgainstBlock = data.blockPlacedAgainst;
BlockPlaceData blockplace = data.blockplace;
final double distance = CheckUtil.reachCheck(player, placedAgainstBlock.x + 0.5D, placedAgainstBlock.y + 0.5D, placedAgainstBlock.z + 0.5D, cc.reachDistance);
if(distance > 0D) {
// Player failed the check
// Increment violation counter
blockplace.reachViolationLevel += distance;
data.reachViolationLevel += distance;
data.reachdistance = distance;
// Prepare some event-specific values for logging and custom actions
data.log.check = "blockplace.reach";
data.log.reachdistance = distance;
cancel = plugin.execute(player, cc.blockplace.reachActions, (int) blockplace.reachViolationLevel, blockplace.history, cc);
cancel = executeActions(player, cc.reachActions.getActions(data.reachViolationLevel));
} else {
blockplace.reachViolationLevel *= 0.9D;
data.reachViolationLevel *= 0.9D;
}
return cancel;
}
@Override
public boolean isEnabled(CCBlockPlace cc) {
return cc.reachCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockplace.reachViolationLevel);
case REACHDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,69 +0,0 @@
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.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
/**
*
*/
public class ChatCheck {
private final NoCheat plugin;
public ChatCheck(NoCheat plugin) {
this.plugin = plugin;
}
public boolean check(final Player player, final String message, final ConfigurationCache cc) {
boolean cancel = false;
final CCChat ccchat = cc.chat;
final boolean spamCheck = ccchat.spamCheck && !player.hasPermission(Permissions.CHAT_SPAM);
if(spamCheck) {
// Maybe it's a command and on the whitelist
for(String s : ccchat.spamWhitelist) {
if(message.startsWith(s)) {
// It is
return false;
}
}
final int time = plugin.getIngameSeconds();
final BaseData data = plugin.getData(player.getName());
final ChatData chat = data.chat;
if(chat.spamLasttime + ccchat.spamTimeframe <= time) {
chat.spamLasttime = time;
chat.messageCount = 0;
}
chat.messageCount++;
if(chat.messageCount > ccchat.spamLimit) {
// Prepare some event-specific values for logging and custom
// actions
data.log.check = "chat.spam";
data.log.text = message;
cancel = plugin.execute(player, ccchat.spamActions, chat.messageCount - ccchat.spamLimit, chat.history, cc);
}
}
return cancel;
}
}

View File

@ -0,0 +1,63 @@
package cc.co.evenprime.bukkit.nocheat.checks.chat;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.ChatCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
public class SpamCheck extends ChatCheck {
public SpamCheck(NoCheat plugin) {
super(plugin, "chat.spam", Permissions.CHAT_SPAM);
}
public boolean check(NoCheatPlayer player, ChatData data, CCChat cc) {
boolean cancel = false;
// Maybe it's a command and on the whitelist
for(String s : cc.spamWhitelist) {
if(data.message.startsWith(s)) {
// It is
return false;
}
}
final int time = plugin.getIngameSeconds();
if(data.spamLasttime + cc.spamTimeframe <= time) {
data.spamLasttime = time;
data.messageCount = 0;
}
data.messageCount++;
if(data.messageCount > cc.spamLimit) {
data.spamVL = data.messageCount - cc.spamLimit;
cancel = executeActions(player, cc.spamActions.getActions(data.spamVL));
}
return cancel;
}
@Override
public boolean isEnabled(CCChat cc) {
return cc.spamCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().chat.spamVL);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,30 +1,31 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Locale;
import net.minecraft.server.Entity;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.checks.FightCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
public class DirectionCheck {
private final NoCheat plugin;
public class DirectionCheck extends FightCheck {
public DirectionCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "fight.direction", Permissions.FIGHT_DIRECTION);
}
public boolean check(final Player player, final BaseData data, final Entity damagee, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, FightData data, CCFight cc) {
boolean cancel = false;
final long time = System.currentTimeMillis();
// Get the width of the damagee
net.minecraft.server.Entity entity = ((CraftEntity) damagee).getHandle();
Entity entity = data.damagee;
final float width = entity.length > entity.width ? entity.length : entity.width;
@ -32,37 +33,48 @@ public class DirectionCheck {
// 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
final double off = CheckUtil.directionCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, width, 2.0D, cc.fight.directionPrecision);
final double off = CheckUtil.directionCheck(player, entity.locX, entity.locY + 1.0D, entity.locZ, width, 2.0D, cc.directionPrecision);
if(off < 0.1D) {
// Player did probably nothing wrong
// reduce violation counter
data.fight.violationLevel *= 0.80D;
data.directionVL *= 0.80D;
} else {
// Player failed the check
// Increment violation counter
if(!plugin.skipCheck()) {
data.fight.violationLevel += Math.sqrt(off);
data.directionVL += Math.sqrt(off);
}
// Prepare some event-specific values for logging and custom
// actions
data.log.check = "fight.direction";
cancel = plugin.execute(player, cc.fight.directionActions, (int) data.fight.violationLevel, data.fight.history, cc);
cancel = executeActions(player, cc.directionActions.getActions(data.directionVL));
if(cancel) {
// Needed to calculate penalty times
data.fight.directionLastViolationTime = time;
data.directionLastViolationTime = time;
}
}
// If the player is still in penalty time, cancel the event anyway
if(data.fight.directionLastViolationTime + cc.fight.directionPenaltyTime >= time) {
if(data.directionLastViolationTime + cc.directionPenaltyTime > time) {
return true;
}
return cancel;
}
@Override
public boolean isEnabled(CCFight cc) {
return cc.directionCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().fight.directionVL);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,55 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import org.bukkit.entity.Entity;
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.BaseData;
/**
* Check various things related to fighting players/entities
*
*/
public class FightCheck {
private final NoCheat plugin;
private final DirectionCheck directionCheck;
private final SelfhitCheck selfhitCheck;
private final NoswingCheck noswingCheck;
public FightCheck(NoCheat plugin) {
this.plugin = plugin;
this.directionCheck = new DirectionCheck(plugin);
this.selfhitCheck = new SelfhitCheck(plugin);
this.noswingCheck = new NoswingCheck(plugin);
}
public boolean check(final Player player, final Entity damagee, final ConfigurationCache cc) {
boolean cancel = false;
final boolean selfhitcheck = cc.fight.selfhitCheck && !player.hasPermission(Permissions.FIGHT_SELFHIT);
final boolean directioncheck = cc.fight.directionCheck && !player.hasPermission(Permissions.FIGHT_DIRECTION);
final boolean noswingcheck = cc.fight.noswingCheck && !player.hasPermission(Permissions.FIGHT_NOSWING);
BaseData data = plugin.getData(player.getName());
if(noswingcheck) {
cancel = noswingCheck.check(player, data, cc);
}
if(!cancel && directioncheck) {
cancel = directionCheck.check(player, data, damagee, cc);
}
if(!cancel && selfhitcheck) {
cancel = selfhitCheck.check(player, data, damagee, cc);
}
return cancel;
}
}

View File

@ -1,36 +1,53 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.FightCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
public class NoswingCheck {
private final NoCheat plugin;
public class NoswingCheck extends FightCheck {
public NoswingCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "fight.noswing", Permissions.FIGHT_NOSWING);
}
public boolean check(final Player player, final BaseData data, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, FightData data, CCFight cc) {
boolean cancel = false;
BaseData d = player.getData();
// did he swing his arm before?
if(data.armswung) {
data.armswung = false;
data.fight.noswingVL *= 0.90D;
if(d.armswung) {
d.armswung = false;
data.noswingVL *= 0.90D;
} else {
data.fight.noswingVL += 1;
// Prepare some event-specific values for logging and custom
// actions
data.log.check = "fight.noswing";
data.noswingVL += 1;
cancel = plugin.execute(player, cc.fight.noswingActions, (int) data.fight.noswingVL, data.fight.history, cc);
cancel = executeActions(player, cc.noswingActions.getActions(data.noswingVL));
}
return cancel;
}
@Override
public boolean isEnabled(CCFight cc) {
return cc.noswingCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().fight.noswingVL);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,39 +1,50 @@
package cc.co.evenprime.bukkit.nocheat.checks.fight;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.FightCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
public class SelfhitCheck {
private final NoCheat plugin;
public class SelfhitCheck extends FightCheck {
public SelfhitCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "fight.selfhit", Permissions.FIGHT_SELFHIT);
}
public boolean check(final Player player, final BaseData data, final Entity damagee, final ConfigurationCache cc) {
public boolean check(NoCheatPlayer player, FightData data, CCFight cc) {
boolean cancel = false;
if(player.equals(damagee)) {
if(player.getPlayer().equals(data.damagee)) {
// Player failed the check obviously
data.fight.selfhitviolationLevel += 1;
// Prepare some event-specific values for logging and custom
// actions
data.log.check = "fight.selfhit";
cancel = plugin.execute(player, cc.fight.selfhitActions, (int) data.fight.selfhitviolationLevel, data.fight.history, cc);
data.selfhitVL += 1;
cancel = executeActions(player, cc.selfhitActions.getActions(data.selfhitVL));
} else {
data.fight.selfhitviolationLevel *= 0.99D;
data.selfhitVL *= 0.99D;
}
return cancel;
}
@Override
public boolean isEnabled(CCFight cc) {
return cc.selfhitCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().fight.selfhitVL);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,17 +1,18 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.GameMode;
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.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
@ -21,24 +22,19 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
* therefore have tighter rules to obey.
*
*/
public class FlyingCheck {
public class FlyingCheck extends MovingCheck {
private final NoCheat plugin;
public FlyingCheck(NoCheat plugin) {
super(plugin, "moving.flying", null);
}
private static final double creativeSpeed = 0.60D;
public FlyingCheck(NoCheat plugin) {
this.plugin = plugin;
}
public PreciseLocation check(NoCheatPlayer player, MovingData moving, CCMoving ccmoving) {
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
final MovingData moving = data.moving;
final PreciseLocation to = moving.to;
final PreciseLocation from = moving.from;
final PreciseLocation setBack = moving.runflySetBackPoint;
final CCMoving ccmoving = cc.moving;
final PreciseLocation from = moving.from;
final PreciseLocation to = moving.to;
if(!setBack.isSet()) {
setBack.set(from);
@ -56,7 +52,7 @@ public class FlyingCheck {
// In case of creative gamemode, give at least 0.60 speed limit
// horizontal
double speedLimitHorizontal = player.getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
double speedLimitHorizontal = player.getPlayer().getGameMode() == GameMode.CREATIVE ? Math.max(creativeSpeed, ccmoving.flyingSpeedLimitHorizontal) : ccmoving.flyingSpeedLimitHorizontal;
EntityPlayer p = ((CraftPlayer) player).getHandle();
@ -67,7 +63,7 @@ public class FlyingCheck {
result += Math.max(0.0D, horizontalDistance - moving.horizFreedom - speedLimitHorizontal);
boolean sprinting = CheckUtil.isSprinting(player);
boolean sprinting = player.getPlayer().isSprinting();
moving.bunnyhopdelay--;
@ -90,10 +86,7 @@ public class FlyingCheck {
// Increment violation counter
moving.runflyViolationLevel += result;
data.log.toLocation.set(to);
data.log.check = "flying/toofast";
boolean cancel = plugin.execute(player, ccmoving.flyingActions, (int) moving.runflyViolationLevel, moving.history, cc);
boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(moving.runflyViolationLevel));
// Was one of the actions a cancel? Then really do it
if(cancel) {
@ -111,4 +104,21 @@ public class FlyingCheck {
return newToLocation;
}
@Override
public boolean isEnabled(CCMoving moving) {
// TODO Auto-generated method stub
return moving.allowFlying && moving.runflyCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyViolationLevel);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,10 +1,13 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
@ -18,60 +21,16 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
* compares it to the "legal" number of packets for that timeframe (22).
*
*/
public class MorePacketsCheck {
public class MorePacketsCheck extends MovingCheck {
private final static int packetsPerTimeframe = 22;
private final static int bufferLimit = 30;
private final NoCheat plugin;
public MorePacketsCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "moving.morepackets", Permissions.MOVE_MOREPACKETS);
}
/**
* Ok, lets write down the internal logic, to not forget what I wanted to
* do when I started it:
*
* A second on the server has 20 ticks
* A second on the client has 20 ticks
* A unmodified client with no lag will send 1 packet per tick = 20 packets
* Ideally checking for 20 packets/second on the server would work
*
* But a client may send 10 packets in second 1, and 30 packets in second 2
* due to lag. This should still be allowed, therefore we give a "buffer".
* If a player doesn't use all of his 20 move packets in one second, he may
* carry over unused packets to the next (the buffer is limited in size for
* obvious reasons).
*
* But the server may not be able to process all packets in time, e.g.
* because it is busy saving the world.
*
* Well that sounded strange...
* Admin: "Hey server, what is taking you so long?"
* Server: "I'm saving the world!"
* Admin: "o_O"
*
* Contrary to client lag, serverside lag could be measured. So let's do
* that. A task will be executed every 20 server ticks, storing the time it
* took the server to process those ticks. If it's much more than 1 second,
* the server was busy, and packets may have piled up during that time. So a
* good idea would be to ignore the following second completely, as it will
* be used to process the stacked-up packets, getting the server back in
* sync with the timeline.
*
* Server identified as being busy -> ignore the second that follows. If
* that second the server is still busy -> ignore the second after that too.
*
* What's with the second during which the server is busy? Can there be more
* packets during that time? Sure. But should we care? No, this initial lag
* can be mitigated by using the time it took to do the 20 ticks and factor
* it with the limit for packets. Problem solved. The only real problem are
* packets that stack up in one second to get processed in the next, which
* is what the "ignoring" is for.
*
* So the general course of action would be:
*
* 1. Collect packets processed within 20 server ticks = packetCounter
* 2. Measure time taken for those 20 server ticks = elapsedTime
* 3. elapsedTime >> 1 second -> ignore next check
@ -82,65 +41,79 @@ public class MorePacketsCheck {
* 8. reset packetCounter, wait for next 20 ticks to pass by.
*
*/
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
PreciseLocation newToLocation = null;
final MovingData moving = data.moving;
moving.morePacketsCounter++;
if(!moving.morePacketsSetbackPoint.isSet()) {
moving.morePacketsSetbackPoint.set(moving.from);
data.morePacketsCounter++;
if(!data.morePacketsSetbackPoint.isSet()) {
data.morePacketsSetbackPoint.set(data.from);
}
int ingameSeconds = plugin.getIngameSeconds();
// Is at least a second gone by and has the server at least processed 20
// ticks since last time
if(ingameSeconds != moving.lastElapsedIngameSeconds) {
if(ingameSeconds != data.lastElapsedIngameSeconds) {
int limit = (int) ((packetsPerTimeframe * plugin.getIngameSecondDuration()) / 1000L);
int difference = limit - moving.morePacketsCounter;
int difference = limit - data.morePacketsCounter;
moving.morePacketsBuffer += difference;
if(moving.morePacketsBuffer > bufferLimit)
moving.morePacketsBuffer = bufferLimit;
data.morePacketsBuffer += difference;
if(data.morePacketsBuffer > bufferLimit)
data.morePacketsBuffer = bufferLimit;
// Are we over the 22 event limit for that time frame now? (limit
// increases with time)
int packetsAboveLimit = (int) -moving.morePacketsBuffer;
int packetsAboveLimit = (int) -data.morePacketsBuffer;
if(moving.morePacketsBuffer < 0)
moving.morePacketsBuffer = 0;
if(data.morePacketsBuffer < 0)
data.morePacketsBuffer = 0;
// Should we react? Only if the check doesn't get skipped and we
// went over the limit
if(!plugin.skipCheck() && packetsAboveLimit > 0) {
moving.morePacketsViolationLevel += packetsAboveLimit;
data.morePacketsViolationLevel += packetsAboveLimit;
data.packets = packetsAboveLimit;
// Packets above limit
data.log.packets = moving.morePacketsCounter - limit;
data.log.check = "moving/morepackets";
final boolean cancel = plugin.execute(player, cc.moving.morePacketsActions, (int) moving.morePacketsViolationLevel, moving.history, cc);
final boolean cancel = executeActions(player, cc.morePacketsActions.getActions(data.morePacketsViolationLevel));
if(cancel)
newToLocation = moving.morePacketsSetbackPoint;
newToLocation = data.morePacketsSetbackPoint;
}
// No new setbackLocation was chosen
if(newToLocation == null) {
moving.morePacketsSetbackPoint.set(player.getLocation());
data.morePacketsSetbackPoint.set(data.from);
}
if(moving.morePacketsViolationLevel > 0)
if(data.morePacketsViolationLevel > 0)
// Shrink the "over limit" value by 20 % every second
moving.morePacketsViolationLevel *= 0.8;
data.morePacketsViolationLevel *= 0.8;
moving.morePacketsCounter = 0; // Count from zero again
moving.lastElapsedIngameSeconds = ingameSeconds;
data.morePacketsCounter = 0; // Count from zero again
data.lastElapsedIngameSeconds = ingameSeconds;
}
return newToLocation;
}
@Override
public boolean isEnabled(CCMoving moving) {
return moving.morePacketsCheck;
}
@Override
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.morePacketsViolationLevel);
case PACKETS:
return String.valueOf(player.getData().moving.packets);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,70 +1,66 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.entity.Player;
import java.util.Locale;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
/**
* A check to see if people cheat by tricking the server to not deal them
* fall damage.
*
*/
public class NoFallCheck {
private final NoCheat plugin;
public class NoFallCheck extends MovingCheck {
public NoFallCheck(NoCheat plugin) {
this.plugin = plugin;
super(plugin, "moving.nofall", Permissions.MOVE_NOFALL);
}
/**
* Calculate if and how much the player "failed" this check.
*
*/
public void check(final Player player, final BaseData data, final boolean fromOnOrInGround, final boolean toOnOrInGround, final ConfigurationCache cc) {
final MovingData moving = data.moving;
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
// This check is pretty much always a step behind for technical reasons.
if(fromOnOrInGround) {
if(data.fromOnOrInGround) {
// Start with zero fall distance
moving.fallDistance = 0F;
data.fallDistance = 0F;
}
// If we increased fall height before for no good reason, reduce now by
// the same amount
if(player.getFallDistance() > moving.lastAddedFallDistance) {
player.setFallDistance(player.getFallDistance() - moving.lastAddedFallDistance);
if(player.getPlayer().getFallDistance() > data.lastAddedFallDistance) {
player.getPlayer().setFallDistance(player.getPlayer().getFallDistance() - data.lastAddedFallDistance);
}
moving.lastAddedFallDistance = 0;
data.lastAddedFallDistance = 0;
// We want to know if the fallDistance recorded by the game is smaller
// than the fall distance recorded by the plugin
final float difference = moving.fallDistance - player.getFallDistance();
final float difference = data.fallDistance - player.getPlayer().getFallDistance();
if(difference > 1.0F && toOnOrInGround && moving.fallDistance > 2.0F) {
moving.nofallViolationLevel += difference;
if(difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallViolationLevel += difference;
// Prepare some event-specific values for logging and custom actions
data.log.falldistance = moving.fallDistance;
data.log.check = "moving/nofall";
final boolean cancel = plugin.execute(player, cc.moving.nofallActions, (int) moving.nofallViolationLevel, moving.history, cc);
final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallViolationLevel));
// If "cancelled", the fall damage gets dealt in a way that's
// visible to other plugins
if(cancel) {
// Increase the fall distance a bit :)
final float totalDistance = moving.fallDistance + difference * (cc.moving.nofallMultiplier - 1.0F);
final float totalDistance = data.fallDistance + difference * (cc.nofallMultiplier - 1.0F);
player.setFallDistance(totalDistance);
player.getPlayer().setFallDistance(totalDistance);
}
data.moving.fallDistance = 0F;
data.fallDistance = 0F;
}
// Increase the fall distance that is recorded by the plugin, AND set
@ -77,24 +73,45 @@ public class NoFallCheck {
// anyway, as to avoid to much deviation
// from the original Minecraft feeling.
final double oldY = moving.from.y;
final double newY = moving.to.y;
final double oldY = data.from.y;
final double newY = data.to.y;
if(oldY > newY) {
final float dist = (float) (oldY - newY);
moving.fallDistance += dist;
data.fallDistance += dist;
if(dist > 1.0F) {
moving.lastAddedFallDistance = dist;
player.setFallDistance(player.getFallDistance() + dist);
data.lastAddedFallDistance = dist;
player.getPlayer().setFallDistance(player.getPlayer().getFallDistance() + dist);
} else {
moving.lastAddedFallDistance = 0.0F;
data.lastAddedFallDistance = 0.0F;
}
} else {
moving.lastAddedFallDistance = 0.0F;
data.lastAddedFallDistance = 0.0F;
}
// Reduce falldamage violation level
moving.nofallViolationLevel *= 0.99D;
data.nofallViolationLevel *= 0.99D;
return null;
}
@Override
public boolean isEnabled(CCMoving moving) {
// TODO Auto-generated method stub
return moving.nofallCheck;
}
@Override
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.nofallViolationLevel);
case FALLDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,130 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
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.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
/**
* The main Check class for Move event checking. It will decide which checks
* need to be executed and in which order. It will also precalculate some values
* that are needed by multiple checks.
*
*/
public class RunFlyCheck {
private final FlyingCheck flyingCheck;
private final RunningCheck runningCheck;
private final NoFallCheck noFallCheck;
private final MorePacketsCheck morePacketsCheck;
private final NoCheat plugin;
public RunFlyCheck(NoCheat plugin) {
this.plugin = plugin;
this.flyingCheck = new FlyingCheck(plugin);
this.noFallCheck = new NoFallCheck(plugin);
this.runningCheck = new RunningCheck(plugin, noFallCheck);
this.morePacketsCheck = new MorePacketsCheck(plugin);
}
/**
* Return the a new destination location or null
*
* @param event
* @return
*/
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
// Players in vehicles are of no interest
if(player.isInsideVehicle())
return null;
/**
* If not null, this will be used as the new target location
*/
PreciseLocation newTo = null;
final MovingData moving = data.moving;
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
if(moving.horizVelocityCounter > 0) {
moving.horizVelocityCounter--;
} else {
moving.horizFreedom *= 0.90;
}
if(moving.vertVelocityCounter > 0) {
moving.vertVelocityCounter--;
moving.vertFreedom += moving.vertVelocity;
moving.vertVelocity *= 0.90;
} else {
moving.vertFreedom = 0;
}
final CCMoving ccmoving = cc.moving;
/************* DECIDE WHICH CHECKS NEED TO BE RUN *************/
final boolean runflyCheck = ccmoving.runflyCheck && !player.hasPermission(Permissions.MOVE_RUNFLY);
final boolean flyAllowed = ccmoving.allowFlying || player.hasPermission(Permissions.MOVE_FLY) || (player.getGameMode() == GameMode.CREATIVE && ccmoving.identifyCreativeMode);
final boolean morepacketsCheck = ccmoving.morePacketsCheck && !player.hasPermission(Permissions.MOVE_MOREPACKETS);
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
// If the player is not allowed to fly and not allowed to run
if(runflyCheck) {
if(flyAllowed) {
newTo = flyingCheck.check(player, data, cc);
} else {
newTo = runningCheck.check(player, data, cc);
}
}
/********* EXECUTE THE MOREPACKETS CHECK ********************/
if(newTo == null && morepacketsCheck) {
newTo = morePacketsCheck.check(player, data, cc);
}
return newTo;
}
/**
* This is a workaround for people placing blocks below them causing false
* positives
* with the move check(s).
*/
public void blockPlaced(Player player, Block blockPlaced) {
BaseData data = plugin.getData(player.getName());
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
return;
}
SimpleLocation lblock = new SimpleLocation();
lblock.set(blockPlaced);
SimpleLocation lplayer = new SimpleLocation();
lplayer.setLocation(player.getLocation());
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
int type = CheckUtil.getType(blockPlaced.getTypeId());
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
if(lblock.y + 1 >= data.moving.runflySetBackPoint.y) {
data.moving.runflySetBackPoint.y = (lblock.y + 1);
data.moving.jumpPhase = 0;
}
}
}
}
}

View File

@ -0,0 +1,48 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import org.bukkit.GameMode;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
public class RunflyCheck extends MovingCheck {
private final FlyingCheck flyingCheck;
private final RunningCheck runningCheck;
public RunflyCheck(NoCheat plugin) {
super(plugin, "moving.runfly", Permissions.MOVE_RUNFLY);
flyingCheck = new FlyingCheck(plugin);
runningCheck = new RunningCheck(plugin);
}
@Override
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
final boolean runflyCheck = cc.runflyCheck && !player.hasPermission(Permissions.MOVE_RUNFLY);
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVE_FLY) || (player.getPlayer().getGameMode() == GameMode.CREATIVE && cc.identifyCreativeMode);
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
// If the player is not allowed to fly and not allowed to run
if(runflyCheck) {
if(flyAllowed) {
return flyingCheck.check(player, data, cc);
} else {
return runningCheck.check(player, data, cc);
}
}
return null;
}
@Override
public boolean isEnabled(CCMoving moving) {
return runningCheck.isEnabled(moving) || flyingCheck.isEnabled(moving);
}
}

View File

@ -1,17 +1,19 @@
package cc.co.evenprime.bukkit.nocheat.checks.moving;
import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.MobEffectList;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
@ -22,7 +24,7 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
* normal ground, while sprinting, sneaking or swimming.
*
*/
public class RunningCheck {
public class RunningCheck extends MovingCheck {
private final static double maxBonus = 1D;
@ -30,26 +32,24 @@ public class RunningCheck {
// lose altitude (or eventually land somewhere)
private final static int jumpingLimit = 6;
private final NoCheat plugin;
private final NoFallCheck noFallCheck;
public RunningCheck(NoCheat plugin, NoFallCheck noFallCheck) {
this.plugin = plugin;
this.noFallCheck = noFallCheck;
public RunningCheck(NoCheat plugin) {
super(plugin, "moving.running", Permissions.MOVE_RUNFLY);
this.noFallCheck = new NoFallCheck(plugin);
}
public PreciseLocation check(final Player player, final BaseData data, final ConfigurationCache cc) {
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
// Some shortcuts:
final MovingData moving = data.moving;
final PreciseLocation to = moving.to;
final PreciseLocation from = moving.from;
final PreciseLocation setBack = moving.runflySetBackPoint;
final CCMoving ccmoving = cc.moving;
final PreciseLocation setBack = data.runflySetBackPoint;
final PreciseLocation to = data.to;
final PreciseLocation from = data.from;
// Calculate some distances
final double xDistance = to.x - from.x;
final double xDistance = data.to.x - from.x;
final double zDistance = to.z - from.z;
final double horizontalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
@ -58,8 +58,8 @@ public class RunningCheck {
}
// To know if a player "is on ground" is useful
final int fromType = CheckUtil.isLocationOnGround(player.getWorld(), from);
final int toType = CheckUtil.isLocationOnGround(player.getWorld(), to);
final int fromType = CheckUtil.isLocationOnGround(player.getPlayer().getWorld(), from);
final int toType = CheckUtil.isLocationOnGround(player.getPlayer().getWorld(), to);
final boolean fromOnGround = CheckUtil.isOnGround(fromType);
final boolean fromInGround = CheckUtil.isInGround(fromType);
@ -68,32 +68,22 @@ public class RunningCheck {
PreciseLocation newToLocation = null;
final double resultHoriz = Math.max(0.0D, checkHorizontal(player, data, CheckUtil.isLiquid(fromType) && CheckUtil.isLiquid(toType), horizontalDistance, ccmoving));
final double resultVert = Math.max(0.0D, checkVertical(moving, fromOnGround, toOnGround, ccmoving));
final double resultHoriz = Math.max(0.0D, checkHorizontal(player, data, CheckUtil.isLiquid(fromType) && CheckUtil.isLiquid(toType), horizontalDistance, cc));
final double resultVert = Math.max(0.0D, checkVertical(data, fromOnGround, toOnGround, cc));
final double result = (resultHoriz + resultVert) * 100;
moving.jumpPhase++;
data.jumpPhase++;
// Slowly reduce the level with each event
moving.runflyViolationLevel *= 0.97;
data.runflyViolationLevel *= 0.97;
if(result > 0) {
// Increment violation counter
moving.runflyViolationLevel += result;
data.runflyViolationLevel += result;
// Prepare some event-specific values for logging and custom actions
data.log.toLocation.set(to);
if(resultHoriz > 0 && resultVert > 0)
data.log.check = "runfly/both";
else if(resultHoriz > 0) {
// We already set the correct value for this
// data.log.check = "runfly/something"
} else if(resultVert > 0)
data.log.check = "runfly/vertical";
boolean cancel = plugin.execute(player, cc.moving.actions, (int) moving.runflyViolationLevel, moving.history, cc);
boolean cancel = executeActions(player, cc.actions.getActions(data.runflyViolationLevel));
// Was one of the actions a cancel? Then do it
if(cancel) {
@ -102,28 +92,30 @@ public class RunningCheck {
// In case it only gets logged, not stopped by NoCheat
// Update the setback location at least a bit
setBack.set(to);
moving.jumpPhase = 0;
data.jumpPhase = 0;
}
} else {
if((toInGround && from.y >= to.y) || CheckUtil.isLiquid(toType)) {
setBack.set(to);
setBack.y = Math.ceil(setBack.y);
moving.jumpPhase = 0;
data.jumpPhase = 0;
} else if(toOnGround && (from.y >= to.y || setBack.y <= Math.floor(to.y))) {
setBack.set(to);
setBack.y = Math.floor(setBack.y);
moving.jumpPhase = 0;
data.jumpPhase = 0;
} else if(fromOnGround || fromInGround || toOnGround || toInGround) {
moving.jumpPhase = 0;
data.jumpPhase = 0;
}
}
/********* EXECUTE THE NOFALL CHECK ********************/
final boolean checkNoFall = cc.moving.nofallCheck && !player.hasPermission(Permissions.MOVE_NOFALL);
final boolean checkNoFall = cc.nofallCheck && !player.hasPermission(Permissions.MOVE_NOFALL);
if(checkNoFall && newToLocation == null) {
noFallCheck.check(player, data, fromOnGround || fromInGround, toOnGround || toInGround, cc);
data.fromOnOrInGround = fromOnGround || fromInGround;
data.toOnOrInGround = toOnGround || toInGround;
noFallCheck.check(player, data, cc);
}
return newToLocation;
@ -133,31 +125,25 @@ public class RunningCheck {
* Calculate how much the player failed this check
*
*/
private double checkHorizontal(final Player player, final BaseData data, final boolean isSwimming, final double totalDistance, final CCMoving ccmoving) {
private double checkHorizontal(final NoCheatPlayer player, final MovingData moving, final boolean isSwimming, final double totalDistance, final CCMoving ccmoving) {
// How much further did the player move than expected??
double distanceAboveLimit = 0.0D;
final boolean sprinting = CheckUtil.isSprinting(player);
final boolean sprinting = player.getPlayer().isSprinting();
double limit = 0.0D;
final EntityPlayer p = ((CraftPlayer) player).getHandle();
final MovingData moving = data.moving;
if(ccmoving.sneakingCheck && player.isSneaking() && !player.hasPermission(Permissions.MOVE_SNEAK)) {
if(ccmoving.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVE_SNEAK)) {
limit = ccmoving.sneakingSpeedLimit;
data.log.check = "runfly/sneak";
} else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVE_SWIM)) {
limit = ccmoving.swimmingSpeedLimit;
data.log.check = "runfly/swim";
} else if(!sprinting) {
limit = ccmoving.walkingSpeedLimit;
data.log.check = "runfly/walk";
} else {
limit = ccmoving.sprintingSpeedLimit;
data.log.check = "runfly/sprint";
}
if(p.hasEffect(MobEffectList.FASTER_MOVEMENT)) {
@ -224,4 +210,20 @@ public class RunningCheck {
return distanceAboveLimit;
}
@Override
public boolean isEnabled(CCMoving moving) {
return moving.runflyCheck && !moving.allowFlying;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyViolationLevel);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -0,0 +1,108 @@
package cc.co.evenprime.bukkit.nocheat.checks.timed;
import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
import cc.co.evenprime.bukkit.nocheat.checks.TimedCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCTimed;
import cc.co.evenprime.bukkit.nocheat.data.TimedData;
public class GodmodeCheck extends TimedCheck {
public GodmodeCheck(NoCheat plugin) {
super(plugin, "timed.godmode", Permissions.TIMED_GODMODE);
}
@Override
public boolean check(NoCheatPlayer player, TimedData data, CCTimed cc) {
// server lag(ged), skip this, or player dead, therefore it's reasonable
// for him to not move :)
if(plugin.skipCheck() || player.getPlayer().isDead())
return false;
EntityPlayer p = ((CraftPlayer) player).getHandle();
// Haven't been checking before
if(data.ticksLived == 0) {
// setup data for next time
data.ticksLived = p.ticksLived;
// And give up already
return false;
}
boolean cancel = false;
// Compare ingame record of players ticks to our last observed value
int difference = p.ticksLived - data.ticksLived;
// difference should be >= tickTime for perfect synchronization
if(difference > cc.tickTime) {
// player was faster than expected, give him credit for the
// difference
data.ticksBehind -= (difference - cc.tickTime);
// Reduce violation level over time
data.godmodeVL *= 0.9D;
} else if(difference >= cc.tickTime / 2) {
// close enough, let it pass
data.ticksBehind -= cc.tickTime / 2;
// Reduce violation level over time
data.godmodeVL *= 0.9D;
} else {
// That's a bit suspicious, why is the player more than half the
// ticktime behind? Keep that in mind
data.ticksBehind += cc.tickTime - difference;
// Is he way too far behind, then correct that
if(data.ticksBehind > cc.godmodeTicksLimit) {
data.godmodeVL += cc.tickTime - difference;
cancel = executeActions(player, cc.godmodeActions.getActions(data.godmodeVL));
// Reduce the time the player is behind accordingly
data.ticksBehind -= cc.tickTime;
}
}
if(data.ticksBehind < 0) {
data.ticksBehind = 0;
}
if(cancel) {
// Catch up for at least some of the ticks
for(int i = 0; i < cc.tickTime; i++) {
p.b(true); // Catch up with the server, one tick at a time
}
}
// setup data for next time
data.ticksLived = p.ticksLived;
return cancel;
}
@Override
public boolean isEnabled(CCTimed cc) {
return cc.godmodeCheck;
}
public String getParameter(WildCard wildcard, NoCheatPlayer player) {
switch (wildcard) {
case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().timed.godmodeVL);
default:
return super.getParameter(wildcard, player);
}
}
}

View File

@ -1,97 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.checks.timed;
import net.minecraft.server.EntityPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
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.BaseData;
public class TimedCheck {
private final NoCheat plugin;
public TimedCheck(NoCheat plugin) {
this.plugin = plugin;
}
public void check(Player player, int tickTime, ConfigurationCache cc) {
// server lag(ged), skip this, or player dead, therefore it's reasonable for him to not move :)
if(plugin.skipCheck() || player.isDead())
return;
if(cc.timed.godmodeCheck && !player.hasPermission(Permissions.TIMED_GODMODE)) {
BaseData data = plugin.getData(player.getName());
EntityPlayer p = ((CraftPlayer) player).getHandle();
// Haven't been checking before
if(data.timed.ticksLived == 0) {
// setup data for next time
data.timed.ticksLived = p.ticksLived;
// And give up already
return;
}
boolean cancel = false;
// Compare ingame record of players ticks to our last observed value
int difference = p.ticksLived - data.timed.ticksLived;
// difference should be >= tickTime for perfect synchronization
if(difference > tickTime) {
// player was faster than expected, give him credit for the
// difference
data.timed.ticksBehind -= (difference - tickTime);
// Reduce violation level over time
data.timed.godmodeVL *= 0.9D;
} else if(difference >= tickTime / 2) {
// close enough, let it pass
data.timed.ticksBehind -= tickTime/2;
// Reduce violation level over time
data.timed.godmodeVL *= 0.9D;
} else {
// That's a bit suspicious, why is the player more than half the
// ticktime behind? Keep that in mind
data.timed.ticksBehind += tickTime - difference;
// Is he way too far behind, then correct that
if(data.timed.ticksBehind > cc.timed.godmodeTicksLimit) {
data.timed.godmodeVL += tickTime - difference;
// Enough is enough
data.log.check = "timed.godmode";
cancel = plugin.execute(player, cc.timed.godmodeActions, (int) data.timed.godmodeVL, data.timed.history, cc);
// Reduce the time the player is behind accordingly
data.timed.ticksBehind -= tickTime;
}
}
if(data.timed.ticksBehind < 0) {
data.timed.ticksBehind = 0;
}
if(cancel) {
// Catch up for at least some of the ticks
for(int i = 0; i < tickTime; i++) {
p.b(true); // Catch up with the server, one tick at a time
}
}
// setup data for next time
data.timed.ticksLived = p.ticksLived;
}
}
}

View File

@ -84,10 +84,6 @@ public abstract class Configuration {
public final static OptionNode BLOCKPLACE_REACH_LIMIT = new OptionNode("limit", BLOCKPLACE_REACH, DataType.INTEGER);
public final static OptionNode BLOCKPLACE_REACH_ACTIONS = new OptionNode("actions", BLOCKPLACE_REACH, DataType.ACTIONLIST);
private final static OptionNode BLOCKPLACE_ONLIQUID = new OptionNode("onliquid", BLOCKPLACE, DataType.PARENT);
public final static OptionNode BLOCKPLACE_ONLIQUID_CHECK = new OptionNode("check", BLOCKPLACE_ONLIQUID, DataType.BOOLEAN);
public final static OptionNode BLOCKPLACE_ONLIQUID_ACTIONS = new OptionNode("actions", BLOCKPLACE_ONLIQUID, DataType.ACTIONLIST);
private final static OptionNode BLOCKPLACE_DIRECTION = new OptionNode("direction", BLOCKPLACE, DataType.PARENT);
public static final OptionNode BLOCKPLACE_DIRECTION_CHECK = new OptionNode("check", BLOCKPLACE_DIRECTION, DataType.BOOLEAN); ;
public static final OptionNode BLOCKPLACE_DIRECTION_PENALTYTIME = new OptionNode("penaltytime", BLOCKPLACE_DIRECTION, DataType.INTEGER);

View File

@ -123,13 +123,6 @@ public class DefaultConfiguration extends Configuration {
reachActionList.setActions(5, action.getActions("reachLog blockplaceCancel".split(" ")));
setValue(BLOCKPLACE_REACH_ACTIONS, reachActionList);
setValue(BLOCKPLACE_ONLIQUID_CHECK, true);
ActionList onliquidActionList = new ActionList();
onliquidActionList.setActions(0, action.getActions("blockplaceCancel".split(" ")));
onliquidActionList.setActions(3, action.getActions("onliquidLog blockplaceCancel".split(" ")));
setValue(BLOCKPLACE_ONLIQUID_ACTIONS, onliquidActionList);
setValue(BLOCKPLACE_DIRECTION_CHECK, true);
setValue(BLOCKPLACE_DIRECTION_PRECISION, 75);
setValue(BLOCKPLACE_DIRECTION_PENALTYTIME, 100);

View File

@ -72,9 +72,6 @@ public class Explainations {
set(Configuration.BLOCKPLACE_REACH_LIMIT, "Set the distance limit for placing blocks.\nUnit is 1/100 of a block, default is 485");
set(Configuration.BLOCKPLACE_REACH_ACTIONS, "What should be done if a player is placing blocks that are too far away.\nUnit is number of place(attempt)s beyond the limit.");
set(Configuration.BLOCKPLACE_ONLIQUID_CHECK, "If true, check if a player is trying to place non-liquid blocks against liquid blocks\nIn a normal Minecraft game, it is impossible to place a block without it touching something that is considered solid (neither air nor a liquid).\nBut if people use a modified client, to can do that. This check tries to identify that trick.");
set(Configuration.BLOCKPLACE_ONLIQUID_ACTIONS, "What should be done if a player is is trying to place non-liquid blocks against liquid blocks.\nUnit is number of place(attempt)s.");
set(Configuration.BLOCKPLACE_DIRECTION_CHECK, "If true, check if a player is looking at the block that he's placing.");
set(Configuration.BLOCKPLACE_DIRECTION_PRECISION, "Define how precise a player has to be when placing blocks. Lower values mean more precision, higher values less precision. Default 75.");
set(Configuration.BLOCKPLACE_DIRECTION_PENALTYTIME, "Define how long after a failed attempt to place blocks a player will be disallowed to place another block. \nUnit is milliseconds, default is 100.");

View File

@ -10,13 +10,13 @@ public class Permissions {
private final static String ADMIN = NOCHEAT + ".admin";
private final static String CHECKS = NOCHEAT + ".checks";
public final static String MOVE = CHECKS + ".moving";
public final static String MOVE_RUNFLY = MOVE + ".runfly";
public final static String MOVE_SNEAK = MOVE + ".sneaking";
public final static String MOVE_SWIM = MOVE + ".swimming";
public final static String MOVE_FLY = MOVE + ".flying";
public final static String MOVE_NOFALL = MOVE + ".nofall";
public final static String MOVE_MOREPACKETS = MOVE + ".morepackets";
public final static String MOVING = CHECKS + ".moving";
public final static String MOVE_RUNFLY = MOVING + ".runfly";
public final static String MOVE_SNEAK = MOVING + ".sneaking";
public final static String MOVE_SWIM = MOVING + ".swimming";
public final static String MOVE_FLY = MOVING + ".flying";
public final static String MOVE_NOFALL = MOVING + ".nofall";
public final static String MOVE_MOREPACKETS = MOVING + ".morepackets";
public final static String BLOCKBREAK = CHECKS + ".blockbreak";
public final static String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";

View File

@ -9,6 +9,7 @@ public class CCTimed {
public final boolean godmodeCheck;
public final double godmodeTicksLimit;
public final ActionList godmodeActions;
public final int tickTime = 10;
public CCTimed(Configuration data) {

View File

@ -47,12 +47,12 @@ public class ActionList {
* @param violationLevel
* @return
*/
public Action[] getActions(int vl) {
public Action[] getActions(double violationLevel) {
Integer result = null;
for(Integer treshold : tresholds) {
if(treshold <= vl) {
if(treshold <= violationLevel) {
result = treshold;
}
}

View File

@ -5,7 +5,6 @@ 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;
public final TimedData timed;
@ -20,13 +19,14 @@ public class BaseData extends Data {
this.blockbreak = new BlockBreakData();
this.blockplace = new BlockPlaceData();
this.chat = new ChatData();
this.log = new LogData();
this.moving = new MovingData();
this.fight = new FightData();
this.timed = new TimedData();
data = new Data[] {this.blockbreak, this.blockplace, this.chat,
this.log, this.moving, this.fight, this.timed};
this.moving, this.fight, this.timed};
this.lastUsedTime = System.currentTimeMillis();
}
public void clearCriticalData() {

View File

@ -6,13 +6,16 @@ package cc.co.evenprime.bukkit.nocheat.data;
*/
public class BlockBreakData extends Data {
public double reachViolationLevel = 0.0D;
public double reachVL = 0.0D;
public double directionViolationLevel = 0.0D;
public long directionLastViolationTime = 0;
public final SimpleLocation instaBrokeBlockLocation = new SimpleLocation();
// Verified
public final SimpleLocation brokenBlockLocation = new SimpleLocation();
public final ExecutionHistory history = new ExecutionHistory();
public double noswingVL = 0.0D;
public double reachDistance;
}

View File

@ -16,6 +16,7 @@ public class BlockPlaceData extends Data {
public final SimpleLocation blockPlacedAgainst = new SimpleLocation();
public final SimpleLocation blockPlaced = new SimpleLocation();
public Material placedType;
public double reachdistance;
public void clearCriticalData() {
blockPlacedAgainst.reset();

View File

@ -8,5 +8,7 @@ public class ChatData extends Data {
public int messageCount = 0;
public int spamLasttime = 0;
public final ExecutionHistory history = new ExecutionHistory();
public String message = "";
public int spamVL;
}

View File

@ -1,90 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* Provide secure access to player-specific data objects for various checks or
* check groups.
*/
public class DataManager {
// Store data between Events
private final Map<String, BaseData> map;
private final List<String> removals;
public DataManager() {
this.map = new HashMap<String, BaseData>();
this.removals = new ArrayList<String>(5);
}
/**
* Get a data object of the specified class. If none is stored yet, create
* one.
*/
public BaseData getData(String playerName) {
BaseData data = this.map.get(playerName);
// intentionally not thread-safe, because bukkit events are handled
// in sequence anyway, so zero chance of two events of the same
// player being handled at the same time
// And if it still happens by accident, it's no real loss anyway, as
// losing data of one instance doesn't really hurt at all
if(data == null) {
data = new BaseData();
data.log.playerName = playerName;
this.map.put(playerName, data);
}
data.lastUsedTime = System.currentTimeMillis();
return data;
}
/**
* Reset data that may cause problems after e.g. changing the config
*
*/
public void clearCriticalData() {
for(BaseData b : this.map.values()) {
b.clearCriticalData();
}
}
/**
* check if some data hasn't been used for a while and remove it
*
*/
public void cleanDataMap() {
synchronized(removals) {
long time = System.currentTimeMillis();
try {
for(Entry<String, BaseData> p : this.map.entrySet()) {
if(p.getValue().shouldBeRemoved(time)) {
removals.add(p.getKey());
}
}
for(String p : removals) {
this.map.remove(p);
}
removals.clear();
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void clearCriticalData(String playerName) {
BaseData data = this.map.get(playerName);
if(data != null) {
data.clearCriticalData();
}
}
}

View File

@ -1,11 +1,14 @@
package cc.co.evenprime.bukkit.nocheat.data;
import net.minecraft.server.Entity;
public class FightData extends Data {
public double violationLevel = 0;
public long directionLastViolationTime = 0;
public final ExecutionHistory history = new ExecutionHistory();
public double selfhitviolationLevel = 0;
public double noswingVL = 0.0D;
public double directionVL = 0;
public long directionLastViolationTime = 0;
public final ExecutionHistory history = new ExecutionHistory();
public double selfhitVL = 0;
public double noswingVL = 0.0D;
public Entity damagee;
}

View File

@ -1,16 +0,0 @@
package cc.co.evenprime.bukkit.nocheat.data;
/**
* Everything that could be relevant for logging or consolecommand actions
*/
public class LogData extends Data {
public String check;
public int violationLevel;
public final PreciseLocation toLocation = new PreciseLocation();
public int packets;
public String text;
public double reachdistance;
public float falldistance;
public String playerName;
}

View File

@ -26,6 +26,8 @@ public class MovingData extends Data {
public int morePacketsCounter;
public int morePacketsBuffer = 50;
public int packets;
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
public double morePacketsViolationLevel;
@ -38,6 +40,9 @@ public class MovingData extends Data {
public final PreciseLocation from = new PreciseLocation();
public final PreciseLocation to = new PreciseLocation();
public boolean fromOnOrInGround;
public boolean toOnOrInGround;
@Override
public void clearCriticalData() {
teleportTo.reset();

View File

@ -0,0 +1,89 @@
package cc.co.evenprime.bukkit.nocheat.data;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.player.NoCheatPlayerImpl;
/**
* Provide secure access to player-specific data objects for various checks or
* check groups.
*/
public class PlayerManager {
// Store data between Events
private final Map<String, NoCheatPlayer> map;
private final NoCheat plugin;
private final List<String> removals;
public PlayerManager(NoCheat plugin) {
this.map = new HashMap<String, NoCheatPlayer>();
this.removals = new ArrayList<String>(5);
this.plugin = plugin;
}
/**
* Get a data object of the specified class. If none is stored yet, create
* one.
*/
public NoCheatPlayer getPlayer(String playerName) {
NoCheatPlayer p = this.map.get(playerName);
if(p == null) {
// TODO: Differentiate which player"type" should be created
p = new NoCheatPlayerImpl(playerName, plugin, new BaseData());
this.map.put(playerName, p);
}
return p;
}
/**
* Reset data that may cause problems after e.g. changing the config
*
*/
public void clearCriticalData() {
for(NoCheatPlayer b : this.map.values()) {
b.getData().clearCriticalData();
}
}
/**
* check if some data hasn't been used for a while and remove it
*
*/
public void cleanDataMap() {
synchronized(removals) {
long time = System.currentTimeMillis();
try {
for(Entry<String, NoCheatPlayer> p : this.map.entrySet()) {
if(p.getValue().getData().shouldBeRemoved(time)) {
removals.add(p.getKey());
}
}
for(String p : removals) {
this.map.remove(p);
}
removals.clear();
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void clearCriticalData(String playerName) {
NoCheatPlayer p = this.map.get(playerName);
if(p != null) {
p.getData().clearCriticalData();
}
}
}

View File

@ -1,9 +1,9 @@
package cc.co.evenprime.bukkit.nocheat.events;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockBreakEvent;
@ -12,10 +12,15 @@ import org.bukkit.event.block.BlockListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakCheck;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.BlockBreakCheck;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.DirectionCheck;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.NoswingCheck;
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.ReachCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -26,15 +31,21 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
*/
public class BlockBreakEventManager extends BlockListener implements EventManager {
private final BlockBreakCheck blockBreakCheck;
private final NoCheat plugin;
private final Performance blockBreakPerformance;
private final Performance blockDamagePerformance;
private final List<BlockBreakCheck> checks;
private final NoCheat plugin;
private final Performance blockBreakPerformance;
private final Performance blockDamagePerformance;
public BlockBreakEventManager(NoCheat plugin) {
this.plugin = plugin;
this.blockBreakCheck = new BlockBreakCheck(plugin);
// Three checks exist for this event type
this.checks = new ArrayList<BlockBreakCheck>(3);
this.checks.add(new DirectionCheck(plugin));
this.checks.add(new NoswingCheck(plugin));
this.checks.add(new ReachCheck(plugin));
this.blockBreakPerformance = plugin.getPerformance(Type.BLOCKBREAK);
this.blockDamagePerformance = plugin.getPerformance(Type.BLOCKDAMAGE);
@ -44,6 +55,45 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.Monitor, plugin);
}
private void handleEvent(BlockBreakEvent event) {
boolean cancelled = false;
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
ConfigurationCache c = player.getConfiguration();
if(!c.blockbreak.check || player.hasPermission(Permissions.BLOCKBREAK)) {
return;
}
CCBlockBreak cc = player.getConfiguration().blockbreak;
BlockBreakData data = player.getData().blockbreak;
data.brokenBlockLocation.set(event.getBlock());
for(BlockBreakCheck check : checks) {
// If it should be executed, do it
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
check.check(player, data, cc);
}
}
if(cancelled) {
event.setCancelled(cancelled);
}
}
private void handleEvent(BlockDamageEvent event) {
// Get the player-specific stored data that applies here
final BlockBreakData data = plugin.getPlayer(event.getPlayer().getName()).getData().blockbreak;
// Remember this location. We ignore block breaks in the block-break
// direction check that are insta-breaks
data.instaBrokeBlockLocation.set(event.getBlock());
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
@ -58,20 +108,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
if(performanceCheck)
nanoTimeStart = System.nanoTime();
final Player player = event.getPlayer();
final ConfigurationCache cc = plugin.getConfig(player);
// Find out if checks need to be done for that player
if(cc.blockbreak.check && !player.hasPermission(Permissions.BLOCKBREAK)) {
boolean cancel = false;
cancel = blockBreakCheck.check(player, event.getBlock(), cc);
if(cancel) {
event.setCancelled(true);
}
}
handleEvent(event);
// store performance time
if(performanceCheck)
@ -93,12 +130,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
if(performanceCheck)
nanoTimeStart = System.nanoTime();
// Get the player-specific stored data that applies here
final BaseData data = plugin.getData(event.getPlayer().getName());
// Remember this location. We ignore block breaks in the block-break
// direction check that are insta-breaks
data.blockbreak.instaBrokeBlockLocation.set(event.getBlock());
handleEvent(event);
// store performance time
if(performanceCheck)

View File

@ -1,9 +1,9 @@
package cc.co.evenprime.bukkit.nocheat.events;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockListener;
@ -11,10 +11,14 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.BlockPlaceCheck;
import cc.co.evenprime.bukkit.nocheat.checks.moving.RunFlyCheck;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.BlockPlaceCheck;
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.DirectionCheck;
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.ReachCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -25,45 +29,30 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
*/
public class BlockPlaceEventManager extends BlockListener implements EventManager {
private final NoCheat plugin;
private final RunFlyCheck movingCheck;
private final BlockPlaceCheck blockPlaceCheck;
private final List<BlockPlaceCheck> checks;
private final NoCheat plugin;
private final Performance blockPlacePerformance;
private final Performance blockPlacePerformance;
public BlockPlaceEventManager(NoCheat p) {
this.plugin = p;
this.movingCheck = new RunFlyCheck(plugin);
this.blockPlaceCheck = new BlockPlaceCheck(plugin);
this.checks = new ArrayList<BlockPlaceCheck>(2);
this.checks.add(new DirectionCheck(plugin));
this.checks.add(new ReachCheck(plugin));
this.blockPlacePerformance = p.getPerformance(Type.BLOCKPLACE);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Lowest, plugin);
// This is part of a workaround for the moving check
pm.registerEvent(Event.Type.BLOCK_PLACE, new BlockListener() {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
final Player player = event.getPlayer();
// Get the player-specific stored data that applies here
movingCheck.blockPlaced(player, event.getBlockPlaced());
}
}, Priority.Monitor, plugin);
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
if(event.isCancelled() || event.getBlock() == null)
return;
// Performance counter setup
@ -73,25 +62,42 @@ public class BlockPlaceEventManager extends BlockListener implements EventManage
if(performanceCheck)
nanoTimeStart = System.nanoTime();
boolean cancel = false;
final Player player = event.getPlayer();
final ConfigurationCache cc = plugin.getConfig(player);
// 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(), cc);
}
if(cancel) {
event.setCancelled(true);
}
handleEvent(event);
// store performance time
if(performanceCheck)
blockPlacePerformance.addTime(System.nanoTime() - nanoTimeStart);
}
private void handleEvent(BlockPlaceEvent event) {
boolean cancelled = false;
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
if(!player.getConfiguration().blockplace.check || player.hasPermission(Permissions.BLOCKPLACE)) {
return;
}
CCBlockPlace cc = player.getConfiguration().blockplace;
BlockPlaceData data = player.getData().blockplace;
data.blockPlaced.set(event.getBlock());
data.blockPlacedAgainst.set(event.getBlockAgainst());
data.placedType = event.getBlock().getType();
for(BlockPlaceCheck check : checks) {
// If it should be executed, do it
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
check.check(player, data, cc);
}
}
if(cancelled) {
event.setCancelled(cancelled);
}
}
public List<String> getActiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();

View File

@ -1,9 +1,12 @@
package cc.co.evenprime.bukkit.nocheat.events;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.entity.Entity;
import net.minecraft.server.Entity;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
@ -14,22 +17,32 @@ import org.bukkit.event.entity.EntityListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.fight.FightCheck;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.FightCheck;
import cc.co.evenprime.bukkit.nocheat.checks.fight.DirectionCheck;
import cc.co.evenprime.bukkit.nocheat.checks.fight.NoswingCheck;
import cc.co.evenprime.bukkit.nocheat.checks.fight.SelfhitCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.FightData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
public class EntityDamageEventManager extends EntityListener implements EventManager {
public class FightEventManager extends EntityListener implements EventManager {
private final NoCheat plugin;
private final FightCheck fightCheck;
private final Performance fightPerformance;
private final NoCheat plugin;
private final List<FightCheck> checks;
private final Performance fightPerformance;
public EntityDamageEventManager(NoCheat plugin) {
public FightEventManager(NoCheat plugin) {
this.plugin = plugin;
this.fightCheck = new FightCheck(plugin);
this.checks = new ArrayList<FightCheck>(3);
this.checks.add(new NoswingCheck(plugin));
this.checks.add(new DirectionCheck(plugin));
this.checks.add(new SelfhitCheck(plugin));
this.fightPerformance = plugin.getPerformance(Type.FIGHT);
@ -58,30 +71,45 @@ public class EntityDamageEventManager extends EntityListener implements EventMan
if(performanceCheck)
nanoTimeStart = System.nanoTime();
final Entity damagee = event.getEntity();
// We can cast like crazy here because we ruled out all other
// possibilities above
final Player player = (Player) ((EntityDamageByEntityEvent) event).getDamager();
final ConfigurationCache cc = plugin.getConfig(player);
// Find out if checks need to be done for that player
if(cc.fight.check && !player.hasPermission(Permissions.FIGHT)) {
boolean cancel = false;
cancel = fightCheck.check(player, damagee, cc);
if(cancel) {
event.setCancelled(true);
}
}
handleEvent(event);
// store performance time
if(performanceCheck)
fightPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
private void handleEvent(EntityDamageEvent event) {
final Entity damagee = ((CraftEntity) event.getEntity()).getHandle();
// We can cast like crazy here because we ruled out all other
// possibilities above
final NoCheatPlayer player = plugin.getPlayer(((Player) ((EntityDamageByEntityEvent) event).getDamager()).getName());
final FightData data = player.getData().fight;
final CCFight cc = player.getConfiguration().fight;
if(!cc.check || player.hasPermission(Permissions.FIGHT)) {
return;
}
boolean cancelled = false;
data.damagee = damagee;
for(FightCheck check : checks) {
// If it should be executed, do it
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
check.check(player, data, cc);
}
}
data.damagee = null;
if(cancelled) {
event.setCancelled(cancelled);
}
}
public List<String> getActiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();

View File

@ -1,9 +1,9 @@
package cc.co.evenprime.bukkit.nocheat.events;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerChatEvent;
@ -12,9 +12,13 @@ import org.bukkit.event.player.PlayerListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.chat.ChatCheck;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.ChatCheck;
import cc.co.evenprime.bukkit.nocheat.checks.chat.SpamCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -23,14 +27,16 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
*/
public class PlayerChatEventManager extends PlayerListener implements EventManager {
private final NoCheat plugin;
private final ChatCheck chatCheck;
private final Performance chatPerformance;
private final NoCheat plugin;
private final List<ChatCheck> checks;
private final Performance chatPerformance;
public PlayerChatEventManager(NoCheat plugin) {
this.plugin = plugin;
this.chatCheck = new ChatCheck(plugin);
this.checks = new ArrayList<ChatCheck>(1);
this.checks.add(new SpamCheck(plugin));
this.chatPerformance = plugin.getPerformance(Type.CHAT);
@ -40,6 +46,13 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this, Priority.Lowest, plugin);
}
@Override
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
// We redirect to the other method anyway, so no need to set up a
// performance counter here
onPlayerChat(event);
}
@Override
public void onPlayerChat(final PlayerChatEvent event) {
@ -54,29 +67,37 @@ public class PlayerChatEventManager extends PlayerListener implements EventManag
if(performanceCheck)
nanoTimeStart = System.nanoTime();
final Player player = event.getPlayer();
final ConfigurationCache cc = plugin.getConfig(player);
// Find out if checks need to be done for that player
if(cc.chat.check && !player.hasPermission(Permissions.CHAT)) {
final boolean cancel = chatCheck.check(player, event.getMessage(), cc);
if(cancel) {
event.setCancelled(true);
}
}
handleEvent(event);
// store performance time
if(performanceCheck)
chatPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
private void handleEvent(PlayerChatEvent event) {
boolean cancelled = false;
// We redirect to the other method anyway, so no need to set up a
// performance counter here
onPlayerChat(event);
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
if(!player.getConfiguration().chat.check || player.hasPermission(Permissions.CHAT)) {
return;
}
CCChat cc = player.getConfiguration().chat;
ChatData data = player.getData().chat;
data.message = event.getMessage();
for(ChatCheck check : checks) {
// If it should be executed, do it
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
check.check(player, data, cc);
}
}
if(cancelled) {
event.setCancelled(cancelled);
}
}
public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -1,12 +1,15 @@
package cc.co.evenprime.bukkit.nocheat.events;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
@ -14,12 +17,18 @@ import org.bukkit.plugin.PluginManager;
import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.moving.RunFlyCheck;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.checks.moving.MorePacketsCheck;
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.CCMoving;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
@ -32,16 +41,19 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
*/
public class PlayerMoveEventManager extends PlayerListener implements EventManager {
private final NoCheat plugin;
private final RunFlyCheck movingCheck;
private final NoCheat plugin;
private final List<MovingCheck> checks;
private final Performance movePerformance;
private final Performance velocityPerformance;
private final Performance movePerformance;
private final Performance velocityPerformance;
public PlayerMoveEventManager(NoCheat plugin) {
public PlayerMoveEventManager(final NoCheat plugin) {
this.plugin = plugin;
this.movingCheck = new RunFlyCheck(plugin);
this.checks = new ArrayList<MovingCheck>(5);
checks.add(new RunflyCheck(plugin));
checks.add(new MorePacketsCheck(plugin));
this.movePerformance = plugin.getPerformance(Type.MOVING);
this.velocityPerformance = plugin.getPerformance(Type.VELOCITY);
@ -50,6 +62,21 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_VELOCITY, this, Priority.Monitor, plugin);
// This is part of a workaround for the moving check
pm.registerEvent(Event.Type.BLOCK_PLACE, new BlockListener() {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(event.isCancelled())
return;
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
// Get the player-specific stored data that applies here
blockPlaced(player, event.getBlockPlaced());
}
}, Priority.Monitor, plugin);
}
@Override
@ -66,43 +93,69 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
if(performanceCheck)
nanoTimeStart = System.nanoTime();
// Get the world-specific configuration that applies here
final Player player = event.getPlayer();
final ConfigurationCache cc = plugin.getConfig(player);
// Find out if checks need to be done for that player
if(cc.moving.check && !player.hasPermission(Permissions.MOVE)) {
// Get some data that's needed from this event, to avoid passing the
// event itself on to the checks (and risk to
// accidentally modifying the event there)
final BaseData data = plugin.getData(player.getName());
final MovingData moving = data.moving;
final Location to = event.getTo();
moving.from.set(event.getFrom());
moving.to.set(to);
// This variable will have the modified data of the event (new
// "to"-location)
final PreciseLocation newTo = movingCheck.check(player, data, cc);
// Did the check(s) decide we need a new "to"-location?
if(newTo != null) {
// Compose a new location based on coordinates of "newTo" and
// viewing direction of "event.getTo()"
event.setTo(new Location(player.getWorld(), newTo.x, newTo.y, newTo.z, to.getYaw(), to.getPitch()));
data.moving.teleportTo.set(newTo);
}
}
handleEvent(event);
// store performance time
if(performanceCheck)
movePerformance.addTime(System.nanoTime() - nanoTimeStart);
}
public void handleEvent(PlayerMoveEvent event) {
// Get the world-specific configuration that applies here
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
final CCMoving cc = player.getConfiguration().moving;
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
return;
}
final MovingData data = player.getData().moving;
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
if(data.horizVelocityCounter > 0) {
data.horizVelocityCounter--;
} else {
data.horizFreedom *= 0.90;
}
if(data.vertVelocityCounter > 0) {
data.vertVelocityCounter--;
data.vertFreedom += data.vertVelocity;
data.vertVelocity *= 0.90;
} else {
data.vertFreedom = 0;
}
// Get some data that's needed from this event, to avoid passing the
// event itself on to the checks (and risk to
// accidentally modifying the event there)
final Location to = event.getTo();
data.from.set(event.getFrom());
data.to.set(to);
// This variable will have the modified data of the event (new
// "to"-location)
PreciseLocation newTo = null;
for(MovingCheck check : checks) {
if(newTo == null && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
newTo = check.check(player, data, cc);
}
}
// Did the check(s) decide we need a new "to"-location?
if(newTo != null) {
// Compose a new location based on coordinates of "newTo" and
// viewing direction of "event.getTo()"
event.setTo(new Location(player.getPlayer().getWorld(), newTo.x, newTo.y, newTo.z, to.getYaw(), to.getPitch()));
data.teleportTo.set(newTo);
}
}
@Override
public void onPlayerVelocity(PlayerVelocityEvent event) {
if(event.isCancelled())
@ -115,22 +168,22 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
if(performanceCheck)
nanoTimeStart = System.nanoTime();
BaseData data = plugin.getData(event.getPlayer().getName());
MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
Vector v = event.getVelocity();
double newVal = v.getY();
if(newVal >= 0.0D) {
data.moving.vertVelocity += newVal;
data.moving.vertFreedom += data.moving.vertVelocity;
data.vertVelocity += newVal;
data.vertFreedom += data.vertVelocity;
}
data.moving.vertVelocityCounter = 50;
data.vertVelocityCounter = 50;
newVal = Math.sqrt(Math.pow(v.getX(), 2) + Math.pow(v.getZ(), 2));
if(newVal > 0.0D) {
data.moving.horizFreedom += newVal;
data.moving.horizVelocityCounter = 30;
data.horizFreedom += newVal;
data.horizVelocityCounter = 30;
}
// store performance time
@ -138,6 +191,35 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
velocityPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
/**
* This is a workaround for people placing blocks below them causing false
* positives with the move check(s).
*/
public void blockPlaced(final NoCheatPlayer player, Block blockPlaced) {
BaseData data = player.getData();
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
return;
}
SimpleLocation lblock = new SimpleLocation();
lblock.set(blockPlaced);
SimpleLocation lplayer = new SimpleLocation();
lplayer.setLocation(player.getPlayer().getLocation());
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
int type = CheckUtil.getType(blockPlaced.getTypeId());
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
if(lblock.y + 1 >= data.moving.runflySetBackPoint.y) {
data.moving.runflySetBackPoint.y = (lblock.y + 1);
data.moving.jumpPhase = 0;
}
}
}
}
public List<String> getActiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>();

View File

@ -47,7 +47,7 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
return;
}
final BaseData data = plugin.getData(event.getPlayer().getName());
final BaseData data = plugin.getPlayer(event.getPlayer().getName()).getData();
if(data.moving.teleportTo.isSet() && data.moving.teleportTo.equals(event.getTo())) {
event.setCancelled(false);

View File

@ -34,7 +34,7 @@ public class SwingEventManager extends PlayerListener implements EventManager {
@Override
public void onPlayerAnimation(final PlayerAnimationEvent event) {
plugin.getData(event.getPlayer().getName()).armswung = true;
plugin.getPlayer(event.getPlayer().getName()).getData().armswung = true;
}
public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -8,30 +8,28 @@ import java.util.List;
import net.minecraft.server.EntityPlayer;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.checks.timed.TimedCheck;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.checks.TimedCheck;
import cc.co.evenprime.bukkit.nocheat.checks.timed.GodmodeCheck;
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCTimed;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.TimedData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
public class TimedEventManager implements EventManager {
private final NoCheat plugin;
private final TimedCheck check;
private final Performance timedPerformance;
public final int taskId;
private final List<TimedCheck> checks;
private final Performance timedPerformance;
public final int taskId;
public TimedEventManager(final NoCheat plugin) {
this.plugin = plugin;
check = new TimedCheck(plugin);
checks = new ArrayList<TimedCheck>(1);
checks.add(new GodmodeCheck(plugin));
this.timedPerformance = plugin.getPerformance(Type.TIMED);
@ -71,7 +69,20 @@ public class TimedEventManager implements EventManager {
// Now initialize the checks one by one
for(EntityPlayer p : entities) {
try {
onTimedEvent((Player) CraftEntity.getEntity(server, p), loopsize);
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = timedPerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(plugin.getPlayer(p.name));
// store performance time
if(performanceCheck)
timedPerformance.addTime(System.nanoTime() - nanoTimeStart);
} catch(Exception e) {
e.printStackTrace();
}
@ -83,24 +94,20 @@ public class TimedEventManager implements EventManager {
}, 0, 1);
}
private void onTimedEvent(Player player, int elapsedTicks) {
private void handleEvent(NoCheatPlayer player) {
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = timedPerformance.isEnabled();
TimedData data = player.getData().timed;
CCTimed cc = player.getConfiguration().timed;
if(performanceCheck)
nanoTimeStart = System.nanoTime();
ConfigurationCache cc = plugin.getConfig(player);
if(cc.timed.check && !player.hasPermission(Permissions.TIMED)) {
check.check(player, elapsedTicks, cc);
if(!cc.check || player.hasPermission(Permissions.TIMED)) {
return;
}
// store performance time
if(performanceCheck)
timedPerformance.addTime(System.nanoTime() - nanoTimeStart);
for(TimedCheck check : checks) {
if(cc.check && !player.hasPermission(Permissions.TIMED)) {
check.check(player, data, cc);
}
}
}
public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -0,0 +1,43 @@
package cc.co.evenprime.bukkit.nocheat.player;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
public class NoCheatPlayerImpl implements NoCheatPlayer {
private final Player player;
private final NoCheat plugin;
private final BaseData data;
public NoCheatPlayerImpl(String playerName, NoCheat plugin, BaseData data) {
this.player = Bukkit.getServer().getPlayer(playerName);
this.plugin = plugin;
this.data = data;
}
public boolean hasPermission(String permission) {
return player.hasPermission(permission);
}
public BaseData getData() {
return data;
}
public Player getPlayer() {
return player;
}
public ConfigurationCache getConfiguration() {
return plugin.getConfig(player);
}
public String getName() {
return player.getName();
}
}