Skip to content

Commit

Permalink
Stop re-assigning ranks when there aren't any level-requiring ranks in
Browse files Browse the repository at this point in the history
the townyperms file.
  • Loading branch information
LlmDl committed Jan 6, 2025
1 parent e47945f commit 2796f29
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ private void attemptPlayerCacheReset(Player player, WorldCoord worldCoord) {

@EventHandler
public void onTownLevelIncrease(TownLevelIncreaseEvent event) {
if (!TownyPerms.ranksWithTownLevelRequirementPresent())
return;
event.getTown().getResidents()
.stream()
.filter(Resident::isOnline)
Expand All @@ -408,6 +410,8 @@ public void onTownLevelIncrease(TownLevelIncreaseEvent event) {

@EventHandler
public void onTownLevelDecrease(TownLevelDecreaseEvent event) {
if (!TownyPerms.ranksWithTownLevelRequirementPresent())
return;
event.getTown().getResidents()
.stream()
.filter(Resident::isOnline)
Expand All @@ -416,6 +420,8 @@ public void onTownLevelDecrease(TownLevelDecreaseEvent event) {

@EventHandler
public void onNationLevelIncrease(NationLevelIncreaseEvent event) {
if (!TownyPerms.ranksWithNationLevelRequirementPresent())
return;
event.getNation().getResidents()
.stream()
.filter(Resident::isOnline)
Expand All @@ -424,6 +430,8 @@ public void onNationLevelIncrease(NationLevelIncreaseEvent event) {

@EventHandler
public void onNationLevelDecrease(NationLevelDecreaseEvent event) {
if (!TownyPerms.ranksWithNationLevelRequirementPresent())
return;
event.getNation().getResidents()
.stream()
.filter(Resident::isOnline)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,25 @@ public static int getRankNationLevelReq(String rank) {
return getNodePriority(node, RANK_NATION_LEVEL_REQUIREMENT_PREFIX.length());
return 0;
}


public static boolean ranksWithTownLevelRequirementPresent() {
for (String rank : getTownRanks()) {
for (String node : getTownRankPermissions(rank))
if (node.startsWith(RANK_TOWN_LEVEL_REQUIREMENT_PREFIX))
return true;
}
return false;
}

public static boolean ranksWithNationLevelRequirementPresent() {
for (String rank : getNationRanks()) {
for (String node : getNationRankPermissions(rank))
if (node.startsWith(RANK_NATION_LEVEL_REQUIREMENT_PREFIX))
return true;
}
return false;
}

/*
* Permission utility functions taken from GroupManager (which I wrote anyway).
*/
Expand Down

0 comments on commit 2796f29

Please sign in to comment.