mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-16 20:41:20 +01:00
Nicer handling of events
This commit is contained in:
parent
ae8cacb97b
commit
3ce696ee1f
@ -15,6 +15,10 @@ public interface NoCheatPlayer {
|
||||
|
||||
public BaseData getData();
|
||||
|
||||
public int getTicksLived();
|
||||
|
||||
public void increaseAge(int ticks);
|
||||
|
||||
public ConfigurationCache getConfiguration();
|
||||
|
||||
|
||||
|
@ -18,7 +18,6 @@ public abstract class TimedCheck extends Check {
|
||||
|
||||
@Override
|
||||
protected ExecutionHistory getHistory(NoCheatPlayer player) {
|
||||
// TODO Auto-generated method stub
|
||||
return player.getData().timed.history;
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
if(off < 0.1D) {
|
||||
// Player did nothing wrong
|
||||
// reduce violation counter
|
||||
blockbreak.directionViolationLevel *= 0.9D;
|
||||
blockbreak.directionVL *= 0.9D;
|
||||
} else {
|
||||
// Player failed the check
|
||||
// Increment violation counter
|
||||
@ -51,9 +51,9 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
// hard on people failing them
|
||||
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) {
|
||||
// Needed to calculate penalty times
|
||||
@ -78,7 +78,7 @@ public class DirectionCheck extends BlockBreakCheck {
|
||||
switch (wildcard) {
|
||||
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().blockbreak.directionViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().blockbreak.directionVL);
|
||||
|
||||
default:
|
||||
return super.getParameter(wildcard, player);
|
||||
|
@ -57,15 +57,15 @@ public class DirectionCheck extends BlockPlaceCheck {
|
||||
if(off < 0.1D) {
|
||||
// Player did nothing wrong
|
||||
// reduce violation counter
|
||||
data.directionViolationLevel *= 0.9D;
|
||||
data.directionVL *= 0.9D;
|
||||
} else {
|
||||
// Player failed the check
|
||||
// Increment violation counter
|
||||
data.directionViolationLevel += off;
|
||||
data.directionVL += off;
|
||||
|
||||
// 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) {
|
||||
// Needed to calculate penalty times
|
||||
@ -91,7 +91,7 @@ public class DirectionCheck extends BlockPlaceCheck {
|
||||
switch (wildcard) {
|
||||
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().blockplace.directionViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().blockplace.directionVL);
|
||||
|
||||
default:
|
||||
return super.getParameter(wildcard, player);
|
||||
|
@ -35,12 +35,12 @@ public class ReachCheck extends BlockPlaceCheck {
|
||||
// Player failed the check
|
||||
|
||||
// Increment violation counter
|
||||
data.reachViolationLevel += distance;
|
||||
data.reachVL += distance;
|
||||
data.reachdistance = distance;
|
||||
|
||||
cancel = executeActions(player, cc.reachActions.getActions(data.reachViolationLevel));
|
||||
cancel = executeActions(player, cc.reachActions.getActions(data.reachVL));
|
||||
} else {
|
||||
data.reachViolationLevel *= 0.9D;
|
||||
data.reachVL *= 0.9D;
|
||||
}
|
||||
|
||||
return cancel;
|
||||
@ -56,7 +56,7 @@ public class ReachCheck extends BlockPlaceCheck {
|
||||
switch (wildcard) {
|
||||
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().blockplace.reachViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().blockplace.reachVL);
|
||||
|
||||
case REACHDISTANCE:
|
||||
return String.format(Locale.US, "%.2f", player.getData().blockplace.reachdistance);
|
||||
|
@ -84,9 +84,9 @@ public class FlyingCheck extends MovingCheck {
|
||||
if(result > 0) {
|
||||
|
||||
// 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
|
||||
if(cancel) {
|
||||
@ -95,7 +95,7 @@ public class FlyingCheck extends MovingCheck {
|
||||
}
|
||||
|
||||
// Slowly reduce the level with each event
|
||||
moving.runflyViolationLevel *= 0.97;
|
||||
moving.runflyVL *= 0.97;
|
||||
|
||||
// Some other cleanup 'n' stuff
|
||||
if(newToLocation == null) {
|
||||
@ -107,7 +107,6 @@ public class FlyingCheck extends MovingCheck {
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(CCMoving moving) {
|
||||
// TODO Auto-generated method stub
|
||||
return moving.allowFlying && moving.runflyCheck;
|
||||
}
|
||||
|
||||
@ -116,7 +115,7 @@ public class FlyingCheck extends MovingCheck {
|
||||
switch (wildcard) {
|
||||
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().moving.runflyViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().moving.runflyVL);
|
||||
default:
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
private final static int bufferLimit = 30;
|
||||
|
||||
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
|
||||
// went over the limit
|
||||
if(!plugin.skipCheck() && packetsAboveLimit > 0) {
|
||||
data.morePacketsViolationLevel += packetsAboveLimit;
|
||||
data.morePacketsVL += 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)
|
||||
newToLocation = data.morePacketsSetbackPoint;
|
||||
@ -88,9 +88,9 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
data.morePacketsSetbackPoint.set(data.from);
|
||||
}
|
||||
|
||||
if(data.morePacketsViolationLevel > 0)
|
||||
if(data.morePacketsVL > 0)
|
||||
// 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.lastElapsedIngameSeconds = ingameSeconds;
|
||||
@ -109,7 +109,7 @@ public class MorePacketsCheck extends MovingCheck {
|
||||
|
||||
switch (wildcard) {
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().moving.morePacketsViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().moving.morePacketsVL);
|
||||
case PACKETS:
|
||||
return String.valueOf(player.getData().moving.packets);
|
||||
default:
|
||||
|
@ -19,7 +19,7 @@ import cc.co.evenprime.bukkit.nocheat.data.PreciseLocation;
|
||||
public class NoFallCheck extends MovingCheck {
|
||||
|
||||
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();
|
||||
|
||||
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
|
||||
// visible to other plugins
|
||||
@ -91,14 +91,13 @@ public class NoFallCheck extends MovingCheck {
|
||||
}
|
||||
|
||||
// Reduce falldamage violation level
|
||||
data.nofallViolationLevel *= 0.99D;
|
||||
data.nofallVL *= 0.99D;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled(CCMoving moving) {
|
||||
// TODO Auto-generated method stub
|
||||
return moving.nofallCheck;
|
||||
}
|
||||
|
||||
@ -107,7 +106,7 @@ public class NoFallCheck extends MovingCheck {
|
||||
|
||||
switch (wildcard) {
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().moving.nofallViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().moving.nofallVL);
|
||||
case FALLDISTANCE:
|
||||
return String.format(Locale.US, "%.2f", player.getData().moving.fallDistance);
|
||||
default:
|
||||
|
@ -16,7 +16,7 @@ public class RunflyCheck extends MovingCheck {
|
||||
private final RunningCheck runningCheck;
|
||||
|
||||
public RunflyCheck(NoCheat plugin) {
|
||||
super(plugin, "moving.runfly", Permissions.MOVE_RUNFLY);
|
||||
super(plugin, "moving.runfly", Permissions.MOVING_RUNFLY);
|
||||
|
||||
flyingCheck = new FlyingCheck(plugin);
|
||||
runningCheck = new RunningCheck(plugin);
|
||||
@ -25,8 +25,8 @@ public class RunflyCheck extends MovingCheck {
|
||||
@Override
|
||||
public PreciseLocation check(NoCheatPlayer player, MovingData data, CCMoving cc) {
|
||||
|
||||
final boolean runflyCheck = cc.runflyCheck && !player.hasPermission(Permissions.MOVE_RUNFLY);
|
||||
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVE_FLY) || (player.getPlayer().getGameMode() == GameMode.CREATIVE && cc.identifyCreativeMode);
|
||||
final boolean runflyCheck = cc.runflyCheck && !player.hasPermission(Permissions.MOVING_RUNFLY);
|
||||
final boolean flyAllowed = cc.allowFlying || player.hasPermission(Permissions.MOVING_FLYING) || (player.getPlayer().getGameMode() == GameMode.CREATIVE && cc.identifyCreativeMode);
|
||||
|
||||
/********************* EXECUTE THE FLY/JUMP/RUNNING CHECK ********************/
|
||||
// If the player is not allowed to fly and not allowed to run
|
||||
|
@ -36,7 +36,7 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
public RunningCheck(NoCheat plugin) {
|
||||
|
||||
super(plugin, "moving.running", Permissions.MOVE_RUNFLY);
|
||||
super(plugin, "moving.running", Permissions.MOVING_RUNFLY);
|
||||
|
||||
this.noFallCheck = new NoFallCheck(plugin);
|
||||
}
|
||||
@ -76,14 +76,14 @@ public class RunningCheck extends MovingCheck {
|
||||
data.jumpPhase++;
|
||||
|
||||
// Slowly reduce the level with each event
|
||||
data.runflyViolationLevel *= 0.97;
|
||||
data.runflyVL *= 0.97;
|
||||
|
||||
if(result > 0) {
|
||||
|
||||
// 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
|
||||
if(cancel) {
|
||||
@ -110,7 +110,7 @@ public class RunningCheck extends MovingCheck {
|
||||
}
|
||||
|
||||
/********* 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) {
|
||||
data.fromOnOrInGround = fromOnGround || fromInGround;
|
||||
@ -136,9 +136,9 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
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;
|
||||
} else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVE_SWIM)) {
|
||||
} else if(ccmoving.swimmingCheck && isSwimming && !player.hasPermission(Permissions.MOVING_SWIMMING)) {
|
||||
limit = ccmoving.swimmingSpeedLimit;
|
||||
} else if(!sprinting) {
|
||||
limit = ccmoving.walkingSpeedLimit;
|
||||
@ -221,7 +221,7 @@ public class RunningCheck extends MovingCheck {
|
||||
switch (wildcard) {
|
||||
|
||||
case VIOLATIONS:
|
||||
return String.format(Locale.US, "%d", player.getData().moving.runflyViolationLevel);
|
||||
return String.format(Locale.US, "%d", player.getData().moving.runflyVL);
|
||||
default:
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
@ -2,10 +2,6 @@ package cc.co.evenprime.bukkit.nocheat.checks.timed;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheatPlayer;
|
||||
import cc.co.evenprime.bukkit.nocheat.actions.types.ActionWithParameters.WildCard;
|
||||
@ -27,11 +23,12 @@ public class GodmodeCheck extends TimedCheck {
|
||||
if(plugin.skipCheck() || player.getPlayer().isDead())
|
||||
return false;
|
||||
|
||||
EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
final int ticksLived = player.getTicksLived();
|
||||
|
||||
// Haven't been checking before
|
||||
if(data.ticksLived == 0) {
|
||||
// setup data for next time
|
||||
data.ticksLived = p.ticksLived;
|
||||
data.ticksLived = ticksLived;
|
||||
|
||||
// And give up already
|
||||
return false;
|
||||
@ -40,7 +37,7 @@ public class GodmodeCheck extends TimedCheck {
|
||||
boolean cancel = false;
|
||||
|
||||
// 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
|
||||
if(difference > cc.tickTime) {
|
||||
@ -78,13 +75,11 @@ public class GodmodeCheck extends TimedCheck {
|
||||
|
||||
if(cancel) {
|
||||
// Catch up for at least some of the ticks
|
||||
for(int i = 0; i < cc.tickTime; i++) {
|
||||
p.b(true); // Catch up with the server, one tick at a time
|
||||
}
|
||||
player.increaseAge(cc.tickTime);
|
||||
}
|
||||
|
||||
// setup data for next time
|
||||
data.ticksLived = p.ticksLived;
|
||||
data.ticksLived = player.getTicksLived();
|
||||
|
||||
return cancel;
|
||||
|
||||
|
@ -10,13 +10,13 @@ public class Permissions {
|
||||
private final static String ADMIN = NOCHEAT + ".admin";
|
||||
private final static String CHECKS = NOCHEAT + ".checks";
|
||||
|
||||
public final static String MOVING = CHECKS + ".moving";
|
||||
public final static String MOVE_RUNFLY = MOVING + ".runfly";
|
||||
public final static String MOVE_SNEAK = MOVING + ".sneaking";
|
||||
public final static String MOVE_SWIM = MOVING + ".swimming";
|
||||
public final static String MOVE_FLY = MOVING + ".flying";
|
||||
public final static String MOVE_NOFALL = MOVING + ".nofall";
|
||||
public final static String MOVE_MOREPACKETS = MOVING + ".morepackets";
|
||||
public final static String MOVING = CHECKS + ".moving";
|
||||
public final static String MOVING_RUNFLY = MOVING + ".runfly";
|
||||
public final static String MOVING_SNEAKING = MOVING + ".sneaking";
|
||||
public final static String MOVING_SWIMMING = MOVING + ".swimming";
|
||||
public final static String MOVING_FLYING = MOVING + ".flying";
|
||||
public final static String MOVING_NOFALL = MOVING + ".nofall";
|
||||
public final static String MOVING_MOREPACKETS = MOVING + ".morepackets";
|
||||
|
||||
public final static String BLOCKBREAK = CHECKS + ".blockbreak";
|
||||
public final static String BLOCKBREAK_REACH = BLOCKBREAK + ".reach";
|
||||
|
@ -7,12 +7,10 @@ package cc.co.evenprime.bukkit.nocheat.data;
|
||||
public class BlockBreakData extends Data {
|
||||
|
||||
public double reachVL = 0.0D;
|
||||
public double directionViolationLevel = 0.0D;
|
||||
public double directionVL = 0.0D;
|
||||
|
||||
public long directionLastViolationTime = 0;
|
||||
public final SimpleLocation instaBrokeBlockLocation = new SimpleLocation();
|
||||
|
||||
// Verified
|
||||
public final SimpleLocation brokenBlockLocation = new SimpleLocation();
|
||||
|
||||
public final ExecutionHistory history = new ExecutionHistory();
|
||||
|
@ -7,10 +7,9 @@ import org.bukkit.Material;
|
||||
*/
|
||||
public class BlockPlaceData extends Data {
|
||||
|
||||
public double onliquidViolationLevel = 0.0D;
|
||||
public double reachViolationLevel = 0.0D;
|
||||
public double reachVL = 0.0D;
|
||||
public final ExecutionHistory history = new ExecutionHistory();
|
||||
public double directionViolationLevel = 0.0D;
|
||||
public double directionVL = 0.0D;
|
||||
public long directionLastViolationTime = 0;
|
||||
|
||||
public final SimpleLocation blockPlacedAgainst = new SimpleLocation();
|
||||
|
@ -9,7 +9,7 @@ public class MovingData extends Data {
|
||||
|
||||
public final PreciseLocation runflySetBackPoint = new PreciseLocation();
|
||||
|
||||
public double runflyViolationLevel;
|
||||
public double runflyVL;
|
||||
|
||||
public double vertFreedom;
|
||||
public double vertVelocity;
|
||||
@ -17,7 +17,7 @@ public class MovingData extends Data {
|
||||
public double horizFreedom;
|
||||
public int horizVelocityCounter;
|
||||
|
||||
public double nofallViolationLevel;
|
||||
public double nofallVL;
|
||||
public float fallDistance;
|
||||
public float lastAddedFallDistance;
|
||||
|
||||
@ -29,7 +29,7 @@ public class MovingData extends Data {
|
||||
public int packets;
|
||||
|
||||
public final PreciseLocation morePacketsSetbackPoint = new PreciseLocation();
|
||||
public double morePacketsViolationLevel;
|
||||
public double morePacketsVL;
|
||||
|
||||
public final PreciseLocation teleportTo = new PreciseLocation();
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class PlayerManager {
|
||||
NoCheatPlayer p = this.map.get(playerName);
|
||||
|
||||
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());
|
||||
this.map.put(playerName, p);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ public class TimedData extends Data {
|
||||
public int ticksLived;
|
||||
public int ticksBehind;
|
||||
public double godmodeVL;
|
||||
public final ExecutionHistory history = new ExecutionHistory(); ;
|
||||
public final ExecutionHistory history = new ExecutionHistory(); ;
|
||||
|
||||
public TimedData() {}
|
||||
|
||||
|
@ -8,8 +8,6 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
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.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.ConfigurationCache;
|
||||
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
|
||||
* relevant checks
|
||||
*
|
||||
*/
|
||||
public class BlockBreakEventManager extends BlockListener implements EventManager {
|
||||
public class BlockBreakEventManager extends EventManager {
|
||||
|
||||
private final List<BlockBreakCheck> checks;
|
||||
private final NoCheat plugin;
|
||||
private final Performance blockBreakPerformance;
|
||||
private final Performance blockDamagePerformance;
|
||||
|
||||
public BlockBreakEventManager(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
super(plugin);
|
||||
|
||||
// Three checks exist for this event type
|
||||
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 ReachCheck(plugin));
|
||||
|
||||
this.blockBreakPerformance = plugin.getPerformance(Type.BLOCKBREAK);
|
||||
this.blockDamagePerformance = plugin.getPerformance(Type.BLOCKDAMAGE);
|
||||
|
||||
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);
|
||||
registerListener(Event.Type.BLOCK_BREAK, Priority.Lowest, true);
|
||||
registerListener(Event.Type.BLOCK_DAMAGE, Priority.Monitor, true);
|
||||
}
|
||||
|
||||
private void handleEvent(BlockBreakEvent event) {
|
||||
@Override
|
||||
protected void handleBlockBreakEvent(BlockBreakEvent event, Priority priority) {
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
@ -71,7 +60,7 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
|
||||
BlockBreakData data = player.getData().blockbreak;
|
||||
|
||||
data.brokenBlockLocation.set(event.getBlock());
|
||||
|
||||
|
||||
for(BlockBreakCheck check : checks) {
|
||||
// If it should be executed, do it
|
||||
if(!cancelled && check.isEnabled(cc) && !player.hasPermission(check.getPermission())) {
|
||||
@ -84,8 +73,15 @@ public class BlockBreakEventManager extends BlockListener implements EventManage
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleBlockDamageEvent(BlockDamageEvent event, Priority priority) {
|
||||
|
||||
// Only interested in insta-break events here
|
||||
if(!event.getInstaBreak()) {
|
||||
return;
|
||||
}
|
||||
|
||||
private void handleEvent(BlockDamageEvent event) {
|
||||
// Get the player-specific stored data that applies here
|
||||
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());
|
||||
}
|
||||
|
||||
@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) {
|
||||
LinkedList<String> s = new LinkedList<String>();
|
||||
|
||||
|
@ -6,9 +6,7 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
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.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
/**
|
||||
* Central location to listen to Block-related events and dispatching them to
|
||||
* checks
|
||||
*
|
||||
*/
|
||||
public class BlockPlaceEventManager extends BlockListener implements EventManager {
|
||||
public class BlockPlaceEventManager extends EventManager {
|
||||
|
||||
private final List<BlockPlaceCheck> checks;
|
||||
private final NoCheat plugin;
|
||||
|
||||
private final Performance blockPlacePerformance;
|
||||
public BlockPlaceEventManager(NoCheat plugin) {
|
||||
|
||||
public BlockPlaceEventManager(NoCheat p) {
|
||||
|
||||
this.plugin = p;
|
||||
super(plugin);
|
||||
|
||||
this.checks = new ArrayList<BlockPlaceCheck>(2);
|
||||
this.checks.add(new DirectionCheck(plugin));
|
||||
this.checks.add(new ReachCheck(plugin));
|
||||
|
||||
this.blockPlacePerformance = p.getPerformance(Type.BLOCKPLACE);
|
||||
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
pm.registerEvent(Event.Type.BLOCK_PLACE, this, Priority.Lowest, plugin);
|
||||
registerListener(Event.Type.BLOCK_PLACE, Priority.Lowest, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
|
||||
|
||||
if(event.isCancelled() || event.getBlock() == null)
|
||||
if(event.getBlock() == null)
|
||||
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;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
@ -1,11 +1,230 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.events;
|
||||
|
||||
import java.util.Collections;
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,6 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
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.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.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.FightData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
public class FightEventManager extends EntityListener implements EventManager {
|
||||
public class FightEventManager extends EventManager {
|
||||
|
||||
private final NoCheat plugin;
|
||||
private final List<FightCheck> checks;
|
||||
private final Performance fightPerformance;
|
||||
|
||||
public FightEventManager(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
super(plugin);
|
||||
|
||||
this.checks = new ArrayList<FightCheck>(3);
|
||||
this.checks.add(new NoswingCheck(plugin));
|
||||
this.checks.add(new DirectionCheck(plugin));
|
||||
this.checks.add(new SelfhitCheck(plugin));
|
||||
|
||||
this.fightPerformance = plugin.getPerformance(Type.FIGHT);
|
||||
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Lowest, plugin);
|
||||
registerListener(Event.Type.ENTITY_DAMAGE, Priority.Lowest, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
|
||||
// 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) {
|
||||
protected void handleEntityDamageEvent(EntityDamageEvent event, Priority priority) {
|
||||
|
||||
final Entity damagee = ((CraftEntity) event.getEntity()).getHandle();
|
||||
|
||||
@ -102,7 +64,7 @@ public class FightEventManager extends EntityListener implements EventManager {
|
||||
check.check(player, data, cc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
data.damagee = null;
|
||||
|
||||
if(cancelled) {
|
||||
|
@ -8,8 +8,6 @@ import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.player.PlayerChatEvent;
|
||||
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.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.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class PlayerChatEventManager extends PlayerListener implements EventManager {
|
||||
public class PlayerChatEventManager extends EventManager {
|
||||
|
||||
private final NoCheat plugin;
|
||||
private final List<ChatCheck> checks;
|
||||
private final Performance chatPerformance;
|
||||
|
||||
public PlayerChatEventManager(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
super(plugin);
|
||||
|
||||
this.checks = new ArrayList<ChatCheck>(1);
|
||||
this.checks.add(new SpamCheck(plugin));
|
||||
|
||||
this.chatPerformance = plugin.getPerformance(Type.CHAT);
|
||||
|
||||
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);
|
||||
registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true);
|
||||
registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event) {
|
||||
// We redirect to the other method anyway, so no need to set up a
|
||||
// performance counter here
|
||||
onPlayerChat(event);
|
||||
protected void handlePlayerCommandPreprocessEvent(PlayerCommandPreprocessEvent event, Priority priority) {
|
||||
handleEvent((PlayerChatEvent) event, priority);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
@ -8,12 +8,9 @@ import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.block.BlockListener;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerListener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerVelocityEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
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.PreciseLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.SimpleLocation;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.Performance;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
public class PlayerMoveEventManager extends PlayerListener implements EventManager {
|
||||
public class PlayerMoveEventManager extends EventManager {
|
||||
|
||||
private final NoCheat plugin;
|
||||
private final List<MovingCheck> checks;
|
||||
|
||||
private final Performance movePerformance;
|
||||
private final Performance velocityPerformance;
|
||||
|
||||
public PlayerMoveEventManager(final NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
this.checks = new ArrayList<MovingCheck>(5);
|
||||
super(plugin);
|
||||
|
||||
this.checks = new ArrayList<MovingCheck>(2);
|
||||
|
||||
checks.add(new RunflyCheck(plugin));
|
||||
checks.add(new MorePacketsCheck(plugin));
|
||||
|
||||
this.movePerformance = plugin.getPerformance(Type.MOVING);
|
||||
this.velocityPerformance = plugin.getPerformance(Type.VELOCITY);
|
||||
|
||||
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
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
// Get the player-specific stored data that applies here
|
||||
blockPlaced(player, event.getBlockPlaced());
|
||||
|
||||
}
|
||||
}, Priority.Monitor, plugin);
|
||||
registerListener(Event.Type.PLAYER_MOVE, Priority.Lowest, true);
|
||||
registerListener(Event.Type.PLAYER_VELOCITY, Priority.Monitor, true);
|
||||
registerListener(Event.Type.BLOCK_PLACE, Priority.Monitor, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(final PlayerMoveEvent event) {
|
||||
protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
|
||||
|
||||
// Cancelled events are ignored
|
||||
if(event.isCancelled())
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
// Get the player-specific stored data that applies here
|
||||
BaseData data = player.getData();
|
||||
|
||||
Block blockPlaced = event.getBlockPlaced();
|
||||
|
||||
if(blockPlaced == null || !data.moving.runflySetBackPoint.isSet()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Performance counter setup
|
||||
long nanoTimeStart = 0;
|
||||
final boolean performanceCheck = movePerformance.isEnabled();
|
||||
SimpleLocation lblock = new SimpleLocation();
|
||||
lblock.set(blockPlaced);
|
||||
SimpleLocation lplayer = new SimpleLocation();
|
||||
lplayer.setLocation(player.getPlayer().getLocation());
|
||||
|
||||
if(performanceCheck)
|
||||
nanoTimeStart = System.nanoTime();
|
||||
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) {
|
||||
|
||||
handleEvent(event);
|
||||
|
||||
// store performance time
|
||||
if(performanceCheck)
|
||||
movePerformance.addTime(System.nanoTime() - nanoTimeStart);
|
||||
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 void handleEvent(PlayerMoveEvent event) {
|
||||
@Override
|
||||
protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
|
||||
|
||||
// Get the world-specific configuration that applies here
|
||||
final NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
@ -157,16 +140,7 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
|
||||
// Performance counter setup
|
||||
long nanoTimeStart = 0;
|
||||
final boolean performanceCheck = velocityPerformance.isEnabled();
|
||||
|
||||
if(performanceCheck)
|
||||
nanoTimeStart = System.nanoTime();
|
||||
protected void handlePlayerVelocityEvent(PlayerVelocityEvent event, Priority priority) {
|
||||
|
||||
MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
|
||||
|
||||
@ -185,39 +159,6 @@ public class PlayerMoveEventManager extends PlayerListener implements EventManag
|
||||
data.horizFreedom += newVal;
|
||||
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) {
|
||||
|
@ -1,85 +1,65 @@
|
||||
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.Priority;
|
||||
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.plugin.PluginManager;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BaseData;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
|
||||
|
||||
/**
|
||||
* Only place that listens to Player-teleport related events and dispatches them
|
||||
* 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;
|
||||
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_MOVE, this, Priority.Monitor, plugin);
|
||||
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();
|
||||
|
||||
if(data.moving.teleportTo.isSet() && data.moving.teleportTo.equals(event.getTo())) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
}, Priority.Highest, plugin);
|
||||
registerListener(Event.Type.PLAYER_MOVE, Priority.Monitor, false);
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true);
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Highest, false);
|
||||
registerListener(Event.Type.PLAYER_PORTAL, Priority.Monitor, true);
|
||||
registerListener(Event.Type.PLAYER_RESPAWN, Priority.Monitor, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
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;
|
||||
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
}
|
||||
final MovingData data = plugin.getPlayer(event.getPlayer().getName()).getData().moving;
|
||||
|
||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||
if(event.isCancelled())
|
||||
return;
|
||||
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
// Workaround for buggy Playermove cancelling
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if(!event.isCancelled()) {
|
||||
return;
|
||||
if(data.teleportTo.isSet() && data.teleportTo.equals(event.getTo())) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerPortalEvent(PlayerPortalEvent event, Priority priority) {
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerRespawnEvent(PlayerRespawnEvent event, Priority priority) {
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handlePlayerMoveEvent(PlayerMoveEvent event, Priority priority) {
|
||||
// No typo here. I really only handle cancelled events and ignore others
|
||||
if(!event.isCancelled())
|
||||
return;
|
||||
|
||||
handleTeleportation(event.getPlayer().getName());
|
||||
}
|
||||
@ -88,8 +68,4 @@ public class PlayerTeleportEventManager extends PlayerListener implements EventM
|
||||
|
||||
plugin.clearCriticalData(playerName);
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,10 @@
|
||||
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.Priority;
|
||||
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.config.cache.ConfigurationCache;
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
public class SwingEventManager extends PlayerListener implements EventManager {
|
||||
|
||||
private final NoCheat plugin;
|
||||
public class SwingEventManager extends EventManager {
|
||||
|
||||
public SwingEventManager(NoCheat plugin) {
|
||||
|
||||
this.plugin = plugin;
|
||||
super(plugin);
|
||||
|
||||
PluginManager pm = plugin.getServer().getPluginManager();
|
||||
|
||||
pm.registerEvent(Event.Type.PLAYER_ANIMATION, this, Priority.Lowest, plugin);
|
||||
registerListener(Event.Type.PLAYER_ANIMATION, Priority.Monitor, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerAnimation(final PlayerAnimationEvent event) {
|
||||
protected void handlePlayerAnimationEvent(PlayerAnimationEvent event, Priority priority) {
|
||||
plugin.getPlayer(event.getPlayer().getName()).getData().armswung = true;
|
||||
}
|
||||
|
||||
public List<String> getActiveChecks(ConfigurationCache cc) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
@ -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.PerformanceManager.Type;
|
||||
|
||||
public class TimedEventManager implements EventManager {
|
||||
public class TimedEventManager extends EventManager {
|
||||
|
||||
private final List<TimedCheck> checks;
|
||||
private final Performance timedPerformance;
|
||||
@ -28,6 +28,8 @@ public class TimedEventManager implements EventManager {
|
||||
|
||||
public TimedEventManager(final NoCheat plugin) {
|
||||
|
||||
super(plugin);
|
||||
|
||||
checks = new ArrayList<TimedCheck>(1);
|
||||
checks.add(new GodmodeCheck(plugin));
|
||||
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.player;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import cc.co.evenprime.bukkit.nocheat.NoCheat;
|
||||
@ -40,4 +43,17 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user