@@ -43,6 +43,7 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
43
43
return true ;
44
44
45
45
FPlayer me = FPlayers .getInstance ().getById (player .getUniqueId ().toString ());
46
+ Faction myFaction = me .getFaction ();
46
47
if (me .isAdminBypassing ())
47
48
return true ;
48
49
@@ -82,58 +83,20 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
82
83
me .msg ("<b>You can't " + action + " in a war zone." );
83
84
84
85
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 );
85
95
}
86
96
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 ;
137
100
}
138
101
139
102
@ EventHandler (priority = EventPriority .NORMAL , ignoreCancelled = true )
@@ -520,18 +483,39 @@ public void onFarmLandDamage(EntityChangeBlockEvent event) {
520
483
/// <param name="loc">The World location where the action is being executed</param>
521
484
/// <param name="myFaction">The faction of the player being checked</param>
522
485
/// <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 ) {
525
488
boolean landOwned = (myFaction .doesLocationHaveOwnersSet (loc ) && !myFaction .getOwnerList (loc ).isEmpty ());
526
489
if (landOwned && myFaction .getOwnerListString (loc ).contains (player .getName ()) || me .getRole () == Role .LEADER ) return true ;
527
490
else if (landOwned && !myFaction .getOwnerListString (loc ).contains (player .getName ())) {
528
491
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
+ }
529
496
return false ;
530
497
} 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
+ }
531
502
me .msg (TL .GENERIC_NOPERMISSION , action );
532
503
return false ;
533
504
}
534
505
// We assume faction land is not owned, and the access is not set to DENY, so we allow to execute the action
535
506
return true ;
536
507
}
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
+ }
537
521
}
0 commit comments