From 2320fe2586e156df3c1de7c37d015208d1554042 Mon Sep 17 00:00:00 2001 From: ProSavage Date: Wed, 18 Jul 2018 09:48:25 -0500 Subject: [PATCH] If player is owner of a claim, all permissions are bypassed The order is OP -> Ownership -> Permission --- .../java/com/massivecraft/factions/P.java | 7 +- .../factions/cmd/CmdSetDefaultRole.java | 1 + .../listeners/FactionsBlockListener.java | 236 +++++++++--------- .../listeners/FactionsPlayerListener.java | 103 ++++---- 4 files changed, 186 insertions(+), 161 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/P.java b/src/main/java/com/massivecraft/factions/P.java index a3187935..a5020e92 100644 --- a/src/main/java/com/massivecraft/factions/P.java +++ b/src/main/java/com/massivecraft/factions/P.java @@ -236,7 +236,11 @@ public class P extends MPlugin { Type accessTypeAdatper = new TypeToken>>() { }.getType(); - return new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().enableComplexMapKeySerialization().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE).registerTypeAdapter(accessTypeAdatper, new PermissionsMapTypeAdapter()).registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()).registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()).registerTypeAdapterFactory(EnumTypeAdapter.ENUM_FACTORY); + return new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().enableComplexMapKeySerialization().excludeFieldsWithModifiers(Modifier.TRANSIENT, Modifier.VOLATILE) + .registerTypeAdapter(accessTypeAdatper, new PermissionsMapTypeAdapter()) + .registerTypeAdapter(LazyLocation.class, new MyLocationTypeAdapter()) + .registerTypeAdapter(mapFLocToStringSetType, new MapFLocToStringSetTypeAdapter()) + .registerTypeAdapterFactory(EnumTypeAdapter.ENUM_FACTORY); } @Override @@ -245,6 +249,7 @@ public class P extends MPlugin { if (this.loadSuccessful) { Conf.save(); } + if (AutoLeaveTask != null) { this.getServer().getScheduler().cancelTask(AutoLeaveTask); AutoLeaveTask = null; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java index 1a4ae4ac..df878ce9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java @@ -35,6 +35,7 @@ public class CmdSetDefaultRole extends FCommand { return; } + myFaction.setDefaultRole(target); msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename); } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 88a641e3..fa0709e4 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -4,6 +4,7 @@ import com.massivecraft.factions.*; import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Relation; +import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.zcore.fperms.Access; import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.util.TL; @@ -26,124 +27,6 @@ public class FactionsBlockListener implements Listener { this.p = p; } - public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) { - String name = player.getName(); - if (Conf.playersWhoBypassAllProtection.contains(name)) { - return true; - } - - FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); - if (me.isAdminBypassing()) { - return true; - } - - FLocation loc = new FLocation(location); - Faction otherFaction = Board.getInstance().getFactionAt(loc); - - if (otherFaction.isWilderness()) { - if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { - return true; - } - - if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) { - return true; // This is not faction territory. Use whatever you like here. - } - - if (!justCheck) { - me.msg("You can't " + action + " in the wilderness."); - } - - return false; - } else if (otherFaction.isSafeZone()) { - if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { - return true; - } - - if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) { - return true; - } - - if (!justCheck) { - me.msg("You can't " + action + " in a safe zone."); - } - - return false; - } else if (otherFaction.isWarZone()) { - if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { - return true; - } - - if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) { - return true; - } - - if (!justCheck) { - me.msg("You can't " + action + " in a war zone."); - } - - return false; - } - if (P.p.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); - - // 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)); - } - } - - Access access = otherFaction.getAccess(me, PermissableAction.fromString(action)); - if (access != null && access != Access.UNDEFINED) { - // TODO: Update this once new access values are added other than just allow / deny. - if (access == Access.DENY) { - me.msg(TL.GENERIC_NOPERMISSION, action); - return false; - } else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) return false; - else - // the perm is true, so it can build - return true; // has to be allow - } - - // 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; - } - } - - return true; - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockPlace(BlockPlaceEvent event) { if (!event.canBuild()) { @@ -307,4 +190,121 @@ public class FactionsBlockListener implements Listener { return !rel.confDenyBuild(otherFaction.hasPlayersOnline()); } + + public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) { + String name = player.getName(); + if (Conf.playersWhoBypassAllProtection.contains(name)) { + return true; + } + + FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); + if (me.isAdminBypassing()) { + return true; + } + + FLocation loc = new FLocation(location); + Faction otherFaction = Board.getInstance().getFactionAt(loc); + + if (otherFaction.isWilderness()) { + if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { + return true; + } + + if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) { + return true; // This is not faction territory. Use whatever you like here. + } + + if (!justCheck) { + me.msg("You can't " + action + " in the wilderness."); + } + + return false; + } else if (otherFaction.isSafeZone()) { + if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { + return true; + } + + if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) { + return true; + } + + if (!justCheck) { + me.msg("You can't " + action + " in a safe zone."); + } + + return false; + } else if (otherFaction.isWarZone()) { + if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) { + return true; + } + + if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) { + return true; + } + + if (!justCheck) { + me.msg("You can't " + action + " in a war zone."); + } + + return false; + } + if (P.p.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); + + // 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. + Access access = otherFaction.getAccess(me, PermissableAction.fromString(action)); + if (access != Access.ALLOW && me.getRole() != Role.ADMIN) { + // TODO: Update this once new access values are added other than just allow / deny. + if (access == Access.DENY) { + me.msg(TL.GENERIC_NOPERMISSION, action); + return false; + } else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) { + me.msg("You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + return false; + } + } + return true; + } } diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index f5fe5cec..37e36d86 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -80,6 +80,7 @@ public class FactionsPlayerListener implements Listener { return true; } + FPlayer me = FPlayers.getInstance().getByPlayer(player); if (me.isAdminBypassing()) { return true; @@ -87,7 +88,16 @@ public class FactionsPlayerListener implements Listener { FLocation loc = new FLocation(location); Faction otherFaction = Board.getInstance().getFactionAt(loc); + Faction myFaction = me.getFaction(); + Relation rel = myFaction.getRelationTo(otherFaction); + // Also cancel if player doesn't have ownership rights for this claim + if (Conf.ownedAreasEnabled && myFaction == otherFaction && !myFaction.playerHasOwnershipRights(me, loc)) { + if (!justCheck) { + me.msg("You can't use that in this territory, it is owned by: " + otherFaction.getOwnerListString(loc)); + } + return false; + } if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() >= otherFaction.getPowerRounded()) { return true; } @@ -134,10 +144,6 @@ public class FactionsPlayerListener implements Listener { return false; } - Faction myFaction = me.getFaction(); - Relation rel = myFaction.getRelationTo(otherFaction); - - // Cancel if we are not in our own territory if (rel.confDenyUseage()) { if (!justCheck) { @@ -146,19 +152,19 @@ public class FactionsPlayerListener implements Listener { return false; } + Access access = otherFaction.getAccess(me, PermissableAction.ITEM); if (access != null && access != Access.UNDEFINED) { // TODO: Update this once new access values are added other than just allow / deny. - return access == Access.ALLOW; - } - - // Also cancel if player doesn't have ownership rights for this claim - if (Conf.ownedAreasEnabled && Conf.ownedAreaDenyUseage && !otherFaction.playerHasOwnershipRights(me, loc)) { - if (!justCheck) { - me.msg(TL.PLAYER_USE_OWNED, TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); + if ((myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && myFaction.getOwnerListString(loc).contains(player.getName()))) { + return true; + } else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) { + me.msg("You can't use items in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + return false; + } else if (access == Access.DENY) { + me.msg(TL.GENERIC_NOPERMISSION, PermissableAction.ITEM); + return false; } - - return false; } return true; @@ -175,8 +181,12 @@ public class FactionsPlayerListener implements Listener { } Material material = block.getType(); + // Dupe fix. FLocation loc = new FLocation(block); Faction otherFaction = Board.getInstance().getFactionAt(loc); + Faction myFaction = me.getFaction(); + Relation rel = myFaction.getRelationTo(otherFaction); + // no door/chest/whatever protection in wilderness, war zones, or safe zones if (!otherFaction.isNormal()) { @@ -187,10 +197,7 @@ public class FactionsPlayerListener implements Listener { return true; } - // Dupe fix. - Faction myFaction = me.getFaction(); - Relation rel = myFaction.getRelationTo(otherFaction); - if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand() != null) { + if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand().getType() != null) { switch (player.getItemInHand().getType()) { case CHEST: case SIGN_POST: @@ -223,6 +230,12 @@ public class FactionsPlayerListener implements Listener { case TRAP_DOOR: case WOOD_DOOR: case WOODEN_DOOR: + case FENCE_GATE: + 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: @@ -237,16 +250,6 @@ public class FactionsPlayerListener implements Listener { } break; } - - // F PERM check runs through before other checks. - Access access = otherFaction.getAccess(me, action); - if (action == PermissableAction.CONTAINER && (access == Access.UNDEFINED || access == Access.ALLOW) && me.getFaction() == otherFaction) { - return true; - } else if (access == null || access == Access.DENY) { - me.msg(TL.GENERIC_NOPERMISSION, action); - return false; - } - // We only care about some material types. if (otherFaction.hasPlayersOnline()) { if (!Conf.territoryProtectedMaterials.contains(material)) { @@ -263,19 +266,22 @@ public class FactionsPlayerListener implements Listener { if (!justCheck) { me.msg(TL.PLAYER_USE_TERRITORY, (material == Material.SOIL ? "trample " : "use ") + TextUtil.getMaterialName(material), otherFaction.getTag(myFaction)); } - return false; } - // Also cancel if player doesn't have ownership rights for this claim - if (Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc)) { - if (!justCheck) { - me.msg(TL.PLAYER_USE_OWNED, TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); + Access access = otherFaction.getAccess(me, action); + if (access != Access.ALLOW && me.getRole() != Role.ADMIN) { + // TODO: Update this once new access values are added other than just allow / deny. + if ((myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && myFaction.getOwnerListString(loc).contains(player.getName()))) { + return true; + } else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) { + me.msg("You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc)); + return false; + } else if (access == Access.DENY) { + me.msg(TL.GENERIC_NOPERMISSION, action); + return false; } - - return false; } - return true; } @@ -443,9 +449,7 @@ public class FactionsPlayerListener implements Listener { Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() { @Override public void run() { - if (fallMap.containsKey(me.getPlayer())) { - fallMap.remove(me.getPlayer()); - } + fallMap.remove(me.getPlayer()); } }, 180L); @@ -511,9 +515,7 @@ public class FactionsPlayerListener implements Listener { } } - if (CmdSeeChunk.seeChunkMap.containsKey(event.getPlayer().getName())) { - CmdSeeChunk.seeChunkMap.remove(event.getPlayer().getName()); - } + CmdSeeChunk.seeChunkMap.remove(event.getPlayer().getName()); FScoreboard.remove(me); } @@ -887,6 +889,24 @@ 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; @@ -926,7 +946,6 @@ public class FactionsPlayerListener implements Listener { event.setCancelled(true); } } - @EventHandler(priority = EventPriority.HIGH) public void onPlayerRespawn(PlayerRespawnEvent event) { FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer());