mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-02 13:57:49 +01:00
Restructured how data and config per check is created and stored,
bundle checkspecific stuff in packets, use our own "CommandSender" instead of Bukkits consolecommandsender for issuing commands
This commit is contained in:
parent
eb87a37d5b
commit
bc9869a68f
5
src/cc/co/evenprime/bukkit/nocheat/ConfigItem.java
Normal file
5
src/cc/co/evenprime/bukkit/nocheat/ConfigItem.java
Normal file
@ -0,0 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
public interface ConfigItem {
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@ -7,11 +7,9 @@ import java.util.Map;
|
||||
* Every class that is extending this has to implement an empty Constructor()
|
||||
*
|
||||
*/
|
||||
public abstract class Data {
|
||||
public interface DataItem {
|
||||
|
||||
public void clearCriticalData() {
|
||||
|
||||
}
|
||||
public void clearCriticalData();
|
||||
|
||||
public abstract void collectData(Map<String, Object> map);
|
||||
}
|
@ -2,9 +2,9 @@ package cc.co.evenprime.bukkit.nocheat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
|
||||
public interface EventManager {
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc);
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc);
|
||||
}
|
||||
|
@ -12,22 +12,22 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.blockbreak.BlockBreakEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.blockplace.BlockPlaceEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.chat.ChatEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.fight.FightEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.inventory.InventoryEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.moving.MovingEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.command.CommandHandler;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
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;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.BlockBreakEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.BlockPlaceEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.ChatEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.FightEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.InventoryEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.MovingEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.WorkaroundsEventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogManager;
|
||||
@ -59,7 +59,7 @@ public class NoCheat extends JavaPlugin {
|
||||
public void onDisable() {
|
||||
|
||||
PluginDescriptionFile pdfFile = this.getDescription();
|
||||
|
||||
|
||||
if(taskId != -1) {
|
||||
getServer().getScheduler().cancelTask(taskId);
|
||||
taskId = -1;
|
||||
@ -118,15 +118,15 @@ public class NoCheat extends JavaPlugin {
|
||||
log.logToConsole(LogLevel.LOW, "[NoCheat] version [" + this.getDescription().getVersion() + "] is enabled.");
|
||||
}
|
||||
|
||||
public ConfigurationCache getConfig(Player player) {
|
||||
public ConfigurationCacheStore getConfig(Player player) {
|
||||
return conf.getConfigurationCacheForWorld(player.getWorld().getName());
|
||||
}
|
||||
|
||||
public ConfigurationCache getConfig(World world) {
|
||||
public ConfigurationCacheStore getConfig(World world) {
|
||||
return conf.getConfigurationCacheForWorld(world.getName());
|
||||
}
|
||||
|
||||
public void log(LogLevel level, String message, ConfigurationCache cc) {
|
||||
public void log(LogLevel level, String message, ConfigurationCacheStore cc) {
|
||||
log.log(level, message, cc);
|
||||
}
|
||||
|
||||
@ -141,12 +141,12 @@ public class NoCheat extends JavaPlugin {
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
boolean result = CommandHandler.handleCommand(this, sender, command, label, args);
|
||||
|
||||
|
||||
if(!result && sender instanceof Player) {
|
||||
sender.sendMessage("Unknown command. Type \"help\" for help.");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -2,8 +2,8 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
|
||||
public interface NoCheatPlayer {
|
||||
|
||||
@ -13,15 +13,15 @@ public interface NoCheatPlayer {
|
||||
|
||||
public Player getPlayer();
|
||||
|
||||
public BaseData getData();
|
||||
public DataStore getDataStore();
|
||||
|
||||
public boolean isDead();
|
||||
|
||||
|
||||
public boolean isSprinting();
|
||||
|
||||
public int getTicksLived();
|
||||
|
||||
public ConfigurationCache getConfiguration();
|
||||
public ConfigurationCacheStore getConfigurationStore();
|
||||
|
||||
public float getSpeedAmplifier();
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.actions;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.PermissibleBase;
|
||||
|
||||
public class NoCheatCommandSender extends PermissibleBase implements CommandSender {
|
||||
|
||||
public NoCheatCommandSender() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "NoCheatCommandSender";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
// We don't want to receive messages, as we can't do anything with them
|
||||
// anyway
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return Bukkit.getServer();
|
||||
}
|
||||
|
||||
}
|
@ -18,4 +18,4 @@ public enum ParameterName {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,9 @@ package cc.co.evenprime.bukkit.nocheat.actions.types;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
|
||||
/**
|
||||
* This is only used to not lose config entries in case an action isn't defined correctly
|
||||
*
|
||||
* This is only used to not lose config entries in case an action isn't defined
|
||||
* correctly
|
||||
*
|
||||
*/
|
||||
public class DummyAction extends Action {
|
||||
|
||||
|
@ -1,23 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
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.ParameterName;
|
||||
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(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.TEXT)
|
||||
return player.getData().chat.message;
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
}
|
@ -9,12 +9,13 @@ import org.bukkit.command.CommandSender;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.Action;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.NoCheatCommandSender;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.types.ConsolecommandAction;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.types.DummyAction;
|
||||
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.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
public abstract class Check {
|
||||
@ -45,7 +46,7 @@ public abstract class Check {
|
||||
|
||||
final long time = System.currentTimeMillis() / 1000;
|
||||
|
||||
final ConfigurationCache cc = player.getConfiguration();
|
||||
final ConfigurationCacheStore cc = player.getConfigurationStore();
|
||||
|
||||
for(Action ac : actions) {
|
||||
if(getHistory(player).executeAction(ac, time)) {
|
||||
@ -66,18 +67,18 @@ public abstract class Check {
|
||||
|
||||
protected abstract ExecutionHistory getHistory(NoCheatPlayer player);
|
||||
|
||||
private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCache cc) {
|
||||
private final void executeLogAction(LogAction l, Check check, NoCheatPlayer player, ConfigurationCacheStore 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) {
|
||||
private final void executeConsoleCommand(ConsolecommandAction action, Check check, NoCheatPlayer player, ConfigurationCacheStore cc) {
|
||||
String command = "";
|
||||
|
||||
|
||||
try {
|
||||
command = action.getCommand(player, check);
|
||||
plugin.getServer().dispatchCommand(noCheatCommandSender, command);
|
||||
} catch(CommandException e) {
|
||||
System.out.println("[NoCheat] failed to execute the command '" + command + "': "+e.getMessage()+", please check if everything is setup correct. ");
|
||||
System.out.println("[NoCheat] failed to execute the command '" + command + "': " + e.getMessage() + ", please check if everything is setup correct. ");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -150,14 +150,16 @@ public class CheckUtil {
|
||||
// Player can stand on and "in" lilipads
|
||||
types[Material.WATER_LILY.getId()] = SOLID | NONSOLID;
|
||||
|
||||
/*for(int i = 0; i < 256; i++) {
|
||||
if(Block.byId[i] != null) {
|
||||
System.out.println(Material.getMaterial(i) +
|
||||
(isSolid(types[i]) ? " solid " : "") + (isNonSolid(types[i])
|
||||
? " nonsolid " : "") + (isLiquid(types[i]) ? " liquid " :
|
||||
""));
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
* for(int i = 0; i < 256; i++) {
|
||||
* if(Block.byId[i] != null) {
|
||||
* System.out.println(Material.getMaterial(i) +
|
||||
* (isSolid(types[i]) ? " solid " : "") + (isNonSolid(types[i])
|
||||
* ? " nonsolid " : "") + (isLiquid(types[i]) ? " liquid " :
|
||||
* ""));
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -250,7 +252,7 @@ public class CheckUtil {
|
||||
return INGROUND;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Last simple case: Player touches liquid
|
||||
if(isLiquid(base) || isLiquid(top)) {
|
||||
return LIQUID | INGROUND;
|
||||
|
@ -1,27 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
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.CCInventory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.InventoryData;
|
||||
|
||||
|
||||
public abstract class InventoryCheck extends Check {
|
||||
|
||||
public InventoryCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, name, permission);
|
||||
}
|
||||
|
||||
public abstract boolean check(NoCheatPlayer player, InventoryData data, CCInventory cc);
|
||||
|
||||
public abstract boolean isEnabled(CCInventory cc);
|
||||
|
||||
@Override
|
||||
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
|
||||
return player.getData().inventory.history;
|
||||
}
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
|
||||
public class NoCheatCommandSender implements CommandSender {
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(Permission perm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String name) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Permission perm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttachment(PermissionAttachment attachment) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recalculatePermissions() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Server getServer() {
|
||||
return Bukkit.getServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "NoCheatCommandSender";
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
public abstract class BlockBreakCheck extends Check {
|
||||
|
||||
private static final String id = "blockbreak";
|
||||
|
||||
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 getData(player.getDataStore()).history;
|
||||
}
|
||||
|
||||
public static BlockBreakData getData(DataStore base) {
|
||||
BlockBreakData data = base.get(id);
|
||||
if(data == null) {
|
||||
data = new BlockBreakData();
|
||||
base.set(id, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static CCBlockBreak getConfig(ConfigurationCacheStore cache) {
|
||||
CCBlockBreak config = cache.get(id);
|
||||
if(config == null) {
|
||||
config = new CCBlockBreak(cache.getConfiguration());
|
||||
cache.set(id, config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,12 +1,16 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
/**
|
||||
* Playerspecific data for the blockbreak check group
|
||||
*
|
||||
*/
|
||||
public class BlockBreakData extends Data {
|
||||
public class BlockBreakData implements DataItem {
|
||||
|
||||
public double reachVL = 0.0D;
|
||||
public double reachTotalVL = 0.0D;
|
||||
@ -37,9 +41,9 @@ public class BlockBreakData extends Data {
|
||||
|
||||
@Override
|
||||
public void collectData(Map<String, Object> map) {
|
||||
map.put("blockbreak.reach.vl", (int)reachTotalVL);
|
||||
map.put("blockbreak.direction.vl", (int)directionTotalVL);
|
||||
map.put("blockbreak.noswing.vl", (int)noswingTotalVL);
|
||||
map.put("blockbreak.reach.vl", (int) reachTotalVL);
|
||||
map.put("blockbreak.direction.vl", (int) directionTotalVL);
|
||||
map.put("blockbreak.noswing.vl", (int) noswingTotalVL);
|
||||
map.put("blockbreak.reach.failed", reachFailed);
|
||||
map.put("blockbreak.direction.failed", directionFailed);
|
||||
map.put("blockbreak.noswing.failed", noswingFailed);
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@ -12,15 +12,10 @@ import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.ConfigurationCacheStore;
|
||||
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.BlockBreakData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
/**
|
||||
* Central location to listen to player-interact events and dispatch them to
|
||||
@ -52,13 +47,13 @@ public class BlockBreakEventManager extends EventManagerImpl {
|
||||
boolean cancelled = false;
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final CCBlockBreak cc = player.getConfiguration().blockbreak;
|
||||
final CCBlockBreak cc = BlockBreakCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.BLOCKBREAK)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockBreakData data = player.getData().blockbreak;
|
||||
final BlockBreakData data = BlockBreakCheck.getData(player.getDataStore());
|
||||
|
||||
data.brokenBlockLocation.set(event.getBlock());
|
||||
|
||||
@ -80,27 +75,26 @@ public class BlockBreakEventManager extends EventManagerImpl {
|
||||
if(!event.getInstaBreak())
|
||||
return;
|
||||
|
||||
// Get the player-specific stored data that applies here
|
||||
final BlockBreakData data = plugin.getPlayer(event.getPlayer()).getData().blockbreak;
|
||||
|
||||
// Remember this location. We ignore block breaks in the block-break
|
||||
// direction check that are insta-breaks
|
||||
data.instaBrokenBlockLocation.set(event.getBlock());
|
||||
BlockBreakCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).instaBrokenBlockLocation.set(event.getBlock());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) {
|
||||
plugin.getPlayer(event.getPlayer()).getData().blockbreak.armswung = true;
|
||||
BlockBreakCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).armswung = true;
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
if(cc.blockbreak.check && cc.blockbreak.directionCheck)
|
||||
CCBlockBreak bb = BlockBreakCheck.getConfig(cc);
|
||||
|
||||
if(bb.check && bb.directionCheck)
|
||||
s.add("blockbreak.direction");
|
||||
if(cc.blockbreak.check && cc.blockbreak.reachCheck)
|
||||
if(bb.check && bb.reachCheck)
|
||||
s.add("blockbreak.reach");
|
||||
if(cc.blockbreak.check && cc.blockbreak.noswingCheck)
|
||||
if(bb.check && bb.noswingCheck)
|
||||
s.add("blockbreak.noswing");
|
||||
|
||||
return s;
|
@ -1,5 +1,6 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockbreak;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
@ -8,7 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
* Every world gets one of these assigned to it.
|
||||
*
|
||||
*/
|
||||
public class CCBlockBreak {
|
||||
public class CCBlockBreak implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
public final boolean checkinstabreakblocks;
|
@ -5,11 +5,8 @@ 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.ParameterName;
|
||||
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.data.BlockBreakData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
/**
|
||||
@ -82,7 +79,7 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().blockbreak.directionVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).directionVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -5,10 +5,7 @@ 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.ParameterName;
|
||||
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.BlockBreakData;
|
||||
|
||||
public class NoswingCheck extends BlockBreakCheck {
|
||||
|
||||
@ -42,7 +39,7 @@ public class NoswingCheck extends BlockBreakCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().blockbreak.noswingVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).noswingVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -5,11 +5,8 @@ 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.ParameterName;
|
||||
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.data.BlockBreakData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
/**
|
||||
@ -55,9 +52,9 @@ public class ReachCheck extends BlockBreakCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().blockbreak.reachVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).reachVL);
|
||||
else if(wildcard == ParameterName.REACHDISTANCE)
|
||||
return String.format(Locale.US, "%.2f", player.getData().blockbreak.reachDistance);
|
||||
return String.format(Locale.US, "%.2f", getData(player.getDataStore()).reachDistance);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
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.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
@ -15,6 +16,8 @@ import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
*/
|
||||
public abstract class BlockPlaceCheck extends Check {
|
||||
|
||||
private static final String id = "blockplace";
|
||||
|
||||
public BlockPlaceCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, name, permission);
|
||||
}
|
||||
@ -25,13 +28,13 @@ public abstract class BlockPlaceCheck extends Check {
|
||||
|
||||
@Override
|
||||
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
|
||||
return player.getData().blockplace.history;
|
||||
return getData(player.getDataStore()).history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
if(wildcard == ParameterName.PLACE_LOCATION) {
|
||||
SimpleLocation l = player.getData().blockplace.blockPlaced;
|
||||
SimpleLocation l = getData(player.getDataStore()).blockPlaced;
|
||||
if(l.isSet()) {
|
||||
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
|
||||
} else {
|
||||
@ -40,7 +43,7 @@ public abstract class BlockPlaceCheck extends Check {
|
||||
}
|
||||
|
||||
else if(wildcard == ParameterName.PLACE_AGAINST) {
|
||||
SimpleLocation l = player.getData().blockplace.blockPlacedAgainst;
|
||||
SimpleLocation l = getData(player.getDataStore()).blockPlacedAgainst;
|
||||
if(l.isSet()) {
|
||||
return String.format(Locale.US, "%d %d %d", l.x, l.y, l.z);
|
||||
} else {
|
||||
@ -51,4 +54,22 @@ public abstract class BlockPlaceCheck extends Check {
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
||||
public static BlockPlaceData getData(DataStore base) {
|
||||
BlockPlaceData data = base.get(id);
|
||||
if(data == null) {
|
||||
data = new BlockPlaceData();
|
||||
base.set(id, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static CCBlockPlace getConfig(ConfigurationCacheStore cache) {
|
||||
CCBlockPlace config = cache.get(id);
|
||||
if(config == null) {
|
||||
config = new CCBlockPlace(cache.getConfiguration());
|
||||
cache.set(id, config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class BlockPlaceData extends Data {
|
||||
public class BlockPlaceData implements DataItem {
|
||||
|
||||
public double reachVL = 0.0D;
|
||||
public double reachTotalVL = 0.0D;
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@ -10,14 +10,10 @@ import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.ConfigurationCacheStore;
|
||||
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.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
/**
|
||||
* Central location to listen to Block-related events and dispatching them to
|
||||
@ -48,13 +44,13 @@ public class BlockPlaceEventManager extends EventManagerImpl {
|
||||
boolean cancelled = false;
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final CCBlockPlace cc = player.getConfiguration().blockplace;
|
||||
final CCBlockPlace cc = BlockPlaceCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.BLOCKPLACE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final BlockPlaceData data = player.getData().blockplace;
|
||||
final BlockPlaceData data = BlockPlaceCheck.getData(player.getDataStore());
|
||||
|
||||
data.blockPlaced.set(event.getBlock());
|
||||
data.blockPlacedAgainst.set(event.getBlockAgainst());
|
||||
@ -70,10 +66,12 @@ public class BlockPlaceEventManager extends EventManagerImpl {
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
if(cc.blockplace.check && cc.blockplace.reachCheck)
|
||||
CCBlockPlace bp = BlockPlaceCheck.getConfig(cc);
|
||||
|
||||
if(bp.check && bp.reachCheck)
|
||||
s.add("blockplace.reach");
|
||||
|
||||
return s;
|
@ -1,12 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.blockplace;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class CCBlockPlace {
|
||||
public class CCBlockPlace implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
|
@ -5,11 +5,8 @@ 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.ParameterName;
|
||||
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.data.BlockPlaceData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
public class DirectionCheck extends BlockPlaceCheck {
|
||||
@ -96,7 +93,7 @@ public class DirectionCheck extends BlockPlaceCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().blockplace.directionVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).directionVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -5,11 +5,8 @@ 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.ParameterName;
|
||||
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.data.BlockPlaceData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
|
||||
/**
|
||||
@ -56,9 +53,9 @@ public class ReachCheck extends BlockPlaceCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().blockplace.reachVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).reachVL);
|
||||
else if(wildcard == ParameterName.REACHDISTANCE)
|
||||
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);
|
||||
return String.format(Locale.US, "%.2f", getData(player.getDataStore()).reachdistance);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.chat;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
public class CCChat {
|
||||
public class CCChat implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
public final boolean spamCheck;
|
@ -0,0 +1,55 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.chat;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
public abstract class ChatCheck extends Check {
|
||||
|
||||
private static final String id = "chat";
|
||||
|
||||
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 getData(player.getDataStore()).history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.TEXT)
|
||||
return getData(player.getDataStore()).message;
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
||||
public static ChatData getData(DataStore base) {
|
||||
ChatData data = base.get(id);
|
||||
if(data == null) {
|
||||
data = new ChatData();
|
||||
base.set(id, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static CCChat getConfig(ConfigurationCacheStore cache) {
|
||||
CCChat config = cache.get(id);
|
||||
if(config == null) {
|
||||
config = new CCChat(cache.getConfiguration());
|
||||
cache.set(id, config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.chat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@ -11,14 +11,11 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.ChatCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.chat.EmptyCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.chat.SpamCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
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.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
public class ChatEventManager extends EventManagerImpl {
|
||||
|
||||
@ -47,13 +44,13 @@ public class ChatEventManager extends EventManagerImpl {
|
||||
boolean cancelled = false;
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final CCChat cc = player.getConfiguration().chat;
|
||||
final CCChat cc = ChatCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.CHAT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final ChatData data = player.getData().chat;
|
||||
final ChatData data = ChatCheck.getData(player.getDataStore());
|
||||
|
||||
data.message = event.getMessage();
|
||||
|
||||
@ -69,12 +66,13 @@ public class ChatEventManager extends EventManagerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
if(cc.chat.check && cc.chat.spamCheck)
|
||||
CCChat c = ChatCheck.getConfig(cc);
|
||||
if(c.check && c.spamCheck)
|
||||
s.add("chat.spam");
|
||||
if(cc.chat.check && cc.chat.emptyCheck)
|
||||
if(c.check && c.emptyCheck)
|
||||
s.add("chat.empty");
|
||||
return s;
|
||||
}
|
@ -5,9 +5,7 @@ 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.ParameterName;
|
||||
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 EmptyCheck extends ChatCheck {
|
||||
@ -40,7 +38,7 @@ public class EmptyCheck extends ChatCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", player.getData().chat.emptyVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).emptyVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ 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.ParameterName;
|
||||
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 {
|
||||
@ -60,7 +58,7 @@ public class SpamCheck extends ChatCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", player.getData().chat.spamVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).spamVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
public class CCFight {
|
||||
public class CCFight implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
public final boolean directionCheck;
|
@ -10,10 +10,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.CheckUtil;
|
||||
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 extends FightCheck {
|
||||
|
||||
@ -87,7 +84,7 @@ public class DirectionCheck extends FightCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().fight.directionVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).directionVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
/**
|
||||
* Check various things related to fighting players/entities
|
||||
*
|
||||
*/
|
||||
public abstract class FightCheck extends Check {
|
||||
|
||||
private static final String id = "fight";
|
||||
|
||||
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 getData(player.getDataStore()).history;
|
||||
}
|
||||
|
||||
public static FightData getData(DataStore base) {
|
||||
FightData data = base.get(id);
|
||||
if(data == null) {
|
||||
data = new FightData();
|
||||
base.set(id, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static CCFight getConfig(ConfigurationCacheStore cache) {
|
||||
CCFight config = cache.get(id);
|
||||
if(config == null) {
|
||||
config = new CCFight(cache.getConfiguration());
|
||||
cache.set(id, config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.server.Entity;
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
public class FightData extends Data {
|
||||
public class FightData implements DataItem {
|
||||
|
||||
public double directionVL = 0.0D;
|
||||
public double directionTotalVL = 0.0D;
|
||||
@ -32,4 +34,9 @@ public class FightData extends Data {
|
||||
map.put("fight.selfhit.failed", selfhitFailed);
|
||||
map.put("fight.noswing.failed", noswingFailed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCriticalData() {
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.fight;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@ -14,15 +14,10 @@ import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.ConfigurationCacheStore;
|
||||
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.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
public class FightEventManager extends EventManagerImpl {
|
||||
|
||||
@ -46,13 +41,13 @@ public class FightEventManager extends EventManagerImpl {
|
||||
final Player damager = (Player) event.getDamager();
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(damager);
|
||||
final CCFight cc = player.getConfiguration().fight;
|
||||
final CCFight cc = FightCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.FIGHT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final FightData data = player.getData().fight;
|
||||
final FightData data = FightCheck.getData(player.getDataStore());
|
||||
|
||||
// For some reason we decided to skip this event anyway
|
||||
if(data.skipNext) {
|
||||
@ -84,7 +79,7 @@ public class FightEventManager extends EventManagerImpl {
|
||||
final Player damager = (Player) ((Projectile) event.getDamager()).getShooter();
|
||||
final NoCheatPlayer player = plugin.getPlayer(damager);
|
||||
|
||||
final FightData data = player.getData().fight;
|
||||
final FightData data = FightCheck.getData(player.getDataStore());
|
||||
|
||||
// Skip the next damage event, because it is the same as this one
|
||||
// just mislabelled as a "direct" attack from one player onto another
|
||||
@ -99,7 +94,7 @@ public class FightEventManager extends EventManagerImpl {
|
||||
final Player damager = (Player) event.getDamager();
|
||||
final NoCheatPlayer player = plugin.getPlayer(damager);
|
||||
|
||||
final FightData data = player.getData().fight;
|
||||
final FightData data = FightCheck.getData(player.getDataStore());
|
||||
|
||||
// Skip the next damage event, because it is with high probability
|
||||
// something from the Heroes plugin
|
||||
@ -110,17 +105,19 @@ public class FightEventManager extends EventManagerImpl {
|
||||
|
||||
@Override
|
||||
protected void handlePlayerAnimationEvent(final PlayerAnimationEvent event, final Priority priority) {
|
||||
plugin.getPlayer(event.getPlayer()).getData().fight.armswung = true;
|
||||
FightCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore()).armswung = true;
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
if(cc.fight.check && cc.fight.directionCheck)
|
||||
CCFight f = FightCheck.getConfig(cc);
|
||||
|
||||
if(f.check && f.directionCheck)
|
||||
s.add("fight.direction");
|
||||
if(cc.fight.check && cc.fight.selfhitCheck)
|
||||
if(f.check && f.selfhitCheck)
|
||||
s.add("fight.selfhit");
|
||||
if(cc.fight.check && cc.fight.noswingCheck)
|
||||
if(f.check && f.noswingCheck)
|
||||
s.add("fight.noswing");
|
||||
return s;
|
||||
}
|
@ -5,10 +5,7 @@ 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.ParameterName;
|
||||
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 NoswingCheck extends FightCheck {
|
||||
|
||||
@ -43,7 +40,7 @@ public class NoswingCheck extends FightCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().fight.noswingVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).noswingVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -5,10 +5,7 @@ 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.ParameterName;
|
||||
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 extends FightCheck {
|
||||
|
||||
@ -43,7 +40,7 @@ public class SelfhitCheck extends FightCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().fight.selfhitVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).selfhitVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.inventory;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
public class CCInventory {
|
||||
public class CCInventory implements ConfigItem {
|
||||
|
||||
public final boolean closebeforeteleports;
|
||||
public final boolean check;
|
@ -5,10 +5,7 @@ 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.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.InventoryCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCInventory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.InventoryData;
|
||||
|
||||
public class DropCheck extends InventoryCheck {
|
||||
|
||||
@ -55,7 +52,7 @@ public class DropCheck extends InventoryCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", player.getData().inventory.dropVL);
|
||||
return String.format(Locale.US, "%d", getData(player.getDataStore()).dropVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.inventory;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
public abstract class InventoryCheck extends Check {
|
||||
|
||||
private static final String id = "inventory";
|
||||
|
||||
public InventoryCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, name, permission);
|
||||
}
|
||||
|
||||
public abstract boolean check(NoCheatPlayer player, InventoryData data, CCInventory cc);
|
||||
|
||||
public abstract boolean isEnabled(CCInventory cc);
|
||||
|
||||
@Override
|
||||
protected final ExecutionHistory getHistory(NoCheatPlayer player) {
|
||||
return getData(player.getDataStore()).history;
|
||||
}
|
||||
|
||||
public static InventoryData getData(DataStore base) {
|
||||
InventoryData data = base.get(id);
|
||||
if(data == null) {
|
||||
data = new InventoryData();
|
||||
base.set(id, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static CCInventory getConfig(ConfigurationCacheStore cache) {
|
||||
CCInventory config = cache.get(id);
|
||||
if(config == null) {
|
||||
config = new CCInventory(cache.getConfiguration());
|
||||
cache.set(id, config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.inventory;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class InventoryData extends Data {
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
|
||||
public class InventoryData implements DataItem {
|
||||
|
||||
public int dropVL = 0;
|
||||
public double dropTotalVL = 0;
|
||||
@ -16,4 +19,9 @@ public class InventoryData extends Data {
|
||||
map.put("inventory.drop.vl", (int) dropTotalVL);
|
||||
map.put("inventory.drop.failed", (int) dropFailed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCriticalData() {
|
||||
|
||||
}
|
||||
}
|
@ -1,22 +1,21 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.inventory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.InventoryCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.inventory.DropCheck;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCInventory;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.InventoryData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
public class InventoryEventManager extends EventManagerImpl {
|
||||
|
||||
@ -29,19 +28,29 @@ public class InventoryEventManager extends EventManagerImpl {
|
||||
this.checks.add(new DropCheck(plugin));
|
||||
|
||||
registerListener(Event.Type.PLAYER_DROP_ITEM, Priority.Lowest, true, plugin.getPerformance(EventType.INVENTORY));
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerTeleportEvent(final PlayerTeleportEvent event, final Priority priority) {
|
||||
|
||||
CraftPlayer player = (CraftPlayer) event.getPlayer();
|
||||
if(InventoryCheck.getConfig(plugin.getPlayer(player).getConfigurationStore()).closebeforeteleports && event.getTo() != null && !(event.getTo().getWorld().equals(player.getWorld()))) {
|
||||
player.getHandle().closeInventory();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerDropItemEvent(final PlayerDropItemEvent event, final Priority priority) {
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final CCInventory cc = player.getConfiguration().inventory;
|
||||
final CCInventory cc = InventoryCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.INVENTORY)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final InventoryData data = player.getData().inventory;
|
||||
final InventoryData data = InventoryCheck.getData(player.getDataStore());
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
@ -56,12 +65,12 @@ public class InventoryEventManager extends EventManagerImpl {
|
||||
event.setCancelled(cancelled);
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
if(cc.inventory.check && cc.inventory.dropCheck)
|
||||
CCInventory i = InventoryCheck.getConfig(cc);
|
||||
if(i.check && i.dropCheck)
|
||||
s.add("inventory.dropCheck");
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
|
||||
@ -8,7 +9,7 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionList;
|
||||
* assigned to it.
|
||||
*
|
||||
*/
|
||||
public class CCMoving {
|
||||
public class CCMoving implements ConfigItem {
|
||||
|
||||
public final boolean check;
|
||||
|
||||
@ -35,7 +36,7 @@ public class CCMoving {
|
||||
public final boolean morePacketsCheck;
|
||||
public final ActionList morePacketsActions;
|
||||
|
||||
public final double flyingHeightLimit;
|
||||
public final double flyingHeightLimit;
|
||||
|
||||
public CCMoving(Configuration data) {
|
||||
|
@ -5,9 +5,6 @@ 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.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -35,7 +32,7 @@ public class FlyingCheck extends MovingCheck {
|
||||
}
|
||||
|
||||
PreciseLocation newToLocation = null;
|
||||
|
||||
|
||||
// Before doing anything, do a basic height check
|
||||
// This is silent for now, will log messages later
|
||||
// probably
|
||||
@ -127,7 +124,7 @@ public class FlyingCheck extends MovingCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).runflyVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -5,10 +5,7 @@ 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.ParameterName;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -110,9 +107,9 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().moving.morePacketsVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).morePacketsVL);
|
||||
else if(wildcard == ParameterName.PACKETS)
|
||||
return String.valueOf(player.getData().moving.packets);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).packets);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -1,17 +1,20 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.checks;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
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.ParameterName;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCMoving;
|
||||
import cc.co.evenprime.bukkit.nocheat.checks.Check;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
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 {
|
||||
|
||||
private static final String id = "moving";
|
||||
|
||||
public MovingCheck(NoCheat plugin, String name, String permission) {
|
||||
super(plugin, name, permission);
|
||||
}
|
||||
@ -28,24 +31,42 @@ public abstract class MovingCheck extends Check {
|
||||
|
||||
@Override
|
||||
protected ExecutionHistory getHistory(NoCheatPlayer player) {
|
||||
return player.getData().moving.history;
|
||||
return getData(player.getDataStore()).history;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.LOCATION) {
|
||||
PreciseLocation from = player.getData().moving.from;
|
||||
PreciseLocation from = getData(player.getDataStore()).from;
|
||||
return String.format(Locale.US, "%.2f,%.2f,%.2f", from.x, from.y, from.z);
|
||||
} else if(wildcard == ParameterName.MOVEDISTANCE) {
|
||||
PreciseLocation from = player.getData().moving.from;
|
||||
PreciseLocation to = player.getData().moving.to;
|
||||
PreciseLocation from = getData(player.getDataStore()).from;
|
||||
PreciseLocation to = getData(player.getDataStore()).to;
|
||||
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x - from.x, to.y - from.y, to.z - from.z);
|
||||
} else if(wildcard == ParameterName.LOCATION_TO) {
|
||||
PreciseLocation to = player.getData().moving.to;
|
||||
PreciseLocation to = getData(player.getDataStore()).to;
|
||||
return String.format(Locale.US, "%.2f,%.2f,%.2f", to.x, to.y, to.z);
|
||||
} else
|
||||
return super.getParameter(wildcard, player);
|
||||
|
||||
}
|
||||
|
||||
public static MovingData getData(DataStore base) {
|
||||
MovingData data = base.get(id);
|
||||
if(data == null) {
|
||||
data = new MovingData();
|
||||
base.set(id, data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static CCMoving getConfig(ConfigurationCacheStore cache) {
|
||||
CCMoving config = cache.get(id);
|
||||
if(config == null) {
|
||||
config = new CCMoving(cache.getConfiguration());
|
||||
cache.set(id, config);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
}
|
@ -1,11 +1,15 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ExecutionHistory;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
|
||||
/**
|
||||
* Player specific data for the moving check group
|
||||
*/
|
||||
public class MovingData extends Data {
|
||||
public class MovingData implements DataItem {
|
||||
|
||||
public double runflyVL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
@ -17,16 +17,12 @@ import org.bukkit.util.Vector;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.ConfigurationCacheStore;
|
||||
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.MovingData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.EventType;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
|
||||
/**
|
||||
* The only place that listens to and modifies player_move events if necessary
|
||||
@ -59,7 +55,7 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
// Get the player-specific stored data that applies here
|
||||
final MovingData data = player.getData().moving;
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
final Block blockPlaced = event.getBlockPlaced();
|
||||
|
||||
@ -92,7 +88,7 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
return;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer());
|
||||
final MovingData data = player.getData().moving;
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
||||
event.setCancelled(false);
|
||||
@ -112,13 +108,13 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
return;
|
||||
}
|
||||
|
||||
final CCMoving cc = player.getConfiguration().moving;
|
||||
final CCMoving cc = MovingCheck.getConfig(player.getConfigurationStore());
|
||||
|
||||
if(!cc.check || player.hasPermission(Permissions.MOVING)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final MovingData data = player.getData().moving;
|
||||
final MovingData data = MovingCheck.getData(player.getDataStore());
|
||||
|
||||
/******** DO GENERAL DATA MODIFICATIONS ONCE FOR EACH EVENT *****/
|
||||
if(data.horizVelocityCounter > 0) {
|
||||
@ -167,7 +163,7 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
@Override
|
||||
protected void handlePlayerVelocityEvent(final PlayerVelocityEvent event, final Priority priority) {
|
||||
|
||||
final MovingData data = plugin.getPlayer(event.getPlayer()).getData().moving;
|
||||
final MovingData data = MovingCheck.getData(plugin.getPlayer(event.getPlayer()).getDataStore());
|
||||
|
||||
final Vector v = event.getVelocity();
|
||||
|
||||
@ -186,25 +182,27 @@ public class MovingEventManager extends EventManagerImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
if(cc.moving.check) {
|
||||
if(cc.moving.runflyCheck) {
|
||||
CCMoving m = MovingCheck.getConfig(cc);
|
||||
|
||||
if(!cc.moving.allowFlying) {
|
||||
if(m.check) {
|
||||
if(m.runflyCheck) {
|
||||
|
||||
if(!m.allowFlying) {
|
||||
s.add("moving.runfly");
|
||||
if(cc.moving.swimmingCheck)
|
||||
if(m.swimmingCheck)
|
||||
s.add("moving.swimming");
|
||||
if(cc.moving.sneakingCheck)
|
||||
if(m.sneakingCheck)
|
||||
s.add("moving.sneaking");
|
||||
if(cc.moving.nofallCheck)
|
||||
if(m.nofallCheck)
|
||||
s.add("moving.nofall");
|
||||
} else
|
||||
s.add("moving.flying");
|
||||
|
||||
}
|
||||
if(cc.moving.morePacketsCheck)
|
||||
if(m.morePacketsCheck)
|
||||
s.add("moving.morepackets");
|
||||
}
|
||||
|
@ -5,10 +5,7 @@ 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.ParameterName;
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -35,13 +32,13 @@ public class NoFallCheck extends MovingCheck {
|
||||
data.lastAddedFallDistance = 0F;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// This check is pretty much always a step behind for technical reasons.
|
||||
if(data.fromOnOrInGround) {
|
||||
// Start with zero fall distance
|
||||
data.fallDistance = 0F;
|
||||
}
|
||||
|
||||
|
||||
// If we increased fall height before for no good reason, reduce now by
|
||||
// the same amount
|
||||
if(player.getPlayer().getFallDistance() > data.lastAddedFallDistance) {
|
||||
@ -115,9 +112,9 @@ public class NoFallCheck extends MovingCheck {
|
||||
public String getParameter(ParameterName wildcard, NoCheatPlayer player) {
|
||||
|
||||
if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().moving.nofallVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).nofallVL);
|
||||
else if(wildcard == ParameterName.FALLDISTANCE)
|
||||
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
|
||||
return String.format(Locale.US, "%.2f", getData(player.getDataStore()).fallDistance);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -2,10 +2,7 @@ package cc.co.evenprime.bukkit.nocheat.checks.moving;
|
||||
|
||||
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 {
|
||||
|
@ -6,10 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.ParameterName;
|
||||
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.data.MovingData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
|
||||
/**
|
||||
@ -232,9 +229,9 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
if(wildcard == ParameterName.CHECK)
|
||||
// Workaround for something until I find a better way to do it
|
||||
return getName() + "." + player.getData().moving.checknamesuffix;
|
||||
return getName() + "." + getData(player.getDataStore()).checknamesuffix;
|
||||
else if(wildcard == ParameterName.VIOLATIONS)
|
||||
return String.format(Locale.US, "%d", (int) player.getData().moving.runflyVL);
|
||||
return String.format(Locale.US, "%d", (int) getData(player.getDataStore()).runflyVL);
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
public class CCDebug {
|
||||
|
@ -1,8 +1,7 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.Colors;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||
|
@ -37,10 +37,10 @@ public abstract class Configuration {
|
||||
public static final OptionNode INVENTORY_CHECK = new OptionNode("check", INVENTORY, DataType.BOOLEAN);
|
||||
|
||||
private final static OptionNode INVENTORY_DROP = new OptionNode("drop", INVENTORY, DataType.PARENT);
|
||||
public final static OptionNode INVENTORY_DROP_CHECK = new OptionNode("check", INVENTORY_DROP, DataType.BOOLEAN);
|
||||
public final static OptionNode INVENTORY_DROP_TIMEFRAME = new OptionNode("timeframe", INVENTORY_DROP, DataType.INTEGER);
|
||||
public final static OptionNode INVENTORY_DROP_LIMIT = new OptionNode("limit", INVENTORY_DROP, DataType.INTEGER);
|
||||
public final static OptionNode INVENTORY_DROP_ACTIONS = new OptionNode("actions", INVENTORY_DROP, DataType.ACTIONLIST);
|
||||
public final static OptionNode INVENTORY_DROP_CHECK = new OptionNode("check", INVENTORY_DROP, DataType.BOOLEAN);
|
||||
public final static OptionNode INVENTORY_DROP_TIMEFRAME = new OptionNode("timeframe", INVENTORY_DROP, DataType.INTEGER);
|
||||
public final static OptionNode INVENTORY_DROP_LIMIT = new OptionNode("limit", INVENTORY_DROP, DataType.INTEGER);
|
||||
public final static OptionNode INVENTORY_DROP_ACTIONS = new OptionNode("actions", INVENTORY_DROP, DataType.ACTIONLIST);
|
||||
|
||||
private final static OptionNode MOVING = new OptionNode("moving", ROOT, DataType.PARENT);
|
||||
public final static OptionNode MOVING_CHECK = new OptionNode("check", MOVING, DataType.BOOLEAN);
|
||||
|
@ -0,0 +1,48 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.ConfigItem;
|
||||
|
||||
/**
|
||||
* A class to keep all configurables of the plugin associated with
|
||||
* a world
|
||||
*
|
||||
*/
|
||||
public class ConfigurationCacheStore {
|
||||
|
||||
public final CCLogging logging;
|
||||
public final CCDebug debug;
|
||||
|
||||
private final Map<String, ConfigItem> configMap = new HashMap<String, ConfigItem>();
|
||||
|
||||
private final Configuration data;
|
||||
|
||||
/**
|
||||
* Instantiate a config cache and populate it with the data of a
|
||||
* Config tree (and its parent tree)
|
||||
*/
|
||||
public ConfigurationCacheStore(Configuration data, Logger worldSpecificFileLogger) {
|
||||
|
||||
logging = new CCLogging(data, worldSpecificFileLogger);
|
||||
debug = new CCDebug(data);
|
||||
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends ConfigItem>T get(String id) {
|
||||
return (T) configMap.get(id);
|
||||
}
|
||||
|
||||
public void set(String id, ConfigItem config) {
|
||||
|
||||
configMap.put(id, config);
|
||||
}
|
||||
|
||||
public Configuration getConfiguration() {
|
||||
return this.data;
|
||||
}
|
||||
}
|
@ -15,7 +15,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper;
|
||||
|
||||
/**
|
||||
@ -24,17 +23,17 @@ import cc.co.evenprime.bukkit.nocheat.config.util.ActionMapper;
|
||||
*/
|
||||
public class ConfigurationManager {
|
||||
|
||||
private final static String configFileName = "config.txt";
|
||||
private final static String actionFileName = "actions.txt";
|
||||
private final static String defaultActionFileName = "default_actions.txt";
|
||||
private final static String configFileName = "config.txt";
|
||||
private final static String actionFileName = "actions.txt";
|
||||
private final static String defaultActionFileName = "default_actions.txt";
|
||||
|
||||
private final Map<String, ConfigurationCache> worldnameToConfigCacheMap = new HashMap<String, ConfigurationCache>();
|
||||
private final Map<String, ConfigurationCacheStore> worldnameToConfigCacheMap = new HashMap<String, ConfigurationCacheStore>();
|
||||
|
||||
// Only use one filehandler per file, therefore keep open filehandlers in a
|
||||
// map
|
||||
private final Map<File, FileHandler> fileToFileHandlerMap = new HashMap<File, FileHandler>();
|
||||
private final Map<File, FileHandler> fileToFileHandlerMap = new HashMap<File, FileHandler>();
|
||||
|
||||
private final Configuration defaultConfig;
|
||||
private final Configuration defaultConfig;
|
||||
|
||||
private static class LogFileFormatter extends Formatter {
|
||||
|
||||
@ -136,7 +135,7 @@ public class ConfigurationManager {
|
||||
|
||||
// Create a corresponding Configuration Cache
|
||||
// put the global config on the config map
|
||||
worldnameToConfigCacheMap.put(null, new ConfigurationCache(root, setupFileLogger(new File(rootConfigFolder, root.getString(DefaultConfiguration.LOGGING_FILENAME)))));
|
||||
worldnameToConfigCacheMap.put(null, new ConfigurationCacheStore(root, setupFileLogger(new File(rootConfigFolder, root.getString(DefaultConfiguration.LOGGING_FILENAME)))));
|
||||
|
||||
// Try to find world-specific config files
|
||||
Map<String, File> worldFiles = getWorldSpecificConfigFiles(rootConfigFolder);
|
||||
@ -162,9 +161,9 @@ public class ConfigurationManager {
|
||||
}
|
||||
}
|
||||
|
||||
private ConfigurationCache createConfigurationCache(File rootConfigFolder, Configuration configProvider) {
|
||||
private ConfigurationCacheStore createConfigurationCache(File rootConfigFolder, Configuration configProvider) {
|
||||
|
||||
return new ConfigurationCache(configProvider, setupFileLogger(new File(rootConfigFolder, configProvider.getString(DefaultConfiguration.LOGGING_FILENAME))));
|
||||
return new ConfigurationCacheStore(configProvider, setupFileLogger(new File(rootConfigFolder, configProvider.getString(DefaultConfiguration.LOGGING_FILENAME))));
|
||||
|
||||
}
|
||||
|
||||
@ -238,7 +237,7 @@ public class ConfigurationManager {
|
||||
public void cleanup() {
|
||||
|
||||
// Remove handlers from the logger
|
||||
for(ConfigurationCache c : worldnameToConfigCacheMap.values()) {
|
||||
for(ConfigurationCacheStore c : worldnameToConfigCacheMap.values()) {
|
||||
for(Handler h : c.logging.filelogger.getHandlers()) {
|
||||
c.logging.filelogger.removeHandler(h);
|
||||
}
|
||||
@ -258,9 +257,9 @@ public class ConfigurationManager {
|
||||
* @param worldname
|
||||
* @return
|
||||
*/
|
||||
public ConfigurationCache getConfigurationCacheForWorld(String worldname) {
|
||||
public ConfigurationCacheStore getConfigurationCacheForWorld(String worldname) {
|
||||
|
||||
ConfigurationCache cache = worldnameToConfigCacheMap.get(worldname);
|
||||
ConfigurationCacheStore cache = worldnameToConfigCacheMap.get(worldname);
|
||||
|
||||
if(cache != null) {
|
||||
return cache;
|
||||
|
@ -30,7 +30,7 @@ public class Explainations {
|
||||
set(Configuration.INVENTORY_PREVENTITEMDUPE, "Close inventories of players before they get teleported between worlds, preventing creation of duplicate items.");
|
||||
set(Configuration.INVENTORY_CHECK, "If true, do various checks on Inventory related things.");
|
||||
set(Configuration.INVENTORY_DROP_CHECK, "If true, prevent players from dropping too many items in a short timeframe to reduce lag");
|
||||
set(Configuration.INVENTORY_DROP_TIMEFRAME , "Over how many seconds should item drops be counted.");
|
||||
set(Configuration.INVENTORY_DROP_TIMEFRAME, "Over how many seconds should item drops be counted.");
|
||||
set(Configuration.INVENTORY_DROP_LIMIT, "How many seperate items should the player be allowed to drop during that timeframe");
|
||||
set(Configuration.INVENTORY_DROP_ACTIONS, "What should be done if a player drops more items than that.\nUnit is item drops above the limit.");
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.config.cache;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Configuration;
|
||||
|
||||
/**
|
||||
* A class to keep all configurables of the plugin associated with
|
||||
* a world, everything unmodifiable for security/performance
|
||||
*
|
||||
*/
|
||||
public class ConfigurationCache {
|
||||
|
||||
public final CCMoving moving;
|
||||
public final CCLogging logging;
|
||||
public final CCBlockBreak blockbreak;
|
||||
public final CCBlockPlace blockplace;
|
||||
public final CCChat chat;
|
||||
public final CCDebug debug;
|
||||
public final CCFight fight;
|
||||
public final CCInventory inventory;
|
||||
|
||||
/**
|
||||
* Instantiate a config cache and populate it with the data of a
|
||||
* Config tree (and its parent tree)
|
||||
*/
|
||||
public ConfigurationCache(Configuration data, Logger worldSpecificFileLogger) {
|
||||
|
||||
moving = new CCMoving(data);
|
||||
blockbreak = new CCBlockBreak(data);
|
||||
blockplace = new CCBlockPlace(data);
|
||||
chat = new CCChat(data);
|
||||
logging = new CCLogging(data, worldSpecificFileLogger);
|
||||
debug = new CCDebug(data);
|
||||
fight = new CCFight(data);
|
||||
inventory = new CCInventory(data);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class BaseData extends Data {
|
||||
|
||||
public final BlockBreakData blockbreak;
|
||||
public final BlockPlaceData blockplace;
|
||||
public final ChatData chat;
|
||||
public final MovingData moving;
|
||||
public final FightData fight;
|
||||
public final InventoryData inventory;
|
||||
|
||||
private final Data[] data; // for convenience
|
||||
|
||||
private final long timestamp;
|
||||
|
||||
public BaseData() {
|
||||
this.blockbreak = new BlockBreakData();
|
||||
this.blockplace = new BlockPlaceData();
|
||||
this.chat = new ChatData();
|
||||
this.moving = new MovingData();
|
||||
this.fight = new FightData();
|
||||
this.inventory = new InventoryData();
|
||||
|
||||
data = new Data[] {this.blockbreak, this.blockplace, this.chat,
|
||||
this.moving, this.fight, this.inventory};
|
||||
|
||||
this.timestamp = System.currentTimeMillis();
|
||||
|
||||
}
|
||||
|
||||
public void clearCriticalData() {
|
||||
for(Data d : data) {
|
||||
d.clearCriticalData();
|
||||
}
|
||||
}
|
||||
|
||||
public void collectData(Map<String, Object> map) {
|
||||
for(Data d : data) {
|
||||
d.collectData(map);
|
||||
}
|
||||
|
||||
map.put("nocheat.starttime", timestamp);
|
||||
map.put("nocheat.endtime", System.currentTimeMillis());
|
||||
}
|
||||
}
|
@ -2,10 +2,12 @@ package cc.co.evenprime.bukkit.nocheat.data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class ChatData extends Data {
|
||||
public class ChatData implements DataItem {
|
||||
|
||||
public int spamVL;
|
||||
public int spamTotalVL;
|
||||
@ -26,4 +28,9 @@ public class ChatData extends Data {
|
||||
map.put("chat.spam.failed", spamFailed);
|
||||
map.put("chat.empty.failed", emptyFailed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCriticalData() {
|
||||
|
||||
}
|
||||
}
|
||||
|
37
src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java
Normal file
37
src/cc/co/evenprime/bukkit/nocheat/data/DataStore.java
Normal file
@ -0,0 +1,37 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.data;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.DataItem;
|
||||
|
||||
public class DataStore {
|
||||
|
||||
private final Map<String, DataItem> dataMap = new HashMap<String, DataItem>();
|
||||
|
||||
private final long timestamp = System.currentTimeMillis();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends DataItem>T get(String id) {
|
||||
return (T) dataMap.get(id);
|
||||
}
|
||||
|
||||
public void set(String id, DataItem data) {
|
||||
dataMap.put(id, data);
|
||||
}
|
||||
|
||||
public void clearCriticalData() {
|
||||
for(DataItem data : dataMap.values()) {
|
||||
data.clearCriticalData();
|
||||
}
|
||||
}
|
||||
|
||||
public void collectData(Map<String, Object> map) {
|
||||
for(DataItem data : dataMap.values()) {
|
||||
data.collectData(map);
|
||||
}
|
||||
|
||||
map.put("nocheat.starttime", timestamp);
|
||||
map.put("nocheat.endtime", System.currentTimeMillis());
|
||||
}
|
||||
}
|
@ -52,14 +52,14 @@ public class PlayerManager {
|
||||
*/
|
||||
public void clearCriticalData() {
|
||||
for(NoCheatPlayer b : this.players.values()) {
|
||||
b.getData().clearCriticalData();
|
||||
b.getDataStore().clearCriticalData();
|
||||
}
|
||||
}
|
||||
|
||||
public void clearCriticalData(String playerName) {
|
||||
NoCheatPlayer p = this.players.get(playerName.toLowerCase());
|
||||
if(p != null) {
|
||||
p.getData().clearCriticalData();
|
||||
p.getDataStore().clearCriticalData();
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,9 +83,8 @@ public class PlayerManager {
|
||||
NoCheatPlayer player = this.players.get(playerName.toLowerCase());
|
||||
|
||||
if(player != null) {
|
||||
BaseData data = player.getData();
|
||||
player.getDataStore().collectData(map);
|
||||
|
||||
data.collectData(map);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@ import org.bukkit.World;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.events.EventManagerImpl;
|
||||
import cc.co.evenprime.bukkit.nocheat.log.LogLevel;
|
||||
|
||||
@ -24,7 +24,7 @@ public class ActiveCheckPrinter {
|
||||
|
||||
int length = line.length();
|
||||
|
||||
ConfigurationCache cc = plugin.getConfig(world);
|
||||
ConfigurationCacheStore cc = plugin.getConfig(world);
|
||||
|
||||
if(!cc.debug.showchecks)
|
||||
continue;
|
||||
|
@ -27,7 +27,7 @@ public class LagMeasureTask implements Runnable {
|
||||
// If the previous second took to long, skip checks during
|
||||
// this second
|
||||
skipCheck = lastIngamesecondDuration > 1500;
|
||||
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
lastIngamesecondDuration = time - lastIngamesecondTime;
|
||||
if(lastIngamesecondDuration < 1000)
|
||||
@ -38,13 +38,12 @@ public class LagMeasureTask implements Runnable {
|
||||
}
|
||||
lastIngamesecondTime = time;
|
||||
ingameseconds++;
|
||||
|
||||
|
||||
// Check if some data is outdated now and let it be removed
|
||||
if(ingameseconds % 62 == 0) {
|
||||
plugin.cleanDataMap();
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
} catch(Exception e) {
|
||||
// Just prevent this thread from dying for whatever reason
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.EventManager;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
|
||||
/**
|
||||
@ -157,7 +157,7 @@ public abstract class EventManagerImpl implements EventManager {
|
||||
m.handlePlayerMoveEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPlayerDropItem(final PlayerDropItemEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
@ -382,7 +382,7 @@ public abstract class EventManagerImpl implements EventManager {
|
||||
* .co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache)
|
||||
*/
|
||||
@Override
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
public List<String> getActiveChecks(ConfigurationCacheStore cc) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@ -453,7 +453,7 @@ public abstract class EventManagerImpl implements EventManager {
|
||||
protected void handleCustomDamageByPlayerEvent(EntityDamageByEntityEvent event, Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
||||
|
||||
protected void handlePlayerDropItemEvent(PlayerDropItemEvent event, Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
@ -56,7 +55,7 @@ public class WorkaroundsEventManager extends EventManagerImpl {
|
||||
|
||||
// Fix a common mistake that other developers make (cancelling move
|
||||
// events is crazy, rather set the target location to the from location)
|
||||
if(plugin.getPlayer(event.getPlayer()).getConfiguration().debug.overrideIdiocy) {
|
||||
if(plugin.getPlayer(event.getPlayer()).getConfigurationStore().debug.overrideIdiocy) {
|
||||
event.setCancelled(false);
|
||||
event.setTo(event.getFrom().clone());
|
||||
}
|
||||
@ -65,15 +64,12 @@ public class WorkaroundsEventManager extends EventManagerImpl {
|
||||
@Override
|
||||
protected void handlePlayerToggleSprintEvent(final PlayerToggleSprintEvent event, final Priority priority) {
|
||||
if(event.isCancelled() && event.isSprinting()) {
|
||||
if(plugin.getPlayer(event.getPlayer()).getConfiguration().debug.overrideIdiocy)
|
||||
if(plugin.getPlayer(event.getPlayer()).getConfigurationStore().debug.overrideIdiocy)
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleTeleportation(final Player player, final Location to) {
|
||||
if(plugin.getPlayer(player).getConfiguration().inventory.closebeforeteleports && player instanceof CraftPlayer && to != null && !(to.getWorld().equals(player.getWorld()))) {
|
||||
((CraftPlayer) player).getHandle().closeInventory();
|
||||
}
|
||||
plugin.clearCriticalData(player.getName());
|
||||
}
|
||||
}
|
||||
|
@ -6,8 +6,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
|
||||
/**
|
||||
* Manage logging throughout NoCheat. Messages may be logged directly to a
|
||||
@ -28,7 +28,7 @@ public class LogManager {
|
||||
* @param message
|
||||
* @param cc
|
||||
*/
|
||||
public void log(LogLevel level, String message, ConfigurationCache cc) {
|
||||
public void log(LogLevel level, String message, ConfigurationCacheStore cc) {
|
||||
|
||||
if(!cc.logging.active)
|
||||
return;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.player;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
|
||||
@ -11,30 +9,29 @@ 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;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.ConfigurationCacheStore;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.DataStore;
|
||||
|
||||
public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
|
||||
protected Player player;
|
||||
protected final NoCheat plugin;
|
||||
protected final BaseData data;
|
||||
protected long lastUsedTime;
|
||||
|
||||
// The method that's used to artifically "fast-forward" the player
|
||||
protected static Method incAge = null;
|
||||
protected Player player;
|
||||
protected final NoCheat plugin;
|
||||
protected final DataStore data;
|
||||
protected ConfigurationCacheStore config;
|
||||
protected long lastUsedTime;
|
||||
|
||||
public NoCheatPlayerImpl(Player player, NoCheat plugin) {
|
||||
|
||||
this.player = player;
|
||||
this.plugin = plugin;
|
||||
this.data = new BaseData();
|
||||
this.data = new DataStore();
|
||||
|
||||
this.lastUsedTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public void refresh(Player player) {
|
||||
this.player = player;
|
||||
this.config = plugin.getConfig(player);
|
||||
}
|
||||
|
||||
public boolean isDead() {
|
||||
@ -49,18 +46,18 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
return player.hasPermission(permission);
|
||||
}
|
||||
|
||||
public BaseData getData() {
|
||||
public DataStore getDataStore() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public ConfigurationCacheStore getConfigurationStore() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public ConfigurationCache getConfiguration() {
|
||||
return plugin.getConfig(player);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return player.getName();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user