mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-12-30 20:37:52 +01:00
Reintroduced Performance measurement and fixed casting bug in
moveEventHandling
This commit is contained in:
parent
3ce696ee1f
commit
40f187b55c
@ -21,5 +21,5 @@ public interface NoCheatPlayer {
|
||||
|
||||
public ConfigurationCache getConfiguration();
|
||||
|
||||
|
||||
public int getSpeedAmplifier();
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class RunningCheck extends MovingCheck {
|
||||
|
||||
double limit = 0.0D;
|
||||
|
||||
final EntityPlayer p = ((CraftPlayer) player).getHandle();
|
||||
final EntityPlayer p = ((CraftPlayer) player.getPlayer()).getHandle();
|
||||
|
||||
if(ccmoving.sneakingCheck && player.getPlayer().isSneaking() && !player.hasPermission(Permissions.MOVING_SNEAKING)) {
|
||||
limit = ccmoving.sneakingSpeedLimit;
|
||||
|
@ -19,6 +19,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockBreak;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BlockBreakData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
/**
|
||||
* Central location to listen to player-interact events and dispatch them to
|
||||
@ -39,8 +40,8 @@ public class BlockBreakEventManager extends EventManager {
|
||||
this.checks.add(new NoswingCheck(plugin));
|
||||
this.checks.add(new ReachCheck(plugin));
|
||||
|
||||
registerListener(Event.Type.BLOCK_BREAK, Priority.Lowest, true);
|
||||
registerListener(Event.Type.BLOCK_DAMAGE, Priority.Monitor, true);
|
||||
registerListener(Event.Type.BLOCK_BREAK, Priority.Lowest, true, plugin.getPerformance(Type.BLOCKBREAK));
|
||||
registerListener(Event.Type.BLOCK_DAMAGE, Priority.Monitor, true, plugin.getPerformance(Type.BLOCKDAMAGE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,7 +74,7 @@ public class BlockBreakEventManager extends EventManager {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void handleBlockDamageEvent(BlockDamageEvent event, Priority priority) {
|
||||
|
||||
|
@ -17,6 +17,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCBlockPlace;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.BlockPlaceData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
/**
|
||||
* Central location to listen to Block-related events and dispatching them to
|
||||
@ -35,7 +36,7 @@ public class BlockPlaceEventManager extends EventManager {
|
||||
this.checks.add(new DirectionCheck(plugin));
|
||||
this.checks.add(new ReachCheck(plugin));
|
||||
|
||||
registerListener(Event.Type.BLOCK_PLACE, Priority.Lowest, true);
|
||||
registerListener(Event.Type.BLOCK_PLACE, Priority.Lowest, true, plugin.getPerformance(Type.BLOCKPLACE));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,7 +44,7 @@ public class BlockPlaceEventManager extends EventManager {
|
||||
|
||||
if(event.getBlock() == null)
|
||||
return;
|
||||
|
||||
|
||||
boolean cancelled = false;
|
||||
|
||||
NoCheatPlayer player = plugin.getPlayer(event.getPlayer().getName());
|
||||
|
@ -25,6 +25,7 @@ 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.debug.Performance;
|
||||
|
||||
public abstract class EventManager {
|
||||
|
||||
@ -35,32 +36,55 @@ public abstract class EventManager {
|
||||
private final EventManager m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
|
||||
public BlockL(EventManager m, Priority priority, boolean ignoreCancelled) {
|
||||
public BlockL(EventManager m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
this.m = m;
|
||||
this.priority = priority;
|
||||
this.ignoreCancelledEvents = ignoreCancelled;
|
||||
this.measureTime = measureTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handleBlockPlaceEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handleBlockPlaceEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handleBlockPlaceEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handleBlockBreakEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handleBlockBreakEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handleBlockBreakEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockDamage(BlockDamageEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handleBlockDamageEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handleBlockDamageEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handleBlockDamageEvent(event, priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -69,66 +93,125 @@ public abstract class EventManager {
|
||||
private final EventManager m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
|
||||
public PlayerL(EventManager m, Priority priority, boolean ignoreCancelled) {
|
||||
public PlayerL(EventManager m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
this.m = m;
|
||||
this.priority = priority;
|
||||
this.ignoreCancelledEvents = ignoreCancelled;
|
||||
this.measureTime = measureTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerChatEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerChatEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerChatEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerCommandPreprocessEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerCommandPreprocessEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerCommandPreprocessEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerMoveEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerMoveEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerMoveEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerVelocity(PlayerVelocityEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerVelocityEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerVelocityEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerVelocityEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
// if(ignoreCancelledEvents && event.isCancelled()) return;
|
||||
m.handlePlayerRespawnEvent(event, priority);
|
||||
// if(ignoreCancelledEvents && event.isCancelled())
|
||||
// return;
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerRespawnEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerRespawnEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPortal(PlayerPortalEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerPortalEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerPortalEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerPortalEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerTeleport(PlayerTeleportEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerTeleportEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerTeleportEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerTeleportEvent(event, priority);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event) {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handlePlayerAnimationEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handlePlayerAnimationEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handlePlayerAnimationEvent(event, priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,11 +220,13 @@ public abstract class EventManager {
|
||||
private final EventManager m;
|
||||
private final Priority priority;
|
||||
private final boolean ignoreCancelledEvents;
|
||||
private final Performance measureTime;
|
||||
|
||||
public EntityL(EventManager m, Priority priority, boolean ignoreCancelled) {
|
||||
public EntityL(EventManager m, Priority priority, boolean ignoreCancelled, Performance measureTime) {
|
||||
this.m = m;
|
||||
this.priority = priority;
|
||||
this.ignoreCancelledEvents = ignoreCancelled;
|
||||
this.measureTime = measureTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -149,6 +234,14 @@ public abstract class EventManager {
|
||||
if(ignoreCancelledEvents && event.isCancelled())
|
||||
return;
|
||||
m.handleEntityDamageEvent(event, priority);
|
||||
|
||||
if(measureTime != null && measureTime.isEnabled()) {
|
||||
long startTime = System.nanoTime();
|
||||
m.handleEntityDamageEvent(event, priority);
|
||||
measureTime.addTime(System.nanoTime() - startTime);
|
||||
} else {
|
||||
m.handleEntityDamageEvent(event, priority);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,16 +249,16 @@ public abstract class EventManager {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected void registerListener(Type type, Priority priority, boolean ignoreCancelled) {
|
||||
protected void registerListener(Type type, Priority priority, boolean ignoreCancelled, Performance performance) {
|
||||
switch (type.getCategory()) {
|
||||
case BLOCK:
|
||||
Bukkit.getServer().getPluginManager().registerEvent(type, new BlockL(this, priority, ignoreCancelled), priority, plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvent(type, new BlockL(this, priority, ignoreCancelled, performance), priority, plugin);
|
||||
break;
|
||||
case PLAYER:
|
||||
Bukkit.getServer().getPluginManager().registerEvent(type, new PlayerL(this, priority, ignoreCancelled), priority, plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvent(type, new PlayerL(this, priority, ignoreCancelled, performance), priority, plugin);
|
||||
break;
|
||||
case ENTITY:
|
||||
Bukkit.getServer().getPluginManager().registerEvent(type, new EntityL(this, priority, ignoreCancelled), priority, plugin);
|
||||
Bukkit.getServer().getPluginManager().registerEvent(type, new EntityL(this, priority, ignoreCancelled, performance), priority, plugin);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Can't register a listener for " + type);
|
||||
@ -180,6 +273,10 @@ public abstract class EventManager {
|
||||
System.out.println("Handling of event " + event.getType() + " not implemented for " + this);
|
||||
}
|
||||
|
||||
/***
|
||||
* OVERRIDE THESE IN THE SUBCLASSES, IF YOU LISTEN TO THE RELEVANT EVENT(S)
|
||||
*/
|
||||
|
||||
protected void handleBlockPlaceEvent(BlockPlaceEvent event, Priority priority) {
|
||||
handleEvent(event, priority);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCFight;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.FightData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
public class FightEventManager extends EventManager {
|
||||
|
||||
@ -36,7 +37,7 @@ public class FightEventManager extends EventManager {
|
||||
this.checks.add(new DirectionCheck(plugin));
|
||||
this.checks.add(new SelfhitCheck(plugin));
|
||||
|
||||
registerListener(Event.Type.ENTITY_DAMAGE, Priority.Lowest, true);
|
||||
registerListener(Event.Type.ENTITY_DAMAGE, Priority.Lowest, true, plugin.getPerformance(Type.FIGHT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,7 @@ import cc.co.evenprime.bukkit.nocheat.config.Permissions;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.CCChat;
|
||||
import cc.co.evenprime.bukkit.nocheat.config.cache.ConfigurationCache;
|
||||
import cc.co.evenprime.bukkit.nocheat.data.ChatData;
|
||||
import cc.co.evenprime.bukkit.nocheat.debug.PerformanceManager.Type;
|
||||
|
||||
public class PlayerChatEventManager extends EventManager {
|
||||
|
||||
@ -29,8 +30,8 @@ public class PlayerChatEventManager extends EventManager {
|
||||
this.checks = new ArrayList<ChatCheck>(1);
|
||||
this.checks.add(new SpamCheck(plugin));
|
||||
|
||||
registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true);
|
||||
registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true);
|
||||
registerListener(Event.Type.PLAYER_CHAT, Priority.Lowest, true, plugin.getPerformance(Type.CHAT));
|
||||
registerListener(Event.Type.PLAYER_COMMAND_PREPROCESS, Priority.Lowest, true, plugin.getPerformance(Type.CHAT));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,6 +26,7 @@ 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.PerformanceManager.Type;
|
||||
|
||||
/**
|
||||
* The only place that listens to and modifies player_move events if necessary
|
||||
@ -47,9 +48,9 @@ public class PlayerMoveEventManager extends EventManager {
|
||||
checks.add(new RunflyCheck(plugin));
|
||||
checks.add(new MorePacketsCheck(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);
|
||||
registerListener(Event.Type.PLAYER_MOVE, Priority.Lowest, true, plugin.getPerformance(Type.MOVING));
|
||||
registerListener(Event.Type.PLAYER_VELOCITY, Priority.Monitor, true, plugin.getPerformance(Type.VELOCITY));
|
||||
registerListener(Event.Type.BLOCK_PLACE, Priority.Monitor, true, plugin.getPerformance(Type.BLOCKPLACE));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,11 +21,11 @@ public class PlayerTeleportEventManager extends EventManager {
|
||||
|
||||
super(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);
|
||||
registerListener(Event.Type.PLAYER_MOVE, Priority.Monitor, false, null);
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Monitor, true, null);
|
||||
registerListener(Event.Type.PLAYER_TELEPORT, Priority.Highest, false, null);
|
||||
registerListener(Event.Type.PLAYER_PORTAL, Priority.Monitor, true, null);
|
||||
registerListener(Event.Type.PLAYER_RESPAWN, Priority.Monitor, true, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,7 +19,7 @@ public class SwingEventManager extends EventManager {
|
||||
|
||||
super(plugin);
|
||||
|
||||
registerListener(Event.Type.PLAYER_ANIMATION, Priority.Monitor, false);
|
||||
registerListener(Event.Type.PLAYER_ANIMATION, Priority.Monitor, false, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cc.co.evenprime.bukkit.nocheat.player;
|
||||
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.MobEffectList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
@ -56,4 +57,8 @@ public class NoCheatPlayerImpl implements NoCheatPlayer {
|
||||
}
|
||||
}
|
||||
|
||||
public int getSpeedAmplifier() {
|
||||
return ((CraftPlayer)player).getHandle().getEffect(MobEffectList.FASTER_MOVEMENT).getAmplifier();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user