diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index c7be53a..38d7d4c 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -20,6 +20,7 @@ import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.Vector; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; @@ -111,6 +112,16 @@ public class Chairs extends JavaPlugin { protected HashMap sitblock = new HashMap(); protected HashMap sitblockbr = new HashMap(); protected HashMap sitstopteleportloc = new HashMap(); + protected HashMap sittask = new HashMap(); + protected void reSitPlayer(final Player player) + { + player.eject(); + sit.get(player.getName()).remove(); + Block block = sitblockbr.get(player.getName()); + Entity arrow = block.getWorld().spawnArrow(block.getLocation().add(0.5, 0, 0.5), new Vector(0, 0, 0), 0, 0); + arrow.setPassenger(player); + sit.put(player.getName(), arrow); + } protected void ejectPlayer(final Player player) { player.eject(); @@ -126,6 +137,11 @@ public class Chairs extends JavaPlugin { } unSit(player); } + private void ejectPlayerOnDisable(Player player) + { + player.eject(); + unSit(player); + } protected void unSit(Player player) { if (sit.containsKey(player.getName())) { @@ -134,20 +150,13 @@ public class Chairs extends JavaPlugin { 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); } } } - private void ejectPlayerOnDisable(Player player) - { - player.eject(); - sit.get(player.getName()).remove(); - sitblock.remove(sitblockbr.get(player.getName())); - sitblockbr.remove(player.getName()); - sitstopteleportloc.remove(player.getName()); - sit.remove(player.getName()); - } public void loadConfig() { diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index ae2f466..b6e89bf 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -282,10 +282,24 @@ public class EventListener implements Listener { plugin.sit.put(player.getName(), arrow); plugin.sitblock.put(block, player.getName()); plugin.sitblockbr.put(player.getName(), block); + startReSitTask(player); sit = true; } } + protected void startReSitTask(final Player player) + { + int task = + Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() + { + public void run() + { + plugin.reSitPlayer(player); + } + },1150,1150); + plugin.sittask.put(player.getName(), task); + } + // https://github.com/sk89q/craftbook/blob/master/src/main/java/com/sk89q/craftbook/util/BlockUtil.java public static Location getBlockCentre(Block block) { diff --git a/target/Chairs.jar b/target/Chairs.jar index ada2913..87e0182 100644 Binary files a/target/Chairs.jar and b/target/Chairs.jar differ