diff --git a/classes/artifacts/Factions_jar/Factions.jar b/classes/artifacts/Factions_jar/Factions.jar index a42c5a92..2fe0a4a2 100644 Binary files a/classes/artifacts/Factions_jar/Factions.jar and b/classes/artifacts/Factions_jar/Factions.jar differ diff --git a/pom.xml b/pom.xml index 321741ed..0a92fbeb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.massivecraft Factions - 1.6.9.5-U0.2.1-RC-1.6-RC + 1.6.9.5-U0.2.1-RC-1.6.1-RC jar SavageFactions diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index eb164320..c44342f2 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -219,7 +219,7 @@ public class Conf { /// This defines a set of materials which should always be allowed to use, regardless of factions permissions. /// Useful for HCF features. /// - public static Set territoryBypassAllProtection = EnumSet.noneOf(Material.class); + public static Set territoryBypasssProtectedMaterials = EnumSet.noneOf(Material.class); // Economy settings public static boolean econEnabled = false; @@ -363,73 +363,29 @@ public class Conf { territoryEnemyDenyCommands.add("tpaccept"); territoryEnemyDenyCommands.add("tpa"); - territoryProtectedMaterials.add(SavageFactions.plugin.WOODEN_DOOR); - 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); + /// TODO: Consider removing this in a future release, as permissions works just fine now territoryProtectedMaterials.add(Material.BEACON); - territoryProtectedMaterials.add(Material.ANVIL); - territoryProtectedMaterials.add(Material.TRAPPED_CHEST); - territoryProtectedMaterials.add(Material.DROPPER); - territoryProtectedMaterials.add(Material.HOPPER); + + // Config is not loading if value is empty ??? + territoryBypasssProtectedMaterials.add(Material.COOKIE); territoryDenyUseageMaterials.add(SavageFactions.plugin.FIREBALL); territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL); territoryDenyUseageMaterials.add(Material.BUCKET); territoryDenyUseageMaterials.add(Material.WATER_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) { 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.ANVIL); - territoryProtectedMaterialsWhenOffline.add(Material.TRAPPED_CHEST); - territoryProtectedMaterialsWhenOffline.add(Material.DROPPER); - territoryProtectedMaterialsWhenOffline.add(Material.HOPPER); territoryDenyUseageMaterialsWhenOffline.add(SavageFactions.plugin.FIREBALL); territoryDenyUseageMaterialsWhenOffline.add(Material.FLINT_AND_STEEL); territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET); territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_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) { territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND); } diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 5e97f012..6467f7dc 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -176,7 +176,7 @@ public interface Faction extends EconomyParticipator { boolean noMonstersInTerritory(); boolean isNormal(); - + boolean isSystemFaction(); @Deprecated boolean isNone(); diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 781a5294..884b3c8e 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -43,6 +43,7 @@ public class FactionsBlockListener implements Listener { return true; FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); + Faction myFaction = me.getFaction(); if (me.isAdminBypassing()) return true; @@ -82,58 +83,19 @@ public class FactionsBlockListener implements Listener { me.msg("You can't " + action + " in a war zone."); 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()) + return true; + // Get faction pain build access relation to me + boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; + return CheckActionState(otherFaction, loc, me, PermissableAction.fromString(action), pain); + } else if (otherFaction.getId().equals(myFaction.getId())) { + boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; + return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain); } - if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) - return true; - - Faction myFaction = me.getFaction(); - Relation rel = myFaction.getRelationTo(otherFaction); - boolean online = otherFaction.hasPlayersOnline(); - boolean pain = !justCheck && rel.confPainBuild(online); - boolean deny = rel.confDenyBuild(online); - - 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("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("You can't " + action + " in the territory of " + otherFaction.getTag(myFaction)); - } - - 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("It is painful to try to " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc)); - } - } - if (Conf.ownedAreaDenyBuild) { - if (!justCheck) { - me.msg("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)); + // Something failed prevent build + return false; } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -520,18 +482,39 @@ public class FactionsBlockListener implements Listener { /// The World location where the action is being executed /// The faction of the player being checked /// The current's faction access permission for the action - private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action) { - if (access == null) access = Access.DENY; // Let's deny by default + /// Determine whether we should hurt the player when access is denied + 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()); - 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 && me.getFactionId().equals(myFaction.getId()))) return true; else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { me.msg("You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + me.msg("It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction)); + } return false; } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway - me.msg(TL.GENERIC_NOPERMISSION, action); + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + me.msg("It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction)); + } + me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); return false; + } else if (access == Access.ALLOW) return true; + me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); + return false; + } + + 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("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; + } } - // 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 CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain); } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index d7293fcc..df6b2f33 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -18,7 +18,7 @@ import com.massivecraft.factions.util.MultiversionMaterials; import com.massivecraft.factions.util.VisualizeUtil; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; -import com.massivecraft.factions.zcore.persist.MemoryFPlayer; +import com.massivecraft.factions.zcore.persist.*; import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TagUtil; import com.massivecraft.factions.zcore.util.TextUtil; @@ -30,6 +30,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.entity.Player; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -147,7 +148,7 @@ public class FactionsPlayerListener implements Listener { } 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") @@ -161,9 +162,6 @@ public class FactionsPlayerListener implements Listener { Material material = block.getType(); - // Check if the material is bypassing protection - if (Conf.territoryBypassAllProtection.contains(material)) return true; - // Dupe fix. FLocation loc = new FLocation(block); Faction otherFaction = Board.getInstance().getFactionAt(loc); @@ -171,148 +169,18 @@ public class FactionsPlayerListener implements Listener { Relation rel = myFaction.getRelationTo(otherFaction); // no door/chest/whatever protection in wilderness, war zones, or safe zones - if (!otherFaction.isNormal()) - return true; + if (otherFaction.isSystemFaction()) return true; + if (myFaction.isWilderness()) { + me.msg(TL.GENERIC_NOPERMISSION, TL.GENERIC_DOTHAT); + return false; + } if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) return true; - if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand().getType() != null) { - - if (player.getItemInHand().getType().toString().toUpperCase().contains("DOOR")) - return false; - } - - PermissableAction action = null; - if (SavageFactions.plugin.mc113) { - switch (block.getType()) { - case LEVER: - action = PermissableAction.LEVER; - break; - - case ACACIA_BUTTON: - case BIRCH_BUTTON: - case DARK_OAK_BUTTON: - case JUNGLE_BUTTON: - case OAK_BUTTON: - case SPRUCE_BUTTON: - case STONE_BUTTON: - action = PermissableAction.BUTTON; - break; - - case ACACIA_DOOR: - case BIRCH_DOOR: - case IRON_DOOR: - case JUNGLE_DOOR: - case OAK_DOOR: - case SPRUCE_DOOR: - case DARK_OAK_DOOR: - - case ACACIA_TRAPDOOR: - case BIRCH_TRAPDOOR: - case DARK_OAK_TRAPDOOR: - case IRON_TRAPDOOR: - case JUNGLE_TRAPDOOR: - case OAK_TRAPDOOR: - case SPRUCE_TRAPDOOR: - - case ACACIA_FENCE_GATE: - case BIRCH_FENCE_GATE: - case DARK_OAK_FENCE_GATE: - case JUNGLE_FENCE_GATE: - case OAK_FENCE_GATE: - case SPRUCE_FENCE_GATE: - action = PermissableAction.DOOR; - break; - - case CHEST: - case TRAPPED_CHEST: - case CHEST_MINECART: - - case SHULKER_BOX: - case BLACK_SHULKER_BOX: - case BLUE_SHULKER_BOX: - case BROWN_SHULKER_BOX: - case CYAN_SHULKER_BOX: - case GRAY_SHULKER_BOX: - case GREEN_SHULKER_BOX: - case LIGHT_BLUE_SHULKER_BOX: - case LIGHT_GRAY_SHULKER_BOX: - case LIME_SHULKER_BOX: - case MAGENTA_SHULKER_BOX: - case ORANGE_SHULKER_BOX: - case PINK_SHULKER_BOX: - case PURPLE_SHULKER_BOX: - case RED_SHULKER_BOX: - case WHITE_SHULKER_BOX: - case YELLOW_SHULKER_BOX: - - case FURNACE: - case DROPPER: - case DISPENSER: - case ENCHANTING_TABLE: - case BREWING_STAND: - case CAULDRON: - case HOPPER: - case BEACON: - case JUKEBOX: - - case ANVIL: - case CHIPPED_ANVIL: - case DAMAGED_ANVIL: - action = PermissableAction.CONTAINER; - break; - default: - // Check for doors that might have diff material name in old version. - if (block.getType().name().contains("DOOR")) { - action = PermissableAction.DOOR; - } - break; - } - } else { - if (block.getType().toString().toUpperCase().contains("BUTTON")) { - action = PermissableAction.BUTTON; - } - - switch (block.getType()) { - case LEVER: - action = PermissableAction.LEVER; - break; - case DARK_OAK_DOOR: - case ACACIA_DOOR: - case BIRCH_DOOR: - case IRON_DOOR: - case JUNGLE_DOOR: - case SPRUCE_DOOR: - case ACACIA_FENCE_GATE: - case BIRCH_FENCE_GATE: - case DARK_OAK_FENCE_GATE: - case JUNGLE_FENCE_GATE: - case SPRUCE_FENCE_GATE: - action = PermissableAction.DOOR; - break; - case CHEST: - case ENDER_CHEST: - case TRAPPED_CHEST: - case DISPENSER: - case ENCHANTING_TABLE: - case DROPPER: - case FURNACE: - case HOPPER: - case ANVIL: - case CHIPPED_ANVIL: - case DAMAGED_ANVIL: - case BREWING_STAND: - action = PermissableAction.CONTAINER; - break; - default: - // Check for doors that might have diff material name in old version. - if (block.getType().name().contains("DOOR")) - action = PermissableAction.DOOR; - break; - } - } - + if (otherFaction.getId().equals(myFaction.getId()) && me.getRole() == Role.LEADER) return true; + PermissableAction action = GetPermissionFromUsableBlock(block); + if (action == null) return false; // We only care about some material types. /// Who was the idiot? if (otherFaction.hasPlayersOnline()) { @@ -326,29 +194,14 @@ public class FactionsPlayerListener implements Listener { } // Move up access check to check for exceptions - Access access = otherFaction.getAccess(me, action); - boolean doTerritoryEnemyProtectedCheck = true; - - if (action != null && (action.equals(PermissableAction.CONTAINER) || - action.equals(PermissableAction.DOOR))) { - if (access == Access.ALLOW) { - doTerritoryEnemyProtectedCheck = false; - } + if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own + // Get faction pain build access relation to me + boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; + return CheckPlayerAccess(player, me, loc, otherFaction, otherFaction.getAccess(me, action), action, pain); + } else if (otherFaction.getId().equals(myFaction.getId())) { + return CheckPlayerAccess(player, me, loc, myFaction, myFaction.getAccess(me, action), action, (!justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW)); } - - // 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); + return CheckPlayerAccess(player, me, loc, myFaction, otherFaction.getAccess(me, action), action, Conf.territoryPainBuild); } @@ -878,60 +731,34 @@ public class FactionsPlayerListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) 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("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 - if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) - return; - + if (event.getAction().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) return; Block block = event.getClickedBlock(); Player player = event.getPlayer(); - - if (block == null) - return; // clicked in air, apparently - - if (!canPlayerUseBlock(player, block, false)) { - 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)); - } + // Check if the material is bypassing protection + if (Conf.territoryBypasssProtectedMaterials.contains(block.getType())) return; + if (block == null) return; // clicked in air, apparently + if (GetPermissionFromUsableBlock(event.getClickedBlock().getType()) != null) { + if (!canPlayerUseBlock(player, block, false)) { + event.setCancelled(true); + event.setUseInteractedBlock(Event.Result.DENY); + return; } - return; } - - if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { - return; // only interested on right-clicks for below + 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; + } } - + if (event.getMaterial().isSolid()) return; if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) { event.setCancelled(true); + event.setUseInteractedBlock(Event.Result.DENY); + return; } } @@ -1064,20 +891,146 @@ public class FactionsPlayerListener implements Listener { /// The World location where the action is being executed /// The faction of the player being checked /// The current's faction access permission for the action - 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) { // TODO: Update this once new access values are added other than just allow / deny. 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 && me.getFactionId().equals(myFaction.getId()))) return true; else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { me.msg("You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + if (doPain) { + player.damage(Conf.actionDeniedPainAmount); + } return false; - } else if (!landOwned && access != Access.DENY) return true; + } else if (!landOwned && access == Access.ALLOW) return true; else { - me.msg(TL.GENERIC_NOPERMISSION, action); + me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); return false; } } - return true; + me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction())); + return false; + } + /// + /// This will try to resolve a permission action based on the item material, if it's not usable, will return null + /// + private static PermissableAction GetPermissionFromUsableBlock(Block block) { + return GetPermissionFromUsableBlock(block.getType()); + } + private static PermissableAction GetPermissionFromUsableBlock(Material material) { + // Check for doors that might have diff material name in old version. + if (material.name().contains("DOOR")) + return PermissableAction.DOOR; + if (material.name().toUpperCase().contains("BUTTON") || material.name().toUpperCase().contains("PRESSURE")) return PermissableAction.BUTTON; + if (SavageFactions.plugin.mc113) { + switch (material) { + case LEVER: + return PermissableAction.LEVER; + + case ACACIA_BUTTON: + case BIRCH_BUTTON: + case DARK_OAK_BUTTON: + case JUNGLE_BUTTON: + case OAK_BUTTON: + case SPRUCE_BUTTON: + case STONE_BUTTON: + return PermissableAction.BUTTON; + + case ACACIA_DOOR: + case BIRCH_DOOR: + case IRON_DOOR: + case JUNGLE_DOOR: + case OAK_DOOR: + case SPRUCE_DOOR: + case DARK_OAK_DOOR: + + case ACACIA_TRAPDOOR: + case BIRCH_TRAPDOOR: + case DARK_OAK_TRAPDOOR: + case IRON_TRAPDOOR: + case JUNGLE_TRAPDOOR: + case OAK_TRAPDOOR: + case SPRUCE_TRAPDOOR: + + case ACACIA_FENCE_GATE: + case BIRCH_FENCE_GATE: + case DARK_OAK_FENCE_GATE: + case JUNGLE_FENCE_GATE: + case OAK_FENCE_GATE: + case SPRUCE_FENCE_GATE: + return PermissableAction.DOOR; + + case CHEST: + case TRAPPED_CHEST: + case CHEST_MINECART: + + case SHULKER_BOX: + case BLACK_SHULKER_BOX: + case BLUE_SHULKER_BOX: + case BROWN_SHULKER_BOX: + case CYAN_SHULKER_BOX: + case GRAY_SHULKER_BOX: + case GREEN_SHULKER_BOX: + case LIGHT_BLUE_SHULKER_BOX: + case LIGHT_GRAY_SHULKER_BOX: + case LIME_SHULKER_BOX: + case MAGENTA_SHULKER_BOX: + case ORANGE_SHULKER_BOX: + case PINK_SHULKER_BOX: + case PURPLE_SHULKER_BOX: + case RED_SHULKER_BOX: + case WHITE_SHULKER_BOX: + case YELLOW_SHULKER_BOX: + + case FURNACE: + case DROPPER: + case DISPENSER: + case ENCHANTING_TABLE: + case BREWING_STAND: + case CAULDRON: + case HOPPER: + case BEACON: + case JUKEBOX: + case ANVIL: + case CHIPPED_ANVIL: + case DAMAGED_ANVIL: + return PermissableAction.CONTAINER; + default: + return null; + } + } else { + switch (material) { + case LEVER: + return PermissableAction.LEVER; + case DARK_OAK_DOOR: + case ACACIA_DOOR: + case BIRCH_DOOR: + case IRON_DOOR: + case JUNGLE_DOOR: + case SPRUCE_DOOR: + case ACACIA_FENCE_GATE: + case BIRCH_FENCE_GATE: + case DARK_OAK_FENCE_GATE: + case JUNGLE_FENCE_GATE: + case SPRUCE_FENCE_GATE: + return PermissableAction.DOOR; + case CHEST: + case ENDER_CHEST: + case TRAPPED_CHEST: + case DISPENSER: + case ENCHANTING_TABLE: + case DROPPER: + case FURNACE: + case HOPPER: + case ANVIL: + case CHIPPED_ANVIL: + case DAMAGED_ANVIL: + case BREWING_STAND: + return PermissableAction.CONTAINER; + default: + return null; + } + } } } diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index b6ea8227..4b325e5c 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -754,6 +754,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { public boolean isWarZone() { return this.getId().equals("-2"); } + public boolean isSystemFaction() { return this.isSafeZone() || this.isWarZone() || this.isWilderness(); } public boolean isPlayerFreeType() { return this.isSafeZone() || this.isWarZone();