From 2162a4abe4475cdf6c7fd1b1b8dcc92325c70f73 Mon Sep 17 00:00:00 2001 From: DNx5 Date: Thu, 26 Nov 2015 03:37:55 +0700 Subject: [PATCH] Cleanup some listener code. --- .../authme/listener/AuthMeBlockListener.java | 7 +++---- .../authme/listener/AuthMeEntityListener.java | 6 +++--- .../authme/listener/AuthMePlayerListener.java | 15 +++++++-------- .../authme/listener/AuthMePlayerListener16.java | 4 ++-- .../authme/listener/AuthMePlayerListener18.java | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java index 497b9e336..6cab19587 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeBlockListener.java @@ -20,7 +20,6 @@ public class AuthMeBlockListener implements Listener { * @param instance AuthMe */ public AuthMeBlockListener(AuthMe instance) { - this.instance = instance; } @@ -31,8 +30,9 @@ public class AuthMeBlockListener implements Listener { */ @EventHandler(ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { - if (Utils.checkAuth(event.getPlayer())) + if (Utils.checkAuth(event.getPlayer())) { return; + } event.setCancelled(true); } @@ -43,8 +43,7 @@ public class AuthMeBlockListener implements Listener { */ @EventHandler(ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { - Player player = event.getPlayer(); - if (player == null || Utils.checkAuth(player)) { + if (Utils.checkAuth(event.getPlayer())) { return; } event.setCancelled(true); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index 02c94e83e..5e27814e2 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -183,12 +183,12 @@ public class AuthMeEntityListener implements Listener { */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onProjectileLaunch(ProjectileLaunchEvent event) { - Projectile projectile = event.getEntity(); - Player player = null; - if (projectile == null) { + if (event.getEntity() == null) { return; } + Player player = null; + Projectile projectile = event.getEntity(); if (shooterIsProjectileSource) { ProjectileSource shooter = projectile.getShooter(); if (shooter == null || !(shooter instanceof Player)) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 502d2f4f3..60c8c7735 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -93,12 +93,15 @@ public class AuthMePlayerListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { String cmd = event.getMessage().split(" ")[0].toLowerCase(); - if (Settings.useEssentialsMotd && cmd.equals("/motd")) + if (Settings.useEssentialsMotd && cmd.equals("/motd")) { return; - if (Settings.allowCommands.contains(cmd)) + } + if (Settings.allowCommands.contains(cmd)) { return; - if (Utils.checkAuth(event.getPlayer())) + } + if (Utils.checkAuth(event.getPlayer())) { return; + } event.setCancelled(true); } @@ -167,12 +170,8 @@ public class AuthMePlayerListener implements Listener { * * @param event PlayerMoveEvent */ - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) public void onPlayerMove(PlayerMoveEvent event) { - if (event.isCancelled()) { - return; - } - if (Settings.isMovementAllowed && Settings.getMovementRadius <= 0) { return; } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java index d06780c28..39e585811 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener16.java @@ -30,9 +30,9 @@ public class AuthMePlayerListener16 implements Listener { */ @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) public void onPlayerEditBook(PlayerEditBookEvent event) { - Player player = event.getPlayer(); - if (player == null || Utils.checkAuth(player)) + if (Utils.checkAuth(event.getPlayer())) { return; + } event.setCancelled(true); } diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java index ef5e27dd9..abf5c5da3 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener18.java @@ -30,9 +30,9 @@ public class AuthMePlayerListener18 implements Listener { */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerInteractAtEntity(PlayerInteractAtEntityEvent event) { - Player player = event.getPlayer(); - if (player == null || Utils.checkAuth(player)) + if (Utils.checkAuth(event.getPlayer())) { return; + } event.setCancelled(true); }