From 7a4550246fb0d345b85534809f21d248140bd5b3 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Thu, 9 Jul 2015 18:04:43 +0200 Subject: [PATCH] Fix Fly and GameMode --- src/main/java/fr/xephi/authme/AuthMe.java | 2 +- src/main/java/fr/xephi/authme/api/API.java | 14 +----- .../xephi/authme/cache/limbo/LimboCache.java | 5 +- .../authme/listener/AuthMeEntityListener.java | 48 +++++++++---------- .../authme/listener/AuthMePlayerListener.java | 24 +++++----- .../plugin/manager/CitizensCommunicator.java | 2 +- .../authme/process/join/AsyncronousJoin.java | 4 +- .../login/ProcessSyncronousPlayerLogin.java | 15 ++++-- .../logout/ProcessSyncronousPlayerLogout.java | 6 ++- .../authme/process/quit/AsyncronousQuit.java | 2 +- 10 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index c1b99337d..4a097b93c 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -460,7 +460,7 @@ public class AuthMe extends JavaPlugin { public void savePlayer(Player player) throws IllegalStateException, NullPointerException { try { - if ((citizens.isNPC(player, this)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { + if ((citizens.isNPC(player)) || (Utils.getInstance().isUnrestricted(player)) || (CombatTagComunicator.isNPC(player))) { return; } } catch (Exception e) { diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 1117dbdfa..c60de1210 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -67,25 +67,13 @@ public class API { return PlayerCache.getInstance().isAuthenticated(player.getName()); } - /** - * - * @param player - * @return true if player is a npc - */ - @Deprecated - public boolean isaNPC(Player player) { - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) - return true; - return CombatTagComunicator.isNPC(player); - } - /** * * @param player * @return true if player is a npc */ public boolean isNPC(Player player) { - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return true; return CombatTagComunicator.isNPC(player); } diff --git a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java index c09c27b39..a67a3d1ce 100644 --- a/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java +++ b/src/main/java/fr/xephi/authme/cache/limbo/LimboCache.java @@ -39,7 +39,7 @@ public class LimboCache { boolean flying = false; if (playerData.doesCacheExist(player)) { - StoreInventoryEvent event = new StoreInventoryEvent(player, playerData); + final StoreInventoryEvent event = new StoreInventoryEvent(player, playerData); Bukkit.getServer().getPluginManager().callEvent(event); if (!event.isCancelled() && event.getInventory() != null && event.getArmor() != null) { inv = event.getInventory(); @@ -90,6 +90,9 @@ public class LimboCache { player.sendMessage("Your inventory has been cleaned!"); } } + if (gameMode == GameMode.CREATIVE) { + flying = false; + } gameMode = GameMode.SURVIVAL; } if (player.isDead()) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index 52829e7af..56b637e94 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -5,8 +5,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityInteractEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityTargetEvent; @@ -29,7 +29,7 @@ public class AuthMeEntityListener implements Listener { this.instance = instance; } - @EventHandler (priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST) public void onEntityDamage(EntityDamageEvent event) { if (event.isCancelled()) { return; @@ -44,7 +44,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -67,7 +67,7 @@ public class AuthMeEntityListener implements Listener { event.setCancelled(true); } - @EventHandler (priority = EventPriority.LOWEST) + @EventHandler(priority = EventPriority.LOWEST) public void onEntityTarget(EntityTargetEvent event) { if (event.isCancelled()) { return; @@ -79,7 +79,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -97,22 +97,22 @@ public class AuthMeEntityListener implements Listener { event.setTarget(null); event.setCancelled(true); } - + @EventHandler(priority = EventPriority.LOWEST) - public void onDmg(EntityDamageByEntityEvent event) { - if (event.isCancelled()) { + public void onDmg(EntityDamageByEntityEvent event) { + if (event.isCancelled()) { return; } - - Entity entity = event.getDamager(); - - if (entity == null || !(entity instanceof Player)) { + + Entity entity = event.getDamager(); + + if (entity == null || !(entity instanceof Player)) { return; } - - Player player = (Player) entity; - String name = player.getName().toLowerCase(); - + + Player player = (Player) entity; + String name = player.getName().toLowerCase(); + if (PlayerCache.getInstance().isAuthenticated(name)) { return; } @@ -122,11 +122,11 @@ public class AuthMeEntityListener implements Listener { return; } } - - event.setCancelled(true); - } - @EventHandler (priority = EventPriority.LOWEST) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) public void onFoodLevelChange(FoodLevelChangeEvent event) { if (event.isCancelled()) { return; @@ -137,7 +137,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -168,7 +168,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(entity, instance)) + if (instance.citizens.isNPC(entity)) return; Player player = (Player) entity; @@ -205,7 +205,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(player, instance)) + if (instance.citizens.isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName())) { @@ -237,7 +237,7 @@ public class AuthMeEntityListener implements Listener { return; } - if (instance.citizens.isNPC(player, instance)) + if (instance.citizens.isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName())) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 218858976..cda89dc58 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -50,7 +50,6 @@ import fr.xephi.authme.settings.Settings; public class AuthMePlayerListener implements Listener { - public static GameMode gm = GameMode.SURVIVAL; public static ConcurrentHashMap gameMode = new ConcurrentHashMap(); public static ConcurrentHashMap joinMessage = new ConcurrentHashMap(); private Messages m = Messages.getInstance(); @@ -328,7 +327,7 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); String name = player.getName().toLowerCase(); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -407,7 +406,7 @@ public class AuthMePlayerListener implements Listener { final String name = player.getName().toLowerCase(); boolean isAuthAvailable = data.isAuthAvailable(name); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -616,7 +615,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(name)) { @@ -644,7 +643,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -673,7 +672,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -702,7 +701,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -727,7 +726,7 @@ public class AuthMePlayerListener implements Listener { Player player = event.getPlayer(); String name = player.getName().toLowerCase(); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -755,7 +754,7 @@ public class AuthMePlayerListener implements Listener { return; } - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) { @@ -827,7 +826,7 @@ public class AuthMePlayerListener implements Listener { if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) return; - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(name)) @@ -855,8 +854,6 @@ public class AuthMePlayerListener implements Listener { return; if (event.getPlayer() == null || event == null) return; - if (!Settings.isForceSurvivalModeEnabled) - return; Player player = event.getPlayer(); @@ -868,7 +865,7 @@ public class AuthMePlayerListener implements Listener { if (Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) return; - if (plugin.getCitizensCommunicator().isNPC(player, plugin)) + if (plugin.getCitizensCommunicator().isNPC(player)) return; if (PlayerCache.getInstance().isAuthenticated(name)) @@ -880,6 +877,7 @@ public class AuthMePlayerListener implements Listener { if (causeByAuthMe.containsKey(name) && causeByAuthMe.get(name)) return; + event.setCancelled(true); } } diff --git a/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java b/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java index b93314355..d09a5fcdd 100644 --- a/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java +++ b/src/main/java/fr/xephi/authme/plugin/manager/CitizensCommunicator.java @@ -13,7 +13,7 @@ public class CitizensCommunicator { this.instance = instance; } - public boolean isNPC(final Entity player, AuthMe instance) { + public boolean isNPC(final Entity player) { if (!this.instance.isCitizensActive) return false; try { diff --git a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java index 78fd0f8d3..d13754047 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsyncronousJoin.java @@ -53,7 +53,7 @@ public class AsyncronousJoin { AuthMePlayerListener.gameMode.put(name, player.getGameMode()); BukkitScheduler sched = plugin.getServer().getScheduler(); - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } @@ -216,7 +216,7 @@ public class AsyncronousJoin { public void run() { if (player.isOp()) player.setOp(false); - if (!Settings.isMovementAllowed) { + if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(true); player.setFlying(true); } diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java index eaee58ee1..276a8c23b 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java @@ -10,7 +10,6 @@ import org.bukkit.potion.PotionEffectType; import fr.xephi.authme.AuthMe; import fr.xephi.authme.Utils; import fr.xephi.authme.Utils.groupType; -import fr.xephi.authme.api.API; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.backup.FileCache; import fr.xephi.authme.cache.limbo.LimboCache; @@ -53,8 +52,13 @@ public class ProcessSyncronousPlayerLogin implements Runnable { protected void restoreOpState() { player.setOp(limbo.getOperator()); if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { - player.setAllowFlight(limbo.isFlying()); - player.setFlying(limbo.isFlying()); + if (limbo.getGameMode() != GameMode.CREATIVE) { + player.setAllowFlight(limbo.isFlying()); + player.setFlying(limbo.isFlying()); + } else { + player.setAllowFlight(false); + player.setFlying(false); + } } } @@ -120,8 +124,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable { * ProtectInventoryEvent after Teleporting Also it's the current * world inventory ! */ + player.setGameMode(limbo.getGameMode()); if (!Settings.forceOnlyAfterLogin) { - player.setGameMode(limbo.getGameMode()); // Inventory - Make it after restore GameMode , cause we need to // restore the // right inventory in the right gamemode @@ -146,7 +150,8 @@ public class ProcessSyncronousPlayerLogin implements Runnable { } else { teleportBackFromSpawn(); } - } else if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { + } else + if (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName())) { teleportToSpawn(); } else if (Settings.isSaveQuitLocationEnabled && auth.getQuitLocY() != 0) { packQuitLocation(); diff --git a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java index 1a0ddab6e..29077488f 100644 --- a/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java +++ b/src/main/java/fr/xephi/authme/process/logout/ProcessSyncronousPlayerLogout.java @@ -51,8 +51,10 @@ public class ProcessSyncronousPlayerLogout implements Runnable { if (Settings.applyBlindEffect) player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); player.setOp(false); - player.setAllowFlight(true); - player.setFlying(true); + if (!Settings.isMovementAllowed) { + player.setAllowFlight(true); + player.setFlying(true); + } // Player is now logout... Time to fire event ! sched.scheduleSyncDelayedTask(plugin, new Runnable() { diff --git a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java index 5e34fd008..6394cac80 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java @@ -45,7 +45,7 @@ public class AsyncronousQuit { public void process() { final Player player = p; - if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { + if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; }