From f30bccd7d3ad57efd652e0ffbb399e6084936fb0 Mon Sep 17 00:00:00 2001 From: asofold Date: Fri, 19 Oct 2012 11:32:32 +0200 Subject: [PATCH] Remove workarounds listener (split to moving + combined). --- .../neatmonster/nocheatplus/NoCheatPlus.java | 2 - .../nocheatplus/checks/Workarounds.java | 76 ------------------- .../checks/combined/CombinedListener.java | 25 ++++++ .../checks/moving/MovingListener.java | 29 +++++++ 4 files changed, 54 insertions(+), 78 deletions(-) delete mode 100644 src/fr/neatmonster/nocheatplus/checks/Workarounds.java diff --git a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java index 3879141c..37bf0816 100644 --- a/src/fr/neatmonster/nocheatplus/NoCheatPlus.java +++ b/src/fr/neatmonster/nocheatplus/NoCheatPlus.java @@ -21,7 +21,6 @@ import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.java.JavaPlugin; import fr.neatmonster.nocheatplus.checks.CheckType; -import fr.neatmonster.nocheatplus.checks.Workarounds; import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener; import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractListener; import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceListener; @@ -247,7 +246,6 @@ public class NoCheatPlus extends JavaPlugin implements Listener { new FightListener(), new InventoryListener(), new MovingListener(), - new Workarounds(), new INotifyReload() { @Override public void onReload() { diff --git a/src/fr/neatmonster/nocheatplus/checks/Workarounds.java b/src/fr/neatmonster/nocheatplus/checks/Workarounds.java deleted file mode 100644 index b28568f8..00000000 --- a/src/fr/neatmonster/nocheatplus/checks/Workarounds.java +++ /dev/null @@ -1,76 +0,0 @@ -package fr.neatmonster.nocheatplus.checks; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerToggleSprintEvent; - -/* - * M""MMM""MMM""M dP dP - * M MMM MMM M 88 88 - * M MMP MMP M .d8888b. 88d888b. 88 .dP .d8888b. 88d888b. .d8888b. dP dP 88d888b. .d888b88 .d8888b. - * M MM' MM' .M 88' `88 88' `88 88888" 88' `88 88' `88 88' `88 88 88 88' `88 88' `88 Y8ooooo. - * M `' . '' .MM 88. .88 88 88 `8b. 88. .88 88 88. .88 88. .88 88 88 88. .88 88 - * M .d .dMMM `88888P' dP dP `YP `88888P8 dP `88888P' `88888P' dP dP `88888P8 `88888P' - * MMMMMMMMMMMMMM - */ -/** - * Only place that listens to player-teleport related events and dispatches them to relevant checks. - */ -public class Workarounds implements Listener { - - /** - * A listener listening to PlayerMoveEvents. - * - * @param event - * the event - */ - @EventHandler( - priority = EventPriority.HIGHEST) - public void onPlayerMove(final PlayerMoveEvent event) { - /* - * _____ _ __ __ - * | __ \| | | \/ | - * | |__) | | __ _ _ _ ___ _ __ | \ / | _____ _____ - * | ___/| |/ _` | | | |/ _ \ '__| | |\/| |/ _ \ \ / / _ \ - * | | | | (_| | |_| | __/ | | | | | (_) \ V / __/ - * |_| |_|\__,_|\__, |\___|_| |_| |_|\___/ \_/ \___| - * __/ | - * |___/ - */ - // No typo here. I really only handle cancelled events and ignore others. - if (!event.isCancelled()) - return; - - // Fix a common mistake that other developers make (cancelling move events is crazy, rather set the target - // location to the from location). - event.setCancelled(false); - event.setTo(event.getFrom().clone()); - } - - /** - * A listener listening to PlayerToggleSprintEvents. - * - * @param event - * the event - */ - @EventHandler( - priority = EventPriority.HIGHEST) - public void onPlayerToggleSprint(final PlayerToggleSprintEvent event) { - /* - * _____ _ _______ _ _____ _ _ - * | __ \| | |__ __| | | / ____| (_) | | - * | |__) | | __ _ _ _ ___ _ __ | | ___ __ _ __ _| | ___ | (___ _ __ _ __ _ _ __ | |_ - * | ___/| |/ _` | | | |/ _ \ '__| | |/ _ \ / _` |/ _` | |/ _ \ \___ \| '_ \| '__| | '_ \| __| - * | | | | (_| | |_| | __/ | | | (_) | (_| | (_| | | __/ ____) | |_) | | | | | | | |_ - * |_| |_|\__,_|\__, |\___|_| |_|\___/ \__, |\__, |_|\___| |_____/| .__/|_| |_|_| |_|\__| - * __/ | __/ | __/ | | | - * |___/ |___/ |___/ |_| - */ - // Some plugins cancel "sprinting", which makes no sense at all because it doesn't stop people from sprinting - // and rewards them by reducing their hunger bar as if they were walking instead of sprinting. - if (event.isCancelled() && event.isSprinting()) - event.setCancelled(false); - } -} diff --git a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java index 6ecf53cb..97c205b8 100644 --- a/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/combined/CombinedListener.java @@ -99,5 +99,30 @@ public class CombinedListener implements Listener { // Still invulnerable. event.setCancelled(true); } + + /** + * A workaround for cancelled PlayerToggleSprintEvents. + * + * @param event + * the event + */ + @EventHandler( + priority = EventPriority.HIGHEST) + public void onPlayerToggleSprintHighest(final PlayerToggleSprintEvent event) { + /* + * _____ _ _______ _ _____ _ _ + * | __ \| | |__ __| | | / ____| (_) | | + * | |__) | | __ _ _ _ ___ _ __ | | ___ __ _ __ _| | ___ | (___ _ __ _ __ _ _ __ | |_ + * | ___/| |/ _` | | | |/ _ \ '__| | |/ _ \ / _` |/ _` | |/ _ \ \___ \| '_ \| '__| | '_ \| __| + * | | | | (_| | |_| | __/ | | | (_) | (_| | (_| | | __/ ____) | |_) | | | | | | | |_ + * |_| |_|\__,_|\__, |\___|_| |_|\___/ \__, |\__, |_|\___| |_____/| .__/|_| |_|_| |_|\__| + * __/ | __/ | __/ | | | + * |___/ |___/ |___/ |_| + */ + // Some plugins cancel "sprinting", which makes no sense at all because it doesn't stop people from sprinting + // and rewards them by reducing their hunger bar as if they were walking instead of sprinting. + if (event.isCancelled() && event.isSprinting()) + event.setCancelled(false); + } } diff --git a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java index 63571130..48b6fd76 100644 --- a/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java +++ b/src/fr/neatmonster/nocheatplus/checks/moving/MovingListener.java @@ -417,6 +417,35 @@ public class MovingListener implements Listener { moveInfo.cleanup(); parkedInfo.add(moveInfo); } + + /** + * A workaround for cancelled PlayerMoveEvents. + * + * @param event + * the event + */ + @EventHandler( + priority = EventPriority.HIGHEST) + public void onPlayerMoveHighest(final PlayerMoveEvent event) { + /* + * _____ _ __ __ + * | __ \| | | \/ | + * | |__) | | __ _ _ _ ___ _ __ | \ / | _____ _____ + * | ___/| |/ _` | | | |/ _ \ '__| | |\/| |/ _ \ \ / / _ \ + * | | | | (_| | |_| | __/ | | | | | (_) \ V / __/ + * |_| |_|\__,_|\__, |\___|_| |_| |_|\___/ \_/ \___| + * __/ | + * |___/ + */ + // No typo here. I really only handle cancelled events and ignore others. + if (!event.isCancelled()) + return; + + // Fix a common mistake that other developers make (cancelling move events is crazy, rather set the target + // location to the from location). + event.setCancelled(false); + event.setTo(event.getFrom().clone()); + } /** * When a player uses a portal, all information related to the moving checks becomes invalid.