diff --git a/src/com/cnaude/chairs/Chairs.java b/src/com/cnaude/chairs/Chairs.java index ea3efd2..9ca83ef 100644 --- a/src/com/cnaude/chairs/Chairs.java +++ b/src/com/cnaude/chairs/Chairs.java @@ -91,6 +91,35 @@ public class Chairs extends JavaPlugin { protected HashMap sitblockbr = new HashMap(); protected HashMap sitstopteleportloc = new HashMap(); protected HashMap sittask = new HashMap(); + protected void sitPlayer(Player player, Location sitlocation) + { + if (notifyplayer && !msgSitting.isEmpty()) { + player.sendMessage(msgSitting); + } + Block block = sitlocation.getBlock(); + sitstopteleportloc.put(player.getName(), player.getLocation()); + Entity arrow = block.getWorld().spawnArrow(block.getLocation().add(0.5, 0 , 0.5), new Vector(0, 0.1, 0), 0, 0); + player.teleport(sitlocation); + player.setSneaking(false); + arrow.setPassenger(player); + sit.put(player.getName(), arrow); + sitblock.put(block, player.getName()); + sitblockbr.put(player.getName(), block); + startReSitTask(player); + player.teleport(player.getWorld().getSpawnLocation()); + } + protected void startReSitTask(final Player player) + { + int task = + Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() + { + public void run() + { + reSitPlayer(player); + } + },1000,1000); + sittask.put(player.getName(), task); + } protected void reSitPlayer(final Player player) { player.eject(); diff --git a/src/com/cnaude/chairs/EventListener.java b/src/com/cnaude/chairs/EventListener.java index 7ca3c26..2bd99fd 100644 --- a/src/com/cnaude/chairs/EventListener.java +++ b/src/com/cnaude/chairs/EventListener.java @@ -15,12 +15,10 @@ import org.bukkit.event.block.Action; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.material.Stairs; import org.bukkit.material.Step; import org.bukkit.material.WoodenStep; -import org.bukkit.util.Vector; public class EventListener implements Listener { @@ -58,16 +56,6 @@ public class EventListener implements Listener { plugin.unSitPlayer(player,false); } } - - @EventHandler(priority=EventPriority.MONITOR,ignoreCancelled=true) - public void onPlayerMove(PlayerMoveEvent event) - { - Player player = event.getPlayer(); - if (plugin.sit.containsKey(player.getName())) - { - plugin.unSitPlayer(player,false); - } - } @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { @@ -84,12 +72,11 @@ public class EventListener implements Listener { { event.setCancelled(true); Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); - sitPlayer(player, sitLocation); + plugin.sitPlayer(player, sitLocation); } } } - private boolean sitAllowed(Player player, Block block) { Stairs stairs = null; @@ -270,35 +257,7 @@ public class EventListener implements Listener { return plocation; } - - private void sitPlayer(Player player, Location sitlocation) - { - if (plugin.notifyplayer && !plugin.msgSitting.isEmpty()) { - player.sendMessage(plugin.msgSitting); - } - Block block = sitlocation.getBlock(); - plugin.sitstopteleportloc.put(player.getName(), player.getLocation()); - player.teleport(sitlocation); - player.setSneaking(false); - Entity arrow = block.getWorld().spawnArrow(block.getLocation().add(0.5, 0 , 0.5), new Vector(0, 0, 0), 0, 0); - arrow.setPassenger(player); - plugin.sit.put(player.getName(), arrow); - plugin.sitblock.put(block, player.getName()); - plugin.sitblockbr.put(player.getName(), block); - startReSitTask(player); - } - private void startReSitTask(final Player player) - { - int task = - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() - { - public void run() - { - plugin.reSitPlayer(player); - } - },1000,1000); - plugin.sittask.put(player.getName(), task); - } + private boolean isValidChair(Block block) { for (ChairBlock cb : plugin.allowedBlocks) {