Move some methods
This commit is contained in:
parent
e307801bdd
commit
04562288dd
@ -91,6 +91,35 @@ public class Chairs extends JavaPlugin {
|
|||||||
protected HashMap<String, Block> sitblockbr = new HashMap<String, Block>();
|
protected HashMap<String, Block> sitblockbr = new HashMap<String, Block>();
|
||||||
protected HashMap<String, Location> sitstopteleportloc = new HashMap<String, Location>();
|
protected HashMap<String, Location> sitstopteleportloc = new HashMap<String, Location>();
|
||||||
protected HashMap<String, Integer> sittask = new HashMap<String, Integer>();
|
protected HashMap<String, Integer> sittask = new HashMap<String, Integer>();
|
||||||
|
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)
|
protected void reSitPlayer(final Player player)
|
||||||
{
|
{
|
||||||
player.eject();
|
player.eject();
|
||||||
|
@ -15,12 +15,10 @@ import org.bukkit.event.block.Action;
|
|||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.material.Stairs;
|
import org.bukkit.material.Stairs;
|
||||||
import org.bukkit.material.Step;
|
import org.bukkit.material.Step;
|
||||||
import org.bukkit.material.WoodenStep;
|
import org.bukkit.material.WoodenStep;
|
||||||
import org.bukkit.util.Vector;
|
|
||||||
|
|
||||||
public class EventListener implements Listener {
|
public class EventListener implements Listener {
|
||||||
|
|
||||||
@ -58,16 +56,6 @@ public class EventListener implements Listener {
|
|||||||
plugin.unSitPlayer(player,false);
|
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
|
@EventHandler
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
@ -84,12 +72,11 @@ public class EventListener implements Listener {
|
|||||||
{
|
{
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
|
Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
|
||||||
sitPlayer(player, sitLocation);
|
plugin.sitPlayer(player, sitLocation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private boolean sitAllowed(Player player, Block block)
|
private boolean sitAllowed(Player player, Block block)
|
||||||
{
|
{
|
||||||
Stairs stairs = null;
|
Stairs stairs = null;
|
||||||
@ -270,35 +257,7 @@ public class EventListener implements Listener {
|
|||||||
return plocation;
|
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) {
|
private boolean isValidChair(Block block) {
|
||||||
for (ChairBlock cb : plugin.allowedBlocks) {
|
for (ChairBlock cb : plugin.allowedBlocks) {
|
||||||
|
Loading…
Reference in New Issue
Block a user