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

Commit 66fba62

Browse files
author
SvenjaReißaus
committedMar 13, 2019
WIP: Not reviewed, but should fix Ownerships and Items useage bypass
1 parent 0a41d15 commit 66fba62

File tree

5 files changed

+65
-46
lines changed

5 files changed

+65
-46
lines changed
 

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,17 @@ public class Conf {
333333
public static transient char[] mapKeyChrs = "\\/#$%=&^ABCDEFGHJKLMNOPQRSTUVWXYZ1234567890abcdeghjmnopqrsuvwxyz?".toCharArray();
334334

335335

336-
// Default Options
336+
// Default Options - Is this even shown on the Conf.json?
337337
public static boolean useCustomDefaultPermissions = false;
338338
public static boolean usePermissionHints = false;
339339
public static HashMap<String, DefaultPermissions> defaultFactionPermissions = new HashMap<>();
340-
// Custom Ranks
340+
// Custom Ranks - Oof I forgot I was doing this _SvenjaReissaus_
341341
//public static boolean enableCustomRanks = false; // We will disable it by default to avoid any migration error
342342
//public static int maxCustomRanks = 2; // Setting this to -1 will allow unlimited custom ranks
343343
// -------------------------------------------- //
344344
// Persistance
345345
// -------------------------------------------- //
346+
346347
private static transient Conf i = new Conf();
347348

348349
static {

‎src/main/java/com/massivecraft/factions/cmd/CmdShowClaims.java

-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ public CmdShowClaims() {
1818
this.senderMustBePlayer = true;
1919
this.senderMustBeMember = true;
2020
this.senderMustBeModerator = false;
21-
this.senderMustBePlayer = true;
22-
23-
2421
}
2522

2623
@Override

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

+29-14
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,7 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
133133
}
134134

135135
// Check the permission just after making sure the land isn't owned by someone else to avoid bypass.
136-
137-
if (access != Access.ALLOW && me.getRole() != Role.LEADER) {
138-
// TODO: Update this once new access values are added other than just allow / deny.
139-
if (access == Access.DENY) {
140-
if (!justCheck)
141-
me.msg(TL.GENERIC_NOPERMISSION, action);
142-
return false;
143-
} else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) {
144-
if (!justCheck)
145-
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
146-
return false;
147-
}
148-
}
149-
return true;
136+
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.fromString(action));
150137
}
151138

152139
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
@@ -519,4 +506,32 @@ public void onFarmLandDamage(EntityChangeBlockEvent event) {
519506
}
520507
}
521508
}
509+
510+
/// <summary>
511+
/// This checks if the current player can execute an action based on it's factions access and surroundings
512+
/// It will grant access in the following priorities:
513+
/// - If Faction Land is Owned and the Owner is the current player, or player is faction leader.
514+
/// - If Faction Land is not Owned and my access value is not set to DENY
515+
/// - If none of the filters above matches, then we consider access is set to ALLOW|UNDEFINED
516+
/// This check does not performs any kind of bypass check (i.e.: me.isAdminBypassing())
517+
/// </summary>
518+
/// <param name="player">The player entity which the check will be made upon</param>
519+
/// <param name="me">The Faction player object related to the player</param>
520+
/// <param name="loc">The World location where the action is being executed</param>
521+
/// <param name="myFaction">The faction of the player being checked</param>
522+
/// <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
525+
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
526+
if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true;
527+
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
528+
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
529+
return false;
530+
} else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway
531+
me.msg(TL.GENERIC_NOPERMISSION, action);
532+
return false;
533+
}
534+
// We assume faction land is not owned, and the access is not set to DENY, so we allow to execute the action
535+
return true;
536+
}
522537
}

‎src/main/java/com/massivecraft/factions/listeners/FactionsChatListener.java

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public void onPlayerEarlyChat(AsyncPlayerChatEvent event) {
6060
// Just in case player gets demoted while in faction chat.
6161
me.msg(TL.COMMAND_CHAT_MOD_ONLY);
6262
event.setCancelled(true);
63+
me.setChatMode(ChatMode.FACTION);
6364
return;
6465
}
6566

‎src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java

+32-27
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,7 @@ public static boolean playerCanUseItemHere(Player player, Location location, Mat
148148
}
149149

150150
Access access = otherFaction.getAccess(me, PermissableAction.ITEM);
151-
if (access != null && access != Access.UNDEFINED) {
152-
// TODO: Update this once new access values are added other than just allow / deny.
153-
if ((myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && myFaction.getOwnerListString(loc).contains(player.getName()))) {
154-
return true;
155-
} else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) {
156-
me.msg("<b>You can't use items in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
157-
return false;
158-
} else if (access == Access.DENY) {
159-
me.msg(TL.GENERIC_NOPERMISSION, PermissableAction.ITEM);
160-
return false;
161-
}
162-
}
163-
164-
return true;
151+
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.ITEM);
165152
}
166153

167154
@SuppressWarnings("deprecation")
@@ -356,21 +343,10 @@ public static boolean canPlayerUseBlock(Player player, Block block, boolean just
356343
}
357344
}
358345

359-
if (access != Access.ALLOW && me.getRole() != Role.LEADER) {
360-
// TODO: Update this once new access values are added other than just allow / deny.
361-
if ((myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && myFaction.getOwnerListString(loc).contains(player.getName()))) {
362-
return true;
363-
} else if (myFaction.getOwnerListString(loc) != null && !myFaction.getOwnerListString(loc).isEmpty() && !myFaction.getOwnerListString(loc).contains(player.getName())) {
364-
me.msg("<b>You can't " + action + " in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
365-
return false;
366-
} else if (access == Access.DENY) {
367-
me.msg(TL.GENERIC_NOPERMISSION, action);
368-
return false;
369-
}
370-
}
371-
return true;
346+
return CheckPlayerAccess(player, me, loc, myFaction, access, PermissableAction.CONTAINER);
372347
}
373348

349+
374350
public static boolean preventCommand(String fullCmd, Player player) {
375351
if ((Conf.territoryNeutralDenyCommands.isEmpty() && Conf.territoryEnemyDenyCommands.isEmpty() && Conf.permanentFactionMemberDenyCommands.isEmpty() && Conf.warzoneDenyCommands.isEmpty())) {
376352
return false;
@@ -1070,4 +1046,33 @@ public int increment() {
10701046
return attempts;
10711047
}
10721048
}
1049+
/// <summary>
1050+
/// This checks if the current player can execute an action based on it's factions access and surroundings
1051+
/// It will grant access in the following priorities:
1052+
/// - If Faction Land is Owned and the Owner is the current player, or player is faction leader.
1053+
/// - If Faction Land is not Owned and my access value is not set to DENY
1054+
/// - If none of the filters above matches, then we consider access is set to ALLOW|UNDEFINED
1055+
/// This check does not performs any kind of bypass check (i.e.: me.isAdminBypassing())
1056+
/// </summary>
1057+
/// <param name="player">The player entity which the check will be made upon</param>
1058+
/// <param name="me">The Faction player object related to the player</param>
1059+
/// <param name="loc">The World location where the action is being executed</param>
1060+
/// <param name="myFaction">The faction of the player being checked</param>
1061+
/// <param name="access">The current's faction access permission for the action</param>
1062+
private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action) {
1063+
if (access != null && access != Access.UNDEFINED) {
1064+
// TODO: Update this once new access values are added other than just allow / deny.
1065+
boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty());
1066+
if (landOwned && myFaction.getOwnerListString(loc).contains(player.getName()) || me.getRole() == Role.LEADER) return true;
1067+
else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) {
1068+
me.msg("<b>You can't do that in this territory, it is owned by: " + myFaction.getOwnerListString(loc));
1069+
return false;
1070+
} else if (!landOwned && access != Access.DENY) return true;
1071+
else {
1072+
me.msg(TL.GENERIC_NOPERMISSION, action);
1073+
return false;
1074+
}
1075+
}
1076+
return true;
1077+
}
10731078
}

0 commit comments

Comments
 (0)
This repository has been archived.