Move sit method
This commit is contained in:
parent
ad3e1b7991
commit
c4386ab262
@ -87,198 +87,206 @@ public class EventListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
if (event.hasBlock() && event.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
sitPlayer(player, event.getClickedBlock());
|
||||||
|
if (sit) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
sit = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private boolean sit = false;
|
||||||
|
protected void sitPlayer(Player player, Block block)
|
||||||
|
{
|
||||||
|
Stairs stairs = null;
|
||||||
|
Step step = null;
|
||||||
|
WoodenStep wStep = null;
|
||||||
|
double sh = plugin.sittingHeight;
|
||||||
|
boolean blockOkay = false;
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
if (ignoreList.isIgnored(player.getName())) {
|
||||||
Stairs stairs = null;
|
return;
|
||||||
Step step = null;
|
}
|
||||||
WoodenStep wStep = null;
|
// Permissions Check
|
||||||
double sh = plugin.sittingHeight;
|
if (plugin.permissions) {
|
||||||
boolean blockOkay = false;
|
if (!player.hasPermission("chairs.sit")) {
|
||||||
|
|
||||||
if (ignoreList.isIgnored(player.getName())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Permissions Check
|
}
|
||||||
if (plugin.permissions) {
|
if (plugin.perItemPerms) {
|
||||||
if (!player.hasPermission("chairs.sit")) {
|
if (plugin.pm.getPermission("chairs.sit." + block.getTypeId()) == null) {
|
||||||
return;
|
plugin.pm.addPermission(new Permission("chairs.sit." + block.getTypeId(),
|
||||||
}
|
"Allow players to sit on a '" + block.getType().name() + "'",
|
||||||
|
PermissionDefault.FALSE));
|
||||||
}
|
}
|
||||||
if (plugin.perItemPerms) {
|
if (plugin.pm.getPermission("chairs.sit." + block.getType().toString()) == null) {
|
||||||
if (plugin.pm.getPermission("chairs.sit." + block.getTypeId()) == null) {
|
plugin.pm.addPermission(new Permission("chairs.sit." + block.getType().toString(),
|
||||||
plugin.pm.addPermission(new Permission("chairs.sit." + block.getTypeId(),
|
"Allow players to sit on a '" + block.getType().name() + "'",
|
||||||
"Allow players to sit on a '" + block.getType().name() + "'",
|
PermissionDefault.FALSE));
|
||||||
PermissionDefault.FALSE));
|
|
||||||
}
|
|
||||||
if (plugin.pm.getPermission("chairs.sit." + block.getType().toString()) == null) {
|
|
||||||
plugin.pm.addPermission(new Permission("chairs.sit." + block.getType().toString(),
|
|
||||||
"Allow players to sit on a '" + block.getType().name() + "'",
|
|
||||||
PermissionDefault.FALSE));
|
|
||||||
}
|
|
||||||
if (plugin.pm.getPermission("chairs.sit." + block.getTypeId() + ":" + block.getData()) == null) {
|
|
||||||
plugin.pm.addPermission(new Permission("chairs.sit." + block.getTypeId() + ":" + block.getData(),
|
|
||||||
"Allow players to sit on a '" + block.getType().name() + "'",
|
|
||||||
PermissionDefault.FALSE));
|
|
||||||
}
|
|
||||||
if (plugin.pm.getPermission("chairs.sit." + block.getType().toString() + ":" + block.getData()) == null) {
|
|
||||||
plugin.pm.addPermission(new Permission("chairs.sit." + block.getType().toString() + ":" + block.getData(),
|
|
||||||
"Allow players to sit on a '" + block.getType().name() + "'",
|
|
||||||
PermissionDefault.FALSE));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (plugin.pm.getPermission("chairs.sit." + block.getTypeId() + ":" + block.getData()) == null) {
|
||||||
|
plugin.pm.addPermission(new Permission("chairs.sit." + block.getTypeId() + ":" + block.getData(),
|
||||||
|
"Allow players to sit on a '" + block.getType().name() + "'",
|
||||||
|
PermissionDefault.FALSE));
|
||||||
|
}
|
||||||
|
if (plugin.pm.getPermission("chairs.sit." + block.getType().toString() + ":" + block.getData()) == null) {
|
||||||
|
plugin.pm.addPermission(new Permission("chairs.sit." + block.getType().toString() + ":" + block.getData(),
|
||||||
|
"Allow players to sit on a '" + block.getType().name() + "'",
|
||||||
|
PermissionDefault.FALSE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ChairBlock cb : plugin.allowedBlocks) {
|
for (ChairBlock cb : plugin.allowedBlocks) {
|
||||||
if (cb.getMat().toString().contains("STAIRS")) {
|
if (cb.getMat().toString().contains("STAIRS")) {
|
||||||
if (cb.getMat().equals(block.getType())) {
|
if (cb.getMat().equals(block.getType())) {
|
||||||
blockOkay = true;
|
|
||||||
sh = cb.getSitHeight();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else if (cb.getMat().equals(block.getType())
|
|
||||||
&& cb.getDamage() == block.getData()) {
|
|
||||||
blockOkay = true;
|
blockOkay = true;
|
||||||
sh = cb.getSitHeight();
|
sh = cb.getSitHeight();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
} else if (cb.getMat().equals(block.getType())
|
||||||
if (blockOkay
|
&& cb.getDamage() == block.getData()) {
|
||||||
|| (player.hasPermission("chairs.sit." + block.getTypeId() + ":" + block.getData()) && plugin.perItemPerms)
|
blockOkay = true;
|
||||||
|| (player.hasPermission("chairs.sit." + block.getType().toString() + ":" + block.getData()) && plugin.perItemPerms)
|
sh = cb.getSitHeight();
|
||||||
|| (player.hasPermission("chairs.sit." + block.getTypeId()) && plugin.perItemPerms)
|
continue;
|
||||||
|| (player.hasPermission("chairs.sit." + block.getType().toString()) && plugin.perItemPerms)) {
|
|
||||||
|
|
||||||
if (block.getState().getData() instanceof Stairs) {
|
|
||||||
stairs = (Stairs) block.getState().getData();
|
|
||||||
} else if (block.getState().getData() instanceof Step) {
|
|
||||||
step = (Step) block.getState().getData();
|
|
||||||
} else if (block.getState().getData() instanceof WoodenStep) {
|
|
||||||
wStep = (WoodenStep) block.getState().getData();
|
|
||||||
} else {
|
|
||||||
sh += plugin.sittingHeightAdj;
|
|
||||||
}
|
|
||||||
|
|
||||||
int chairwidth = 1;
|
|
||||||
|
|
||||||
// Check if block beneath chair is solid.
|
|
||||||
if (block.getRelative(BlockFace.DOWN).isLiquid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for distance distance between player and chair.
|
|
||||||
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stairs != null) {
|
|
||||||
if (stairs.isInverted() && plugin.invertedStairCheck) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (step != null) {
|
|
||||||
if (step.isInverted() && plugin.invertedStepCheck) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (wStep != null) {
|
|
||||||
if (wStep.isInverted() && plugin.invertedStepCheck) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for signs.
|
|
||||||
if (plugin.signCheck == true && stairs != null) {
|
|
||||||
boolean sign1 = false;
|
|
||||||
boolean sign2 = false;
|
|
||||||
|
|
||||||
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
|
|
||||||
sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player);
|
|
||||||
sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player);
|
|
||||||
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
|
|
||||||
sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player);
|
|
||||||
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(sign1 == true && sign2 == true)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for maximal chair width.
|
|
||||||
if (plugin.maxChairWidth > 0 && stairs != null) {
|
|
||||||
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
|
|
||||||
chairwidth += getChairWidth(block, BlockFace.EAST);
|
|
||||||
chairwidth += getChairWidth(block, BlockFace.WEST);
|
|
||||||
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
|
|
||||||
chairwidth += getChairWidth(block, BlockFace.NORTH);
|
|
||||||
chairwidth += getChairWidth(block, BlockFace.SOUTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (chairwidth > plugin.maxChairWidth) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sit-down process.
|
|
||||||
if (plugin.seatOccupiedCheck) {
|
|
||||||
if (!plugin.sit.isEmpty()) {
|
|
||||||
if (plugin.sitblock.containsKey(block))
|
|
||||||
{
|
|
||||||
if (!plugin.msgOccupied.isEmpty()) {
|
|
||||||
player.sendMessage(plugin.msgOccupied.replaceAll("%PLAYER%", plugin.sitblock.get(block)));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Location plocation = block.getLocation().clone();
|
|
||||||
plocation.add(0.5D, (sh - 0.5D), 0.5D);
|
|
||||||
|
|
||||||
// Rotate the player's view to the descending side of the block.
|
|
||||||
if (plugin.autoRotate && stairs != null) {
|
|
||||||
switch (stairs.getDescendingDirection()) {
|
|
||||||
case NORTH:
|
|
||||||
plocation.setYaw(180);
|
|
||||||
break;
|
|
||||||
case EAST:
|
|
||||||
plocation.setYaw(-90);
|
|
||||||
break;
|
|
||||||
case SOUTH:
|
|
||||||
plocation.setYaw(0);
|
|
||||||
break;
|
|
||||||
case WEST:
|
|
||||||
plocation.setYaw(90);
|
|
||||||
default:
|
|
||||||
;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
plocation.setYaw(player.getLocation().getYaw());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (plugin.notifyplayer && !plugin.msgSitting.isEmpty()) {
|
|
||||||
player.sendMessage(plugin.msgSitting);
|
|
||||||
}
|
|
||||||
|
|
||||||
plugin.sitstopteleportloc.put(player.getName(), player.getLocation());
|
|
||||||
player.teleport(plocation);
|
|
||||||
Entity arrow = block.getWorld().spawnArrow(getBlockCentre(block).subtract(0, 0.5, 0), new Vector(0, 0, 0), 0, 0);
|
|
||||||
arrow.setPassenger(player);
|
|
||||||
player.setSneaking(false);
|
|
||||||
arrow.setTicksLived(1);
|
|
||||||
plugin.sit.put(player.getName(), arrow);
|
|
||||||
plugin.sitblock.put(block, player.getName());
|
|
||||||
plugin.sitblockbr.put(player.getName(), block);
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (blockOkay
|
||||||
|
|| (player.hasPermission("chairs.sit." + block.getTypeId() + ":" + block.getData()) && plugin.perItemPerms)
|
||||||
|
|| (player.hasPermission("chairs.sit." + block.getType().toString() + ":" + block.getData()) && plugin.perItemPerms)
|
||||||
|
|| (player.hasPermission("chairs.sit." + block.getTypeId()) && plugin.perItemPerms)
|
||||||
|
|| (player.hasPermission("chairs.sit." + block.getType().toString()) && plugin.perItemPerms)) {
|
||||||
|
|
||||||
|
if (block.getState().getData() instanceof Stairs) {
|
||||||
|
stairs = (Stairs) block.getState().getData();
|
||||||
|
} else if (block.getState().getData() instanceof Step) {
|
||||||
|
step = (Step) block.getState().getData();
|
||||||
|
} else if (block.getState().getData() instanceof WoodenStep) {
|
||||||
|
wStep = (WoodenStep) block.getState().getData();
|
||||||
|
} else {
|
||||||
|
sh += plugin.sittingHeightAdj;
|
||||||
|
}
|
||||||
|
|
||||||
|
int chairwidth = 1;
|
||||||
|
|
||||||
|
// Check if block beneath chair is solid.
|
||||||
|
if (block.getRelative(BlockFace.DOWN).isLiquid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (block.getRelative(BlockFace.DOWN).isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!block.getRelative(BlockFace.DOWN).getType().isSolid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for distance distance between player and chair.
|
||||||
|
if (plugin.distance > 0 && player.getLocation().distance(block.getLocation().add(0.5, 0, 0.5)) > plugin.distance) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stairs != null) {
|
||||||
|
if (stairs.isInverted() && plugin.invertedStairCheck) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (step != null) {
|
||||||
|
if (step.isInverted() && plugin.invertedStepCheck) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (wStep != null) {
|
||||||
|
if (wStep.isInverted() && plugin.invertedStepCheck) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for signs.
|
||||||
|
if (plugin.signCheck == true && stairs != null) {
|
||||||
|
boolean sign1 = false;
|
||||||
|
boolean sign2 = false;
|
||||||
|
|
||||||
|
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
|
||||||
|
sign1 = checkSign(block, BlockFace.EAST) || checkFrame(block, BlockFace.EAST, player);
|
||||||
|
sign2 = checkSign(block, BlockFace.WEST) || checkFrame(block, BlockFace.WEST, player);
|
||||||
|
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
|
||||||
|
sign1 = checkSign(block, BlockFace.NORTH) || checkFrame(block, BlockFace.NORTH, player);
|
||||||
|
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(sign1 == true && sign2 == true)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for maximal chair width.
|
||||||
|
if (plugin.maxChairWidth > 0 && stairs != null) {
|
||||||
|
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
|
||||||
|
chairwidth += getChairWidth(block, BlockFace.EAST);
|
||||||
|
chairwidth += getChairWidth(block, BlockFace.WEST);
|
||||||
|
} else if (stairs.getDescendingDirection() == BlockFace.EAST || stairs.getDescendingDirection() == BlockFace.WEST) {
|
||||||
|
chairwidth += getChairWidth(block, BlockFace.NORTH);
|
||||||
|
chairwidth += getChairWidth(block, BlockFace.SOUTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (chairwidth > plugin.maxChairWidth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sit-down process.
|
||||||
|
if (plugin.seatOccupiedCheck) {
|
||||||
|
if (!plugin.sit.isEmpty()) {
|
||||||
|
if (plugin.sitblock.containsKey(block))
|
||||||
|
{
|
||||||
|
if (!plugin.msgOccupied.isEmpty()) {
|
||||||
|
player.sendMessage(plugin.msgOccupied.replaceAll("%PLAYER%", plugin.sitblock.get(block)));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Location plocation = block.getLocation().clone();
|
||||||
|
plocation.add(0.5D, (sh - 0.5D), 0.5D);
|
||||||
|
|
||||||
|
// Rotate the player's view to the descending side of the block.
|
||||||
|
if (plugin.autoRotate && stairs != null) {
|
||||||
|
switch (stairs.getDescendingDirection()) {
|
||||||
|
case NORTH:
|
||||||
|
plocation.setYaw(180);
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
plocation.setYaw(-90);
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
plocation.setYaw(0);
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
plocation.setYaw(90);
|
||||||
|
default:
|
||||||
|
;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plocation.setYaw(player.getLocation().getYaw());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.notifyplayer && !plugin.msgSitting.isEmpty()) {
|
||||||
|
player.sendMessage(plugin.msgSitting);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.sitstopteleportloc.put(player.getName(), player.getLocation());
|
||||||
|
player.teleport(plocation);
|
||||||
|
Entity arrow = block.getWorld().spawnArrow(getBlockCentre(block).subtract(0, 0.5, 0), new Vector(0, 0, 0), 0, 0);
|
||||||
|
arrow.setPassenger(player);
|
||||||
|
player.setSneaking(false);
|
||||||
|
arrow.setTicksLived(1);
|
||||||
|
plugin.sit.put(player.getName(), arrow);
|
||||||
|
plugin.sitblock.put(block, player.getName());
|
||||||
|
plugin.sitblockbr.put(player.getName(), block);
|
||||||
|
sit = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// https://github.com/sk89q/craftbook/blob/master/src/main/java/com/sk89q/craftbook/util/BlockUtil.java
|
// https://github.com/sk89q/craftbook/blob/master/src/main/java/com/sk89q/craftbook/util/BlockUtil.java
|
||||||
public static Location getBlockCentre(Block block) {
|
public static Location getBlockCentre(Block block) {
|
||||||
return block.getLocation().add(0.5, 0.5, 0.5);
|
return block.getLocation().add(0.5, 0.5, 0.5);
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user