Skip to content

Commit 1a76817

Browse files
ImperialSam12LlmDl
andauthored
Allow Towny admins to bypass PvP damage prevention (TownyAdvanced#7013)
* check if player has towny.admin permission * fix error when referring to the attacking player * try to fix formatting issues * just some minor testing, will be reverted * undo recent testing, hopefully fix formatting issues * fix formatting issues * comply with reviews * Unnest if statement, make cancelled local to its own if block, extract isTownyAdmin method for readability, update comments to reflect what is happening. --------- Co-authored-by: LlmDl <llmdlio@gmail.com>
1 parent 0620e0f commit 1a76817

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Towny/src/main/java/com/palmergames/bukkit/towny/utils/CombatUtil.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,23 @@ private static boolean preventDamageCall(TownyWorld world, Entity attackingEntit
136136
*/
137137
if (attackingPlayer != null && isNotNPC(attackingPlayer)) {
138138

139-
boolean cancelled = false;
140-
141139
/*
142140
* Defender is a player, which is not an NPC..
143141
*/
144142
if (defendingPlayer != null && isNotNPC(defendingPlayer)) {
145-
143+
144+
boolean cancelled = false;
145+
146146
/*
147-
* Both townblocks are not Arena plots.
147+
* Both townblocks are not Arena plot and Player is not considered an Admin by Towny.
148+
* Arena plots never prevent pvp, admins are never prevented from pvping.
148149
*/
149-
if (!isArenaPlot(attackerTB, defenderTB)) {
150+
if (!isArenaPlot(attackerTB, defenderTB) && !isTownyAdmin(attackingPlayer)) {
150151
/*
151152
* Check if we are preventing friendly fire between allies
152-
* Check the attackers TownBlock and it's Town for their PvP status, else the world.
153-
* Check the defenders TownBlock and it's Town for their PvP status, else the world.
153+
* Check the attackers TownBlock for its PvP status, else the world.
154+
* Check the defenders TownBlock for its PvP status, else the world.
155+
* Check whether this involves someone who is jailed and in a Jail plot.
154156
*/
155157
cancelled = preventFriendlyFire(attackingPlayer, defendingPlayer, world) || preventPvP(world, attackerTB) || preventPvP(world, defenderTB) || preventJailedPVP(defendingPlayer, attackingPlayer);
156158
}
@@ -702,4 +704,8 @@ private static boolean isNotNPC(Entity entity) {
702704
return null;
703705
}
704706
}
707+
708+
private static boolean isTownyAdmin(Player attackingPlayer) {
709+
return TownyUniverse.getInstance().getPermissionSource().isTownyAdmin(attackingPlayer);
710+
}
705711
}

0 commit comments

Comments
 (0)