If player is owner of a claim, all permissions are bypassed The order is OP -> Ownership -> Permission

This commit is contained in:
ProSavage 2018-07-18 09:48:25 -05:00
parent da32970389
commit 2320fe2586
4 changed files with 186 additions and 161 deletions

@ -236,7 +236,11 @@ public class P extends MPlugin {
Type accessTypeAdatper = new TypeToken<Map<Permissable, Map<PermissableAction, Access>>>() { Type accessTypeAdatper = new TypeToken<Map<Permissable, Map<PermissableAction, Access>>>() {
}.getType(); }.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 @Override
@ -245,6 +249,7 @@ public class P extends MPlugin {
if (this.loadSuccessful) { if (this.loadSuccessful) {
Conf.save(); Conf.save();
} }
if (AutoLeaveTask != null) { if (AutoLeaveTask != null) {
this.getServer().getScheduler().cancelTask(AutoLeaveTask); this.getServer().getScheduler().cancelTask(AutoLeaveTask);
AutoLeaveTask = null; AutoLeaveTask = null;

@ -35,6 +35,7 @@ public class CmdSetDefaultRole extends FCommand {
return; return;
} }
myFaction.setDefaultRole(target); myFaction.setDefaultRole(target);
msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename); msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename);
} }

@ -4,6 +4,7 @@ import com.massivecraft.factions.*;
import com.massivecraft.factions.integration.Worldguard; import com.massivecraft.factions.integration.Worldguard;
import com.massivecraft.factions.struct.Permission; import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation; 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.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction; import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL; import com.massivecraft.factions.zcore.util.TL;
@ -26,124 +27,6 @@ public class FactionsBlockListener implements Listener {
this.p = p; 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("<b>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("<b>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("<b>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("<b>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("<b>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("<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;
}
}
return true;
}
@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()) {
@ -307,4 +190,121 @@ public class FactionsBlockListener implements Listener {
return !rel.confDenyBuild(otherFaction.hasPlayersOnline()); 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("<b>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("<b>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("<b>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("<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));
}
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.
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("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
return false;
}
}
return true;
}
} }

@ -80,6 +80,7 @@ public class FactionsPlayerListener implements Listener {
return true; return true;
} }
FPlayer me = FPlayers.getInstance().getByPlayer(player); FPlayer me = FPlayers.getInstance().getByPlayer(player);
if (me.isAdminBypassing()) { if (me.isAdminBypassing()) {
return true; return true;
@ -87,7 +88,16 @@ public class FactionsPlayerListener implements Listener {
FLocation loc = new FLocation(location); FLocation loc = new FLocation(location);
Faction otherFaction = Board.getInstance().getFactionAt(loc); 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("<b>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()) { if (P.p.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() >= otherFaction.getPowerRounded()) {
return true; return true;
} }
@ -134,10 +144,6 @@ public class FactionsPlayerListener implements Listener {
return false; return false;
} }
Faction myFaction = me.getFaction();
Relation rel = myFaction.getRelationTo(otherFaction);
// Cancel if we are not in our own territory // Cancel if we are not in our own territory
if (rel.confDenyUseage()) { if (rel.confDenyUseage()) {
if (!justCheck) { if (!justCheck) {
@ -146,19 +152,19 @@ public class FactionsPlayerListener implements Listener {
return false; return false;
} }
Access access = otherFaction.getAccess(me, PermissableAction.ITEM); Access access = otherFaction.getAccess(me, PermissableAction.ITEM);
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.
return access == Access.ALLOW; 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())) {
// Also cancel if player doesn't have ownership rights for this claim me.msg("<b>You can't use items in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
if (Conf.ownedAreasEnabled && Conf.ownedAreaDenyUseage && !otherFaction.playerHasOwnershipRights(me, loc)) { return false;
if (!justCheck) { } else if (access == Access.DENY) {
me.msg(TL.PLAYER_USE_OWNED, TextUtil.getMaterialName(material), otherFaction.getOwnerListString(loc)); me.msg(TL.GENERIC_NOPERMISSION, PermissableAction.ITEM);
return false;
} }
return false;
} }
return true; return true;
@ -175,8 +181,12 @@ public class FactionsPlayerListener implements Listener {
} }
Material material = block.getType(); Material material = block.getType();
// Dupe fix.
FLocation loc = new FLocation(block); FLocation loc = new FLocation(block);
Faction otherFaction = Board.getInstance().getFactionAt(loc); 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 // no door/chest/whatever protection in wilderness, war zones, or safe zones
if (!otherFaction.isNormal()) { if (!otherFaction.isNormal()) {
@ -187,10 +197,7 @@ public class FactionsPlayerListener implements Listener {
return true; return true;
} }
// Dupe fix. if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand().getType() != null) {
Faction myFaction = me.getFaction();
Relation rel = myFaction.getRelationTo(otherFaction);
if (!rel.isMember() || !otherFaction.playerHasOwnershipRights(me, loc) && player.getItemInHand() != null) {
switch (player.getItemInHand().getType()) { switch (player.getItemInHand().getType()) {
case CHEST: case CHEST:
case SIGN_POST: case SIGN_POST:
@ -223,6 +230,12 @@ public class FactionsPlayerListener implements Listener {
case TRAP_DOOR: case TRAP_DOOR:
case WOOD_DOOR: case WOOD_DOOR:
case WOODEN_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; action = PermissableAction.DOOR;
break; break;
case CHEST: case CHEST:
@ -237,16 +250,6 @@ public class FactionsPlayerListener implements Listener {
} }
break; 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. // We only care about some material types.
if (otherFaction.hasPlayersOnline()) { if (otherFaction.hasPlayersOnline()) {
if (!Conf.territoryProtectedMaterials.contains(material)) { if (!Conf.territoryProtectedMaterials.contains(material)) {
@ -263,19 +266,22 @@ public class FactionsPlayerListener implements Listener {
if (!justCheck) { if (!justCheck) {
me.msg(TL.PLAYER_USE_TERRITORY, (material == Material.SOIL ? "trample " : "use ") + TextUtil.getMaterialName(material), otherFaction.getTag(myFaction)); me.msg(TL.PLAYER_USE_TERRITORY, (material == Material.SOIL ? "trample " : "use ") + TextUtil.getMaterialName(material), otherFaction.getTag(myFaction));
} }
return false; return false;
} }
// Also cancel if player doesn't have ownership rights for this claim Access access = otherFaction.getAccess(me, action);
if (Conf.ownedAreasEnabled && Conf.ownedAreaProtectMaterials && !otherFaction.playerHasOwnershipRights(me, loc)) { if (access != Access.ALLOW && me.getRole() != Role.ADMIN) {
if (!justCheck) { // TODO: Update this once new access values are added other than just allow / deny.
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("<b>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; return true;
} }
@ -443,9 +449,7 @@ public class FactionsPlayerListener implements Listener {
Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() { Bukkit.getScheduler().scheduleSyncDelayedTask(P.p, new Runnable() {
@Override @Override
public void run() { public void run() {
if (fallMap.containsKey(me.getPlayer())) { fallMap.remove(me.getPlayer());
fallMap.remove(me.getPlayer());
}
} }
}, 180L); }, 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); FScoreboard.remove(me);
} }
@ -887,6 +889,24 @@ 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.RIGHT_CLICK_BLOCK && event.getAction() != Action.PHYSICAL) {
return; return;
@ -926,7 +946,6 @@ public class FactionsPlayerListener implements Listener {
event.setCancelled(true); event.setCancelled(true);
} }
} }
@EventHandler(priority = EventPriority.HIGH) @EventHandler(priority = EventPriority.HIGH)
public void onPlayerRespawn(PlayerRespawnEvent event) { public void onPlayerRespawn(PlayerRespawnEvent event) {
FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer()); FPlayer me = FPlayers.getInstance().getByPlayer(event.getPlayer());