Format source

This commit is contained in:
Shevchik 2014-03-07 09:33:07 +04:00
parent 6a19624e4b
commit bcc9e92efb

View File

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