Also unsit player on teleport event

This commit is contained in:
Shevchik 2013-12-15 18:59:10 +04:00
parent 03c683af03
commit ef9f272a57
2 changed files with 37 additions and 23 deletions

View File

@ -83,7 +83,7 @@ public class Chairs extends JavaPlugin {
public void onDisable() { public void onDisable() {
for (Player player : getServer().getOnlinePlayers()) { for (Player player : getServer().getOnlinePlayers()) {
if (sit.containsKey(player.getName())) { if (sit.containsKey(player.getName())) {
unSitPlayer(player, true); unSitPlayer(player, false, true);
} }
} }
if (ignoreList != null) { if (ignoreList != null) {
@ -175,14 +175,14 @@ public class Chairs extends JavaPlugin {
arrow.setPassenger(player); arrow.setPassenger(player);
return arrow; 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()); final Entity arrow = sit.get(player.getName());
sit.remove(player.getName()); sit.remove(player.getName());
player.eject(); player.eject();
arrow.remove(); arrow.remove();
final Location tploc = sitstopteleportloc.get(player.getName()); final Location tploc = sitstopteleportloc.get(player.getName());
if (!playerleft) if (restoreposition)
{ {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{ {
@ -193,6 +193,8 @@ public class Chairs extends JavaPlugin {
} }
},1); },1);
} else } else
{
if (correctnmspostion)
{ {
try { try {
Method getHandleMethod = player.getClass().getDeclaredMethod("getHandle"); Method getHandleMethod = player.getClass().getDeclaredMethod("getHandle");
@ -212,6 +214,7 @@ public class Chairs extends JavaPlugin {
e.printStackTrace(); e.printStackTrace();
} }
} }
}
sitblock.remove(sitblockbr.get(player.getName())); sitblock.remove(sitblockbr.get(player.getName()));
sitblockbr.remove(player.getName()); sitblockbr.remove(player.getName());
sitstopteleportloc.remove(player.getName()); sitstopteleportloc.remove(player.getName());

View File

@ -11,6 +11,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.vehicle.VehicleExitEvent; import org.bukkit.event.vehicle.VehicleExitEvent;
public class TryUnsitEventListener implements Listener { public class TryUnsitEventListener implements Listener {
@ -27,7 +28,17 @@ public class TryUnsitEventListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.sit.containsKey(player.getName())) 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(); Player player = event.getEntity();
if (plugin.sit.containsKey(player.getName())) 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() public void run()
{ {
queueUnsit.remove(player.getName()); 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)) if (plugin.sitblock.containsKey(b))
{ {
Player player = Bukkit.getPlayerExact(plugin.sitblock.get(b)); Player player = Bukkit.getPlayerExact(plugin.sitblock.get(b));
plugin.unSitPlayer(player,false); plugin.unSitPlayer(player, true, false);
} }
} }