Refactor sit allowed check, remove ability to disable inverted check.

This commit is contained in:
Shevchik 2013-12-16 21:43:46 +04:00
parent 46fdc23ff5
commit a5086a4af5
3 changed files with 52 additions and 62 deletions

View File

@ -31,7 +31,7 @@ public class Chairs extends JavaPlugin {
public List<ChairBlock> allowedBlocks; public List<ChairBlock> allowedBlocks;
public List<Material> validSigns; public List<Material> validSigns;
public boolean autoRotate, signCheck, notifyplayer; public boolean autoRotate, signCheck, notifyplayer;
public boolean invertedStairCheck, invertedStepCheck, ignoreIfBlockInHand; public boolean ignoreIfBlockInHand;
public boolean sitEffectsEnabled; public boolean sitEffectsEnabled;
public double distance; public double distance;
public HashSet<String> disabledRegions = new HashSet<String>(); public HashSet<String> disabledRegions = new HashSet<String>();
@ -231,8 +231,6 @@ public class Chairs extends JavaPlugin {
distance = config.getDouble("distance"); distance = config.getDouble("distance");
maxChairWidth = config.getInt("max-chair-width"); maxChairWidth = config.getInt("max-chair-width");
notifyplayer = config.getBoolean("notify-player"); notifyplayer = config.getBoolean("notify-player");
invertedStairCheck = config.getBoolean("upside-down-check");
invertedStepCheck = config.getBoolean("upper-step-check");
ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand"); ignoreIfBlockInHand = config.getBoolean("ignore-if-item-in-hand");
disabledRegions = new HashSet<String>(config.getStringList("disabledWGRegions")); disabledRegions = new HashSet<String>(config.getStringList("disabledWGRegions"));

View File

@ -29,16 +29,9 @@ public class TrySitEventListener implements Listener {
@EventHandler @EventHandler
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (isSitting(player)) {
return;
}
if (plugin.ignoreIfBlockInHand && event.getPlayer().getItemInHand().getType() != Material.AIR) {
return;
}
if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
if (sitAllowed(player, block)) if (sitAllowed(player, block)) {
{
event.setCancelled(true); event.setCancelled(true);
Location sitLocation = getSitLocation(block, player.getLocation().getYaw()); Location sitLocation = getSitLocation(block, player.getLocation().getYaw());
plugin.sitPlayer(player, sitLocation); plugin.sitPlayer(player, sitLocation);
@ -48,30 +41,50 @@ public class TrySitEventListener implements Listener {
private boolean sitAllowed(Player player, Block block) private boolean sitAllowed(Player player, Block block)
{ {
// Check for permissions
if (!player.hasPermission("chairs.sit")) {
return false;
}
// Check for already sitting
if (isSitting(player)) {
return false;
}
// Check for item in hand
if (plugin.ignoreIfBlockInHand && player.getItemInHand().getType() != Material.AIR) {
return false;
}
// Check for sneaking
if (player.isSneaking()) {
return false;
}
// Check for /chairs off
if (ignoreList.isIgnored(player.getName())) {
return false;
}
// Sit occupied check
if (plugin.sitblock.containsKey(block)) {
player.sendMessage(plugin.msgOccupied.replace("%PLAYER%", plugin.sitblock.get(block)));
return false;
}
// Region allowance check
if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation())) {
return false;
}
Stairs stairs = null; Stairs stairs = null;
Step step = null; Step step = null;
WoodenStep wStep = null; WoodenStep wStep = null;
boolean blockOkay = false; boolean blockOkay = false;
if (player.isSneaking()) { // Check for block is chair
return false;
}
if (ignoreList.isIgnored(player.getName())) {
return false;
}
// Permissions Check
if (!player.hasPermission("chairs.sit")) {
return false;
}
for (ChairBlock cb : plugin.allowedBlocks) { for (ChairBlock cb : plugin.allowedBlocks) {
if (cb.getMat().toString().contains("STAIRS")) { if (cb.getMat().equals(block.getType())) {
if (cb.getMat().equals(block.getType())) {
blockOkay = true;
continue;
}
} else if (cb.getMat().equals(block.getType())) {
blockOkay = true; blockOkay = true;
continue; continue;
} }
@ -110,24 +123,19 @@ public class TrySitEventListener implements Listener {
return false; return false;
} }
if (stairs != null) { // Check if block is inverted
if (stairs.isInverted() && plugin.invertedStairCheck) { if (stairs != null && stairs.isInverted()) {
return false; return false;
}
} }
if (step != null) { if (step != null && step.isInverted()) {
if (step.isInverted() && plugin.invertedStepCheck) { return false;
return false;
}
} }
if (wStep != null) { if (wStep != null && wStep.isInverted()) {
if (wStep.isInverted() && plugin.invertedStepCheck) { return false;
return false;
}
} }
// Check for signs. // Check for signs (only for stairs)
if (plugin.signCheck == true && stairs != null) { if (plugin.signCheck && stairs != null) {
boolean sign1 = false; boolean sign1 = false;
boolean sign2 = false; boolean sign2 = false;
@ -139,12 +147,12 @@ public class TrySitEventListener implements Listener {
sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player); sign2 = checkSign(block, BlockFace.SOUTH) || checkFrame(block, BlockFace.SOUTH, player);
} }
if (!(sign1 == true && sign2 == true)) { if (!(sign1 && sign2)) {
return false; return false;
} }
} }
// Check for maximal chair width. // Check for maximal chair width (only for stairs)
if (plugin.maxChairWidth > 0 && stairs != null) { if (plugin.maxChairWidth > 0 && stairs != null) {
if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) { if (stairs.getDescendingDirection() == BlockFace.NORTH || stairs.getDescendingDirection() == BlockFace.SOUTH) {
chairwidth += getChairWidth(block, BlockFace.EAST); chairwidth += getChairWidth(block, BlockFace.EAST);
@ -159,20 +167,6 @@ public class TrySitEventListener implements Listener {
} }
} }
//Sit occupied check
if (plugin.sitblock.containsKey(block))
{
if (!plugin.msgOccupied.isEmpty()) {
player.sendMessage(plugin.msgOccupied.replaceAll("%PLAYER%", plugin.sitblock.get(block)));
}
return false;
}
//region allowance check
if (!WGHook.isAllowedInRegion(plugin.disabledRegions, block.getLocation()))
{
return false;
}
return true; return true;
} }

View File

@ -35,8 +35,6 @@ auto-rotate: true
max-chair-width: 3 max-chair-width: 3
sign-check: false sign-check: false
distance: 2 distance: 2
upside-down-check: true
upper-step-check: true
ignore-if-item-in-hand: false ignore-if-item-in-hand: false
disabledWGRegions: disabledWGRegions:
- exampleregionname - exampleregionname