Move sit method

This commit is contained in:
Shevchik 2013-09-01 16:59:58 +04:00
parent ad3e1b7991
commit c4386ab262
2 changed files with 186 additions and 178 deletions

View File

@ -87,198 +87,206 @@ public class EventListener implements Listener {
return;
}
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();
Stairs stairs = null;
Step step = null;
WoodenStep wStep = null;
double sh = plugin.sittingHeight;
boolean blockOkay = false;
if (ignoreList.isIgnored(player.getName())) {
if (ignoreList.isIgnored(player.getName())) {
return;
}
// Permissions Check
if (plugin.permissions) {
if (!player.hasPermission("chairs.sit")) {
return;
}
// Permissions Check
if (plugin.permissions) {
if (!player.hasPermission("chairs.sit")) {
return;
}
}
if (plugin.perItemPerms) {
if (plugin.pm.getPermission("chairs.sit." + block.getTypeId()) == null) {
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.getTypeId()) == null) {
plugin.pm.addPermission(new Permission("chairs.sit." + block.getTypeId(),
"Allow players to sit on a '" + block.getType().name() + "'",
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.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));
}
}
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().toString().contains("STAIRS")) {
if (cb.getMat().equals(block.getType())) {
blockOkay = true;
sh = cb.getSitHeight();
continue;
}
} else if (cb.getMat().equals(block.getType())
&& cb.getDamage() == block.getData()) {
for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().toString().contains("STAIRS")) {
if (cb.getMat().equals(block.getType())) {
blockOkay = true;
sh = cb.getSitHeight();
continue;
}
}
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);
event.setCancelled(true);
} else if (cb.getMat().equals(block.getType())
&& cb.getDamage() == block.getData()) {
blockOkay = true;
sh = cb.getSitHeight();
continue;
}
}
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
public static Location getBlockCentre(Block block) {
return block.getLocation().add(0.5, 0.5, 0.5);

Binary file not shown.