Attempts to fix permissions

This commit is contained in:
SvenjaReißaus 2019-03-18 19:05:30 -05:00
parent 3c10b8276c
commit a7b824e964
No known key found for this signature in database
GPG Key ID: E5494A03FA36D54B
4 changed files with 80 additions and 185 deletions

@ -219,7 +219,7 @@ public class Conf {
/// This defines a set of materials which should always be allowed to use, regardless of factions permissions. /// This defines a set of materials which should always be allowed to use, regardless of factions permissions.
/// Useful for HCF features. /// Useful for HCF features.
/// </summary> /// </summary>
public static Set<Material> territoryBypassAllProtection = EnumSet.noneOf(Material.class); public static Set<Material> territoryBypasssProtectedMaterials = EnumSet.noneOf(Material.class);
// Economy settings // Economy settings
public static boolean econEnabled = false; public static boolean econEnabled = false;
@ -363,73 +363,29 @@ public class Conf {
territoryEnemyDenyCommands.add("tpaccept"); territoryEnemyDenyCommands.add("tpaccept");
territoryEnemyDenyCommands.add("tpa"); territoryEnemyDenyCommands.add("tpa");
territoryProtectedMaterials.add(SavageFactions.plugin.WOODEN_DOOR); /// TODO: Consider removing this in a future release, as permissions works just fine now
territoryProtectedMaterials.add(SavageFactions.plugin.TRAP_DOOR);
territoryProtectedMaterials.add(SavageFactions.plugin.FENCE_GATE);
territoryProtectedMaterials.add(Material.DISPENSER);
territoryProtectedMaterials.add(Material.CHEST);
territoryProtectedMaterials.add(Material.FURNACE);
territoryProtectedMaterials.add(SavageFactions.plugin.BURNING_FURNACE);
territoryProtectedMaterials.add(SavageFactions.plugin.DIODE_BLOCK_OFF);
territoryProtectedMaterials.add(SavageFactions.plugin.DIODE_BLOCK_ON);
territoryProtectedMaterials.add(Material.JUKEBOX);
territoryProtectedMaterials.add(Material.BREWING_STAND);
territoryProtectedMaterials.add(SavageFactions.plugin.ENCHANTMENT_TABLE);
territoryProtectedMaterials.add(Material.CAULDRON);
territoryProtectedMaterials.add(SavageFactions.plugin.ENCHANTMENT_TABLE);
territoryProtectedMaterials.add(Material.BEACON); territoryProtectedMaterials.add(Material.BEACON);
territoryProtectedMaterials.add(Material.ANVIL);
territoryProtectedMaterials.add(Material.TRAPPED_CHEST); // Config is not loading if value is empty ???
territoryProtectedMaterials.add(Material.DROPPER); territoryBypasssProtectedMaterials.add(Material.COOKIE);
territoryProtectedMaterials.add(Material.HOPPER);
territoryDenyUseageMaterials.add(SavageFactions.plugin.FIREBALL); territoryDenyUseageMaterials.add(SavageFactions.plugin.FIREBALL);
territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL); territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL);
territoryDenyUseageMaterials.add(Material.BUCKET); territoryDenyUseageMaterials.add(Material.BUCKET);
territoryDenyUseageMaterials.add(Material.WATER_BUCKET); territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET); territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
territoryDenyUseageMaterials.add(MultiversionMaterials.ACACIA_BUTTON.parseMaterial());
territoryDenyUseageMaterials.add(MultiversionMaterials.BIRCH_BUTTON.parseMaterial());
territoryDenyUseageMaterials.add(MultiversionMaterials.DARK_OAK_BUTTON.parseMaterial());
territoryDenyUseageMaterials.add(MultiversionMaterials.JUNGLE_BUTTON.parseMaterial());
territoryDenyUseageMaterials.add(MultiversionMaterials.OAK_BUTTON.parseMaterial());
territoryDenyUseageMaterials.add(MultiversionMaterials.STONE_BUTTON.parseMaterial());
if (!SavageFactions.plugin.mc17) { if (!SavageFactions.plugin.mc17) {
territoryDenyUseageMaterials.add(Material.ARMOR_STAND); territoryDenyUseageMaterials.add(Material.ARMOR_STAND);
} }
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.WOODEN_DOOR);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.TRAP_DOOR);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.FENCE_GATE);
territoryProtectedMaterialsWhenOffline.add(Material.DISPENSER);
territoryProtectedMaterialsWhenOffline.add(Material.CHEST);
territoryProtectedMaterialsWhenOffline.add(Material.FURNACE);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.BURNING_FURNACE);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.DIODE_BLOCK_OFF);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.DIODE_BLOCK_OFF);
territoryProtectedMaterialsWhenOffline.add(Material.JUKEBOX);
territoryProtectedMaterialsWhenOffline.add(Material.BREWING_STAND);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.ENCHANTMENT_TABLE);
territoryProtectedMaterialsWhenOffline.add(Material.CAULDRON);
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.SOIL);
territoryProtectedMaterialsWhenOffline.add(Material.BEACON); territoryProtectedMaterialsWhenOffline.add(Material.BEACON);
territoryProtectedMaterialsWhenOffline.add(Material.ANVIL);
territoryProtectedMaterialsWhenOffline.add(Material.TRAPPED_CHEST);
territoryProtectedMaterialsWhenOffline.add(Material.DROPPER);
territoryProtectedMaterialsWhenOffline.add(Material.HOPPER);
territoryDenyUseageMaterialsWhenOffline.add(SavageFactions.plugin.FIREBALL); territoryDenyUseageMaterialsWhenOffline.add(SavageFactions.plugin.FIREBALL);
territoryDenyUseageMaterialsWhenOffline.add(Material.FLINT_AND_STEEL); territoryDenyUseageMaterialsWhenOffline.add(Material.FLINT_AND_STEEL);
territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET);
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.ACACIA_BUTTON.parseMaterial());
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.BIRCH_BUTTON.parseMaterial());
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.DARK_OAK_BUTTON.parseMaterial());
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.JUNGLE_BUTTON.parseMaterial());
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.OAK_BUTTON.parseMaterial());
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.STONE_BUTTON.parseMaterial());
if (!SavageFactions.plugin.mc17) { if (!SavageFactions.plugin.mc17) {
territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND); territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND);
} }

@ -43,6 +43,7 @@ public class FactionsBlockListener implements Listener {
return true; return true;
FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString());
Faction myFaction = me.getFaction();
if (me.isAdminBypassing()) if (me.isAdminBypassing())
return true; return true;
@ -82,60 +83,22 @@ public class FactionsBlockListener implements Listener {
me.msg("<b>You can't " + action + " in a war zone."); me.msg("<b>You can't " + action + " in a war zone.");
return false; return false;
} } else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own
if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
return true; return true;
// Get faction pain build access relation to me
Faction myFaction = me.getFaction(); boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
Relation rel = myFaction.getRelationTo(otherFaction); return CheckActionState(otherFaction, loc, me, PermissableAction.fromString(action), pain);
boolean online = otherFaction.hasPlayersOnline(); } else if (otherFaction.getId().equals(myFaction.getId())) {
boolean pain = !justCheck && rel.confPainBuild(online); boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
boolean deny = rel.confDenyBuild(online); return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain);
Access access = otherFaction.getAccess(me, PermissableAction.fromString(action));
if (access == Access.ALLOW && ((rel == Relation.ALLY) || (rel == Relation.ENEMY) || (rel == Relation.NEUTRAL) || (rel == Relation.TRUCE)))
deny = false;
// hurt the player for building/destroying in other territory?
if (pain) {
player.damage(Conf.actionDeniedPainAmount);
if (!deny) {
me.msg("<b>It is painful to try to " + action + " in the territory of " + otherFaction.getTag(myFaction));
}
}
// cancel building/destroying in other territory?
if (deny) {
if (!justCheck) {
me.msg("<b>You can't " + action + " in the territory of " + otherFaction.getTag(myFaction));
} }
// Something failed prevent build
SavageFactions.plugin.getLogger().info("Unable to determine fallback action for build permissions, defaulting to false");
return false; return false;
} }
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim
if (Conf.ownedAreasEnabled && (Conf.ownedAreaDenyBuild || Conf.ownedAreaPainBuild) && !otherFaction.playerHasOwnershipRights(me, loc)) {
if (!pain && Conf.ownedAreaPainBuild && !justCheck) {
player.damage(Conf.actionDeniedPainAmount);
if (!Conf.ownedAreaDenyBuild) {
me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
}
}
if (Conf.ownedAreaDenyBuild) {
if (!justCheck) {
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
return false;
}
}
}
// Check the permission just after making sure the land isn't owned by someone else to avoid bypass.
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.fromString(action));
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (!event.canBuild()) { if (!event.canBuild()) {
@ -520,18 +483,39 @@ public class FactionsBlockListener implements Listener {
/// <param name="loc">The World location where the action is being executed</param> /// <param name="loc">The World location where the action is being executed</param>
/// <param name="myFaction">The faction of the player being checked</param> /// <param name="myFaction">The faction of the player being checked</param>
/// <param name="access">The current's faction access permission for the action</param> /// <param name="access">The current's faction access permission for the action</param>
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action) { /// <param name="shouldHurt">Determine whether we should hurt the player when access is denied</param>
if (access == null) access = Access.DENY; // Let's deny by default private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean shouldHurt) {
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true; if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true;
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); me.msg("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
if (shouldHurt) {
player.damage(Conf.actionDeniedPainAmount);
me.msg("<b>It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction));
}
return false; return false;
} else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway
if (shouldHurt) {
player.damage(Conf.actionDeniedPainAmount);
me.msg("<b>It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction));
}
me.msg(TL.GENERIC_NOPERMISSION, action); me.msg(TL.GENERIC_NOPERMISSION, action);
return false; return false;
} }
// We assume faction land is not owned, and the access is not set to DENY, so we allow to execute the action // We assume faction land is not owned, and the access is not set to DENY, so we allow to execute the action
return true; return true;
} }
private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain) {
if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) {
// If pain should be applied
if (pain && Conf.ownedAreaPainBuild) me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + target.getOwnerListString(location));
if (Conf.ownedAreaDenyBuild && pain) return false;
else if (Conf.ownedAreaDenyBuild) {
me.msg("You cannot " + action + " in the territory of" + target.getTag(me.getFaction()));
return false;
}
}
return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain);
}
} }

@ -147,7 +147,7 @@ public class FactionsPlayerListener implements Listener {
} }
Access access = otherFaction.getAccess(me, PermissableAction.ITEM); Access access = otherFaction.getAccess(me, PermissableAction.ITEM);
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.ITEM); return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.ITEM, false);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -161,9 +161,6 @@ public class FactionsPlayerListener implements Listener {
Material material = block.getType(); Material material = block.getType();
// Check if the material is bypassing protection
if (Conf.territoryBypassAllProtection.contains(material)) return true;
// Dupe fix. // Dupe fix.
FLocation loc = new FLocation(block); FLocation loc = new FLocation(block);
Faction otherFaction = Board.getInstance().getFactionAt(loc); Faction otherFaction = Board.getInstance().getFactionAt(loc);
@ -171,14 +168,12 @@ public class FactionsPlayerListener implements Listener {
Relation rel = myFaction.getRelationTo(otherFaction); Relation rel = myFaction.getRelationTo(otherFaction);
// no door/chest/whatever protection in wilderness, war zones, or safe zones // no door/chest/whatever protection in wilderness, war zones, or safe zones
if (!otherFaction.isNormal()) if (!otherFaction.isNormal()) return true;
return true;
if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
return true; return true;
if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand().getType() != null) { if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand().getType() != null) {
if (player.getItemInHand().getType().toString().toUpperCase().contains("DOOR")) if (player.getItemInHand().getType().toString().toUpperCase().contains("DOOR"))
return false; return false;
} }
@ -264,16 +259,11 @@ public class FactionsPlayerListener implements Listener {
break; break;
default: default:
// Check for doors that might have diff material name in old version. // Check for doors that might have diff material name in old version.
if (block.getType().name().contains("DOOR")) { if (block.getType().name().contains("DOOR"))
action = PermissableAction.DOOR; action = PermissableAction.DOOR;
}
break; break;
} }
} else { } else {
if (block.getType().toString().toUpperCase().contains("BUTTON")) {
action = PermissableAction.BUTTON;
}
switch (block.getType()) { switch (block.getType()) {
case LEVER: case LEVER:
action = PermissableAction.LEVER; action = PermissableAction.LEVER;
@ -309,10 +299,11 @@ public class FactionsPlayerListener implements Listener {
// Check for doors that might have diff material name in old version. // Check for doors that might have diff material name in old version.
if (block.getType().name().contains("DOOR")) if (block.getType().name().contains("DOOR"))
action = PermissableAction.DOOR; action = PermissableAction.DOOR;
if (block.getType().toString().toUpperCase().contains("BUTTON"))
action = PermissableAction.BUTTON;
break; break;
} }
} }
// We only care about some material types. // We only care about some material types.
/// Who was the idiot? /// Who was the idiot?
if (otherFaction.hasPlayersOnline()) { if (otherFaction.hasPlayersOnline()) {
@ -327,28 +318,17 @@ public class FactionsPlayerListener implements Listener {
// Move up access check to check for exceptions // Move up access check to check for exceptions
Access access = otherFaction.getAccess(me, action); Access access = otherFaction.getAccess(me, action);
boolean doTerritoryEnemyProtectedCheck = true; if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own
if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
if (action != null && (action.equals(PermissableAction.CONTAINER) || return true;
action.equals(PermissableAction.DOOR))) { // Get faction pain build access relation to me
if (access == Access.ALLOW) { boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
doTerritoryEnemyProtectedCheck = false; return CheckPlayerAccess(player, me, loc, otherFaction, access, action, pain);
} else if (otherFaction.getId().equals(myFaction.getId())) {
boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
return CheckPlayerAccess(player, me, loc, myFaction, access, action, pain);
} }
} return CheckPlayerAccess(player, me, loc, myFaction, access, action, Conf.territoryPainBuild);
// Did not nest the boolean so that it stands out when Im looking
// through the code later.
if (doTerritoryEnemyProtectedCheck) {
// You may use any block unless it is another faction's territory...
if (rel.isNeutral() || (rel.isEnemy() && Conf.territoryEnemyProtectMaterials) || (rel.isAlly() && Conf.territoryAllyProtectMaterials) || (rel.isTruce() && Conf.territoryTruceProtectMaterials)) {
if (!justCheck) {
me.msg(TL.PLAYER_USE_TERRITORY, (material == SavageFactions.plugin.SOIL ? "trample " : "use ") + TextUtil.getMaterialName(material), otherFaction.getTag(myFaction));
}
return false;
}
}
return CheckPlayerAccess(player, me, loc, myFaction, access, action);
} }
@ -878,61 +858,32 @@ public class FactionsPlayerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
/// Prevents the use of montster eggs in oned land.
/*if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (event.hasItem() || event.hasBlock()) {
ItemStack itemStack = event.getItem();
if (itemStack.getType() == Material.MONSTER_EGG) {
FLocation loc = new FLocation(event.getClickedBlock().getLocation());
Faction faction = Board.getInstance().getFactionAt(loc);
FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (Conf.ownedAreasEnabled && !faction.playerHasOwnershipRights(me, loc)) {
if (Conf.ownedAreaDenyBuild) {
me.msg("<b>You can't use spawn eggs in this territory, it is owned by: " + faction.getOwnerListString(loc));
event.setCancelled(true);
return;
}
}
}
}
}*/
// only need to check right-clicks and physical as of MC 1.4+; good performance boost // only need to check right-clicks and physical as of MC 1.4+; good performance boost
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) if ((event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) || event.getAction() != Action.PHYSICAL) return;
if (event.getPlayer().getItemInHand() != null) {
Material handItem = event.getPlayer().getItemInHand().getType();
if (handItem.isEdible()
|| handItem.equals(Material.POTION)
|| handItem.equals(Material.LINGERING_POTION)
|| handItem.equals(Material.SPLASH_POTION)) {
return; return;
}
}
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
if (block == null) // Check if the material is bypassing protection
return; // clicked in air, apparently if (Conf.territoryBypasssProtectedMaterials.contains(block.getType())) return;
if (!canPlayerUseBlock(player, block, false)) { if (block == null) return; // clicked in air, apparently
if (canPlayerUseBlock(player, block, false)) return;
if (playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) return;
SavageFactions.plugin.log("Something has failed, canceling the event");
event.setCancelled(true); event.setCancelled(true);
if (Conf.handleExploitInteractionSpam) {
String name = player.getName();
InteractAttemptSpam attempt = interactSpammers.get(name);
if (attempt == null) {
attempt = new InteractAttemptSpam();
interactSpammers.put(name, attempt);
}
int count = attempt.increment();
if (count >= 10) {
FPlayer me = FPlayers.getInstance().getByPlayer(player);
me.msg(TL.PLAYER_OUCH);
player.damage(NumberConversions.floor((double) count / 10));
}
}
return;
}
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
return; // only interested on right-clicks for below
}
if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
event.setCancelled(true);
}
} }
@EventHandler @EventHandler
@ -1064,20 +1015,24 @@ public class FactionsPlayerListener implements Listener {
/// <param name="loc">The World location where the action is being executed</param> /// <param name="loc">The World location where the action is being executed</param>
/// <param name="myFaction">The faction of the player being checked</param> /// <param name="myFaction">The faction of the player being checked</param>
/// <param name="access">The current's faction access permission for the action</param> /// <param name="access">The current's faction access permission for the action</param>
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action) { private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean pain) {
boolean doPain = pain && Conf.handleExploitInteractionSpam;
if (access != null && access != Access.UNDEFINED) { if (access != null && access != Access.UNDEFINED) {
// TODO: Update this once new access values are added other than just allow / deny. // TODO: Update this once new access values are added other than just allow / deny.
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true; if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true;
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
me.msg("<b>You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); me.msg("<b>You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
if (doPain) {
player.damage(Conf.actionDeniedPainAmount);
}
return false; return false;
} else if (!landOwned && access != Access.DENY) return true; } else if (!landOwned && access == Access.ALLOW) return true;
else { else {
me.msg(TL.GENERIC_NOPERMISSION, action); me.msg(TL.GENERIC_NOPERMISSION, action);
return false; return false;
} }
} }
return true; return false;
} }
} }