diff --git a/src/com/cnaude/chairs/core/PlayerSitData.java b/src/com/cnaude/chairs/core/PlayerSitData.java index cd08520..8ac5562 100644 --- a/src/com/cnaude/chairs/core/PlayerSitData.java +++ b/src/com/cnaude/chairs/core/PlayerSitData.java @@ -1,6 +1,5 @@ package com.cnaude.chairs.core; -import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import org.bukkit.Bukkit; @@ -21,15 +20,19 @@ public class PlayerSitData { private HashMap sitblockbr = new HashMap(); private HashMap sitstopteleportloc = new HashMap(); private HashMap sittask = new HashMap(); + public boolean isSitting(Player player) { return sit.containsKey(player.getName()); } + public boolean isBlockOccupied(Block block) { return sitblock.containsKey(block); } + public Player getPlayerOnChair(Block chair) { return Bukkit.getPlayerExact(sitblock.get(chair)); } + public void sitPlayer(Player player, Location sitlocation) { try { if (plugin.notifyplayer) { @@ -39,7 +42,8 @@ public class PlayerSitData { sitstopteleportloc.put(player.getName(), player.getLocation()); player.teleport(sitlocation); Location arrowloc = block.getLocation().add(0.5, 0 , 0.5); - Entity arrow = sitPlayerOnArrow(player, arrowloc); + Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc); + arrow.setPassenger(player); sit.put(player.getName(), arrow); sitblock.put(block, player.getName()); sitblockbr.put(player.getName(), block); @@ -48,16 +52,21 @@ public class PlayerSitData { e.printStackTrace(); } } + public void startReSitTask(final Player player) { - int task = - Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() { - @Override - public void run() { - reSitPlayer(player); - } - },1000,1000); + int task = Bukkit.getScheduler().scheduleSyncRepeatingTask( + plugin, + new Runnable() { + @Override + public void run() { + reSitPlayer(player); + } + }, + 1000, 1000 + ); sittask.put(player.getName(), task); } + public void reSitPlayer(final Player player) { try { final Entity prevarrow = sit.get(player.getName()); @@ -65,32 +74,36 @@ public class PlayerSitData { player.eject(); Block block = sitblockbr.get(player.getName()); Location arrowloc = block.getLocation().add(0.5, 0 , 0.5); - Entity arrow = sitPlayerOnArrow(player, arrowloc); + Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc); + arrow.setPassenger(player); sit.put(player.getName(), arrow); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - prevarrow.remove(); - } - },100); + Bukkit.getScheduler().scheduleSyncDelayedTask( + plugin, + new Runnable() { + @Override + public void run() { + prevarrow.remove(); + } + }, + 100 + ); } catch (Exception e) { e.printStackTrace(); } } - private Entity sitPlayerOnArrow(Player player, Location arrowloc) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - Entity arrow = plugin.getNMSAccess().spawnArrow(arrowloc); - arrow.setPassenger(player); - return arrow; - } + public void unsitPlayerNormal(Player player) { unsitPlayer(player, false, true, false); } + public void unsitPlayerForce(Player player) { unsitPlayer(player, true, true, false); } + public void unsitPlayerNow(Player player) { unsitPlayer(player, true, false, true); } + private void unsitPlayer(final Player player, boolean eject, boolean restoreposition, boolean correctleaveposition) { final Entity arrow = sit.get(player.getName()); sit.remove(player.getName()); @@ -100,13 +113,17 @@ public class PlayerSitData { arrow.remove(); final Location tploc = sitstopteleportloc.get(player.getName()); if (restoreposition) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - @Override - public void run() { - player.teleport(tploc); - player.setSneaking(false); - } - },1); + Bukkit.getScheduler().scheduleSyncDelayedTask( + plugin, + new Runnable() { + @Override + public void run() { + player.teleport(tploc); + player.setSneaking(false); + } + }, + 1 + ); } else if (correctleaveposition) { player.teleport(tploc); }