diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index 60b389c..87ee854 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -83,7 +83,7 @@ public class Chairs extends JavaPlugin { public void onDisable() { for (Player player : getServer().getOnlinePlayers()) { if (sit.containsKey(player.getName())) { - unSitPlayer(player, true); + unSitPlayer(player, false, true); } } if (ignoreList != null) { @@ -175,14 +175,14 @@ public class Chairs extends JavaPlugin { arrow.setPassenger(player); return arrow; } - protected void unSitPlayer(final Player player, boolean playerleft) + protected void unSitPlayer(final Player player, boolean restoreposition, boolean correctnmspostion) { final Entity arrow = sit.get(player.getName()); sit.remove(player.getName()); player.eject(); arrow.remove(); final Location tploc = sitstopteleportloc.get(player.getName()); - if (!playerleft) + if (restoreposition) { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @@ -194,22 +194,25 @@ public class Chairs extends JavaPlugin { },1); } else { - try { - Method getHandleMethod = player.getClass().getDeclaredMethod("getHandle"); - getHandleMethod.setAccessible(true); - Object nmsPlayer = getHandleMethod.invoke(player); - Class entityClass = nmsPlayer.getClass().getSuperclass().getSuperclass().getSuperclass(); - Field locXField = entityClass.getDeclaredField("locX"); - locXField.setAccessible(true); - locXField.set(nmsPlayer, tploc.getX()); - Field locYField = entityClass.getDeclaredField("locY"); - locYField.setAccessible(true); - locYField.set(nmsPlayer, tploc.getY()); - Field locZField = entityClass.getDeclaredField("locZ"); - locZField.setAccessible(true); - locZField.set(nmsPlayer, tploc.getZ()); - } catch (Exception e) { - e.printStackTrace(); + if (correctnmspostion) + { + try { + Method getHandleMethod = player.getClass().getDeclaredMethod("getHandle"); + getHandleMethod.setAccessible(true); + Object nmsPlayer = getHandleMethod.invoke(player); + Class entityClass = nmsPlayer.getClass().getSuperclass().getSuperclass().getSuperclass(); + Field locXField = entityClass.getDeclaredField("locX"); + locXField.setAccessible(true); + locXField.set(nmsPlayer, tploc.getX()); + Field locYField = entityClass.getDeclaredField("locY"); + locYField.setAccessible(true); + locYField.set(nmsPlayer, tploc.getY()); + Field locZField = entityClass.getDeclaredField("locZ"); + locZField.setAccessible(true); + locZField.set(nmsPlayer, tploc.getZ()); + } catch (Exception e) { + e.printStackTrace(); + } } } sitblock.remove(sitblockbr.get(player.getName())); diff --git a/src/com/cnaude/chairs/TryUnsitEventListener.java b/src/com/cnaude/chairs/TryUnsitEventListener.java index 0d03215..ea342ba 100644 --- a/src/com/cnaude/chairs/TryUnsitEventListener.java +++ b/src/com/cnaude/chairs/TryUnsitEventListener.java @@ -11,6 +11,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.vehicle.VehicleExitEvent; public class TryUnsitEventListener implements Listener { @@ -27,7 +28,17 @@ public class TryUnsitEventListener implements Listener { Player player = event.getPlayer(); if (plugin.sit.containsKey(player.getName())) { - plugin.unSitPlayer(player,true); + plugin.unSitPlayer(player, false, true); + } + } + + @EventHandler(priority=EventPriority.LOWEST) + public void onPlayerTeleport(PlayerTeleportEvent event) + { + Player player = event.getPlayer(); + if (plugin.sit.containsKey(player.getName())) + { + plugin.unSitPlayer(player, false, false); } } @@ -37,7 +48,7 @@ public class TryUnsitEventListener implements Listener { Player player = event.getEntity(); if (plugin.sit.containsKey(player.getName())) { - plugin.unSitPlayer(player,true); + plugin.unSitPlayer(player, false, false); } } @@ -59,7 +70,7 @@ public class TryUnsitEventListener implements Listener { public void run() { queueUnsit.remove(player.getName()); - plugin.unSitPlayer(player, false); + plugin.unSitPlayer(player, true, false); } }); } @@ -74,7 +85,7 @@ public class TryUnsitEventListener implements Listener { if (plugin.sitblock.containsKey(b)) { Player player = Bukkit.getPlayerExact(plugin.sitblock.get(b)); - plugin.unSitPlayer(player,false); + plugin.unSitPlayer(player, true, false); } }