Nicer handling of events

This commit is contained in:
Evenprime 2011-11-08 15:30:23 +01:00
parent ae8cacb97b
commit 3ce696ee1f
27 changed files with 410 additions and 423 deletions

View File

@ -15,6 +15,10 @@ public interface NoCheatPlayer {
public BaseData getData(); public BaseData getData();
public int getTicksLived();
public void increaseAge(int ticks);
public ConfigurationCache getConfiguration(); public ConfigurationCache getConfiguration();

View File

@ -18,7 +18,6 @@ public abstract class TimedCheck extends Check {
@Override @Override
protected ExecutionHistory getHistory(NoCheatPlayer player) { protected ExecutionHistory getHistory(NoCheatPlayer player) {
// TODO Auto-generated method stub
return player.getData().timed.history; return player.getData().timed.history;
} }
} }

View File

@ -42,7 +42,7 @@ public class DirectionCheck extends BlockBreakCheck {
if(off < 0.1D) { if(off < 0.1D) {
// Player did nothing wrong // Player did nothing wrong
// reduce violation counter // reduce violation counter
blockbreak.directionViolationLevel *= 0.9D; blockbreak.directionVL *= 0.9D;
} else { } else {
// Player failed the check // Player failed the check
// Increment violation counter // Increment violation counter
@ -51,9 +51,9 @@ public class DirectionCheck extends BlockBreakCheck {
// hard on people failing them // hard on people failing them
off /= 10; off /= 10;
} }
blockbreak.directionViolationLevel += off; blockbreak.directionVL += off;
cancel = executeActions(player, ccblockbreak.directionActions.getActions(blockbreak.directionViolationLevel)); cancel = executeActions(player, ccblockbreak.directionActions.getActions(blockbreak.directionVL));
if(cancel) { if(cancel) {
// Needed to calculate penalty times // Needed to calculate penalty times
@ -78,7 +78,7 @@ public class DirectionCheck extends BlockBreakCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockbreak.directionViolationLevel); return String.format(Locale.US, "%d", player.getData().blockbreak.directionVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);

View File

@ -57,15 +57,15 @@ public class DirectionCheck extends BlockPlaceCheck {
if(off < 0.1D) { if(off < 0.1D) {
// Player did nothing wrong // Player did nothing wrong
// reduce violation counter // reduce violation counter
data.directionViolationLevel *= 0.9D; data.directionVL *= 0.9D;
} else { } else {
// Player failed the check // Player failed the check
// Increment violation counter // Increment violation counter
data.directionViolationLevel += off; data.directionVL += off;
// Prepare some event-specific values for logging and custom actions // Prepare some event-specific values for logging and custom actions
cancel = executeActions(player, cc.directionActions.getActions(data.directionViolationLevel)); cancel = executeActions(player, cc.directionActions.getActions(data.directionVL));
if(cancel) { if(cancel) {
// Needed to calculate penalty times // Needed to calculate penalty times
@ -91,7 +91,7 @@ public class DirectionCheck extends BlockPlaceCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockplace.directionViolationLevel); return String.format(Locale.US, "%d", player.getData().blockplace.directionVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);

View File

@ -35,12 +35,12 @@ public class ReachCheck extends BlockPlaceCheck {
// Player failed the check // Player failed the check
// Increment violation counter // Increment violation counter
data.reachViolationLevel += distance; data.reachVL += distance;
data.reachdistance = distance; data.reachdistance = distance;
cancel = executeActions(player, cc.reachActions.getActions(data.reachViolationLevel)); cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
} else { } else {
data.reachViolationLevel *= 0.9D; data.reachVL *= 0.9D;
} }
return cancel; return cancel;
@ -56,7 +56,7 @@ public class ReachCheck extends BlockPlaceCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().blockplace.reachViolationLevel); return String.format(Locale.US, "%d", player.getData().blockplace.reachVL);
case REACHDISTANCE: case REACHDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance); return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);

View File

@ -84,9 +84,9 @@ public class FlyingCheck extends MovingCheck {
if(result > 0) { if(result > 0) {
// Increment violation counter // Increment violation counter
moving.runflyViolationLevel += result; moving.runflyVL += result;
boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(moving.runflyViolationLevel)); boolean cancel = executeActions(player, ccmoving.flyingActions.getActions(moving.runflyVL));
// Was one of the actions a cancel? Then really do it // Was one of the actions a cancel? Then really do it
if(cancel) { if(cancel) {
@ -95,7 +95,7 @@ public class FlyingCheck extends MovingCheck {
} }
// Slowly reduce the level with each event // Slowly reduce the level with each event
moving.runflyViolationLevel *= 0.97; moving.runflyVL *= 0.97;
// Some other cleanup 'n' stuff // Some other cleanup 'n' stuff
if(newToLocation == null) { if(newToLocation == null) {
@ -107,7 +107,6 @@ public class FlyingCheck extends MovingCheck {
@Override @Override
public boolean isEnabled(CCMoving moving) { public boolean isEnabled(CCMoving moving) {
// TODO Auto-generated method stub
return moving.allowFlying && moving.runflyCheck; return moving.allowFlying && moving.runflyCheck;
} }
@ -116,7 +115,7 @@ public class FlyingCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyViolationLevel); return String.format(Locale.US, "%d", player.getData().moving.runflyVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -27,7 +27,7 @@ public class MorePacketsCheck extends MovingCheck {
private final static int bufferLimit = 30; private final static int bufferLimit = 30;
public MorePacketsCheck(NoCheat plugin) { public MorePacketsCheck(NoCheat plugin) {
super(plugin, "moving.morepackets", Permissions.MOVE_MOREPACKETS); super(plugin, "moving.morepackets", Permissions.MOVING_MOREPACKETS);
} }
/** /**
@ -73,11 +73,11 @@ public class MorePacketsCheck extends MovingCheck {
// Should we react? Only if the check doesn't get skipped and we // Should we react? Only if the check doesn't get skipped and we
// went over the limit // went over the limit
if(!plugin.skipCheck() && packetsAboveLimit > 0) { if(!plugin.skipCheck() && packetsAboveLimit > 0) {
data.morePacketsViolationLevel += packetsAboveLimit; data.morePacketsVL += packetsAboveLimit;
data.packets = packetsAboveLimit; data.packets = packetsAboveLimit;
final boolean cancel = executeActions(player, cc.morePacketsActions.getActions(data.morePacketsViolationLevel)); final boolean cancel = executeActions(player, cc.morePacketsActions.getActions(data.morePacketsVL));
if(cancel) if(cancel)
newToLocation = data.morePacketsSetbackPoint; newToLocation = data.morePacketsSetbackPoint;
@ -88,9 +88,9 @@ public class MorePacketsCheck extends MovingCheck {
data.morePacketsSetbackPoint.set(data.from); data.morePacketsSetbackPoint.set(data.from);
} }
if(data.morePacketsViolationLevel > 0) if(data.morePacketsVL > 0)
// Shrink the "over limit" value by 20 % every second // Shrink the "over limit" value by 20 % every second
data.morePacketsViolationLevel *= 0.8; data.morePacketsVL *= 0.8;
data.morePacketsCounter = 0; // Count from zero again data.morePacketsCounter = 0; // Count from zero again
data.lastElapsedIngameSeconds = ingameSeconds; data.lastElapsedIngameSeconds = ingameSeconds;
@ -109,7 +109,7 @@ public class MorePacketsCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.morePacketsViolationLevel); return String.format(Locale.US, "%d", player.getData().moving.morePacketsVL);
case PACKETS: case PACKETS:
return String.valueOf(player.getData().moving.packets); return String.valueOf(player.getData().moving.packets);
default: default:

View File

@ -19,7 +19,7 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
public class NoFallCheck extends MovingCheck { public class NoFallCheck extends MovingCheck {
public NoFallCheck(NoCheat plugin) { public NoFallCheck(NoCheat plugin) {
super(plugin, "moving.nofall", Permissions.MOVE_NOFALL); super(plugin, "moving.nofall", Permissions.MOVING_NOFALL);
} }
/** /**
@ -47,9 +47,9 @@ public class NoFallCheck extends MovingCheck {
final float difference = data.fallDistance - player.getPlayer().getFallDistance(); final float difference = data.fallDistance - player.getPlayer().getFallDistance();
if(difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) { if(difference > 1.0F && data.toOnOrInGround && data.fallDistance > 2.0F) {
data.nofallViolationLevel += difference; data.nofallVL += difference;
final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallViolationLevel)); final boolean cancel = executeActions(player, cc.nofallActions.getActions(data.nofallVL));
// If "cancelled", the fall damage gets dealt in a way that's // If "cancelled", the fall damage gets dealt in a way that's
// visible to other plugins // visible to other plugins
@ -91,14 +91,13 @@ public class NoFallCheck extends MovingCheck {
} }
// Reduce falldamage violation level // Reduce falldamage violation level
data.nofallViolationLevel *= 0.99D; data.nofallVL *= 0.99D;
return null; return null;
} }
@Override @Override
public boolean isEnabled(CCMoving moving) { public boolean isEnabled(CCMoving moving) {
// TODO Auto-generated method stub
return moving.nofallCheck; return moving.nofallCheck;
} }
@ -107,7 +106,7 @@ public class NoFallCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.nofallViolationLevel); return String.format(Locale.US, "%d", player.getData().moving.nofallVL);
case FALLDISTANCE: case FALLDISTANCE:
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance); return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
default: default:

View File

@ -16,7 +16,7 @@ public class RunflyCheck extends MovingCheck {
private final RunningCheck runningCheck; private final RunningCheck runningCheck;
public RunflyCheck(NoCheat plugin) { public RunflyCheck(NoCheat plugin) {
super(plugin, "moving.runfly", Permissions.MOVE_RUNFLY); super(plugin, "moving.runfly", Permissions.MOVING_RUNFLY);
flyingCheck = new FlyingCheck(plugin); flyingCheck = new FlyingCheck(plugin);
runningCheck = new RunningCheck(plugin); runningCheck = new RunningCheck(plugin);
@ -25,8 +25,8 @@ public class RunflyCheck extends MovingCheck {
@Override @Override
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) { public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
final boolean runflyCheck = cc.runflyCheck && !player.hasPermission(Permissions.MOVE_RUNFLY); final boolean runflyCheck = cc.runflyCheck && !player.hasPermission(Permissions.MOVING_RUNFLY);
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVE_FLY) || (player.getPlayer().getGameMode() == GameMode.CREATIVE && cc.identifyCreativeMode); final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.getPlayer().getGameMode() == GameMode.CREATIVE && cc.identifyCreativeMode);
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/ /********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
// If the player is not allowed to fly and not allowed to run // If the player is not allowed to fly and not allowed to run

View File

@ -36,7 +36,7 @@ public class RunningCheck extends MovingCheck {
public RunningCheck(NoCheat plugin) { public RunningCheck(NoCheat plugin) {
super(plugin, "moving.running", Permissions.MOVE_RUNFLY); super(plugin, "moving.running", Permissions.MOVING_RUNFLY);
this.noFallCheck = new NoFallCheck(plugin); this.noFallCheck = new NoFallCheck(plugin);
} }
@ -76,14 +76,14 @@ public class RunningCheck extends MovingCheck {
data.jumpPhase++; data.jumpPhase++;
// Slowly reduce the level with each event // Slowly reduce the level with each event
data.runflyViolationLevel *= 0.97; data.runflyVL *= 0.97;
if(result > 0) { if(result > 0) {
// Increment violation counter // Increment violation counter
data.runflyViolationLevel += result; data.runflyVL += result;
boolean cancel = executeActions(player, cc.actions.getActions(data.runflyViolationLevel)); boolean cancel = executeActions(player, cc.actions.getActions(data.runflyVL));
// Was one of the actions a cancel? Then do it // Was one of the actions a cancel? Then do it
if(cancel) { if(cancel) {
@ -110,7 +110,7 @@ public class RunningCheck extends MovingCheck {
} }
/********* EXECUTE THE NOFALL CHECK ********************/ /********* EXECUTE THE NOFALL CHECK ********************/
final boolean checkNoFall = cc.nofallCheck && !player.hasPermission(Permissions.MOVE_NOFALL); final boolean checkNoFall = cc.nofallCheck && !player.hasPermission(Permissions.MOVING_NOFALL);
if(checkNoFall && newToLocation == null) { if(checkNoFall && newToLocation == null) {
data.fromOnOrInGround = fromOnGround || fromInGround; data.fromOnOrInGround = fromOnGround || fromInGround;
@ -136,9 +136,9 @@ public class RunningCheck extends MovingCheck {
final EntityPlayer p = ((CraftPlayer) player).getHandle(); final EntityPlayer p = ((CraftPlayer) player).getHandle();
if(ccmoving.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVE_SNEAK)) { if(ccmoving.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVING_SNEAKING)) {
limit = ccmoving.sneakingSpeedLimit; limit = ccmoving.sneakingSpeedLimit;
} else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVE_SWIM)) { } else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVING_SWIMMING)) {
limit = ccmoving.swimmingSpeedLimit; limit = ccmoving.swimmingSpeedLimit;
} else if(!sprinting) { } else if(!sprinting) {
limit = ccmoving.walkingSpeedLimit; limit = ccmoving.walkingSpeedLimit;
@ -221,7 +221,7 @@ public class RunningCheck extends MovingCheck {
switch (wildcard) { switch (wildcard) {
case VIOLATIONS: case VIOLATIONS:
return String.format(Locale.US, "%d", player.getData().moving.runflyViolationLevel); return String.format(Locale.US, "%d", player.getData().moving.runflyVL);
default: default:
return super.getParameter(wildcard, player); return super.getParameter(wildcard, player);
} }

View File

@ -2,10 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.timed;
import java.util.Locale; import java.util.Locale;
import net.minecraft.server.EntityPlayer;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard; import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
@ -27,11 +23,12 @@ public class GodmodeCheck extends TimedCheck {
if(plugin.skipCheck() || player.getPlayer().isDead()) if(plugin.skipCheck() || player.getPlayer().isDead())
return false; return false;
EntityPlayer p = ((CraftPlayer) player).getHandle(); final int ticksLived = player.getTicksLived();
// Haven't been checking before // Haven't been checking before
if(data.ticksLived == 0) { if(data.ticksLived == 0) {
// setup data for next time // setup data for next time
data.ticksLived = p.ticksLived; data.ticksLived = ticksLived;
// And give up already // And give up already
return false; return false;
@ -40,7 +37,7 @@ public class GodmodeCheck extends TimedCheck {
boolean cancel = false; boolean cancel = false;
// Compare ingame record of players ticks to our last observed value // Compare ingame record of players ticks to our last observed value
int difference = p.ticksLived - data.ticksLived; int difference = ticksLived - data.ticksLived;
// difference should be >= tickTime for perfect synchronization // difference should be >= tickTime for perfect synchronization
if(difference > cc.tickTime) { if(difference > cc.tickTime) {
@ -78,13 +75,11 @@ public class GodmodeCheck extends TimedCheck {
if(cancel) { if(cancel) {
// Catch up for at least some of the ticks // Catch up for at least some of the ticks
for(int i = 0; i < cc.tickTime; i++) { player.increaseAge(cc.tickTime);
p.b(true); // Catch up with the server, one tick at a time
}
} }
// setup data for next time // setup data for next time
data.ticksLived = p.ticksLived; data.ticksLived = player.getTicksLived();
return cancel; return cancel;

View File

@ -11,12 +11,12 @@ public class Permissions {
private final static String CHECKS = NOCHEAT + ".checks"; private final static String CHECKS = NOCHEAT + ".checks";
public final static String MOVING = CHECKS + ".moving"; public final static String MOVING = CHECKS + ".moving";
public final static String MOVE_RUNFLY = MOVING + ".runfly"; public final static String MOVING_RUNFLY = MOVING + ".runfly";
public final static String MOVE_SNEAK = MOVING + ".sneaking"; public final static String MOVING_SNEAKING = MOVING + ".sneaking";
public final static String MOVE_SWIM = MOVING + ".swimming"; public final static String MOVING_SWIMMING = MOVING + ".swimming";
public final static String MOVE_FLY = MOVING + ".flying"; public final static String MOVING_FLYING = MOVING + ".flying";
public final static String MOVE_NOFALL = MOVING + ".nofall"; public final static String MOVING_NOFALL = MOVING + ".nofall";
public final static String MOVE_MOREPACKETS = MOVING + ".morepackets"; public final static String MOVING_MOREPACKETS = MOVING + ".morepackets";
public final static String BLOCKBREAK = CHECKS + ".blockbreak"; public final static String BLOCKBREAK = CHECKS + ".blockbreak";
public final static String BLOCKBREAK_REACH = BLOCKBREAK + ".reach"; public final static String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";

View File

@ -7,12 +7,10 @@ package cc.co.evenprime.bukkit.nocheat.data;
public class BlockBreakData extends Data { public class BlockBreakData extends Data {
public double reachVL = 0.0D; public double reachVL = 0.0D;
public double directionViolationLevel = 0.0D; public double directionVL = 0.0D;
public long directionLastViolationTime = 0; public long directionLastViolationTime = 0;
public final SimpleLocation instaBrokeBlockLocation = new SimpleLocation(); public final SimpleLocation instaBrokeBlockLocation = new SimpleLocation();
// Verified
public final SimpleLocation brokenBlockLocation = new SimpleLocation(); public final SimpleLocation brokenBlockLocation = new SimpleLocation();
public final ExecutionHistory history = new ExecutionHistory(); public final ExecutionHistory history = new ExecutionHistory();

View File

@ -7,10 +7,9 @@ import org.bukkit.Material;
*/ */
public class BlockPlaceData extends Data { public class BlockPlaceData extends Data {
public double onliquidViolationLevel = 0.0D; public double reachVL = 0.0D;
public double reachViolationLevel = 0.0D;
public final ExecutionHistory history = new ExecutionHistory(); public final ExecutionHistory history = new ExecutionHistory();
public double directionViolationLevel = 0.0D; public double directionVL = 0.0D;
public long directionLastViolationTime = 0; public long directionLastViolationTime = 0;
public final SimpleLocation blockPlacedAgainst = new SimpleLocation(); public final SimpleLocation blockPlacedAgainst = new SimpleLocation();

View File

@ -9,7 +9,7 @@ public class MovingData extends Data {
public final PreciseLocation runflySetBackPoint = new PreciseLocation(); public final PreciseLocation runflySetBackPoint = new PreciseLocation();
public double runflyViolationLevel; public double runflyVL;
public double vertFreedom; public double vertFreedom;
public double vertVelocity; public double vertVelocity;
@ -17,7 +17,7 @@ public class MovingData extends Data {
public double horizFreedom; public double horizFreedom;
public int horizVelocityCounter; public int horizVelocityCounter;
public double nofallViolationLevel; public double nofallVL;
public float fallDistance; public float fallDistance;
public float lastAddedFallDistance; public float lastAddedFallDistance;
@ -29,7 +29,7 @@ public class MovingData extends Data {
public int packets; public int packets;
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation(); public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
public double morePacketsViolationLevel; public double morePacketsVL;
public final PreciseLocation teleportTo = new PreciseLocation(); public final PreciseLocation teleportTo = new PreciseLocation();

View File

@ -36,7 +36,7 @@ public class PlayerManager {
NoCheatPlayer p = this.map.get(playerName); NoCheatPlayer p = this.map.get(playerName);
if(p == null) { if(p == null) {
// TODO: Differentiate which player"type" should be created // TODO: Differentiate which player"type" should be created, e.g. based on bukkit version
p = new NoCheatPlayerImpl(playerName, plugin, new BaseData()); p = new NoCheatPlayerImpl(playerName, plugin, new BaseData());
this.map.put(playerName, p); this.map.put(playerName, p);
} }

View File

@ -8,8 +8,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent; import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -21,24 +19,19 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak; import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData; import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
/** /**
* Central location to listen to player-interact events and dispatch them to * Central location to listen to player-interact events and dispatch them to
* relevant checks * relevant checks
* *
*/ */
public class BlockBreakEventManager extends BlockListener implements EventManager { public class BlockBreakEventManager extends EventManager {
private final List<BlockBreakCheck> checks; private final List<BlockBreakCheck> checks;
private final NoCheat plugin;
private final Performance blockBreakPerformance;
private final Performance blockDamagePerformance;
public BlockBreakEventManager(NoCheat plugin) { public BlockBreakEventManager(NoCheat plugin) {
this.plugin = plugin; super(plugin);
// Three checks exist for this event type // Three checks exist for this event type
this.checks = new ArrayList<BlockBreakCheck>(3); this.checks = new ArrayList<BlockBreakCheck>(3);
@ -46,16 +39,12 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
this.checks.add(new NoswingCheck(plugin)); this.checks.add(new NoswingCheck(plugin));
this.checks.add(new ReachCheck(plugin)); this.checks.add(new ReachCheck(plugin));
this.blockBreakPerformance = plugin.getPerformance(Type.BLOCKBREAK); registerListener(Event.Type.BLOCK_BREAK, Priority.Lowest, true);
this.blockDamagePerformance = plugin.getPerformance(Type.BLOCKDAMAGE); registerListener(Event.Type.BLOCK_DAMAGE, Priority.Monitor, true);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_BREAK, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.BLOCK_DAMAGE, this, Priority.Monitor, plugin);
} }
private void handleEvent(BlockBreakEvent event) { @Override
protected void handleBlockBreakEvent(BlockBreakEvent event, Priority priority) {
boolean cancelled = false; boolean cancelled = false;
@ -85,7 +74,14 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
} }
private void handleEvent(BlockDamageEvent event) { @Override
protected void handleBlockDamageEvent(BlockDamageEvent event, Priority priority) {
// Only interested in insta-break events here
if(!event.getInstaBreak()) {
return;
}
// Get the player-specific stored data that applies here // Get the player-specific stored data that applies here
final BlockBreakData data = plugin.getPlayer(event.getPlayer().getName()).getData().blockbreak; final BlockBreakData data = plugin.getPlayer(event.getPlayer().getName()).getData().blockbreak;
@ -94,49 +90,6 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
data.instaBrokeBlockLocation.set(event.getBlock()); data.instaBrokeBlockLocation.set(event.getBlock());
} }
@Override
public void onBlockBreak(BlockBreakEvent event) {
if(event.isCancelled()) {
return;
}
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = blockBreakPerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(event);
// store performance time
if(performanceCheck)
blockBreakPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
@Override
public void onBlockDamage(BlockDamageEvent event) {
// Only interested in insta-break events
if(!event.isCancelled() && !event.getInstaBreak()) {
return;
}
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = blockDamagePerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(event);
// store performance time
if(performanceCheck)
blockDamagePerformance.addTime(System.nanoTime() - nanoTimeStart);
}
public List<String> getActiveChecks(ConfigurationCache cc) { public List<String> getActiveChecks(ConfigurationCache cc) {
LinkedList<String> s = new LinkedList<String>(); LinkedList<String> s = new LinkedList<String>();

View File

@ -6,9 +6,7 @@ import java.util.List;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -19,58 +17,33 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace; import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData; import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
/** /**
* Central location to listen to Block-related events and dispatching them to * Central location to listen to Block-related events and dispatching them to
* checks * checks
* *
*/ */
public class BlockPlaceEventManager extends BlockListener implements EventManager { public class BlockPlaceEventManager extends EventManager {
private final List<BlockPlaceCheck> checks; private final List<BlockPlaceCheck> checks;
private final NoCheat plugin;
private final Performance blockPlacePerformance; public BlockPlaceEventManager(NoCheat plugin) {
public BlockPlaceEventManager(NoCheat p) { super(plugin);
this.plugin = p;
this.checks = new ArrayList<BlockPlaceCheck>(2); this.checks = new ArrayList<BlockPlaceCheck>(2);
this.checks.add(new DirectionCheck(plugin)); this.checks.add(new DirectionCheck(plugin));
this.checks.add(new ReachCheck(plugin)); this.checks.add(new ReachCheck(plugin));
this.blockPlacePerformance = p.getPerformance(Type.BLOCKPLACE); registerListener(Event.Type.BLOCK_PLACE, Priority.Lowest, true);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Lowest, plugin);
} }
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) { protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
if(event.isCancelled() || event.getBlock() == null) if(event.getBlock() == null)
return; return;
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = blockPlacePerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(event);
// store performance time
if(performanceCheck)
blockPlacePerformance.addTime(System.nanoTime() - nanoTimeStart);
}
private void handleEvent(BlockPlaceEvent event) {
boolean cancelled = false; boolean cancelled = false;
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName()); NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());

View File

@ -1,11 +1,230 @@
package cc.co.evenprime.bukkit.nocheat.events; package cc.co.evenprime.bukkit.nocheat.events;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
public interface EventManager { public abstract class EventManager {
public List<String> getActiveChecks(ConfigurationCache cc); protected NoCheat plugin;
private static class BlockL extends BlockListener {
private final EventManager m;
private final Priority priority;
private final boolean ignoreCancelledEvents;
public BlockL(EventManager m, Priority priority, boolean ignoreCancelled) {
this.m = m;
this.priority = priority;
this.ignoreCancelledEvents = ignoreCancelled;
}
@Override
public void onBlockPlace(BlockPlaceEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handleBlockPlaceEvent(event, priority);
}
@Override
public void onBlockBreak(BlockBreakEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handleBlockBreakEvent(event, priority);
}
@Override
public void onBlockDamage(BlockDamageEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handleBlockDamageEvent(event, priority);
}
}
private static class PlayerL extends PlayerListener {
private final EventManager m;
private final Priority priority;
private final boolean ignoreCancelledEvents;
public PlayerL(EventManager m, Priority priority, boolean ignoreCancelled) {
this.m = m;
this.priority = priority;
this.ignoreCancelledEvents = ignoreCancelled;
}
@Override
public void onPlayerChat(PlayerChatEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerChatEvent(event, priority);
}
@Override
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerCommandPreprocessEvent(event, priority);
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerMoveEvent(event, priority);
}
@Override
public void onPlayerVelocity(PlayerVelocityEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerVelocityEvent(event, priority);
}
@Override
public void onPlayerRespawn(PlayerRespawnEvent event) {
// if(ignoreCancelledEvents && event.isCancelled()) return;
m.handlePlayerRespawnEvent(event, priority);
}
@Override
public void onPlayerPortal(PlayerPortalEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerPortalEvent(event, priority);
}
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerTeleportEvent(event, priority);
}
@Override
public void onPlayerAnimation(PlayerAnimationEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handlePlayerAnimationEvent(event, priority);
}
}
private static class EntityL extends EntityListener {
private final EventManager m;
private final Priority priority;
private final boolean ignoreCancelledEvents;
public EntityL(EventManager m, Priority priority, boolean ignoreCancelled) {
this.m = m;
this.priority = priority;
this.ignoreCancelledEvents = ignoreCancelled;
}
@Override
public void onEntityDamage(EntityDamageEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
m.handleEntityDamageEvent(event, priority);
}
}
public EventManager(NoCheat plugin) {
this.plugin = plugin;
}
protected void registerListener(Type type, Priority priority, boolean ignoreCancelled) {
switch (type.getCategory()) {
case BLOCK:
Bukkit.getServer().getPluginManager().registerEvent(type, new BlockL(this, priority, ignoreCancelled), priority, plugin);
break;
case PLAYER:
Bukkit.getServer().getPluginManager().registerEvent(type, new PlayerL(this, priority, ignoreCancelled), priority, plugin);
break;
case ENTITY:
Bukkit.getServer().getPluginManager().registerEvent(type, new EntityL(this, priority, ignoreCancelled), priority, plugin);
break;
default:
System.out.println("Can't register a listener for " + type);
}
}
public List<String> getActiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
protected void handleEvent(Event event, Priority priority) {
System.out.println("Handling of event " + event.getType() + " not implemented for " + this);
}
protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handleBlockBreakEvent(BlockBreakEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handleBlockDamageEvent(BlockDamageEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handleEntityDamageEvent(EntityDamageEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerChatEvent(PlayerChatEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerVelocityEvent(PlayerVelocityEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerRespawnEvent(PlayerRespawnEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerPortalEvent(PlayerPortalEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerTeleportEvent(PlayerTeleportEvent event, Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerAnimationEvent(PlayerAnimationEvent event, Priority priority) {
handleEvent(event, priority);
}
} }

View File

@ -12,9 +12,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.entity.EntityListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -26,59 +23,24 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight; import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.FightData; import cc.co.evenprime.bukkit.nocheat.data.FightData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
public class FightEventManager extends EntityListener implements EventManager { public class FightEventManager extends EventManager {
private final NoCheat plugin;
private final List<FightCheck> checks; private final List<FightCheck> checks;
private final Performance fightPerformance;
public FightEventManager(NoCheat plugin) { public FightEventManager(NoCheat plugin) {
super(plugin);
this.plugin = plugin;
this.checks = new ArrayList<FightCheck>(3); this.checks = new ArrayList<FightCheck>(3);
this.checks.add(new NoswingCheck(plugin)); this.checks.add(new NoswingCheck(plugin));
this.checks.add(new DirectionCheck(plugin)); this.checks.add(new DirectionCheck(plugin));
this.checks.add(new SelfhitCheck(plugin)); this.checks.add(new SelfhitCheck(plugin));
this.fightPerformance = plugin.getPerformance(Type.FIGHT); registerListener(Event.Type.ENTITY_DAMAGE, Priority.Lowest, true);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Lowest, plugin);
} }
@Override @Override
public void onEntityDamage(EntityDamageEvent event) { protected void handleEntityDamageEvent(EntityDamageEvent event, Priority priority) {
// Event cancelled?
if(event.isCancelled()) {
return;
}
// Event relevant at all?
if(event.getCause() != DamageCause.ENTITY_ATTACK || !(((EntityDamageByEntityEvent) event).getDamager() instanceof Player)) {
return;
}
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = fightPerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(event);
// store performance time
if(performanceCheck)
fightPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
private void handleEvent(EntityDamageEvent event) {
final Entity damagee = ((CraftEntity) event.getEntity()).getHandle(); final Entity damagee = ((CraftEntity) event.getEntity()).getHandle();

View File

@ -8,8 +8,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer; import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
@ -19,62 +17,30 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat; import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
import cc.co.evenprime.bukkit.nocheat.data.ChatData; import cc.co.evenprime.bukkit.nocheat.data.ChatData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
/** public class PlayerChatEventManager extends EventManager {
*
*/
public class PlayerChatEventManager extends PlayerListener implements EventManager {
private final NoCheat plugin;
private final List<ChatCheck> checks; private final List<ChatCheck> checks;
private final Performance chatPerformance;
public PlayerChatEventManager(NoCheat plugin) { public PlayerChatEventManager(NoCheat plugin) {
this.plugin = plugin; super(plugin);
this.checks = new ArrayList<ChatCheck>(1); this.checks = new ArrayList<ChatCheck>(1);
this.checks.add(new SpamCheck(plugin)); this.checks.add(new SpamCheck(plugin));
this.chatPerformance = plugin.getPerformance(Type.CHAT); registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true);
registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true);
PluginManager pm = plugin.getServer().getPluginManager();
pm.registerEvent(Event.Type.PLAYER_CHAT, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_COMMAND_PREPROCESS, this, Priority.Lowest, plugin);
} }
@Override @Override
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) { protected void handlePlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event, Priority priority) {
// We redirect to the other method anyway, so no need to set up a handleEvent((PlayerChatEvent) event, priority);
// performance counter here
onPlayerChat(event);
} }
@Override @Override
public void onPlayerChat(final PlayerChatEvent event) { protected void handlePlayerChatEvent(PlayerChatEvent event, Priority priority) {
if(event.isCancelled()) {
return;
}
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = chatPerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(event);
// store performance time
if(performanceCheck)
chatPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
private void handleEvent(PlayerChatEvent event) {
boolean cancelled = false; boolean cancelled = false;
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName()); NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());

View File

@ -8,12 +8,9 @@ import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerVelocityEvent; import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.plugin.PluginManager;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
@ -29,8 +26,6 @@ import cc.co.evenprime.bukkit.nocheat.data.BaseData;
import cc.co.evenprime.bukkit.nocheat.data.MovingData; import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation; import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation; import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
/** /**
* The only place that listens to and modifies player_move events if necessary * The only place that listens to and modifies player_move events if necessary
@ -39,68 +34,56 @@ import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
* evaluate the check results and decide what to * evaluate the check results and decide what to
* *
*/ */
public class PlayerMoveEventManager extends PlayerListener implements EventManager { public class PlayerMoveEventManager extends EventManager {
private final NoCheat plugin;
private final List<MovingCheck> checks; private final List<MovingCheck> checks;
private final Performance movePerformance;
private final Performance velocityPerformance;
public PlayerMoveEventManager(final NoCheat plugin) { public PlayerMoveEventManager(final NoCheat plugin) {
this.plugin = plugin; super(plugin);
this.checks = new ArrayList<MovingCheck>(5);
this.checks = new ArrayList<MovingCheck>(2);
checks.add(new RunflyCheck(plugin)); checks.add(new RunflyCheck(plugin));
checks.add(new MorePacketsCheck(plugin)); checks.add(new MorePacketsCheck(plugin));
this.movePerformance = plugin.getPerformance(Type.MOVING); registerListener(Event.Type.PLAYER_MOVE, Priority.Lowest, true);
this.velocityPerformance = plugin.getPerformance(Type.VELOCITY); registerListener(Event.Type.PLAYER_VELOCITY, Priority.Monitor, true);
registerListener(Event.Type.BLOCK_PLACE, Priority.Monitor, true);
PluginManager pm = plugin.getServer().getPluginManager(); }
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Lowest, plugin);
pm.registerEvent(Event.Type.PLAYER_VELOCITY, this, Priority.Monitor, plugin);
// This is part of a workaround for the moving check
pm.registerEvent(Event.Type.BLOCK_PLACE, new BlockListener() {
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) { protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
if(event.isCancelled())
return;
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName()); final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
// Get the player-specific stored data that applies here // Get the player-specific stored data that applies here
blockPlaced(player, event.getBlockPlaced()); BaseData data = player.getData();
Block blockPlaced = event.getBlockPlaced();
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
return;
}
SimpleLocation lblock = new SimpleLocation();
lblock.set(blockPlaced);
SimpleLocation lplayer = new SimpleLocation();
lplayer.setLocation(player.getPlayer().getLocation());
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
int type = CheckUtil.getType(blockPlaced.getTypeId());
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
if(lblock.y + 1 >= data.moving.runflySetBackPoint.y) {
data.moving.runflySetBackPoint.y = (lblock.y + 1);
data.moving.jumpPhase = 0;
}
}
} }
}, Priority.Monitor, plugin);
} }
@Override @Override
public void onPlayerMove(final PlayerMoveEvent event) { protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
// Cancelled events are ignored
if(event.isCancelled())
return;
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = movePerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
handleEvent(event);
// store performance time
if(performanceCheck)
movePerformance.addTime(System.nanoTime() - nanoTimeStart);
}
public void handleEvent(PlayerMoveEvent event) {
// Get the world-specific configuration that applies here // Get the world-specific configuration that applies here
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName()); final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
@ -157,16 +140,7 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
} }
@Override @Override
public void onPlayerVelocity(PlayerVelocityEvent event) { protected void handlePlayerVelocityEvent(PlayerVelocityEvent event, Priority priority) {
if(event.isCancelled())
return;
// Performance counter setup
long nanoTimeStart = 0;
final boolean performanceCheck = velocityPerformance.isEnabled();
if(performanceCheck)
nanoTimeStart = System.nanoTime();
MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving; MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
@ -185,39 +159,6 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
data.horizFreedom += newVal; data.horizFreedom += newVal;
data.horizVelocityCounter = 30; data.horizVelocityCounter = 30;
} }
// store performance time
if(performanceCheck)
velocityPerformance.addTime(System.nanoTime() - nanoTimeStart);
}
/**
* This is a workaround for people placing blocks below them causing false
* positives with the move check(s).
*/
public void blockPlaced(final NoCheatPlayer player, Block blockPlaced) {
BaseData data = player.getData();
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
return;
}
SimpleLocation lblock = new SimpleLocation();
lblock.set(blockPlaced);
SimpleLocation lplayer = new SimpleLocation();
lplayer.setLocation(player.getPlayer().getLocation());
if(Math.abs(lplayer.x - lblock.x) <= 1 && Math.abs(lplayer.z - lblock.z) <= 1 && lplayer.y - lblock.y >= 0 && lplayer.y - lblock.y <= 2) {
int type = CheckUtil.getType(blockPlaced.getTypeId());
if(CheckUtil.isSolid(type) || CheckUtil.isLiquid(type)) {
if(lblock.y + 1 >= data.moving.runflySetBackPoint.y) {
data.moving.runflySetBackPoint.y = (lblock.y + 1);
data.moving.jumpPhase = 0;
}
}
}
} }
public List<String> getActiveChecks(ConfigurationCache cc) { public List<String> getActiveChecks(ConfigurationCache cc) {

View File

@ -1,85 +1,65 @@
package cc.co.evenprime.bukkit.nocheat.events; package cc.co.evenprime.bukkit.nocheat.events;
import java.util.Collections;
import java.util.List;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache; import cc.co.evenprime.bukkit.nocheat.data.MovingData;
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
/** /**
* Only place that listens to Player-teleport related events and dispatches them * Only place that listens to Player-teleport related events and dispatches them
* to relevant checks * to relevant checks
* *
*/ */
public class PlayerTeleportEventManager extends PlayerListener implements EventManager { public class PlayerTeleportEventManager extends EventManager {
private final NoCheat plugin; public PlayerTeleportEventManager(NoCheat plugin) {
public PlayerTeleportEventManager(NoCheat p) { super(plugin);
this.plugin = p; registerListener(Event.Type.PLAYER_MOVE, Priority.Monitor, false);
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true);
PluginManager pm = plugin.getServer().getPluginManager(); registerListener(Event.Type.PLAYER_TELEPORT, Priority.Highest, false);
registerListener(Event.Type.PLAYER_PORTAL, Priority.Monitor, true);
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Monitor, plugin); registerListener(Event.Type.PLAYER_RESPAWN, Priority.Monitor, true);
pm.registerEvent(Event.Type.PLAYER_TELEPORT, this, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_PORTAL, this, Priority.Monitor, plugin);
pm.registerEvent(Event.Type.PLAYER_RESPAWN, this, Priority.Monitor, plugin);
// This belongs to the move-check
// Override decision to cancel teleports initialized by NoCheat by
// uncancelling them, if possible
pm.registerEvent(Event.Type.PLAYER_TELEPORT, new PlayerListener() {
@Override
public void onPlayerTeleport(PlayerTeleportEvent event) {
if(!event.isCancelled()) {
return;
} }
final BaseData data = plugin.getPlayer(event.getPlayer().getName()).getData(); @Override
protected void handlePlayerTeleportEvent(PlayerTeleportEvent event, Priority priority) {
if(priority.equals(Priority.Monitor)) {
handleTeleportation(event.getPlayer().getName());
} else {
// No typo here, I really want to only handle cancelled events
if(!event.isCancelled())
return;
if(data.moving.teleportTo.isSet() && data.moving.teleportTo.equals(event.getTo())) { final MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
event.setCancelled(false); event.setCancelled(false);
} }
} }
}, Priority.Highest, plugin);
} }
@Override @Override
public void onPlayerTeleport(PlayerTeleportEvent event) { protected void handlePlayerPortalEvent(PlayerPortalEvent event, Priority priority) {
if(event.isCancelled())
return;
handleTeleportation(event.getPlayer().getName()); handleTeleportation(event.getPlayer().getName());
} }
public void onPlayerPortal(PlayerPortalEvent event) { @Override
if(event.isCancelled()) protected void handlePlayerRespawnEvent(PlayerRespawnEvent event, Priority priority) {
return;
handleTeleportation(event.getPlayer().getName()); handleTeleportation(event.getPlayer().getName());
} }
public void onPlayerRespawn(PlayerRespawnEvent event) { @Override
handleTeleportation(event.getPlayer().getName()); protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
} // No typo here. I really only handle cancelled events and ignore others
if(!event.isCancelled())
// Workaround for buggy Playermove cancelling
public void onPlayerMove(PlayerMoveEvent event) {
if(!event.isCancelled()) {
return; return;
}
handleTeleportation(event.getPlayer().getName()); handleTeleportation(event.getPlayer().getName());
} }
@ -88,8 +68,4 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
plugin.clearCriticalData(playerName); plugin.clearCriticalData(playerName);
} }
public List<String> getActiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
} }

View File

@ -1,16 +1,10 @@
package cc.co.evenprime.bukkit.nocheat.events; package cc.co.evenprime.bukkit.nocheat.events;
import java.util.Collections;
import java.util.List;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.Event.Priority; import org.bukkit.event.Event.Priority;
import org.bukkit.event.player.PlayerAnimationEvent; import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.plugin.PluginManager;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
/** /**
* The only place that listens to and modifies player_move events if necessary * The only place that listens to and modifies player_move events if necessary
@ -19,25 +13,17 @@ import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
* evaluate the check results and decide what to * evaluate the check results and decide what to
* *
*/ */
public class SwingEventManager extends PlayerListener implements EventManager { public class SwingEventManager extends EventManager {
private final NoCheat plugin;
public SwingEventManager(NoCheat plugin) { public SwingEventManager(NoCheat plugin) {
this.plugin = plugin; super(plugin);
PluginManager pm = plugin.getServer().getPluginManager(); registerListener(Event.Type.PLAYER_ANIMATION, Priority.Monitor, false);
pm.registerEvent(Event.Type.PLAYER_ANIMATION, this, Priority.Lowest, plugin);
} }
@Override @Override
public void onPlayerAnimation(final PlayerAnimationEvent event) { protected void handlePlayerAnimationEvent(PlayerAnimationEvent event, Priority priority) {
plugin.getPlayer(event.getPlayer().getName()).getData().armswung = true; plugin.getPlayer(event.getPlayer().getName()).getData().armswung = true;
} }
public List<String> getActiveChecks(ConfigurationCache cc) {
return Collections.emptyList();
}
} }

View File

@ -20,7 +20,7 @@ import cc.co.evenprime.bukkit.nocheat.data.TimedData;
import cc.co.evenprime.bukkit.nocheat.debug.Performance; import cc.co.evenprime.bukkit.nocheat.debug.Performance;
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type; import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
public class TimedEventManager implements EventManager { public class TimedEventManager extends EventManager {
private final List<TimedCheck> checks; private final List<TimedCheck> checks;
private final Performance timedPerformance; private final Performance timedPerformance;
@ -28,6 +28,8 @@ public class TimedEventManager implements EventManager {
public TimedEventManager(final NoCheat plugin) { public TimedEventManager(final NoCheat plugin) {
super(plugin);
checks = new ArrayList<TimedCheck>(1); checks = new ArrayList<TimedCheck>(1);
checks.add(new GodmodeCheck(plugin)); checks.add(new GodmodeCheck(plugin));

View File

@ -1,6 +1,9 @@
package cc.co.evenprime.bukkit.nocheat.player; package cc.co.evenprime.bukkit.nocheat.player;
import net.minecraft.server.EntityPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import cc.co.evenprime.bukkit.nocheat.NoCheat; import cc.co.evenprime.bukkit.nocheat.NoCheat;
@ -40,4 +43,17 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
return player.getName(); return player.getName();
} }
public int getTicksLived() {
return player.getTicksLived();
}
public void increaseAge(int ticks) {
EntityPlayer p = ((CraftPlayer) player).getHandle();
for(int i = 0; i < ticks; i++) {
// TODO: This is highly fragile and breaks every update!!
p.b(true); // Catch up with the server, one tick at a time
}
}
} }