From e6d1a1ed76278180f844d752e885ad397fd22dc5 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Sat, 14 Dec 2013 21:26:02 +0400 Subject: [PATCH] Properly unsit player --- src/com/cnaude/chairs/Chairs.java | 56 ++++++++++++------------ src/com/cnaude/chairs/EventListener.java | 9 +--- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index be665f1..8565e35 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -83,9 +83,11 @@ public class Chairs extends JavaPlugin { @Override public void onDisable() { - for (String pName : new HashSet(sit.keySet())) { - ejectPlayerOnDisable(Bukkit.getPlayerExact(pName)); - } + for (Player player : getServer().getOnlinePlayers()) { + if (sit.containsKey(player.getName())) { + unSitPlayer(player, true); + } + } if (ignoreList != null) { ignoreList.save(); } @@ -182,40 +184,38 @@ public class Chairs extends JavaPlugin { e.printStackTrace(); } } - protected void unSitPlayer(final Player player, boolean ignoretp) + protected void unSitPlayer(final Player player, boolean ignoretp) { + final Entity arrow = sit.get(player.getName()); + sit.remove(player.getName()); player.eject(); - final Location tploc = sitstopteleportloc.get(player.getName()); - if (tploc != null && !ignoretp) + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { - Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ - public void run() + public void run() + { + arrow.remove(); + } + },20); + final Location tploc = sitstopteleportloc.get(player.getName()); + if (tploc != null && !ignoretp) + { + Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() + { + public void run() { player.teleport(tploc); player.setSneaking(false); } },1); } - clearSitInfo(player); - } - private void ejectPlayerOnDisable(Player player) - { - player.eject(); - clearSitInfo(player); - } - protected void clearSitInfo(Player player) { - if (sit.containsKey(player.getName())) - { - sit.get(player.getName()).remove(); - sitblock.remove(sitblockbr.get(player.getName())); - sitblockbr.remove(player.getName()); - sitstopteleportloc.remove(player.getName()); - sit.remove(player.getName()); - Bukkit.getScheduler().cancelTask(sittask.get(player.getName())); - sittask.remove(player.getName()); - if (notifyplayer && !msgStanding.isEmpty()) { - player.sendMessage(msgStanding); - } + sitblock.remove(sitblockbr.get(player.getName())); + sitblockbr.remove(player.getName()); + sitstopteleportloc.remove(player.getName()); + Bukkit.getScheduler().cancelTask(sittask.get(player.getName())); + sittask.remove(player.getName()); + if (notifyplayer && !msgStanding.isEmpty()) + { + player.sendMessage(msgStanding); } } diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index 5f2d83d..43a9f89 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -281,14 +281,7 @@ public class EventListener implements Listener { } private boolean isSitting(Player player) { - if (plugin.sit.containsKey(player.getName())) { - if (player.isInsideVehicle()) { - return true; - } else { - plugin.clearSitInfo(player); - } - } - return false; + return plugin.sit.containsKey(player.getName()); } private int getChairWidth(Block block, BlockFace face) {