Removed no longer needed workarounds + lots of code formatting

This commit is contained in:
Evenprime 2011-08-09 15:58:05 +02:00
parent 33e9c46716
commit 7e0721da98
48 changed files with 2203 additions and 2311 deletions

View File

@ -3,7 +3,7 @@ name: NoCheat
author: Evenprime
main: cc.co.evenprime.bukkit.nocheat.NoCheat
version: 1.12
version: 1.12a
softdepend: [ Permissions, CraftIRC ]

View File

@ -42,8 +42,7 @@ public class CustomCommandSender implements CommandSender {
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name,
boolean value) {
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
// Whatever it is, I don't care
return null;
}
@ -55,8 +54,7 @@ public class CustomCommandSender implements CommandSender {
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String name,
boolean value, int ticks) {
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
// Whatever it is, I don't care
return null;
}

View File

@ -14,24 +14,25 @@ import cc.co.evenprime.bukkit.nocheat.data.NukeData;
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
import cc.co.evenprime.bukkit.nocheat.data.SpeedhackData;
public class DataManager {
// Store data between Events
private final Map<Player, NoCheatData> playerData = new HashMap<Player, NoCheatData>();
public DataManager() { }
public DataManager() {}
/**
* Go through the playerData HashMap and remove players that are no longer online
* from the map. This should be called in long, regular intervals (e.g. every 10 minutes)
* Go through the playerData HashMap and remove players that are no longer
* online
* from the map. This should be called in long, regular intervals (e.g.
* every 10 minutes)
* to keep the memory footprint of the plugin low
*/
public void cleanPlayerDataCollection() {
synchronized(playerData) {
Iterator<Map.Entry<Player, NoCheatData>> it = playerData.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Player, NoCheatData> pairs = (Map.Entry<Player, NoCheatData>)it.next();
while(it.hasNext()) {
Map.Entry<Player, NoCheatData> pairs = (Map.Entry<Player, NoCheatData>) it.next();
if(!pairs.getKey().isOnline()) {
// Cancel all referenced tasks before removing the entry
cancelTasks(pairs.getValue());
@ -42,7 +43,6 @@ public class DataManager {
}
}
/**
* Main access to data that needs to be stored between different events.
* Always returns a NoCheatData object, because if there isn't one
@ -51,7 +51,7 @@ public class DataManager {
* @param p
* @return
*/
public NoCheatData getPlayerData(Player p) {
private NoCheatData getPlayerData(final Player p) {
NoCheatData data = playerData.get(p);
if(data == null) {
@ -82,7 +82,6 @@ public class DataManager {
if(data.moving == null) {
data.moving = new MovingData();
data.moving.teleportedTo = p.getLocation();
}
return data.moving;
@ -121,16 +120,17 @@ public class DataManager {
return data.speedhack;
}
/**
* Go through the playerData HashMap and remove players that are no longer online
* from the map. This should be called in long, regular intervals (e.g. every 10 minutes)
* Go through the playerData HashMap and remove players that are no longer
* online
* from the map. This should be called in long, regular intervals (e.g.
* every 10 minutes)
* to keep the memory footprint of the plugin low
*/
public void cancelPlayerDataTasks() {
synchronized(playerData) {
Iterator<Map.Entry<Player, NoCheatData>> it = playerData.entrySet().iterator();
while (it.hasNext()) {
while(it.hasNext()) {
cancelTasks(it.next().getValue());
}
}
@ -145,8 +145,7 @@ public class DataManager {
if(id != -1) {
Bukkit.getServer().getScheduler().cancelTask(id);
}
else {
} else {
// To prevent accidentially creating a new one while cleaning up
d.summaryTask = 1;
}
@ -159,8 +158,7 @@ public class DataManager {
if(id != -1) {
Bukkit.getServer().getScheduler().cancelTask(id);
}
else {
} else {
// To prevent accidentially creating a new one while cleaning up
d2.summaryTask = 1;
}

View File

@ -7,6 +7,7 @@ import java.util.logging.Formatter;
import java.util.logging.LogRecord;
public class LogFileFormatter extends Formatter {
private final SimpleDateFormat date;
public LogFileFormatter() {
@ -25,7 +26,7 @@ public class LogFileFormatter extends Formatter {
builder.append(record.getMessage());
builder.append('\n');
if (ex != null) {
if(ex != null) {
StringWriter writer = new StringWriter();
ex.printStackTrace(new PrintWriter(writer));
builder.append(writer);

View File

@ -323,7 +323,9 @@ public class NoCheat extends JavaPlugin {
return false;
if(useNewPermissionSystem) {
//System.out.println("New permissions system asked for " + PermissionData.permissionNames[permission] + " got " + player.hasPermission(PermissionData.permissionNames[permission]));
// System.out.println("New permissions system asked for " +
// PermissionData.permissionNames[permission] + " got " +
// player.hasPermission(PermissionData.permissionNames[permission]));
return player.hasPermission(PermissionData.permissionNames[permission]);
}

View File

@ -9,7 +9,9 @@ public class CancelAction extends Action {
public final static CancelAction cancel = new CancelAction();
private CancelAction() { super(1, true); }
private CancelAction() {
super(1, true);
}
public String getName() {
return "cancel";

View File

@ -22,12 +22,10 @@ public class CustomAction extends Action {
public String getValue() {
if(firstAfter <= 1 && repeat) {
return command;
}
else if(repeat) {
return "["+firstAfter+"] "+ command;
}
else {
return "["+firstAfter+","+repeat+"] "+ command;
} else if(repeat) {
return "[" + firstAfter + "] " + command;
} else {
return "[" + firstAfter + "," + repeat + "] " + command;
}
}
}

View File

@ -15,7 +15,7 @@ public class LogAction extends Action {
public final static LogAction logmed = new LogAction(1, false, Level.WARNING);
public final static LogAction loghigh = new LogAction(1, false, Level.SEVERE);
public final static LogAction[] log = { loglow, logmed, loghigh };
public final static LogAction[] log = {loglow, logmed, loghigh};
private LogAction(int firstAfter, boolean repeat, Level level) {
super(firstAfter, repeat);

View File

@ -20,9 +20,9 @@ import cc.co.evenprime.bukkit.nocheat.data.AirbuildData;
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
import cc.co.evenprime.bukkit.nocheat.listeners.AirbuildBlockListener;
/**
* Check if the player tries to place blocks in midair (which shouldn't be possible)
* Check if the player tries to place blocks in midair (which shouldn't be
* possible)
*
* @author Evenprime
*
@ -41,10 +41,11 @@ public class AirbuildCheck extends Check {
public void check(BlockPlaceEvent event) {
// Should we check at all?
if(skipCheck(event.getPlayer())) return;
if(skipCheck(event.getPlayer()))
return;
// Are all 6 sides "air-blocks" -> cancel the event
if( event.getBlockAgainst().getType() == Material.AIR && event.getBlockPlaced().getType() != Material.AIR ) {
if(event.getBlockAgainst().getType() == Material.AIR && event.getBlockPlaced().getType() != Material.AIR) {
final AirbuildData data = plugin.getDataManager().getAirbuildData(event.getPlayer());
final Player p = event.getPlayer();
@ -57,7 +58,7 @@ public class AirbuildCheck extends Check {
summary(p, data);
// deleting its own reference
data.summaryTask = -1;
}catch(Exception e) {}
} catch(Exception e) {}
}
};
@ -68,9 +69,9 @@ public class AirbuildCheck extends Check {
data.perFiveSeconds++;
// which limit has been reached
for(int i = limits.length-1; i >= 0; i--) {
for(int i = limits.length - 1; i >= 0; i--) {
if(data.perFiveSeconds >= limits[i]) {
action(actions[i], event, data.perFiveSeconds - limits[i]+1);
action(actions[i], event, data.perFiveSeconds - limits[i] + 1);
break;
}
}
@ -79,7 +80,8 @@ public class AirbuildCheck extends Check {
private void action(Action actions[], BlockPlaceEvent event, int violations) {
if(actions == null) return;
if(actions == null)
return;
// Execute actions in order
for(Action a : actions) {
@ -87,14 +89,12 @@ public class AirbuildCheck extends Check {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
final Location l = event.getBlockPlaced().getLocation();
String logMessage = "Airbuild: "+event.getPlayer().getName()+" tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() +"," + l.getBlockZ();
plugin.log(((LogAction)a).level, logMessage);
}
else if(a instanceof CancelAction) {
String logMessage = "Airbuild: " + event.getPlayer().getName() + " tried to place block " + event.getBlockPlaced().getType() + " in the air at " + l.getBlockX() + "," + l.getBlockY() + "," + l.getBlockZ();
plugin.log(((LogAction) a).level, logMessage);
} else if(a instanceof CancelAction) {
event.setCancelled(true);
}
else if(a instanceof CustomAction) {
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
} else if(a instanceof CustomAction) {
plugin.handleCustomAction((CustomAction) a, event.getPlayer());
}
}
}
@ -103,10 +103,11 @@ public class AirbuildCheck extends Check {
private void summary(Player player, AirbuildData data) {
// Give a summary according to the highest violation level we encountered in that second
for(int i = limits.length-1; i >= 0; i--) {
// Give a summary according to the highest violation level we
// encountered in that second
for(int i = limits.length - 1; i >= 0; i--) {
if(data.perFiveSeconds >= limits[i]) {
plugin.log(LogAction.log[i].level, "Airbuild summary: " +player.getName() + " total violations per 5 seconds: " + data.perFiveSeconds);
plugin.log(LogAction.log[i].level, "Airbuild summary: " + player.getName() + " total violations per 5 seconds: " + data.perFiveSeconds);
break;
}
}
@ -132,7 +133,7 @@ public class AirbuildCheck extends Check {
setActive(config.getBooleanValue("active.airbuild"));
} catch (ConfigurationException e) {
} catch(ConfigurationException e) {
setActive(false);
e.printStackTrace();
}

View File

@ -23,14 +23,15 @@ import cc.co.evenprime.bukkit.nocheat.listeners.BogusitemsPlayerListener;
public class BogusitemsCheck extends Check {
public BogusitemsCheck(NoCheat plugin, NoCheatConfiguration config){
public BogusitemsCheck(NoCheat plugin, NoCheatConfiguration config) {
super(plugin, "bogusitems", PermissionData.PERMISSION_BOGUSITEMS, config);
}
public void check(PlayerPickupItemEvent event) {
// Should we check at all?
if(skipCheck(event.getPlayer())) return;
if(skipCheck(event.getPlayer()))
return;
Item i = event.getItem();
if(i != null) {
@ -49,7 +50,8 @@ public class BogusitemsCheck extends Check {
public void check(PlayerInteractEvent event) {
if(skipCheck(event.getPlayer())) return;
if(skipCheck(event.getPlayer()))
return;
if(event.hasItem() && event.getItem().getAmount() <= 0) {// buggy item
event.setCancelled(true);
@ -62,7 +64,8 @@ public class BogusitemsCheck extends Check {
public void check(PlayerDropItemEvent event) {
if(skipCheck(event.getPlayer())) return;
if(skipCheck(event.getPlayer()))
return;
Item item = event.getItemDrop();
@ -98,7 +101,7 @@ public class BogusitemsCheck extends Check {
try {
setActive(config.getBooleanValue("active.bogusitems"));
} catch (ConfigurationException e) {
} catch(ConfigurationException e) {
setActive(false);
e.printStackTrace();
}

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.ConfigurationException;
@ -29,12 +28,11 @@ public abstract class Check {
this.name = name;
try {
checkOPs= config.getBooleanValue(name + ".checkops");
} catch (ConfigurationException e) {
checkOPs = config.getBooleanValue(name + ".checkops");
} catch(ConfigurationException e) {
checkOPs = false;
}
configure(config);
}
@ -67,5 +65,4 @@ public abstract class Check {
return name;
}
}

View File

@ -1,25 +1,27 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
/**
* 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
* 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
*
* @author Evenprime
*
*/
public class FlyingCheck {
public FlyingCheck() { }
public FlyingCheck() {}
// How many move events can a player have in air before he is expected to lose altitude (or eventually land somewhere)
// How many move events can a player have in air before he is expected to
// lose altitude (or eventually land somewhere)
private final static int jumpingLimit = 5;
// How high may a player get compared to his last location with ground contact
// How high may a player get compared to his last location with ground
// contact
private final static double jumpHeight = 1.31D;
// How much points should hovering attempts cause?
@ -28,9 +30,9 @@ public class FlyingCheck {
// How high may a player move in one event on ground
private final static double stepHeight = 0.501D;
/**
* Calculate if and how much the player "failed" this check. The check should not
* Calculate if and how much the player "failed" this check. The check
* should not
* modify any data
*
*/
@ -45,13 +47,11 @@ public class FlyingCheck {
double limit = calculateVerticalLimit(data, fromOnGround) + jumpHeight;
// Walk or start Jump
if(fromOnGround)
{
if(fromOnGround) {
distanceAboveLimit = toY - Math.floor(fromY) - limit;
}
// Land or Fly/Fall
else
{
else {
final Location l;
if(data.setBackPoint == null)
@ -60,16 +60,18 @@ public class FlyingCheck {
l = data.setBackPoint;
if(data.jumpPhase > jumpingLimit) {
limit -= (data.jumpPhase-jumpingLimit) * 0.2D;
limit -= (data.jumpPhase - jumpingLimit) * 0.2D;
}
if(toOnGround) limit += stepHeight;
if(toOnGround)
limit += stepHeight;
distanceAboveLimit = toY - Math.floor(l.getY()) - limit;
// Always give some bonus points in case of identical Y values in midair (hovering player)
// Always give some bonus points in case of identical Y values in
// midair (hovering player)
if(fromY == toY && !toOnGround) {
distanceAboveLimit = Math.max(hoveringPunishment, distanceAboveLimit+hoveringPunishment);
distanceAboveLimit = Math.max(hoveringPunishment, distanceAboveLimit + hoveringPunishment);
}
}
@ -78,27 +80,34 @@ public class FlyingCheck {
private double calculateVerticalLimit(final MovingData data, final boolean onGroundFrom) {
// A halfway lag-resistant method of allowing vertical acceleration without allowing blatant cheating
// A halfway lag-resistant method of allowing vertical acceleration
// without allowing blatant cheating
// FACT: Minecraft server sends player "velocity" to the client and lets the client calculate the movement
// PROBLEM: There may be an arbitrary amount of other move events between the server sending the data
// and the client accepting it/reacting to it. The server can't know when the client starts to
// FACT: Minecraft server sends player "velocity" to the client and lets
// the client calculate the movement
// PROBLEM: There may be an arbitrary amount of other move events
// between the server sending the data
// and the client accepting it/reacting to it. The server can't know
// when the client starts to
// consider the sent "velocity" in its movement.
// SOLUTION: Give the client at least 10 events after sending "velocity" to actually use the velocity for
// its movement, plus additional events if the "velocity" was big and can cause longer flights
// SOLUTION: Give the client at least 10 events after sending "velocity"
// to actually use the velocity for
// its movement, plus additional events if the "velocity" was big and
// can cause longer flights
// The server sent the player a "velocity" packet a short time ago
// consume a counter for this client
if(data.vertFreedomCounter > 0) {
data.vertFreedomCounter--;
data.vertFreedom += data.maxYVelocity*2D;
data.vertFreedom += data.maxYVelocity * 2D;
data.maxYVelocity *= 0.90D;
}
final double limit = data.vertFreedom;
// If the event counter has been consumed, remove the vertical movement limit increase when landing the next time
// If the event counter has been consumed, remove the vertical movement
// limit increase when landing the next time
if(onGroundFrom && data.vertFreedomCounter <= 0) {
data.vertFreedom = 0.0D;
}

View File

@ -1,4 +1,3 @@
package cc.co.evenprime.bukkit.nocheat.checks;
import java.util.Locale;
@ -27,7 +26,8 @@ import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerListener;
import cc.co.evenprime.bukkit.nocheat.listeners.MovingPlayerMonitor;
/**
* 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
* 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
*
* @author Evenprime
*
@ -62,7 +62,11 @@ public class MovingCheck extends Check {
// How should moving violations be treated?
private Action actions[][];
public long statisticTotalEvents = 1; // Prevent accidental division by 0 at some point
public long statisticTotalEvents = 1; // Prevent
// accidental
// division by
// 0 at some
// point
private boolean enforceTeleport;
@ -76,11 +80,11 @@ public class MovingCheck extends Check {
* Second check if the player moved too far horizontally
* Third check if the player moved too high vertically
* Fourth treat any occured violations as configured
*
* @param event
*/
public Location check(Player player, Location from, Location to,
MovingData data) {
public Location check(Player player, Location from, Location to, MovingData data) {
Location newToLocation = null;
@ -94,10 +98,11 @@ public class MovingCheck extends Check {
if(flyCheck || runCheck) {
// In both cases it will be interesting to know the type of underground the player
// In both cases it will be interesting to know the type of
// underground the player
// is in or goes to
final int fromType = helper.isLocationOnGround(from.getWorld(), from.getX(), from.getY(), from.getZ(), waterElevators);
final int toType = helper.isLocationOnGround(to.getWorld(), to.getX(), to.getY(),to.getZ(), waterElevators);
final int toType = helper.isLocationOnGround(to.getWorld(), to.getX(), to.getY(), to.getZ(), waterElevators);
final boolean fromOnGround = fromType != MovingEventHelper.NONSOLID;
final boolean toOnGround = toType != MovingEventHelper.NONSOLID;
@ -109,16 +114,14 @@ public class MovingCheck extends Check {
if(flyCheck) {
result += Math.max(0D, flyingCheck.check(player, from, fromOnGround, to, toOnGround, data));
}
else
{
// If players are allowed to fly, there's no need to remember the last location on ground
} else {
// If players are allowed to fly, there's no need to remember
// the last location on ground
data.setBackPoint = from;
}
if(runCheck) {
result += Math.max(0D, runningCheck.check(from, to,
!allowFakeSneak && player.isSneaking(), !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0, data, this));
result += Math.max(0D, runningCheck.check(from, to, !allowFakeSneak && player.isSneaking(), !allowFastSwim && (fromType & toType & MovingEventHelper.LIQUID) > 0, data, this));
}
/********* HANDLE/COMBINE THE RESULTS OF THE CHECKS ***********/
@ -128,22 +131,22 @@ public class MovingCheck extends Check {
if(fromOnGround) {
data.setBackPoint = from;
data.jumpPhase = 0;
}
else if(result <= 0 && toOnGround) {
} else if(result <= 0 && toOnGround) {
data.jumpPhase = 0;
}
if(result > 0) {
// Increment violation counter
data.violationLevel += result;
if(data.setBackPoint == null) data.setBackPoint = from;
if(data.setBackPoint == null)
data.setBackPoint = from;
}
if(result > 0 && data.violationLevel > 1) {
setupSummaryTask(player, data);
int level = limitCheck(data.violationLevel-1);
int level = limitCheck(data.violationLevel - 1);
data.violationsInARow[level]++;
@ -158,12 +161,13 @@ public class MovingCheck extends Check {
statisticElapsedTimeNano += System.nanoTime() - startTime;
statisticTotalEvents++;
return newToLocation;
}
/**
* Various corner cases that would cause this check to fail or require special treatment
* Various corner cases that would cause this check to fail or require
* special treatment
*
* @param player
* @param data
* @param from
@ -172,34 +176,14 @@ public class MovingCheck extends Check {
*/
public boolean shouldBeApplied(final Player player, final MovingData data, final Location from, final Location to) {
if(player.isDead() || player.isInsideVehicle()) return false;
if(data.wasTeleported) {
// Remember this location
data.teleportedTo = from.clone();
data.wasTeleported = false;
data.jumpPhase = 0;
}
if(data.teleportedTo != null && data.teleportedTo.getWorld().equals(from.getWorld())) {
// As long as the from-Location doesn't change, the player didn't accept the teleport
if(data.teleportedTo.distanceSquared(from) < 0.01D) {
// Event after Teleport ignored
return false;
}
else {
// The player finally accepted the teleport with the previous event
data.teleportedTo = null;
}
}
return true;
}
/**
* Register a task with bukkit that will be run a short time from now, displaying how many
* Register a task with bukkit that will be run a short time from now,
* displaying how many
* violations happened in that timeframe
*
* @param p
* @param data
*/
@ -213,7 +197,7 @@ public class MovingCheck extends Check {
try {
if(data.highestLogLevel != null) {
String logString = String.format(summaryMessage, p.getName(), ticksBeforeSummary/20, data.violationsInARow[0], data.violationsInARow[1],data.violationsInARow[2]);
String logString = String.format(summaryMessage, p.getName(), ticksBeforeSummary / 20, data.violationsInARow[0], data.violationsInARow[1], data.violationsInARow[2]);
plugin.log(data.highestLogLevel, logString);
data.highestLogLevel = Level.ALL;
@ -224,8 +208,7 @@ public class MovingCheck extends Check {
data.violationsInARow[0] = 0;
data.violationsInARow[1] = 0;
data.violationsInARow[2] = 0;
}
catch(Exception e) { }
} catch(Exception e) {}
}
};
@ -235,7 +218,8 @@ public class MovingCheck extends Check {
}
/**
* Call this when a player got successfully teleported with the corresponding event to adjust stored
* Call this when a player got successfully teleported with the
* corresponding event to adjust stored
* data to the new situation
*
* @param event
@ -244,7 +228,8 @@ public class MovingCheck extends Check {
MovingData data = plugin.getDataManager().getMovingData(event.getPlayer());
// We can enforce a teleport, if that flag is explicitly set (but I'd rather have other plugins
// We can enforce a teleport, if that flag is explicitly set (but I'd
// rather have other plugins
// not arbitrarily cancel teleport events in the first place...
if(data.teleportInitializedByMe != null && event.isCancelled() && enforceTeleport && event.getTo().equals(data.teleportInitializedByMe)) {
event.setCancelled(false);
@ -252,24 +237,25 @@ public class MovingCheck extends Check {
}
if(!event.isCancelled()) {
data.wasTeleported = true;
data.setBackPoint = event.getTo().clone();
//data.lastLocation = event.getTo().clone();
data.setBackPoint = null;
}
// reset anyway - if another plugin cancelled our teleport it's no use to try and be precise
// reset anyway - if another plugin cancelled our teleport it's no use
// to try and be precise
data.jumpPhase = 0;
}
/**
* Update the cached values for players velocity to be prepared to
* give them additional movement freedom in their next move events
*
* @param v
* @param data
*/
public void updateVelocity(Vector v, MovingData data) {
// Compare the velocity vector to the existing movement freedom that we've from previous events
// Compare the velocity vector to the existing movement freedom that
// we've from previous events
double tmp = (Math.abs(v.getX()) + Math.abs(v.getZ())) * 3D;
if(tmp > data.horizFreedom)
data.horizFreedom = tmp;
@ -282,16 +268,17 @@ public class MovingCheck extends Check {
/**
* Perform actions that were specified in the config file
*
* @param event
* @param action
* @return
*/
private Location action( Player player, Location from, Location to, Action[] actions, int violations, MovingData data, MovingEventHelper helper) {
private Location action(Player player, Location from, Location to, Action[] actions, int violations, MovingData data, MovingEventHelper helper) {
Location newToLocation = null;
if(actions == null) return newToLocation;
if(actions == null)
return newToLocation;
boolean cancelled = false;
for(Action a : actions) {
@ -299,41 +286,49 @@ public class MovingCheck extends Check {
if(a.firstAfter == violations || a.repeat) {
if(a instanceof LogAction) {
// prepare log message if necessary
String log = String.format(Locale.US, logMessage, player.getName(), from.getWorld().getName(), to.getWorld().getName(), from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), Math.abs(from.getX()-to.getX()),to.getY()-from.getY(), Math.abs(from.getZ()-to.getZ()));
String log = String.format(Locale.US, logMessage, player.getName(), from.getWorld().getName(), to.getWorld().getName(), from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ(), Math.abs(from.getX() - to.getX()), to.getY() - from.getY(), Math.abs(from.getZ() - to.getZ()));
plugin.log(((LogAction)a).level, log);
plugin.log(((LogAction) a).level, log);
// Remember the highest log level we encountered to determine what level the summary log message should have
if(data.highestLogLevel == null) data.highestLogLevel = Level.ALL;
if(data.highestLogLevel.intValue() < ((LogAction)a).level.intValue()) data.highestLogLevel = ((LogAction)a).level;
}
else if(!cancelled && a instanceof CancelAction) {
// Make a modified copy of the setBackPoint to prevent other plugins from accidentally modifying it
// and keep the current pitch and yaw (setbacks "feel" better that way). Plus try to adapt the Y-coord
// Remember the highest log level we encountered to
// determine what level the summary log message should
// have
if(data.highestLogLevel == null)
data.highestLogLevel = Level.ALL;
if(data.highestLogLevel.intValue() < ((LogAction) a).level.intValue())
data.highestLogLevel = ((LogAction) a).level;
} else if(!cancelled && a instanceof CancelAction) {
// Make a modified copy of the setBackPoint to prevent
// other plugins from accidentally modifying it
// and keep the current pitch and yaw (setbacks "feel"
// better that way). Plus try to adapt the Y-coord
// to place the player close to ground
double y = data.setBackPoint.getY();
// search for the first solid block up to 5 blocks below the setbackpoint and teleport the player there
// search for the first solid block up to 5 blocks below
// the setbackpoint and teleport the player there
int i = 0;
for(; i < 20; i++) {
if(helper.isLocationOnGround(data.setBackPoint.getWorld(), data.setBackPoint.getX(), data.setBackPoint.getY() - 0.5*i, data.setBackPoint.getZ(), waterElevators) != MovingData.NONSOLID) {
if(helper.isLocationOnGround(data.setBackPoint.getWorld(), data.setBackPoint.getX(), data.setBackPoint.getY() - 0.5 * i, data.setBackPoint.getZ(), waterElevators) != MovingData.NONSOLID) {
break;
}
}
y -= 0.5*i;
y -= 0.5 * i;
data.setBackPoint.setY(y);
// Remember the location we send the player to, to identify teleports that were started by us
// Remember the location we send the player to, to
// identify teleports that were started by us
data.teleportInitializedByMe = new Location(data.setBackPoint.getWorld(), data.setBackPoint.getX(), y, data.setBackPoint.getZ(), to.getYaw(), to.getPitch());
newToLocation = data.teleportInitializedByMe;
cancelled = true; // just prevent us from treating more than one "cancel" action, which would make no sense
}
else if(a instanceof CustomAction)
plugin.handleCustomAction((CustomAction)a, player);
cancelled = true; // just prevent us from treating more
// than one "cancel" action, which
// would make no sense
} else if(a instanceof CustomAction)
plugin.handleCustomAction((CustomAction) a, player);
}
}
}
@ -344,6 +339,7 @@ public class MovingCheck extends Check {
/**
* Check a value against an array of sorted values to find out
* where it fits in
*
* @param value
* @param limits
* @return
@ -354,8 +350,10 @@ public class MovingCheck extends Check {
if(value > 0.5D) {
if(value > 2.0D)
return 2;
return 1; }
return 0; }
return 1;
}
return 0;
}
return -1;
}
@ -371,19 +369,11 @@ public class MovingCheck extends Check {
checkOPs = config.getBooleanValue("moving.checkops");
logMessage = config.getStringValue("moving.logmessage").
replace("[player]", "%1$s").
replace("[world]", "%2$s").
replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)").
replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)").
replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)");
logMessage = config.getStringValue("moving.logmessage").replace("[player]", "%1$s").replace("[world]", "%2$s").replace("[from]", "(%4$.1f, %5$.1f, %6$.1f)").replace("[to]", "(%7$.1f, %8$.1f, %9$.1f)").replace("[distance]", "(%10$.1f, %11$.1f, %12$.1f)");
summaryMessage = config.getStringValue("moving.summarymessage").
replace("[timeframe]", "%2$d").
replace("[player]", "%1$s").
replace("[violations]", "(%3$d,%4$d,%5$d)");
summaryMessage = config.getStringValue("moving.summarymessage").replace("[timeframe]", "%2$d").replace("[player]", "%1$s").replace("[violations]", "(%3$d,%4$d,%5$d)");
ticksBeforeSummary = config.getIntegerValue("moving.summaryafter")*20;
ticksBeforeSummary = config.getIntegerValue("moving.summaryafter") * 20;
actions = new Action[3][];
@ -395,11 +385,11 @@ public class MovingCheck extends Check {
enforceTeleport = config.getBooleanValue("moving.enforceteleport");
stepWidth = ((double)config.getIntegerValue("moving.limits.walking")) /100D;
sneakWidth = ((double)config.getIntegerValue("moving.limits.sneaking"))/100D;
swimWidth = ((double)config.getIntegerValue("moving.limits.swimming"))/100D;
stepWidth = ((double) config.getIntegerValue("moving.limits.walking")) / 100D;
sneakWidth = ((double) config.getIntegerValue("moving.limits.sneaking")) / 100D;
swimWidth = ((double) config.getIntegerValue("moving.limits.swimming")) / 100D;
} catch (ConfigurationException e) {
} catch(ConfigurationException e) {
setActive(false);
e.printStackTrace();
}

View File

@ -7,6 +7,7 @@ import org.bukkit.World;
/**
* A collection of stuff to process data of move events
*
* @author Evenprime
*
*/
@ -22,7 +23,8 @@ public class MovingEventHelper {
public static final int LADDER = 4; // 0x00000100
public static final int FENCE = 8; // 0x00001000
// Until I can think of a better way to determine if a block is solid or not, this is what I'll do
// Until I can think of a better way to determine if a block is solid or
// not, this is what I'll do
private final int types[] = new int[256];
public MovingEventHelper() {
@ -36,8 +38,7 @@ public class MovingEventHelper {
if(Block.byId[i].material.isSolid()) {
// solid blocks like STONE, CAKE, TRAPDOORS
types[i] = SOLID;
}
else if(Block.byId[i].material.isLiquid()){
} else if(Block.byId[i].material.isLiquid()) {
// WATER, LAVA
types[i] = LIQUID;
}
@ -45,68 +46,65 @@ public class MovingEventHelper {
}
// Special types just for me
types[Material.LADDER.getId()]= LADDER | SOLID;
types[Material.FENCE.getId()]= FENCE | SOLID;
types[Material.LADDER.getId()] = LADDER | SOLID;
types[Material.FENCE.getId()] = FENCE | SOLID;
}
/**
* Check if certain coordinates are considered "on ground"
*
* @param w The world the coordinates belong to
* @param values The coordinates [lowerX, higherX, Y, lowerZ, higherZ] to be checked
* @param l The precise location that was used for calculation of "values"
* @param w
* The world the coordinates belong to
* @param values
* The coordinates [lowerX, higherX, Y, lowerZ, higherZ] to be
* checked
* @param l
* The precise location that was used for calculation of "values"
* @return
*/
public int isLocationOnGround(final World world, final double x, final double y, final double z, boolean waterElevatorsAllowed) {
final int lowerX = lowerBorder(x);
final int upperX = upperBorder(x);
final int Y = (int)Math.floor(y);
final int Y = (int) Math.floor(y);
final int lowerZ = lowerBorder(z);
final int higherZ = upperBorder(z);
int result;
// check in what kind of block the player is standing "in"
result = types[world.getBlockTypeIdAt(lowerX, Y, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y, lowerZ)] |
types[world.getBlockTypeIdAt(lowerX, Y, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y, higherZ)];
result = types[world.getBlockTypeIdAt(lowerX, Y, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y, higherZ)];
if((result & SOLID) != 0) {
// return standing
return SOLID;
}
else if((result & LIQUID) != 0) {
} else if((result & LIQUID) != 0) {
// return swimming
return LIQUID;
}
// Check the four borders of the players hitbox for something he could be standing on
result = types[world.getBlockTypeIdAt(lowerX, Y-1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y-1, lowerZ)] |
types[world.getBlockTypeIdAt(lowerX, Y-1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y-1, higherZ)];
// Check the four borders of the players hitbox for something he could
// be standing on
result = types[world.getBlockTypeIdAt(lowerX, Y - 1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y - 1, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y - 1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y - 1, higherZ)];
if((result & SOLID) != 0) {
// return standing
return SOLID;
}
// check if his head is "stuck" in an block
result = types[world.getBlockTypeIdAt(lowerX, Y+1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y+1, lowerZ)] |
types[world.getBlockTypeIdAt(lowerX, Y+1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y+1, higherZ)];
result = types[world.getBlockTypeIdAt(lowerX, Y + 1, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y + 1, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y + 1, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y + 1, higherZ)];
if((result & SOLID) != 0) {
// return standing
return SOLID;
}
else if((result & LIQUID) != 0) {
} else if((result & LIQUID) != 0) {
// return swimming
return LIQUID;
}
// Running on fences causes problems if not treated specially
result = types[world.getBlockTypeIdAt(lowerX, Y-2, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y-2, lowerZ)] |
types[world.getBlockTypeIdAt(lowerX, Y-2, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y-2, higherZ)];
result = types[world.getBlockTypeIdAt(lowerX, Y - 2, lowerZ)] | types[world.getBlockTypeIdAt(upperX, Y - 2, lowerZ)] | types[world.getBlockTypeIdAt(lowerX, Y - 2, higherZ)] | types[world.getBlockTypeIdAt(upperX, Y - 2, higherZ)];
if((result & FENCE) != 0) {
// return standing
@ -115,25 +113,21 @@ public class MovingEventHelper {
// Water elevators - optional "feature"
if(waterElevatorsAllowed) {
result = types[world.getBlockTypeIdAt(lowerX+1, Y+1, lowerZ+1)] |
types[world.getBlockTypeIdAt(lowerX+1, Y , lowerZ+1)] |
types[world.getBlockTypeIdAt(lowerX, Y+1, lowerZ+1)] |
types[world.getBlockTypeIdAt(lowerX , Y , lowerZ+1)] |
types[world.getBlockTypeIdAt(lowerX+1, Y+1, lowerZ )] |
types[world.getBlockTypeIdAt(lowerX+1, Y , lowerZ )] ;
result = types[world.getBlockTypeIdAt(lowerX + 1, Y + 1, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX + 1, Y, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX, Y + 1, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX, Y, lowerZ + 1)] | types[world.getBlockTypeIdAt(lowerX + 1, Y + 1, lowerZ)] | types[world.getBlockTypeIdAt(lowerX + 1, Y, lowerZ)];
if((result & LIQUID) != 0) {
return SOLID; // Solid? Why that? Because that's closer to what the bug actually does than liquid
return SOLID; // Solid? Why that? Because that's closer to what
// the bug actually does than liquid
}
}
// If nothing matches, he is somewhere in the air
return NONSOLID;
}
/**
* Personal Rounding function to determine if a player is still touching a block or not
* Personal Rounding function to determine if a player is still touching a
* block or not
*
* @param d1
* @return
*/
@ -151,7 +145,9 @@ public class MovingEventHelper {
}
/**
* Personal Rounding function to determine if a player is still touching a block or not
* Personal Rounding function to determine if a player is still touching a
* block or not
*
* @param d1
* @return
*/

View File

@ -20,7 +20,6 @@ import cc.co.evenprime.bukkit.nocheat.data.NukeData;
import cc.co.evenprime.bukkit.nocheat.data.PermissionData;
import cc.co.evenprime.bukkit.nocheat.listeners.NukeBlockListener;
public class NukeCheck extends Check {
private String kickMessage;
@ -37,17 +36,14 @@ public class NukeCheck extends Check {
@Override
protected void configure(NoCheatConfiguration config) {
try {
kickMessage = config.getStringValue("nuke.kickmessage");
logMessage = config.getStringValue("nuke.logmessage").
replace("[player]", "%1$s");
logMessage = config.getStringValue("nuke.logmessage").replace("[player]", "%1$s");
limitReach = config.getBooleanValue("nuke.limitreach");
setActive(config.getBooleanValue("active.nuke"));
} catch (ConfigurationException e) {
} catch(ConfigurationException e) {
setActive(false);
e.printStackTrace();
}
@ -68,9 +64,9 @@ public class NukeCheck extends Check {
// Because it's not very precise on very short distances,
// consider the length of the side of a block to be 2.0 instead of 1.0
final double x1 = ((double)block.getX()) - eyes.getX() - 0.5;
final double y1 = ((double)block.getY()) - eyes.getY() - 0.5;
final double z1 = ((double)block.getZ()) - eyes.getZ() - 0.5;
final double x1 = ((double) block.getX()) - eyes.getX() - 0.5;
final double y1 = ((double) block.getY()) - eyes.getY() - 0.5;
final double z1 = ((double) block.getZ()) - eyes.getZ() - 0.5;
final double x2 = x1 + 2;
final double y2 = y1 + 2;
@ -80,13 +76,11 @@ public class NukeCheck extends Check {
boolean tooFarAway = limitReach && factor > 4.85D;
if(!tooFarAway && factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 &&
factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
if(!tooFarAway && factor * direction.getX() >= x1 && factor * direction.getY() >= y1 && factor * direction.getZ() >= z1 && factor * direction.getX() <= x2 && factor * direction.getY() <= y2 && factor * direction.getZ() <= z2) {
if(data.counter > 0) {
data.counter--;
}
}
else {
} else {
data.counter++;
event.setCancelled(true);
@ -101,10 +95,8 @@ public class NukeCheck extends Check {
}
}
}
@Override
protected void registerListeners() {
PluginManager pm = Bukkit.getServer().getPluginManager();
@ -115,7 +107,6 @@ public class NukeCheck extends Check {
pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.BLOCK_DAMAGE, blockListener, Priority.Monitor, plugin);
}
}

View File

@ -6,8 +6,7 @@ import cc.co.evenprime.bukkit.nocheat.data.MovingData;
public class RunningCheck {
public RunningCheck() { }
public RunningCheck() {}
public double check(final Location from, final Location to, final boolean isSneaking, final boolean isSwimming, final MovingData data, MovingCheck check) {
@ -15,18 +14,16 @@ public class RunningCheck {
double distanceAboveLimit = 0.0D;
// First calculate the distance the player has moved horizontally
final double xDistance = from.getX()-to.getX();
final double zDistance = from.getZ()-to.getZ();
final double xDistance = from.getX() - to.getX();
final double zDistance = from.getZ() - to.getZ();
final double totalDistance = Math.sqrt((xDistance*xDistance + zDistance*zDistance));
final double totalDistance = Math.sqrt((xDistance * xDistance + zDistance * zDistance));
if(isSneaking) {
distanceAboveLimit = totalDistance - check.sneakWidth;
}
else if(isSwimming) {
} else if(isSwimming) {
distanceAboveLimit = totalDistance - check.swimWidth;
}
else {
} else {
distanceAboveLimit = totalDistance - check.stepWidth;
}

View File

@ -22,7 +22,8 @@ import cc.co.evenprime.bukkit.nocheat.data.SpeedhackData;
import cc.co.evenprime.bukkit.nocheat.listeners.SpeedhackPlayerListener;
/**
* Log if a player sends to many move events in a specific time frame, usually the result of tinkering with the system clock
* Log if a player sends to many move events in a specific time frame, usually
* the result of tinkering with the system clock
*
* @author Evenprime
*
@ -47,15 +48,19 @@ public class SpeedhackCheck extends Check {
Player player = event.getPlayer();
// Should we check at all?
if(skipCheck(player)) return;
if(skipCheck(player))
return;
// Ignore events of players in vehicles (these can be the cause of event spam between server and client)
// Ignore events if the player has positive y-Velocity (these can be the cause of event spam between server and client)
// Ignore events of players in vehicles (these can be the cause of event
// spam between server and client)
// Ignore events if the player has positive y-Velocity (these can be the
// cause of event spam between server and client)
if(player.isInsideVehicle() || player.getVelocity().getY() > 0.0D) {
return;
}
// During world transfers many events of same location get sent, ignore them all
// During world transfers many events of same location get sent, ignore
// them all
if(event.getFrom().equals(event.getTo())) {
return;
}
@ -80,14 +85,16 @@ public class SpeedhackCheck extends Check {
if(plugin.getServerLag() > 150) {
// Any data would likely be unreliable with that lag
resetData(data, event.getFrom());
}
else {
} else {
int level = -1;
if(data.eventsSinceLastCheck > limits[2]) level = 2;
else if(data.eventsSinceLastCheck > limits[1]) level = 1;
else if(data.eventsSinceLastCheck > limits[0]) level = 0;
if(data.eventsSinceLastCheck > limits[2])
level = 2;
else if(data.eventsSinceLastCheck > limits[1])
level = 1;
else if(data.eventsSinceLastCheck > limits[0])
level = 0;
else {
resetData(data, event.getFrom());
}
@ -106,9 +113,7 @@ public class SpeedhackCheck extends Check {
}
data.lastCheckTicks = ticks;
}
else if(data.lastCheckTicks + 10 < ticks)
{
} else if(data.lastCheckTicks + 10 < ticks) {
// The player didn't move for the last 10 ticks
resetData(data, event.getFrom());
data.lastCheckTicks = ticks;
@ -126,20 +131,19 @@ public class SpeedhackCheck extends Check {
private void action(Action actions[], PlayerMoveEvent event, int violations, SpeedhackData data) {
if(actions == null) return;
if(actions == null)
return;
for(Action a : actions) {
if(a.firstAfter <= violations) {
if(a instanceof LogAction) {
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck*2, limits[0]);
plugin.log(((LogAction)a).level, log);
}
else if(a.firstAfter == violations || a.repeat) {
String log = String.format(logMessage, event.getPlayer().getName(), data.eventsSinceLastCheck * 2, limits[0]);
plugin.log(((LogAction) a).level, log);
} else if(a.firstAfter == violations || a.repeat) {
if(a instanceof CancelAction) {
resetPlayer(event, data);
}
else if(a instanceof CustomAction) {
plugin.handleCustomAction((CustomAction)a, event.getPlayer());
} else if(a instanceof CustomAction) {
plugin.handleCustomAction((CustomAction) a, event.getPlayer());
}
}
}
@ -148,7 +152,8 @@ public class SpeedhackCheck extends Check {
private static void resetPlayer(PlayerMoveEvent event, SpeedhackData data) {
if(data.setBackPoint == null) data.setBackPoint = event.getFrom();
if(data.setBackPoint == null)
data.setBackPoint = event.getFrom();
// If we have stored a location for the player, we put him back there
event.setTo(data.setBackPoint);
@ -165,8 +170,7 @@ public class SpeedhackCheck extends Check {
limits[1] = config.getIntegerValue("speedhack.limits.med");
limits[2] = config.getIntegerValue("speedhack.limits.high");
logMessage = config.getStringValue("speedhack.logmessage").
replace("[player]", "%1$s").replace("[events]", "%2$d").replace("[limit]", "%3$d");
logMessage = config.getStringValue("speedhack.logmessage").replace("[player]", "%1$s").replace("[events]", "%2$d").replace("[limit]", "%3$d");
actions = new Action[3][];
@ -175,14 +179,12 @@ public class SpeedhackCheck extends Check {
actions[2] = config.getActionValue("speedhack.action.high");
setActive(config.getBooleanValue("active.speedhack"));
} catch (ConfigurationException e) {
} catch(ConfigurationException e) {
setActive(false);
e.printStackTrace();
}
}
@Override
protected void registerListeners() {
PluginManager pm = Bukkit.getServer().getPluginManager();

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.config;
public class BooleanOption extends ChildOption {
/**

View File

@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config;
import cc.co.evenprime.bukkit.nocheat.wizard.gui.Explainations;
public abstract class ChildOption extends Option {
/**
@ -14,7 +13,6 @@ public abstract class ChildOption extends Option {
super(identifier);
}
public abstract String getValue();
@Override

View File

@ -8,7 +8,6 @@ public class CustomActionOption extends ChildOption {
private boolean repeat;
private String command;
public CustomActionOption(String identifier, String command) {
super(identifier);
@ -24,15 +23,12 @@ public class CustomActionOption extends ChildOption {
firstAfter = Integer.parseInt(s2[0]);
repeat = Boolean.parseBoolean(s2[1]);
command = s[1];
}
else if(com.matches("\\[[0-9]*\\] .*")) {
} else if(com.matches("\\[[0-9]*\\] .*")) {
String s[] = com.split(" ", 2);
firstAfter = Integer.parseInt(s[0].replace("[", "").replace("]", ""));
repeat = true;
command = s[1];
}
else
{
} else {
firstAfter = 1;
repeat = true;
command = com;
@ -43,16 +39,13 @@ public class CustomActionOption extends ChildOption {
public String getValue() {
if(firstAfter <= 1 && repeat) {
return command;
}
else if(repeat) {
return "["+firstAfter+"] "+ command;
}
else {
return "["+firstAfter+","+repeat+"] "+ command;
} else if(repeat) {
return "[" + firstAfter + "] " + command;
} else {
return "[" + firstAfter + "," + repeat + "] " + command;
}
}
public CustomAction getCustomActionValue() {
return new CustomAction(firstAfter, repeat, command);
}

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.config;
public class IntegerOption extends TextFieldOption {
/**
@ -16,13 +15,13 @@ public class IntegerOption extends TextFieldOption {
@Override
public boolean isValid(String value) {
if(!super.isValid(value)) return false;
if(!super.isValid(value))
return false;
try {
Integer.parseInt(value);
return true;
}
catch(Exception e) {
} catch(Exception e) {
return false;
}
}

View File

@ -2,7 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.config;
import java.util.logging.Level;
public class LevelOption extends ChildOption {
/**
@ -14,11 +13,7 @@ public class LevelOption extends ChildOption {
public enum LogLevel {
OFF("off", "never", Level.OFF),
LOW("low", "all messages", Level.INFO),
MED("med", "important messages", Level.WARNING),
HIGH("high", "very important messages", Level.SEVERE);
OFF("off", "never", Level.OFF), LOW("low", "all messages", Level.INFO), MED("med", "important messages", Level.WARNING), HIGH("high", "very important messages", Level.SEVERE);
private final String value;
private final String description;
@ -30,10 +25,13 @@ public class LevelOption extends ChildOption {
this.level = level;
}
public String asString() { return this.value; }
public String asString() {
return this.value;
}
public static LogLevel getLogLevelFromString(String s) {
if(s == null) return OFF;
if(s == null)
return OFF;
if("off".equals(s))
return OFF;
else if("low".equals(s))
@ -46,7 +44,6 @@ public class LevelOption extends ChildOption {
return OFF;
}
public String toString() {
return this.name() + ": " + description;
}
@ -62,7 +59,6 @@ public class LevelOption extends ChildOption {
this.option = initialValue;
}
@Override
public String getValue() {
return option.asString();

View File

@ -29,13 +29,12 @@ import cc.co.evenprime.bukkit.nocheat.yaml.SimpleYaml;
*/
public class NoCheatConfiguration {
public final static String configFile = "plugins/NoCheat/nocheat.yml";
public final static String descriptionsFile = "plugins/NoCheat/descriptions.txt";
private ParentOption root;
private final Map<String, Action> actionMap = new HashMap<String,Action>();
private final Map<String, Action> actionMap = new HashMap<String, Action>();
private Map<String, Object> yamlContent = new HashMap<String, Object>();
@ -54,42 +53,35 @@ public class NoCheatConfiguration {
}
/**
* Read the configuration file and assign either standard values or whatever is declared in the file
* Read the configuration file and assign either standard values or whatever
* is declared in the file
*
* @param configurationFile
*/
public void config(File configurationFile, File descriptionsFile) {
try {
yamlContent = (Map<String, Object>) SimpleYaml.read(configurationFile);
} catch (Exception e) {
} catch(Exception e) {
System.out.println("Couldn't use existing nocheat.yml, creating a new file.");
yamlContent = new HashMap<String, Object>();
}
root = new ParentOption("", false);
/*** LOGGING section ***/
{
ParentOption loggingNode = new ParentOption("logging", false);
root.add(loggingNode);
loggingNode.add(new MediumStringOption("filename",
SimpleYaml.getString("logging.filename", "plugins/NoCheat/nocheat.log", yamlContent)));
loggingNode.add(new MediumStringOption("filename", SimpleYaml.getString("logging.filename", "plugins/NoCheat/nocheat.log", yamlContent)));
loggingNode.add(new LevelOption("logtofile",
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtofile", LogLevel.LOW.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtoconsole",
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoconsole", LogLevel.HIGH.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtochat",
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtochat", LogLevel.MED.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtoirc",
LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoirc", LogLevel.MED.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtofile", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtofile", LogLevel.LOW.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtoconsole", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoconsole", LogLevel.HIGH.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtochat", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtochat", LogLevel.MED.asString(), yamlContent))));
loggingNode.add(new LevelOption("logtoirc", LogLevel.getLogLevelFromString(SimpleYaml.getString("logging.logtoirc", LogLevel.MED.asString(), yamlContent))));
loggingNode.add(new ShortStringOption("logtoirctag",
SimpleYaml.getString("logging.logtoirctag", "nocheat", yamlContent)));
loggingNode.add(new ShortStringOption("logtoirctag", SimpleYaml.getString("logging.logtoirctag", "nocheat", yamlContent)));
}
root.add(new BooleanOption("newpermsystem", SimpleYaml.getBoolean("newpermsystem", false, yamlContent)));
@ -100,16 +92,11 @@ public class NoCheatConfiguration {
ParentOption activeNode = new ParentOption("active", false);
root.add(activeNode);
activeNode.add(new BooleanOption("speedhack",
SimpleYaml.getBoolean("active.speedhack", true, yamlContent)));
activeNode.add(new BooleanOption("moving",
SimpleYaml.getBoolean("active.moving", true, yamlContent)));
activeNode.add(new BooleanOption("airbuild",
SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
activeNode.add(new BooleanOption("bogusitems",
SimpleYaml.getBoolean("active.bogusitems", false, yamlContent)));
activeNode.add(new BooleanOption("nuke",
SimpleYaml.getBoolean("active.nuke", false, yamlContent)));
activeNode.add(new BooleanOption("speedhack", SimpleYaml.getBoolean("active.speedhack", true, yamlContent)));
activeNode.add(new BooleanOption("moving", SimpleYaml.getBoolean("active.moving", true, yamlContent)));
activeNode.add(new BooleanOption("airbuild", SimpleYaml.getBoolean("active.airbuild", false, yamlContent)));
activeNode.add(new BooleanOption("bogusitems", SimpleYaml.getBoolean("active.bogusitems", false, yamlContent)));
activeNode.add(new BooleanOption("nuke", SimpleYaml.getBoolean("active.nuke", false, yamlContent)));
}
/*** SPEEDHACK section ***/
@ -117,23 +104,18 @@ public class NoCheatConfiguration {
ParentOption speedhackNode = new ParentOption("speedhack", false);
root.add(speedhackNode);
speedhackNode.add(new LongStringOption("logmessage",
SimpleYaml.getString("speedhack.logmessage", "[player] sent [events] move events, but only [limit] were allowed. Speedhack?", yamlContent)));
speedhackNode.add(new LongStringOption("logmessage", SimpleYaml.getString("speedhack.logmessage", "[player] sent [events] move events, but only [limit] were allowed. Speedhack?", yamlContent)));
speedhackNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("speedhack.checkops", false, yamlContent)));
speedhackNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("speedhack.checkops", false, yamlContent)));
/*** SPEEDHACK LIMITS section ***/
{
ParentOption speedhackLimitsNode = new ParentOption("limits", false);
speedhackNode.add(speedhackLimitsNode);
speedhackLimitsNode.add(new IntegerOption("low",
SimpleYaml.getInt("speedhack.limits.low", 22, yamlContent)));
speedhackLimitsNode.add(new IntegerOption("med",
SimpleYaml.getInt("speedhack.limits.med", 33, yamlContent)));
speedhackLimitsNode.add(new IntegerOption("high",
SimpleYaml.getInt("speedhack.limits.high", 44, yamlContent)));
speedhackLimitsNode.add(new IntegerOption("low", SimpleYaml.getInt("speedhack.limits.low", 22, yamlContent)));
speedhackLimitsNode.add(new IntegerOption("med", SimpleYaml.getInt("speedhack.limits.med", 33, yamlContent)));
speedhackLimitsNode.add(new IntegerOption("high", SimpleYaml.getInt("speedhack.limits.high", 44, yamlContent)));
}
/*** SPEEDHACK ACTIONS section ***/
@ -141,12 +123,9 @@ public class NoCheatConfiguration {
ParentOption speedhackActionNode = new ParentOption("action", false);
speedhackNode.add(speedhackActionNode);
speedhackActionNode.add(new MediumStringOption("low",
SimpleYaml.getString("speedhack.action.low", "loglow cancel", yamlContent)));
speedhackActionNode.add(new MediumStringOption("med",
SimpleYaml.getString("speedhack.action.med", "logmed cancel", yamlContent)));
speedhackActionNode.add(new MediumStringOption("high",
SimpleYaml.getString("speedhack.action.high", "loghigh cancel", yamlContent)));
speedhackActionNode.add(new MediumStringOption("low", SimpleYaml.getString("speedhack.action.low", "loglow cancel", yamlContent)));
speedhackActionNode.add(new MediumStringOption("med", SimpleYaml.getString("speedhack.action.med", "logmed cancel", yamlContent)));
speedhackActionNode.add(new MediumStringOption("high", SimpleYaml.getString("speedhack.action.high", "loghigh cancel", yamlContent)));
}
}
@ -155,42 +134,29 @@ public class NoCheatConfiguration {
ParentOption movingNode = new ParentOption("moving", false);
root.add(movingNode);
movingNode.add(new LongStringOption("logmessage",
SimpleYaml.getString("moving.logmessage", "Moving violation: [player] from [world] [from] to [to] distance [distance]", yamlContent)));
movingNode.add(new LongStringOption("logmessage", SimpleYaml.getString("moving.logmessage", "Moving violation: [player] from [world] [from] to [to] distance [distance]", yamlContent)));
movingNode.add(new LongStringOption("summarymessage",
SimpleYaml.getString("moving.summarymessage", "Moving summary of last ~[timeframe] seconds: [player] total Violations: [violations]", yamlContent)));
movingNode.add(new LongStringOption("summarymessage", SimpleYaml.getString("moving.summarymessage", "Moving summary of last ~[timeframe] seconds: [player] total Violations: [violations]", yamlContent)));
movingNode.add(new IntegerOption("summaryafter",
SimpleYaml.getInt("moving.summaryafter", 15, yamlContent)));
movingNode.add(new IntegerOption("summaryafter", SimpleYaml.getInt("moving.summaryafter", 15, yamlContent)));
movingNode.add(new BooleanOption("allowflying",
SimpleYaml.getBoolean("moving.allowflying", false, yamlContent)));
movingNode.add(new BooleanOption("allowfakesneak",
SimpleYaml.getBoolean("moving.allowfakesneak", true, yamlContent)));
movingNode.add(new BooleanOption("allowfastswim",
SimpleYaml.getBoolean("moving.allowfastswim", false, yamlContent)));
movingNode.add(new BooleanOption("waterelevators",
SimpleYaml.getBoolean("moving.waterelevators", false, yamlContent)));
movingNode.add(new BooleanOption("allowflying", SimpleYaml.getBoolean("moving.allowflying", false, yamlContent)));
movingNode.add(new BooleanOption("allowfakesneak", SimpleYaml.getBoolean("moving.allowfakesneak", true, yamlContent)));
movingNode.add(new BooleanOption("allowfastswim", SimpleYaml.getBoolean("moving.allowfastswim", false, yamlContent)));
movingNode.add(new BooleanOption("waterelevators", SimpleYaml.getBoolean("moving.waterelevators", false, yamlContent)));
movingNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("moving.checkops", false, yamlContent)));
movingNode.add(new BooleanOption("enforceteleport",
SimpleYaml.getBoolean("moving.enforceteleport", false, yamlContent)));
movingNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("moving.checkops", false, yamlContent)));
movingNode.add(new BooleanOption("enforceteleport", SimpleYaml.getBoolean("moving.enforceteleport", false, yamlContent)));
/*** MOVING LIMITS section ***/
{
ParentOption movingLimitsNode = new ParentOption("limits", false);
movingNode.add(movingLimitsNode);
movingLimitsNode.add(new IntegerOption("walking",
SimpleYaml.getInt("moving.limits.walking", 22, yamlContent)));
movingLimitsNode.add(new IntegerOption("sneaking",
SimpleYaml.getInt("moving.limits.sneaking", 14, yamlContent)));
movingLimitsNode.add(new IntegerOption("swimming",
SimpleYaml.getInt("moving.limits.swimming", 18, yamlContent)));
movingLimitsNode.add(new IntegerOption("walking", SimpleYaml.getInt("moving.limits.walking", 22, yamlContent)));
movingLimitsNode.add(new IntegerOption("sneaking", SimpleYaml.getInt("moving.limits.sneaking", 14, yamlContent)));
movingLimitsNode.add(new IntegerOption("swimming", SimpleYaml.getInt("moving.limits.swimming", 18, yamlContent)));
}
/*** MOVING ACTION section ***/
@ -198,12 +164,9 @@ public class NoCheatConfiguration {
ParentOption movingActionNode = new ParentOption("action", false);
movingNode.add(movingActionNode);
movingActionNode.add(new MediumStringOption("low",
SimpleYaml.getString("moving.action.low", "loglow cancel", yamlContent)));
movingActionNode.add(new MediumStringOption("med",
SimpleYaml.getString("moving.action.med", "logmed cancel", yamlContent)));
movingActionNode.add(new MediumStringOption("high",
SimpleYaml.getString("moving.action.high", "loghigh cancel", yamlContent)));
movingActionNode.add(new MediumStringOption("low", SimpleYaml.getString("moving.action.low", "loglow cancel", yamlContent)));
movingActionNode.add(new MediumStringOption("med", SimpleYaml.getString("moving.action.med", "logmed cancel", yamlContent)));
movingActionNode.add(new MediumStringOption("high", SimpleYaml.getString("moving.action.high", "loghigh cancel", yamlContent)));
}
}
@ -212,20 +175,16 @@ public class NoCheatConfiguration {
ParentOption airbuildNode = new ParentOption("airbuild", false);
root.add(airbuildNode);
airbuildNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("airbuild.checkops", false, yamlContent)));
airbuildNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("airbuild.checkops", false, yamlContent)));
/*** AIRBUILD LIMITS section ***/
{
ParentOption airbuildLimitsNode = new ParentOption("limits", false);
airbuildNode.add(airbuildLimitsNode);
airbuildLimitsNode.add(new IntegerOption("low",
SimpleYaml.getInt("airbuild.limits.low", 1, yamlContent)));
airbuildLimitsNode.add(new IntegerOption("med",
SimpleYaml.getInt("airbuild.limits.med", 3, yamlContent)));
airbuildLimitsNode.add(new IntegerOption("high",
SimpleYaml.getInt("airbuild.limits.high", 10, yamlContent)));
airbuildLimitsNode.add(new IntegerOption("low", SimpleYaml.getInt("airbuild.limits.low", 1, yamlContent)));
airbuildLimitsNode.add(new IntegerOption("med", SimpleYaml.getInt("airbuild.limits.med", 3, yamlContent)));
airbuildLimitsNode.add(new IntegerOption("high", SimpleYaml.getInt("airbuild.limits.high", 10, yamlContent)));
}
/*** AIRBUILD ACTION section ***/
@ -233,15 +192,11 @@ public class NoCheatConfiguration {
ParentOption airbuildActionNode = new ParentOption("action", false);
airbuildNode.add(airbuildActionNode);
airbuildActionNode.add(new MediumStringOption("low",
SimpleYaml.getString("airbuild.action.low", "loglow cancel", yamlContent)));
airbuildActionNode.add(new MediumStringOption("med",
SimpleYaml.getString("airbuild.action.med", "logmed cancel", yamlContent)));
airbuildActionNode.add(new MediumStringOption("high",
SimpleYaml.getString("airbuild.action.high", "loghigh cancel", yamlContent)));
airbuildActionNode.add(new MediumStringOption("low", SimpleYaml.getString("airbuild.action.low", "loglow cancel", yamlContent)));
airbuildActionNode.add(new MediumStringOption("med", SimpleYaml.getString("airbuild.action.med", "logmed cancel", yamlContent)));
airbuildActionNode.add(new MediumStringOption("high", SimpleYaml.getString("airbuild.action.high", "loghigh cancel", yamlContent)));
}
}
/*** BOGUSITEMS section ***/
@ -249,24 +204,18 @@ public class NoCheatConfiguration {
ParentOption bogusitemsNode = new ParentOption("bogusitems", false);
root.add(bogusitemsNode);
bogusitemsNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("bogusitems.checkops", false, yamlContent)));
bogusitemsNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("bogusitems.checkops", false, yamlContent)));
}
/*** NUKE section ***/
{
ParentOption nukeNode = new ParentOption("nuke", false);
root.add(nukeNode);
nukeNode.add(new BooleanOption("checkops",
SimpleYaml.getBoolean("nuke.checkops", false, yamlContent)));
nukeNode.add(new LongStringOption("logmessage",
SimpleYaml.getString("nuke.logmessage", "Nuke: [player] tried to nuke the world", yamlContent)));
nukeNode.add(new LongStringOption("kickmessage",
SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent)));
nukeNode.add(new BooleanOption("limitreach",
SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent)));
nukeNode.add(new BooleanOption("checkops", SimpleYaml.getBoolean("nuke.checkops", false, yamlContent)));
nukeNode.add(new LongStringOption("logmessage", SimpleYaml.getString("nuke.logmessage", "Nuke: [player] tried to nuke the world", yamlContent)));
nukeNode.add(new LongStringOption("kickmessage", SimpleYaml.getString("nuke.kickmessage", "No nuking allowed", yamlContent)));
nukeNode.add(new BooleanOption("limitreach", SimpleYaml.getBoolean("nuke.limitreach", true, yamlContent)));
}
@ -279,7 +228,7 @@ public class NoCheatConfiguration {
for(String s : customs) {
CustomActionOption o = new CustomActionOption(s, SimpleYaml.getString("customactions."+s, "unknown", yamlContent));
CustomActionOption o = new CustomActionOption(s, SimpleYaml.getString("customactions." + s, "unknown", yamlContent));
customActionsNode.add(o);
actionMap.put(s, o.getCustomActionValue());
@ -302,7 +251,7 @@ public class NoCheatConfiguration {
fh.setFormatter(new LogFileFormatter());
logger.addHandler(fh);
} catch (Exception e) {
} catch(Exception e) {
e.printStackTrace();
}
}
@ -316,7 +265,7 @@ public class NoCheatConfiguration {
fh.flush();
fh.close();
} catch (Exception e) {
} catch(Exception e) {
e.printStackTrace();
}
}
@ -338,8 +287,7 @@ public class NoCheatConfiguration {
as.add(CancelAction.cancel);
else if(actionMap.get(s) != null)
as.add(actionMap.get(s));
else
{
else {
System.out.println("NC: Couldn't parse custom action '" + s + "'");
}
}
@ -349,6 +297,7 @@ public class NoCheatConfiguration {
/**
* Write configuration file to specific filename
*
* @param f
*/
public static void writeConfigFile(File f, NoCheatConfiguration configuration) {
@ -361,14 +310,16 @@ public class NoCheatConfiguration {
w.write(configuration.getRoot().toYAMLString(""));
w.flush(); w.close();
} catch (IOException e) {
w.flush();
w.close();
} catch(IOException e) {
e.printStackTrace();
}
}
/**
* Write a file with the descriptions of all options
*
* @param f
*/
private static void writeDescriptionFile(File f, NoCheatConfiguration configuration) {
@ -381,8 +332,9 @@ public class NoCheatConfiguration {
w.write(configuration.getRoot().toDescriptionString(""));
w.flush(); w.close();
} catch (IOException e) {
w.flush();
w.close();
} catch(IOException e) {
e.printStackTrace();
}
}
@ -391,15 +343,15 @@ public class NoCheatConfiguration {
return stringToActions(getStringOption(optionName).getValue());
}
public int getIntegerValue(String optionName) throws ConfigurationException {
return getIntegerOption(optionName).getIntegerValue();
}
private IntegerOption getIntegerOption(String optionName) throws ConfigurationException {
Option o = getOption(optionName) ;
Option o = getOption(optionName);
if(o instanceof IntegerOption) {
return (IntegerOption)o;
return (IntegerOption) o;
}
throw new ConfigurationException("Config Node " + optionName + " is not an integer");
@ -408,11 +360,12 @@ public class NoCheatConfiguration {
public String getStringValue(String optionName) throws ConfigurationException {
return getStringOption(optionName).getValue();
}
private TextFieldOption getStringOption(String optionName) throws ConfigurationException {
Option o = getOption(optionName);
if(o instanceof TextFieldOption) {
return (TextFieldOption)o;
return (TextFieldOption) o;
}
throw new ConfigurationException("Config Node " + optionName + " is not a string");
@ -421,17 +374,17 @@ public class NoCheatConfiguration {
public Level getLogLevelValue(String optionName) throws ConfigurationException {
return getLogLevelOption(optionName).getLevelValue();
}
private LevelOption getLogLevelOption(String optionName) throws ConfigurationException {
Option o = getOption(optionName);
if(o instanceof LevelOption) {
return (LevelOption)o;
return (LevelOption) o;
}
throw new ConfigurationException("Config Node " + optionName + " is not a loglevel");
}
public boolean getBooleanValue(String optionName) throws ConfigurationException {
return getBooleanOption(optionName).getBooleanValue();
}
@ -440,13 +393,12 @@ public class NoCheatConfiguration {
Option o = getOption(optionName);
if(o instanceof BooleanOption) {
return (BooleanOption)o;
return (BooleanOption) o;
}
throw new ConfigurationException("Config Node " + optionName + " is not a boolean");
}
private Option getOption(String optionName) throws ConfigurationException {
LinkedList<String> l = new LinkedList<String>();
for(String s : optionName.split("\\.")) {
@ -459,9 +411,8 @@ public class NoCheatConfiguration {
if(names.size() == 0) {
return parent;
}
else if(parent instanceof ParentOption) {
for(Option o2 : ((ParentOption)parent).getChildOptions()) {
} else if(parent instanceof ParentOption) {
for(Option o2 : ((ParentOption) parent).getChildOptions()) {
if(o2.getIdentifier().equals(names.getFirst())) {
names.removeFirst();

View File

@ -4,7 +4,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
public class ParentOption extends Option {
/**
@ -48,9 +47,7 @@ public class ParentOption extends Option {
for(Option o : getChildOptions()) {
s += o.toYAMLString(prefix + " ");
}
}
else
{
} else {
for(Option o : getChildOptions()) {
s += o.toYAMLString(prefix);
}
@ -69,9 +66,7 @@ public class ParentOption extends Option {
for(Option o : getChildOptions()) {
s += o.toDescriptionString(prefix + " ");
}
}
else
{
} else {
for(Option o : getChildOptions()) {
s += o.toDescriptionString(prefix);
}

View File

@ -26,8 +26,7 @@ public abstract class TextFieldOption extends ChildOption {
if(isValid(value)) {
this.value = value;
return true;
}
else
} else
return false;
}

View File

@ -1,9 +1,8 @@
package cc.co.evenprime.bukkit.nocheat.data;
public class AirbuildData {
public int perFiveSeconds = 0;
public int summaryTask = -1;
}

View File

@ -7,15 +7,16 @@ import net.minecraft.server.Block;
import org.bukkit.Location;
import org.bukkit.Material;
public class MovingData {
public int jumpPhase = 0;
public final int violationsInARow[] = { 0, 0, 0 };
public final int violationsInARow[] = {0, 0, 0};
public double horizFreedom = 0.0D;
public double vertFreedom = 0.0D;
public int vertFreedomCounter = 0;
// setbackpoint is a recommendation - try to teleport to first solid block below it
// setbackpoint is a recommendation - try to teleport to first solid block
// below it
// for better effect
public Location setBackPoint = null;
@ -25,8 +26,6 @@ public class MovingData {
public double violationLevel = 0.0D;
public Location teleportInitializedByMe = null;
public boolean wasTeleported = true;
public Location teleportedTo;
// Block types that may need to be treated specially
public static final int NONSOLID = 0; // 0x00000000
@ -35,8 +34,8 @@ public class MovingData {
public static final int LADDER = 4; // 0x00000100
public static final int FENCE = 8; // 0x00001000
// Until I can think of a better way to determine if a block is solid or not, this is what I'll do
// Until I can think of a better way to determine if a block is solid or
// not, this is what I'll do
public static final int types[] = new int[256];
static {
@ -51,19 +50,17 @@ public class MovingData {
if(Block.byId[i].material.isSolid()) {
// solid blocks like STONE, CAKE, TRAPDOORS
types[i] = SOLID;
}
else if(Block.byId[i].material.isLiquid()){
} else if(Block.byId[i].material.isLiquid()) {
// WATER, LAVA
types[i] = LIQUID;
}
else {
} else {
types[i] = NONSOLID;
}
}
}
// Special types just for me
types[Material.LADDER.getId()]= LADDER | SOLID;
types[Material.FENCE.getId()]= FENCE | SOLID;
types[Material.LADDER.getId()] = LADDER | SOLID;
types[Material.FENCE.getId()] = FENCE | SOLID;
}
}

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.data;
/**
* per player storage for data persistence between events
*
@ -10,7 +9,8 @@ package cc.co.evenprime.bukkit.nocheat.data;
public class NoCheatData {
/**
* Don't rely on any of these yet, they are likely going to change their name/functionality
* Don't rely on any of these yet, they are likely going to change their
* name/functionality
*/
public MovingData moving;
public SpeedhackData speedhack;
@ -19,5 +19,5 @@ public class NoCheatData {
public PermissionData permission;
public NukeData nuke;
public NoCheatData() { }
public NoCheatData() {}
}

View File

@ -4,5 +4,4 @@ public class NukeData {
public int counter = 0;
}

View File

@ -11,10 +11,10 @@ public class PermissionData {
public static final int PERMISSION_FLYING = 1;
public static final int PERMISSION_SPEEDHACK = 2;
public static final int PERMISSION_AIRBUILD = 3;
public static final int PERMISSION_BEDTELEPORT = 4; // No longer used
public static final int PERMISSION_BEDTELEPORT = 4; // unused
public static final int PERMISSION_BOGUSITEMS = 5;
public static final int PERMISSION_NOTIFY = 6;
public static final int PERMISSION_ITEMDUPE = 7; // No longer used
public static final int PERMISSION_ITEMDUPE = 7; // unused
public static final int PERMISSION_FAKESNEAK = 8;
public static final int PERMISSION_FASTSWIM = 9;
public static final int PERMISSION_NUKE = 10;

View File

@ -4,10 +4,12 @@ import org.bukkit.Location;
public class SpeedhackData {
public int lastCheckTicks = 0; // timestamp of last check for speedhacks
public int lastCheckTicks = 0; // timestamp of last
// check for speedhacks
public Location setBackPoint = null;
public int eventsSinceLastCheck = 0; // used to identify speedhacks
public final int violationsInARow[] = { 0, 0, 0 };
public int eventsSinceLastCheck = 0; // used to identify
// speedhacks
public final int violationsInARow[] = {0, 0, 0};
public int violationsInARowTotal = 0;
}

View File

@ -22,6 +22,7 @@ public class AirbuildBlockListener extends BlockListener {
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(!event.isCancelled()) check.check(event);
if(!event.isCancelled())
check.check(event);
}
}

View File

@ -18,7 +18,8 @@ public class BogusitemsPlayerListener extends PlayerListener {
@Override
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if(!event.isCancelled()) check.check(event);
if(!event.isCancelled())
check.check(event);
}
@Override
@ -30,8 +31,8 @@ public class BogusitemsPlayerListener extends PlayerListener {
@Override
public void onPlayerInteract(PlayerInteractEvent event) {
if(!event.isCancelled()) check.check(event);
if(!event.isCancelled())
check.check(event);
}
}

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.listeners;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerListener;
@ -29,7 +28,8 @@ public class MovingPlayerListener extends PlayerListener {
@Override
public void onPlayerMove(PlayerMoveEvent event) {
if(event.isCancelled()) return;
if(event.isCancelled())
return;
final Player player = event.getPlayer();
@ -42,7 +42,7 @@ public class MovingPlayerListener extends PlayerListener {
Location newTo = null;
if(check.shouldBeApplied(player, data, from, to)) {
if(!player.isInsideVehicle()) {
// Check it
newTo = check.check(player, from, to, data);
}

View File

@ -29,7 +29,6 @@ public class MovingPlayerMonitor extends PlayerListener {
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
MovingData data = dataManager.getMovingData(event.getPlayer());
data.wasTeleported = true;
data.setBackPoint = null;
data.jumpPhase = 0;
}
@ -53,9 +52,9 @@ public class MovingPlayerMonitor extends PlayerListener {
public void onPlayerMove(PlayerMoveEvent event) {
if(!event.isCancelled()) {
if( event.getPlayer().isInsideVehicle()) {
if(event.getPlayer().isInsideVehicle()) {
MovingData data = dataManager.getMovingData(event.getPlayer());
data.setBackPoint = event.getTo();
data.setBackPoint = null;
}
}
}

View File

@ -16,7 +16,8 @@ public class NukeBlockListener extends BlockListener {
@Override
public void onBlockBreak(BlockBreakEvent event) {
//System.out.println("Break "+ event.getPlayer() + " " + event.getBlock());
// System.out.println("Break "+ event.getPlayer() + " " +
// event.getBlock());
check.check(event);
}

View File

@ -22,12 +22,14 @@ public class SpeedhackPlayerListener extends PlayerListener {
@Override
public void onPlayerMove(PlayerMoveEvent event) {
if(!event.isCancelled()) check.check(event);
if(!event.isCancelled())
check.check(event);
}
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
if(!event.isCancelled()) check.teleported(event);
if(!event.isCancelled())
check.teleported(event);
}
}

View File

@ -21,7 +21,6 @@ public class Wizard extends JFrame {
*/
private static final long serialVersionUID = 8798111079958779207L;
public Wizard() {
JScrollPane scrollable = new JScrollPane();
@ -33,7 +32,7 @@ public class Wizard extends JFrame {
JPanel inside = new JPanel();
scrollable.setViewportView(inside);
inside.setLayout(new BoxLayout(inside,BoxLayout.Y_AXIS));
inside.setLayout(new BoxLayout(inside, BoxLayout.Y_AXIS));
final NoCheatConfiguration config = new NoCheatConfiguration(new File("NoCheat/nocheat.yml"), new File("NoCheat/descriptions.txt"));
@ -51,7 +50,8 @@ public class Wizard extends JFrame {
NoCheatConfiguration.writeConfigFile(new File("NoCheat/nocheat.yml"), config);
JOptionPane.showMessageDialog(null, "Saved");
} });
}
});
b.setAlignmentY(0.0F);
inside.add(b);

View File

@ -1,6 +1,5 @@
package cc.co.evenprime.bukkit.nocheat.wizard.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@ -24,16 +23,13 @@ public class ChildOptionGuiFactory {
public static JComponent create(ChildOption option) {
if(option instanceof BooleanOption) {
return createBoolean((BooleanOption)option);
}
else if(option instanceof TextFieldOption) {
return createTextField((TextFieldOption)option);
}
else if(option instanceof LevelOption) {
return createLogLevel((LevelOption)option);
}
else if(option instanceof CustomActionOption) {
return createCustomAction((CustomActionOption)option);
return createBoolean((BooleanOption) option);
} else if(option instanceof TextFieldOption) {
return createTextField((TextFieldOption) option);
} else if(option instanceof LevelOption) {
return createLogLevel((LevelOption) option);
} else if(option instanceof CustomActionOption) {
return createCustomAction((CustomActionOption) option);
}
throw new RuntimeException("Unknown ChildOption " + option);
@ -52,7 +48,7 @@ public class ChildOptionGuiFactory {
@Override
public void actionPerformed(ActionEvent e) {
option.setValue((LevelOption.LogLevel)comboBox.getSelectedItem());
option.setValue((LevelOption.LogLevel) comboBox.getSelectedItem());
}
@ -104,8 +100,7 @@ public class ChildOptionGuiFactory {
value = Integer.parseInt(firstAfter.getText());
option.setFirsttAfterValue(value);
return true;
}
catch(Exception e) {
} catch(Exception e) {
JOptionPane.showMessageDialog(firstAfter, "Illegal value for this field");
firstAfter.setText(String.valueOf(option.getFirstAfterValue()));
return false;
@ -149,10 +144,9 @@ public class ChildOptionGuiFactory {
@Override
public boolean verify(JComponent arg0) {
if(option.setValue(textField.getText())){
if(option.setValue(textField.getText())) {
return true;
}
else {
} else {
JOptionPane.showMessageDialog(textField, "Illegal value for this field");
textField.setText(option.getValue());
return false;

View File

@ -36,10 +36,7 @@ public class ParentOptionGui extends JPanel {
this.option = option;
if(option.getIdentifier().length() > 0) {
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5,5,5,5), BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2,
2, 2, Color.BLACK), " " + option.getIdentifier() + ": "),
BorderFactory.createEmptyBorder(5,5,5,5))));
this.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.BLACK), " " + option.getIdentifier() + ": "), BorderFactory.createEmptyBorder(5, 5, 5, 5))));
}
this.setLayout(new GridBagLayout());
@ -77,8 +74,6 @@ public class ParentOptionGui extends JPanel {
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
c.gridy = line;
c.gridwidth = 1;
@ -97,9 +92,6 @@ public class ParentOptionGui extends JPanel {
c.ipady = 15;
c.weightx = 1;
this.add(p2, c);
line++;
}
@ -110,7 +102,6 @@ public class ParentOptionGui extends JPanel {
line++;
}
this.revalidate();
}
@ -122,17 +113,16 @@ public class ParentOptionGui extends JPanel {
c.gridy = line;
c.gridwidth = 4; // Spans over three columns
if(this.option.isEditable()) c.gridwidth = 5; // Spans over four columns
if(this.option.isEditable())
c.gridwidth = 5; // Spans over four columns
c.anchor = GridBagConstraints.WEST;
c.ipadx = 5;
c.ipady = 15;
c.weightx = 1;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(new ParentOptionGui((ParentOption)child), c);
}
else if(child instanceof ChildOption)
{
this.add(new ParentOptionGui((ParentOption) child), c);
} else if(child instanceof ChildOption) {
GridBagConstraints c = new GridBagConstraints();
c.gridx = 0;
@ -152,7 +142,7 @@ public class ParentOptionGui extends JPanel {
c.weightx = 0;
c.fill = GridBagConstraints.HORIZONTAL;
JComponent tmp = ChildOptionGuiFactory.create((ChildOption)child);
JComponent tmp = ChildOptionGuiFactory.create((ChildOption) child);
this.add(tmp, c);
@ -171,7 +161,7 @@ public class ParentOptionGui extends JPanel {
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, Explainations.get(((ChildOption)child).getFullIdentifier()), "Description of "+ ((ChildOption)child).getFullIdentifier(), JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, Explainations.get(((ChildOption) child).getFullIdentifier()), "Description of " + ((ChildOption) child).getFullIdentifier(), JOptionPane.INFORMATION_MESSAGE);
}

View File

@ -23,7 +23,6 @@ public class SimpleYaml {
private SimpleYaml() {}
public static Map<String, Object> read(File file) throws IOException {
Map<String, Object> root = new HashMap<String, Object>();
@ -34,7 +33,7 @@ public class SimpleYaml {
String line = null;
while(( line = r.readLine()) != null) {
while((line = r.readLine()) != null) {
lines.add(line);
}
@ -50,23 +49,23 @@ public class SimpleYaml {
while(!lines.isEmpty()) {
line = lines.getFirst();
if(line.trim().startsWith("#")) { lines.removeFirst(); }
else if(line.trim().isEmpty()) { lines.removeFirst(); }
else if(line.startsWith(prefix)) {
if(line.trim().startsWith("#")) {
lines.removeFirst();
} else if(line.trim().isEmpty()) {
lines.removeFirst();
} else if(line.startsWith(prefix)) {
lines.removeFirst();
if(line.contains(":")) {
String pair[] = line.split(":", 2);
if(pair[1].trim().isEmpty()) {
Map<String, Object> m = new HashMap<String, Object>();
root.put(pair[0].trim(), parse(m, lines, prefix + SimpleYaml.prefix));
}
else
{
} else {
root.put(pair[0].trim(), removeQuotationMarks(pair[1].trim()));
}
}
}
else break;
} else
break;
}
return root;
@ -74,10 +73,9 @@ public class SimpleYaml {
private static String removeQuotationMarks(String s) {
if(s.startsWith("\"") && s.endsWith("\"")) {
return s.substring(1, s.length() -1);
}
else if(s.startsWith("\'") && s.endsWith("\'")) {
return s.substring(1, s.length() -1);
return s.substring(1, s.length() - 1);
} else if(s.startsWith("\'") && s.endsWith("\'")) {
return s.substring(1, s.length() - 1);
}
return s;
@ -88,11 +86,9 @@ public class SimpleYaml {
@SuppressWarnings("unchecked")
private final static Object getProperty(String path, Map<String, Object> node) {
if (!path.contains(".")) {
if(!path.contains(".")) {
return node.get(path);
}
else
{
} else {
String[] parts = path.split("\\.", 2);
return getProperty(parts[1], (Map<String, Object>) node.get(parts[0]));
}
@ -101,37 +97,33 @@ public class SimpleYaml {
@SuppressWarnings("unchecked")
public static Set<String> getKeys(String path, Map<String, Object> node) {
try {
return ((Map<String, Object>)getProperty(path, node)).keySet();
}
catch(Exception e) {
//e.printStackTrace();
return ((Map<String, Object>) getProperty(path, node)).keySet();
} catch(Exception e) {
// e.printStackTrace();
return new HashSet<String>();
}
}
public static int getInt(String path, int defaultValue, Map<String, Object> node) {
try {
return Integer.parseInt((String)getProperty(path, node));
}
catch(Exception e) {
//e.printStackTrace();
return Integer.parseInt((String) getProperty(path, node));
} catch(Exception e) {
// e.printStackTrace();
return defaultValue;
}
}
public static boolean getBoolean(String path, boolean defaultValue, Map<String, Object> node) {
try {
if(((String)getProperty(path, node)).equals("true")) {
if(((String) getProperty(path, node)).equals("true")) {
return true;
} else if(((String)getProperty(path, node)).equals("false")) {
} else if(((String) getProperty(path, node)).equals("false")) {
return false;
}
else {
} else {
return defaultValue;
}
}
catch(Exception e) {
//e.printStackTrace();
} catch(Exception e) {
// e.printStackTrace();
return defaultValue;
}
}
@ -139,10 +131,10 @@ public class SimpleYaml {
public static String getString(String path, String defaultValue, Map<String, Object> node) {
try {
String result = (String) getProperty(path, node);
if(result == null) return defaultValue;
if(result == null)
return defaultValue;
return result;
}
catch(Exception e) {
} catch(Exception e) {
return defaultValue;
}
}