Format source
This commit is contained in:
parent
6a19624e4b
commit
bcc9e92efb
@ -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,
|
||||||
@Override
|
new Runnable() {
|
||||||
public void run() {
|
@Override
|
||||||
reSitPlayer(player);
|
public void run() {
|
||||||
}
|
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(
|
||||||
@Override
|
plugin,
|
||||||
public void run() {
|
new Runnable() {
|
||||||
prevarrow.remove();
|
@Override
|
||||||
}
|
public void run() {
|
||||||
},100);
|
prevarrow.remove();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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(
|
||||||
@Override
|
plugin,
|
||||||
public void run() {
|
new Runnable() {
|
||||||
player.teleport(tploc);
|
@Override
|
||||||
player.setSneaking(false);
|
public void run() {
|
||||||
}
|
player.teleport(tploc);
|
||||||
},1);
|
player.setSneaking(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
1
|
||||||
|
);
|
||||||
} else if (correctleaveposition) {
|
} else if (correctleaveposition) {
|
||||||
player.teleport(tploc);
|
player.teleport(tploc);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user