Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit a7b824e

Browse files
author
SvenjaReißaus
committed
Attempts to fix permissions
1 parent 3c10b82 commit a7b824e

File tree

4 files changed

+81
-186
lines changed

4 files changed

+81
-186
lines changed
115 Bytes
Binary file not shown.

src/main/java/com/massivecraft/factions/Conf.java

+5-49
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public class Conf {
219219
/// This defines a set of materials which should always be allowed to use, regardless of factions permissions.
220220
/// Useful for HCF features.
221221
/// </summary>
222-
public static Set<Material> territoryBypassAllProtection = EnumSet.noneOf(Material.class);
222+
public static Set<Material> territoryBypasssProtectedMaterials = EnumSet.noneOf(Material.class);
223223

224224
// Economy settings
225225
public static boolean econEnabled = false;
@@ -363,73 +363,29 @@ public class Conf {
363363
territoryEnemyDenyCommands.add("tpaccept");
364364
territoryEnemyDenyCommands.add("tpa");
365365

366-
territoryProtectedMaterials.add(SavageFactions.plugin.WOODEN_DOOR);
367-
territoryProtectedMaterials.add(SavageFactions.plugin.TRAP_DOOR);
368-
territoryProtectedMaterials.add(SavageFactions.plugin.FENCE_GATE);
369-
territoryProtectedMaterials.add(Material.DISPENSER);
370-
territoryProtectedMaterials.add(Material.CHEST);
371-
territoryProtectedMaterials.add(Material.FURNACE);
372-
territoryProtectedMaterials.add(SavageFactions.plugin.BURNING_FURNACE);
373-
territoryProtectedMaterials.add(SavageFactions.plugin.DIODE_BLOCK_OFF);
374-
territoryProtectedMaterials.add(SavageFactions.plugin.DIODE_BLOCK_ON);
375-
territoryProtectedMaterials.add(Material.JUKEBOX);
376-
territoryProtectedMaterials.add(Material.BREWING_STAND);
377-
territoryProtectedMaterials.add(SavageFactions.plugin.ENCHANTMENT_TABLE);
378-
territoryProtectedMaterials.add(Material.CAULDRON);
379-
territoryProtectedMaterials.add(SavageFactions.plugin.ENCHANTMENT_TABLE);
366+
/// TODO: Consider removing this in a future release, as permissions works just fine now
380367
territoryProtectedMaterials.add(Material.BEACON);
381-
territoryProtectedMaterials.add(Material.ANVIL);
382-
territoryProtectedMaterials.add(Material.TRAPPED_CHEST);
383-
territoryProtectedMaterials.add(Material.DROPPER);
384-
territoryProtectedMaterials.add(Material.HOPPER);
368+
369+
// Config is not loading if value is empty ???
370+
territoryBypasssProtectedMaterials.add(Material.COOKIE);
385371

386372
territoryDenyUseageMaterials.add(SavageFactions.plugin.FIREBALL);
387373
territoryDenyUseageMaterials.add(Material.FLINT_AND_STEEL);
388374
territoryDenyUseageMaterials.add(Material.BUCKET);
389375
territoryDenyUseageMaterials.add(Material.WATER_BUCKET);
390376
territoryDenyUseageMaterials.add(Material.LAVA_BUCKET);
391-
territoryDenyUseageMaterials.add(MultiversionMaterials.ACACIA_BUTTON.parseMaterial());
392-
territoryDenyUseageMaterials.add(MultiversionMaterials.BIRCH_BUTTON.parseMaterial());
393-
territoryDenyUseageMaterials.add(MultiversionMaterials.DARK_OAK_BUTTON.parseMaterial());
394-
territoryDenyUseageMaterials.add(MultiversionMaterials.JUNGLE_BUTTON.parseMaterial());
395-
territoryDenyUseageMaterials.add(MultiversionMaterials.OAK_BUTTON.parseMaterial());
396-
territoryDenyUseageMaterials.add(MultiversionMaterials.STONE_BUTTON.parseMaterial());
397377
if (!SavageFactions.plugin.mc17) {
398378
territoryDenyUseageMaterials.add(Material.ARMOR_STAND);
399379
}
400380

401381

402-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.WOODEN_DOOR);
403-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.TRAP_DOOR);
404-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.FENCE_GATE);
405-
territoryProtectedMaterialsWhenOffline.add(Material.DISPENSER);
406-
territoryProtectedMaterialsWhenOffline.add(Material.CHEST);
407-
territoryProtectedMaterialsWhenOffline.add(Material.FURNACE);
408-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.BURNING_FURNACE);
409-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.DIODE_BLOCK_OFF);
410-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.DIODE_BLOCK_OFF);
411-
territoryProtectedMaterialsWhenOffline.add(Material.JUKEBOX);
412-
territoryProtectedMaterialsWhenOffline.add(Material.BREWING_STAND);
413-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.ENCHANTMENT_TABLE);
414-
territoryProtectedMaterialsWhenOffline.add(Material.CAULDRON);
415-
territoryProtectedMaterialsWhenOffline.add(SavageFactions.plugin.SOIL);
416382
territoryProtectedMaterialsWhenOffline.add(Material.BEACON);
417-
territoryProtectedMaterialsWhenOffline.add(Material.ANVIL);
418-
territoryProtectedMaterialsWhenOffline.add(Material.TRAPPED_CHEST);
419-
territoryProtectedMaterialsWhenOffline.add(Material.DROPPER);
420-
territoryProtectedMaterialsWhenOffline.add(Material.HOPPER);
421383

422384
territoryDenyUseageMaterialsWhenOffline.add(SavageFactions.plugin.FIREBALL);
423385
territoryDenyUseageMaterialsWhenOffline.add(Material.FLINT_AND_STEEL);
424386
territoryDenyUseageMaterialsWhenOffline.add(Material.BUCKET);
425387
territoryDenyUseageMaterialsWhenOffline.add(Material.WATER_BUCKET);
426388
territoryDenyUseageMaterialsWhenOffline.add(Material.LAVA_BUCKET);
427-
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.ACACIA_BUTTON.parseMaterial());
428-
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.BIRCH_BUTTON.parseMaterial());
429-
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.DARK_OAK_BUTTON.parseMaterial());
430-
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.JUNGLE_BUTTON.parseMaterial());
431-
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.OAK_BUTTON.parseMaterial());
432-
territoryDenyUseageMaterialsWhenOffline.add(MultiversionMaterials.STONE_BUTTON.parseMaterial());
433389
if (!SavageFactions.plugin.mc17) {
434390
territoryDenyUseageMaterialsWhenOffline.add(Material.ARMOR_STAND);
435391
}

src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java

+36-52
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
4343
return true;
4444

4545
FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString());
46+
Faction myFaction = me.getFaction();
4647
if (me.isAdminBypassing())
4748
return true;
4849

@@ -82,58 +83,20 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
8283
me.msg("<b>You can't " + action + " in a war zone.");
8384

8485
return false;
86+
} else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own
87+
if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
88+
return true;
89+
// Get faction pain build access relation to me
90+
boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
91+
return CheckActionState(otherFaction, loc, me, PermissableAction.fromString(action), pain);
92+
} else if (otherFaction.getId().equals(myFaction.getId())) {
93+
boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW;
94+
return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain);
8595
}
8696

87-
if (SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded())
88-
return true;
89-
90-
Faction myFaction = me.getFaction();
91-
Relation rel = myFaction.getRelationTo(otherFaction);
92-
boolean online = otherFaction.hasPlayersOnline();
93-
boolean pain = !justCheck && rel.confPainBuild(online);
94-
boolean deny = rel.confDenyBuild(online);
95-
96-
Access access = otherFaction.getAccess(me, PermissableAction.fromString(action));
97-
if (access == Access.ALLOW && ((rel == Relation.ALLY) || (rel == Relation.ENEMY) || (rel == Relation.NEUTRAL) || (rel == Relation.TRUCE)))
98-
deny = false;
99-
100-
// hurt the player for building/destroying in other territory?
101-
if (pain) {
102-
player.damage(Conf.actionDeniedPainAmount);
103-
104-
if (!deny) {
105-
me.msg("<b>It is painful to try to " + action + " in the territory of " + otherFaction.getTag(myFaction));
106-
}
107-
}
108-
109-
110-
// cancel building/destroying in other territory?
111-
if (deny) {
112-
if (!justCheck) {
113-
me.msg("<b>You can't " + action + " in the territory of " + otherFaction.getTag(myFaction));
114-
}
115-
116-
return false;
117-
}
118-
119-
// Also cancel and/or cause pain if player doesn't have ownership rights for this claim
120-
if (Conf.ownedAreasEnabled && (Conf.ownedAreaDenyBuild || Conf.ownedAreaPainBuild) && !otherFaction.playerHasOwnershipRights(me, loc)) {
121-
if (!pain && Conf.ownedAreaPainBuild && !justCheck) {
122-
player.damage(Conf.actionDeniedPainAmount);
123-
if (!Conf.ownedAreaDenyBuild) {
124-
me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
125-
}
126-
}
127-
if (Conf.ownedAreaDenyBuild) {
128-
if (!justCheck) {
129-
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + otherFaction.getOwnerListString(loc));
130-
return false;
131-
}
132-
}
133-
}
134-
135-
// Check the permission just after making sure the land isn't owned by someone else to avoid bypass.
136-
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.fromString(action));
97+
// Something failed prevent build
98+
SavageFactions.plugin.getLogger().info("Unable to determine fallback action for build permissions, defaulting to false");
99+
return false;
137100
}
138101

139102
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@@ -520,18 +483,39 @@ public void onFarmLandDamage(EntityChangeBlockEvent event) {
520483
/// <param name="loc">The World location where the action is being executed</param>
521484
/// <param name="myFaction">The faction of the player being checked</param>
522485
/// <param name="access">The current's faction access permission for the action</param>
523-
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action) {
524-
if (access == null) access = Access.DENY; // Let's deny by default
486+
/// <param name="shouldHurt">Determine whether we should hurt the player when access is denied</param>
487+
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean shouldHurt) {
525488
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
526489
if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true;
527490
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
528491
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
492+
if (shouldHurt) {
493+
player.damage(Conf.actionDeniedPainAmount);
494+
me.msg("<b>It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction));
495+
}
529496
return false;
530497
} else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway
498+
if (shouldHurt) {
499+
player.damage(Conf.actionDeniedPainAmount);
500+
me.msg("<b>It is painful to try to " + action + " in the territory of " + Board.getInstance().getFactionAt(loc).getTag(myFaction));
501+
}
531502
me.msg(TL.GENERIC_NOPERMISSION, action);
532503
return false;
533504
}
534505
// We assume faction land is not owned, and the access is not set to DENY, so we allow to execute the action
535506
return true;
536507
}
508+
509+
private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain) {
510+
if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) {
511+
// If pain should be applied
512+
if (pain && Conf.ownedAreaPainBuild) me.msg("<b>It is painful to try to " + action + " in this territory, it is owned by: " + target.getOwnerListString(location));
513+
if (Conf.ownedAreaDenyBuild && pain) return false;
514+
else if (Conf.ownedAreaDenyBuild) {
515+
me.msg("You cannot " + action + " in the territory of" + target.getTag(me.getFaction()));
516+
return false;
517+
}
518+
}
519+
return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain);
520+
}
537521
}

0 commit comments

Comments
 (0)