Properly unsit player

This commit is contained in:
Shevchik 2013-12-14 21:26:02 +04:00
parent ab080914b0
commit e6d1a1ed76
2 changed files with 29 additions and 36 deletions

View File

@ -83,8 +83,10 @@ public class Chairs extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
for (String pName : new HashSet<String>(sit.keySet())) { for (Player player : getServer().getOnlinePlayers()) {
ejectPlayerOnDisable(Bukkit.getPlayerExact(pName)); if (sit.containsKey(player.getName())) {
unSitPlayer(player, true);
}
} }
if (ignoreList != null) { if (ignoreList != null) {
ignoreList.save(); ignoreList.save();
@ -184,11 +186,21 @@ public class Chairs extends JavaPlugin {
} }
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(); player.eject();
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run()
{
arrow.remove();
}
},20);
final Location tploc = sitstopteleportloc.get(player.getName()); final Location tploc = sitstopteleportloc.get(player.getName());
if (tploc != null && !ignoretp) if (tploc != null && !ignoretp)
{ {
Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){ Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable()
{
public void run() public void run()
{ {
player.teleport(tploc); player.teleport(tploc);
@ -196,28 +208,16 @@ public class Chairs extends JavaPlugin {
} }
},1); },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())); sitblock.remove(sitblockbr.get(player.getName()));
sitblockbr.remove(player.getName()); sitblockbr.remove(player.getName());
sitstopteleportloc.remove(player.getName()); sitstopteleportloc.remove(player.getName());
sit.remove(player.getName());
Bukkit.getScheduler().cancelTask(sittask.get(player.getName())); Bukkit.getScheduler().cancelTask(sittask.get(player.getName()));
sittask.remove(player.getName()); sittask.remove(player.getName());
if (notifyplayer && !msgStanding.isEmpty()) { if (notifyplayer && !msgStanding.isEmpty())
{
player.sendMessage(msgStanding); player.sendMessage(msgStanding);
} }
} }
}
public void loadConfig() { public void loadConfig() {
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml")); FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(),"config.yml"));

View File

@ -281,14 +281,7 @@ public class EventListener implements Listener {
} }
private boolean isSitting(Player player) { private boolean isSitting(Player player) {
if (plugin.sit.containsKey(player.getName())) { return plugin.sit.containsKey(player.getName());
if (player.isInsideVehicle()) {
return true;
} else {
plugin.clearSitInfo(player);
}
}
return false;
} }
private int getChairWidth(Block block, BlockFace face) { private int getChairWidth(Block block, BlockFace face) {