@@ -148,20 +148,7 @@ public static boolean playerCanUseItemHere(Player player, Location location, Mat
148
148
}
149
149
150
150
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 );
165
152
}
166
153
167
154
@ SuppressWarnings ("deprecation" )
@@ -356,21 +343,10 @@ public static boolean canPlayerUseBlock(Player player, Block block, boolean just
356
343
}
357
344
}
358
345
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 );
372
347
}
373
348
349
+
374
350
public static boolean preventCommand (String fullCmd , Player player ) {
375
351
if ((Conf .territoryNeutralDenyCommands .isEmpty () && Conf .territoryEnemyDenyCommands .isEmpty () && Conf .permanentFactionMemberDenyCommands .isEmpty () && Conf .warzoneDenyCommands .isEmpty ())) {
376
352
return false ;
@@ -1070,4 +1046,33 @@ public int increment() {
1070
1046
return attempts ;
1071
1047
}
1072
1048
}
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
+ }
1073
1078
}
0 commit comments