From 16fce317a1a53101ee2d120699c32e9214bb2703 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Thu, 14 Nov 2013 16:43:24 +0400 Subject: [PATCH] Unsit player on teleport --- src/com/cnaude/chairs/Chairs.java | 4 ++-- src/com/cnaude/chairs/EventListener.java | 14 ++++++++++++-- src/com/cnaude/chairs/PacketListener.java | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index 9a64b81..962138c 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -147,11 +147,11 @@ public class Chairs extends JavaPlugin { } },100); } - protected void unSitPlayer(final Player player) + protected void unSitPlayer(final Player player, boolean ignoretp) { player.eject(); final Location tploc = sitstopteleportloc.get(player.getName()); - if (tploc != null) + if (tploc != null && !ignoretp) { Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ public void run() diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index 17b0439..5df81a3 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -16,6 +16,7 @@ import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.material.Stairs; import org.bukkit.material.Step; import org.bukkit.material.WoodenStep; @@ -49,7 +50,16 @@ public class EventListener implements Listener { if (plugin.sit.containsKey(player.getName())) { plugin.savePlayerSitstoploc(player.getName()); - plugin.unSitPlayer(player); + plugin.unSitPlayer(player,true); + } + } + + @EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) + public void onTeleport(PlayerTeleportEvent e) + { + if (plugin.sit.containsKey(e.getPlayer().getName())) + { + plugin.unSitPlayer(e.getPlayer(), true); } } @@ -60,7 +70,7 @@ public class EventListener implements Listener { if (plugin.sitblock.containsKey(b)) { Player player = Bukkit.getPlayerExact(plugin.sitblock.get(b)); - plugin.unSitPlayer(player); + plugin.unSitPlayer(player,false); } } diff --git a/src/com/cnaude/chairs/PacketListener.java b/src/com/cnaude/chairs/PacketListener.java index 8c34102..df22854 100644 --- a/src/com/cnaude/chairs/PacketListener.java +++ b/src/com/cnaude/chairs/PacketListener.java @@ -41,7 +41,7 @@ public class PacketListener { //just eject player if he is sitting on chair if (pluginInstance.sit.containsKey(player.getName())) { - pluginInstance.unSitPlayer(player); + pluginInstance.unSitPlayer(player,false); } } } @@ -68,7 +68,7 @@ public class PacketListener { Player player = e.getPlayer(); if (pluginInstance.sit.containsKey(player.getName())) { - pluginInstance.unSitPlayer(player); + pluginInstance.unSitPlayer(player,false); } } }