Merge pull request #132 from ProSavage/permsfix
PR: Fixes issues with Permissions, and completes it's improvements
This commit is contained in:
commit
b1afbbf8df
Binary file not shown.
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>com.massivecraft</groupId>
|
<groupId>com.massivecraft</groupId>
|
||||||
<artifactId>Factions</artifactId>
|
<artifactId>Factions</artifactId>
|
||||||
<version>1.6.9.5-U0.2.1-RC-1.6-RC</version>
|
<version>1.6.9.5-U0.2.1-RC-1.6.1-RC</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>SavageFactions</name>
|
<name>SavageFactions</name>
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ public interface Faction extends EconomyParticipator {
|
|||||||
boolean noMonstersInTerritory();
|
boolean noMonstersInTerritory();
|
||||||
|
|
||||||
boolean isNormal();
|
boolean isNormal();
|
||||||
|
boolean isSystemFaction();
|
||||||
@Deprecated
|
@Deprecated
|
||||||
boolean isNone();
|
boolean isNone();
|
||||||
|
|
||||||
|
@ -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,58 +83,19 @@ 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())
|
||||||
|
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())
|
// Something failed prevent build
|
||||||
return true;
|
return false;
|
||||||
|
|
||||||
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("<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.
|
|
||||||
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.fromString(action));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
|
||||||
@ -520,18 +482,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 && me.getFactionId().equals(myFaction.getId()))) 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
|
||||||
me.msg(TL.GENERIC_NOPERMISSION, action);
|
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("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction()));
|
||||||
return false;
|
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("<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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// We assume faction land is not owned, and the access is not set to DENY, so we allow to execute the action
|
return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ import com.massivecraft.factions.util.MultiversionMaterials;
|
|||||||
import com.massivecraft.factions.util.VisualizeUtil;
|
import com.massivecraft.factions.util.VisualizeUtil;
|
||||||
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.persist.MemoryFPlayer;
|
import com.massivecraft.factions.zcore.persist.*;
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import com.massivecraft.factions.zcore.util.TagUtil;
|
import com.massivecraft.factions.zcore.util.TagUtil;
|
||||||
import com.massivecraft.factions.zcore.util.TextUtil;
|
import com.massivecraft.factions.zcore.util.TextUtil;
|
||||||
@ -30,6 +30,7 @@ import org.bukkit.Location;
|
|||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
@ -147,7 +148,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 +162,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,148 +169,18 @@ 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.isSystemFaction()) return true;
|
||||||
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())
|
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 (otherFaction.getId().equals(myFaction.getId()) && me.getRole() == Role.LEADER) return true;
|
||||||
|
PermissableAction action = GetPermissionFromUsableBlock(block);
|
||||||
if (player.getItemInHand().getType().toString().toUpperCase().contains("DOOR"))
|
if (action == null) return false;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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()) {
|
||||||
@ -326,29 +194,14 @@ 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);
|
if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own
|
||||||
boolean doTerritoryEnemyProtectedCheck = true;
|
// Get faction pain build access relation to me
|
||||||
|
boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
|
||||||
if (action != null && (action.equals(PermissableAction.CONTAINER) ||
|
return CheckPlayerAccess(player, me, loc, otherFaction, otherFaction.getAccess(me, action), action, pain);
|
||||||
action.equals(PermissableAction.DOOR))) {
|
} else if (otherFaction.getId().equals(myFaction.getId())) {
|
||||||
if (access == Access.ALLOW) {
|
return CheckPlayerAccess(player, me, loc, myFaction, myFaction.getAccess(me, action), action, (!justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW));
|
||||||
doTerritoryEnemyProtectedCheck = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return CheckPlayerAccess(player, me, loc, myFaction, otherFaction.getAccess(me, action), 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,60 +731,34 @@ 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().equals(Action.LEFT_CLICK_BLOCK) || event.getAction().equals(Action.LEFT_CLICK_AIR)) return;
|
||||||
return;
|
|
||||||
|
|
||||||
Block block = event.getClickedBlock();
|
Block block = event.getClickedBlock();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
// Check if the material is bypassing protection
|
||||||
if (block == null)
|
if (Conf.territoryBypasssProtectedMaterials.contains(block.getType())) return;
|
||||||
return; // clicked in air, apparently
|
if (block == null) return; // clicked in air, apparently
|
||||||
|
if (GetPermissionFromUsableBlock(event.getClickedBlock().getType()) != null) {
|
||||||
if (!canPlayerUseBlock(player, block, false)) {
|
if (!canPlayerUseBlock(player, block, false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (Conf.handleExploitInteractionSpam) {
|
event.setUseInteractedBlock(Event.Result.DENY);
|
||||||
String name = player.getName();
|
return;
|
||||||
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.getPlayer().getItemInHand() != null) {
|
||||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) {
|
Material handItem = event.getPlayer().getItemInHand().getType();
|
||||||
return; // only interested on right-clicks for below
|
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)) {
|
if (!playerCanUseItemHere(player, block.getLocation(), event.getMaterial(), false)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
event.setUseInteractedBlock(Event.Result.DENY);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1064,20 +891,146 @@ 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 && me.getFactionId().equals(myFaction.getId()))) 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("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
me.msg("You cannot " + action + " in the territory of " + myFaction.getTag(me.getFaction()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// This will try to resolve a permission action based on the item material, if it's not usable, will return null
|
||||||
|
/// </summary>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -754,6 +754,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
|
|||||||
public boolean isWarZone() {
|
public boolean isWarZone() {
|
||||||
return this.getId().equals("-2");
|
return this.getId().equals("-2");
|
||||||
}
|
}
|
||||||
|
public boolean isSystemFaction() { return this.isSafeZone() || this.isWarZone() || this.isWilderness(); }
|
||||||
|
|
||||||
public boolean isPlayerFreeType() {
|
public boolean isPlayerFreeType() {
|
||||||
return this.isSafeZone() || this.isWarZone();
|
return this.isSafeZone() || this.isWarZone();
|
||||||
|
Loading…
Reference in New Issue
Block a user