Lots of renames and moving stuff around to be better organized

This commit is contained in:
Evenprime 2011-03-01 15:17:12 +01:00
parent 2bca8f5ead
commit 11bba9e6ae
13 changed files with 166 additions and 114 deletions

View File

@ -3,5 +3,5 @@ name: NoCheatPlugin
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheatPlugin
version: 0.6
version: 0.6a

View File

@ -24,20 +24,29 @@ public class NoCheatConfiguration {
public static final Logger logger = Logger.getLogger(loggerName);
// Which checks are active
public static boolean speedhackCheckActive = true;
public static boolean movingCheckActive = true;
public static boolean airbuildCheckActive = false;
public static boolean dupebydeathCheckActive = false;
public static boolean speedhackCheckActive;
public static boolean movingCheckActive;
public static boolean airbuildCheckActive;
public static boolean dupebydeathCheckActive;
// Limits for the speedhack check
public static int speedhackLow = 30;
public static int speedhackMed = 45;
public static int speedhackHigh = 60;
public static int speedhackLimitLow;
public static int speedhackLimitMed;
public static int speedhackLimitHigh;
// How should speedhack violations be treated?
public static String speedhackActionMinor = "";
public static String speedhackActionNormal = "";
public static String speedhackActionHeavy = "";
public static int movingFreeMoves = 10;
// Should moving violations be punished?
public static boolean movingLogOnly = false;
// How should moving violations be treated?
public static String movingActionMinor = "";
public static String movingActionNormal = "";
public static String movingActionHeavy = "";
public static boolean movingLogOnly;
// The log level above which players with the permission nocheat.notify will get informed about violations
public static Level notifyLevel = Level.OFF;
@ -93,13 +102,22 @@ public class NoCheatConfiguration {
airbuildCheckActive = c.getBoolean("active.airbuild", false);
dupebydeathCheckActive = c.getBoolean("active.dupebydeath", false);
speedhackLow = c.getInt("speedhack.limits.low", 30);
speedhackMed = c.getInt("speedhack.limits.med", 45);
speedhackHigh = c.getInt("speedhack.limits.high", 60);
speedhackLimitLow = c.getInt("speedhack.limits.low", 30);
speedhackLimitMed = c.getInt("speedhack.limits.med", 45);
speedhackLimitHigh = c.getInt("speedhack.limits.high", 60);
movingLogOnly = c.getBoolean("moving.logonly", false);
movingFreeMoves = c.getInt("moving.freemoves", 10);
movingActionMinor = c.getString("moving.action.low", "log reset");
movingActionNormal = c.getString("moving.action.med", "log reset");
movingActionHeavy = c.getString("moving.action.high", "log reset");
speedhackActionMinor = c.getString("speedhack.action.low", "log");
speedhackActionNormal = c.getString("speedhack.action.med", "log");
speedhackActionHeavy = c.getString("speedhack.action.high", "log");
if(movingFreeMoves < 10) movingFreeMoves = 10;
}
@ -114,9 +132,9 @@ public class NoCheatConfiguration {
return Level.OFF;
}
if(string.trim().equals("info")) return Level.INFO;
if(string.trim().equals("warn")) return Level.WARNING;
if(string.trim().equals("severe")) return Level.SEVERE;
if(string.trim().equals("info") || string.trim().equals("low")) return Level.INFO;
if(string.trim().equals("warn") || string.trim().equals("med")) return Level.WARNING;
if(string.trim().equals("severe")|| string.trim().equals("high")) return Level.SEVERE;
return Level.OFF;
}
@ -130,27 +148,35 @@ public class NoCheatConfiguration {
f.createNewFile();
BufferedWriter w = new BufferedWriter(new FileWriter(f));
w.write("# Logging: potential log levels are info, warn, severe, off"); w.newLine();
w.write("# Logging: potential log levels are low (info), med (warn), high (severe), off"); w.newLine();
w.write("logging:"); w.newLine();
w.write(" filename: plugins/NoCheat/nocheat.log"); w.newLine();
w.write(" logtofile: info"); w.newLine();
w.write(" logtoconsole: severe"); w.newLine();
w.write(" logtonotify: warn"); w.newLine();
w.write("# Checks that are activated (true or false)"); w.newLine();
w.write(" logtofile: low"); w.newLine();
w.write(" logtoconsole: high"); w.newLine();
w.write(" logtonotify: med"); w.newLine();
w.write("# Checks and Preventions that are activated (true or false)"); w.newLine();
w.write("active:"); w.newLine();
w.write(" speedhack: true"); w.newLine();
w.write(" moving: true"); w.newLine();
w.write(" airbuild: false"); w.newLine();
w.write(" dupebydeath: false"); w.newLine();
w.write("# Speedhack: interval in milliseconds, limits are events in that interval") ;w.newLine();
w.write("# Speedhack specific options. Limits are move-events per second, action is what should happen in each case") ;w.newLine();
w.write("speedhack:"); w.newLine();
w.write(" limits:"); w.newLine();
w.write(" low: 30"); w.newLine();
w.write(" med: 45"); w.newLine();
w.write(" high: 60"); w.newLine();
w.write(" action:"); w.newLine();
w.write(" low: loglow"); w.newLine();
w.write(" med: logmed"); w.newLine();
w.write(" high: loghigh"); w.newLine();
w.write("# Moving specific options. Higher freemoves values mean less strict checks, action is what should happen in each case") ;w.newLine();
w.write("moving:"); w.newLine();
w.write(" logonly: false"); w.newLine();
w.write(" freemoves: 10"); w.newLine();
w.write(" action:"); w.newLine();
w.write(" low: loglow reset"); w.newLine();
w.write(" med: logmed reset"); w.newLine();
w.write(" high: loghigh reset"); w.newLine();
w.flush(); w.close();
} catch (IOException e) {
// TODO Auto-generated catch block

View File

@ -0,0 +1,32 @@
package cc.co.evenprime.bukkit.nocheat;
import org.bukkit.Location;
/**
* Storage for data persistence between events
*
* @author Evenprime
*
*/
public class NoCheatData {
/**
* Don't rely on any of these yet, they are likely going to change their name/functionality
*/
public int movingJumpPhase = 0; // current jumpingPhase
public int movingMinorViolationsInARow = 0;
public int movingNormalViolationsInARow = 0;
public int movingHeavyViolationsInARow = 0;
public Location movingSetBackPoint = null;
public int movingIgnoreNextXEvents = 0;
public long speedhackLastCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks
public int speedhackEventsSinceLastCheck = 0; // used to identify speedhacks
public int speedhackViolationsInARow = 0;
NoCheatData() { }
}

View File

@ -13,6 +13,11 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatBlockListener;
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatEntityListener;
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatPlayerListener;
import cc.co.evenprime.bukkit.nocheat.listeners.NoCheatVehicleListener;
import com.nijikokun.bukkit.Permissions.Permissions;
import com.nijiko.permissions.PermissionHandler;
import org.bukkit.plugin.Plugin;
@ -28,63 +33,43 @@ import org.bukkit.plugin.Plugin;
public class NoCheatPlugin extends JavaPlugin {
// Various listeners needed for different Checks
private final NoCheatPluginPlayerListener playerListener;
private final NoCheatPluginVehicleListener vehicleListener;
private final NoCheatPluginBlockListener blockListener;
private final NoCheatEntityListener entityListener;
private NoCheatPlayerListener playerListener;
private NoCheatVehicleListener vehicleListener;
private NoCheatBlockListener blockListener;
private NoCheatEntityListener entityListener;
// My main logger
private static Logger log;
private static NoCheatPlugin p;
// Permissions 2.0, if available
public static PermissionHandler Permissions = null;
// A reference to the instance of the plugin
private static NoCheatPlugin p = null;
// Store data between Events
public static Map<Player, NoCheatPluginData> playerData = new HashMap<Player, NoCheatPluginData>();
public static Map<Player, NoCheatData> playerData = new HashMap<Player, NoCheatData>();
/**
* Ridiculously long constructor to keep supporting older bukkit versions, as long as it is possible
*
* @param pluginLoader
* @param instance
* @param desc
* @param f1
* @param f2
* @param cLoader
*/
public NoCheatPlugin() {
// Create our listeners and feed them with neccessary information
playerListener = new NoCheatPluginPlayerListener();
vehicleListener = new NoCheatPluginVehicleListener(playerListener);
blockListener = new NoCheatPluginBlockListener();
entityListener = new NoCheatEntityListener();
log = NoCheatConfiguration.logger;
public NoCheatPlugin() {
p = this;
}
/**
* Main access to data that needs to be stored between different events.
* Always returns a NoCheatPluginData object, because if there isn't one
* Always returns a NoCheatData object, because if there isn't one
* for the specified player, one will be created.
*
* @param p
* @return
*/
public static NoCheatPluginData getPlayerData(Player p) {
NoCheatPluginData data = null;
public static NoCheatData getPlayerData(Player p) {
NoCheatData data = null;
if((data = playerData.get(p)) == null ) {
synchronized(playerData) {
data = playerData.get(p);
if(data == null) {
// If we have no data for the player, create some
data = new NoCheatPluginData();
data = new NoCheatData();
playerData.put(p, data);
}
}
@ -96,11 +81,17 @@ public class NoCheatPlugin extends JavaPlugin {
public void onDisable() {
PluginDescriptionFile pdfFile = this.getDescription();
Logger.getLogger("Minecraft").info( "[NoCheatPlugin] version [" + pdfFile.getVersion() + "] is disabled.");
}
public void onEnable() {
// Create our listeners and feed them with neccessary information
playerListener = new NoCheatPlayerListener();
vehicleListener = new NoCheatVehicleListener(playerListener);
blockListener = new NoCheatBlockListener();
entityListener = new NoCheatEntityListener();
log = NoCheatConfiguration.logger;
PluginManager pm = getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Lowest, this); // needed for speedhack and moving checks
pm.registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Monitor, this); // used to delete old data of users

View File

@ -1,30 +0,0 @@
package cc.co.evenprime.bukkit.nocheat;
import org.bukkit.Location;
/**
* Storage for data persistence between events
*
* @author Evenprime
*
*/
public class NoCheatPluginData {
/**
* Don't rely on any of these yet, they are likely going to change their name/functionality
*/
int movingIgnoreNextXEvents = 0;
int movingJumpPhase = 0; // current jumpingPhase
int movingMinorViolationsInARow = 0;
int movingNormalViolationsInARow = 0;
int movingHeavyViolationsInARow = 0;
Location movingSetBackPoint = null;
long speedhackLastCheck = System.currentTimeMillis(); // timestamp of last check for speedhacks
int speedhackEventsSinceLastCheck = 0; // used to identify speedhacks
int speedhackViolationsInARow = 0;
NoCheatPluginData() { }
}

View File

@ -1,10 +1,12 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.checks;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.block.BlockPlaceEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
/**
* Check if the player tries to place blocks in midair (which shouldn't be possible)

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.checks;
import java.util.List;
@ -7,6 +7,8 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
public class DupePrevention {
/**
@ -19,6 +21,14 @@ public class DupePrevention {
Player p = (Player)event.getEntity();
// Should we prevent at all?
if(NoCheatPlugin.Permissions != null && NoCheatPlugin.Permissions.has(p, "nocheat.dupebydeath")) {
return;
}
else if(NoCheatPlugin.Permissions == null && p.isOp() ) {
return;
}
PlayerInventory playerInventory = p.getInventory();
List<ItemStack> drops = event.getDrops();

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.checks;
import org.bukkit.Location;
@ -6,6 +6,10 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.event.player.PlayerMoveEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
/**
* Check if the player should be allowed to make that move, e.g. is he allowed to jump here or move that far in one step
*
@ -128,7 +132,7 @@ public class MovingCheck {
}
public static void check(NoCheatPluginData data, PlayerMoveEvent event) {
public static void check(NoCheatData data, PlayerMoveEvent event) {
// Should we check at all
if(NoCheatPlugin.Permissions != null && NoCheatPlugin.Permissions.has(event.getPlayer(), "nocheat.moving")) {
@ -271,7 +275,7 @@ public class MovingCheck {
}
protected static void minorViolation(NoCheatPluginData data, PlayerMoveEvent event) {
protected static void minorViolation(NoCheatData data, PlayerMoveEvent event) {
// If it is the first violation, store the "from" location for potential later use
if(data.movingMinorViolationsInARow == 0) {
@ -296,7 +300,7 @@ public class MovingCheck {
}
}
protected static void normalViolation(NoCheatPluginData data, PlayerMoveEvent event) {
protected static void normalViolation(NoCheatData data, PlayerMoveEvent event) {
// Log the first violation in a row
if(data.movingNormalViolationsInARow == 0)
NoCheatPlugin.logNormal("NoCheatPlugin: Moving violation: "+event.getPlayer().getName()+" from " + String.format("(%.5f, %.5f, %.5f) to (%.5f, %.5f, %.5f)", event.getFrom().getX(), event.getFrom().getY(), event.getFrom().getZ(), event.getTo().getX(), event.getTo().getY(), event.getTo().getZ()));
@ -306,7 +310,7 @@ public class MovingCheck {
data.movingNormalViolationsInARow++;
}
protected static void heavyViolation(NoCheatPluginData data, PlayerMoveEvent event) {
protected static void heavyViolation(NoCheatData data, PlayerMoveEvent event) {
// Log the first violation in a row
if(data.movingHeavyViolationsInARow == 0)
@ -317,7 +321,7 @@ public class MovingCheck {
data.movingHeavyViolationsInARow++;
}
protected static void legitimateMove(NoCheatPluginData data, PlayerMoveEvent event) {
protected static void legitimateMove(NoCheatData data, PlayerMoveEvent event) {
// Give some additional logs about now ending violations
if(data.movingHeavyViolationsInARow > 0) {
NoCheatPlugin.logHeavy("NoCheatPlugin: Moving violation stopped: "+event.getPlayer().getName() + " total Events: "+ data.movingHeavyViolationsInARow);
@ -345,7 +349,7 @@ public class MovingCheck {
* @param data
* @param event
*/
private static void resetPlayer(NoCheatPluginData data, PlayerMoveEvent event) {
private static void resetPlayer(NoCheatData data, PlayerMoveEvent event) {
// If we only log, we never reset the player to his original location and can end here already
if(NoCheatConfiguration.movingLogOnly) return;

View File

@ -1,7 +1,11 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.checks;
import org.bukkit.event.player.PlayerMoveEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
/**
* Log if a player sends to many move events in a specific time frame, usually the result of tinkering with the system clock
*
@ -19,7 +23,7 @@ public class SpeedhackCheck {
private static final long interval = 1000;
private static final int violationsLimit = 3;
public static void check(NoCheatPluginData data, PlayerMoveEvent event) {
public static void check(NoCheatData data, PlayerMoveEvent event) {
// Should we check at all?
if(NoCheatPlugin.Permissions != null && NoCheatPlugin.Permissions.has(event.getPlayer(), "nocheat.speedhack")) {
@ -39,9 +43,9 @@ public class SpeedhackCheck {
// Yes
// TODO: Needs some better handling for server lag
int limitLow = (int)((NoCheatConfiguration.speedhackLow * (time - data.speedhackLastCheck)) / interval);
int limitMed = (int)((NoCheatConfiguration.speedhackMed * (time - data.speedhackLastCheck)) / interval);
int limitHigh = (int)((NoCheatConfiguration.speedhackHigh * (time - data.speedhackLastCheck)) / interval);
int limitLow = (int)((NoCheatConfiguration.speedhackLimitLow * (time - data.speedhackLastCheck)) / interval);
int limitMed = (int)((NoCheatConfiguration.speedhackLimitMed * (time - data.speedhackLastCheck)) / interval);
int limitHigh = (int)((NoCheatConfiguration.speedhackLimitHigh * (time - data.speedhackLastCheck)) / interval);
if(data.speedhackEventsSinceLastCheck > limitHigh) vl = HEAVY;

View File

@ -1,18 +1,21 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.checks.BlockPlacingCheck;
/**
* Handle events for all Block related events
*
* @author Evenprime
*
*/
public class NoCheatPluginBlockListener extends BlockListener {
public class NoCheatBlockListener extends BlockListener {
public NoCheatPluginBlockListener() {
public NoCheatBlockListener() {
}

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.listeners;
import java.util.List;
@ -8,6 +8,9 @@ import org.bukkit.event.entity.EntityListener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import cc.co.evenprime.bukkit.nocheat.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.checks.DupePrevention;
public class NoCheatEntityListener extends EntityListener {
@Override

View File

@ -1,4 +1,4 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.listeners;
@ -7,17 +7,23 @@ import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheatConfiguration;
import cc.co.evenprime.bukkit.nocheat.NoCheatData;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlugin;
import cc.co.evenprime.bukkit.nocheat.checks.MovingCheck;
import cc.co.evenprime.bukkit.nocheat.checks.SpeedhackCheck;
/**
* Handle events for all Player related events
*
* @author Evenprime
*/
public class NoCheatPluginPlayerListener extends PlayerListener {
public class NoCheatPlayerListener extends PlayerListener {
public NoCheatPluginPlayerListener() { }
public NoCheatPlayerListener() { }
@Override
public void onPlayerQuit(PlayerEvent event) {
@ -26,7 +32,7 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
public void ingoreNextXEvents(Entity player, int count) {
NoCheatPluginData data = NoCheatPlugin.playerData.get(player);
NoCheatData data = NoCheatPlugin.playerData.get(player);
if(data != null) {
data.movingIgnoreNextXEvents = count;
}
@ -36,7 +42,7 @@ public class NoCheatPluginPlayerListener extends PlayerListener {
public void onPlayerMove(PlayerMoveEvent event) {
// Get the player-specific data
NoCheatPluginData data = NoCheatPlugin.getPlayerData(event.getPlayer());
NoCheatData data = NoCheatPlugin.getPlayerData(event.getPlayer());
if(data.movingIgnoreNextXEvents > 0 ) {
data.movingIgnoreNextXEvents--;

View File

@ -1,21 +1,22 @@
package cc.co.evenprime.bukkit.nocheat;
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.event.vehicle.VehicleDamageEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.event.vehicle.VehicleListener;
/**
* Handle events for all Player related events
*
* @author Evenprime
*/
public class NoCheatPluginVehicleListener extends VehicleListener {
public class NoCheatVehicleListener extends VehicleListener {
private final NoCheatPluginPlayerListener playerListener;
private final NoCheatPlayerListener playerListener;
public NoCheatPluginVehicleListener(NoCheatPluginPlayerListener playerListener) {
public NoCheatVehicleListener(NoCheatPlayerListener playerListener) {
this.playerListener = playerListener;
}