Fix two common mistakes by other plugins (cancelling move

events and cancelling toggle sprint events)
This commit is contained in:
Evenprime 2011-11-15 17:05:06 +01:00
parent 5a02e78888
commit e853eac486
7 changed files with 44 additions and 3 deletions

View File

@ -30,7 +30,8 @@ public abstract class Configuration {
private final static OptionNode DEBUG = new OptionNode("debug", ROOT, DataType.PARENT);
public final static OptionNode DEBUG_SHOWACTIVECHECKS = new OptionNode("showactivechecks", DEBUG, DataType.BOOLEAN);
public static final OptionNode DEBUG_COMPATIBILITY = new OptionNode("compatibility", DEBUG, DataType.BOOLEAN);
private final static OptionNode MOVING = new OptionNode("moving", ROOT, DataType.PARENT);
public final static OptionNode MOVING_CHECK = new OptionNode("check", MOVING, DataType.BOOLEAN);
public final static OptionNode MOVING_IDENTIFYCREATIVEMODE = new OptionNode("identifycreativemode", MOVING, DataType.BOOLEAN);

View File

@ -32,6 +32,7 @@ public class DefaultConfiguration extends Configuration {
/*** DEBUG ***/
{
setValue(DEBUG_SHOWACTIVECHECKS, false);
setValue(DEBUG_COMPATIBILITY, true);
}
/*** MOVING ***/

View File

@ -25,6 +25,7 @@ public class Explainations {
set(Configuration.LOGGING_CHATLEVEL, "What log-level need messages to have to get displayed in the ingame chat. Values are:\n low: all messages\n med: med and high messages only\n high: high messages only\n off: no messages at all.");
set(Configuration.DEBUG_SHOWACTIVECHECKS, "Print to the console an overview of all checks that are enabled when NoCheat gets loaded.");
set(Configuration.DEBUG_COMPATIBILITY, "Do some voodoo to fix common mistakes of other plugins which interfere with NoCheat.");
set(Configuration.MOVING_CHECK, "If true, do various checks on PlayerMove events.");
set(Configuration.MOVING_IDENTIFYCREATIVEMODE, "If true, NoCheat will automatically identify if players are in creative mode and will allow them to fly, avoid fall damage etc.");

View File

@ -5,10 +5,12 @@ import cc.co.evenprime.bukkit.nocheat.config.Configuration;
public class CCDebug {
public final boolean showchecks;
public final boolean overrideIdiocy;
public CCDebug(Configuration data) {
showchecks = data.getBoolean(Configuration.DEBUG_SHOWACTIVECHECKS);
overrideIdiocy = data.getBoolean(Configuration.DEBUG_COMPATIBILITY);
}
}

View File

@ -24,6 +24,7 @@ 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.PlayerToggleSprintEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
@ -224,6 +225,20 @@ public abstract class EventManager {
m.handlePlayerAnimationEvent(event, priority);
}
}
@Override
public void onPlayerToggleSprint(final PlayerToggleSprintEvent event) {
if(ignoreCancelledEvents && event.isCancelled())
return;
if(measureTime != null && measureTime.isEnabled()) {
final long startTime = System.nanoTime();
m.handlePlayerToggleSprintEvent(event, priority);
measureTime.addTime(System.nanoTime() - startTime);
} else {
m.handlePlayerToggleSprintEvent(event, priority);
}
}
}
private static class EntityL extends EntityListener {
@ -358,4 +373,8 @@ public abstract class EventManager {
protected void handleEntityDamageByEntityEvent(final EntityDamageByEntityEvent event, final Priority priority) {
handleEvent(event, priority);
}
protected void handlePlayerToggleSprintEvent(PlayerToggleSprintEvent event, Priority priority) {
handleEvent(event, priority);
}
}

View File

@ -36,7 +36,7 @@ public class PlayerChatEventManager extends EventManager {
@Override
protected void handlePlayerCommandPreprocessEvent(final PlayerCommandPreprocessEvent event, final Priority priority) {
handleEvent((PlayerChatEvent) event, priority);
handlePlayerChatEvent((PlayerChatEvent) event, priority);
}
@Override

View File

@ -7,6 +7,7 @@ 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.PlayerToggleSprintEvent;
import cc.co.evenprime.bukkit.nocheat.NoCheat;
import cc.co.evenprime.bukkit.nocheat.data.MovingData;
@ -22,7 +23,8 @@ public class PlayerTeleportEventManager extends EventManager {
super(plugin);
registerListener(Event.Type.PLAYER_MOVE, Priority.Monitor, false, null);
registerListener(Event.Type.PLAYER_MOVE, Priority.Highest, false, null);
registerListener(Event.Type.PLAYER_TOGGLE_SPRINT, Priority.Highest, 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);
@ -63,6 +65,21 @@ public class PlayerTeleportEventManager extends EventManager {
return;
handleTeleportation(event.getPlayer());
// Fix a common mistake that other developers make (cancelling move
// events is crazy, rather set the target location to the from location
if(plugin.getPlayer(event.getPlayer().getName()).getConfiguration().debug.overrideIdiocy) {
event.setCancelled(false);
event.setTo(event.getFrom().clone());
}
}
@Override
protected void handlePlayerToggleSprintEvent(final PlayerToggleSprintEvent event, final Priority priority) {
if(event.isCancelled() && event.isSprinting()) {
if(plugin.getPlayer(event.getPlayer().getName()).getConfiguration().debug.overrideIdiocy)
event.setCancelled(false);
}
}
private void handleTeleportation(final Player player) {