Skip to content

Commit

Permalink
- Fix redundant permission node tests in Towny command.
Browse files Browse the repository at this point in the history
  - Add child nodes to towny.command.towny.top command.
    - Closes #5580.
  - New permission node:
    - towny.command.towny.top.*
      - Child Node of towny.command.towny.top
      - Children: - towny.command.towny.top.residents
                  - towny.command.towny.top.land
                  - towny.command.towny.top.balance
  • Loading branch information
LlmDl committed Dec 29, 2021
1 parent 4ded10c commit 403d2bd
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.palmergames.bukkit.towny</groupId>
<artifactId>towny</artifactId>
<packaging>jar</packaging>
<version>0.97.5.6</version>
<version>0.97.5.7</version>

<licenses>
<license>
Expand Down
13 changes: 12 additions & 1 deletion resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7109,4 +7109,15 @@ v0.92.0.11:
- Closes #5569.
0.97.5.6:
- Overhaul of CommentedConfiguration, adding support for old and new versions of Bukkit servers.
- Servers not running up-to-date MC 1.18.1 implementations might see some multi-lining in their chatconfig.yml, which isn't an actual issue.
- Servers not running up-to-date MC 1.18.1 implementations might see some multi-lining in their chatconfig.yml, which isn't an actual issue.
0.97.5.7:
- Fix redundant permission node tests in Towny command.
- Add child nodes to towny.command.towny.top command.
- Closes #5580.
- New permission node:
- towny.command.towny.top.*
- Child Node of towny.command.towny.top
- Children: - towny.command.towny.top.residents
- towny.command.towny.top.land
- towny.command.towny.top.balance

16 changes: 16 additions & 0 deletions resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,22 @@ permissions:
towny.command.towny.war: true
towny.command.towny.war.hud: true

# Towny top command permissions
towny.command.towny.top:
description: User has access to full top command.
default: false
children:
towny.command.towny.top.*: true

# Towny top.* command permissions
towny.command.towny.top.*:
description: User has access to full top command.
default: false
children:
towny.command.towny.top.residents: true
towny.command.towny.top.land: true
towny.command.towny.top.balance: true

# TownyWorld command permissions
towny.command.townyworld.*:
description: User can access the admin toggle commands.
Expand Down
21 changes: 12 additions & 9 deletions src/com/palmergames/bukkit/towny/command/TownyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void parseTownyCommand(Player player, String[] split) {
throw new TownyException(Translatable.of("msg_err_usingtowny_disabled"));

if (split[0].equalsIgnoreCase("map")) {
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_MAP.getNode(split[0].toLowerCase())))
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_MAP.getNode()))
throw new TownyException(Translatable.of("msg_err_command_disable"));

if (split.length > 1 && split[1].equalsIgnoreCase("big"))
Expand Down Expand Up @@ -251,24 +251,22 @@ else if (split.length > 1 && split[1].equalsIgnoreCase("hud"))
Resident resident = getResidentOrThrow(player.getUniqueId());
ResidentUtil.openGUIInventory(resident, world.getPlotManagementMayorDelete(), Translatable.of("gui_title_towny_plotclear").forLocale(player));
} else if (split[0].equalsIgnoreCase("top")) {
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_TOP.getNode(split[0].toLowerCase())))
throw new TownyException(Translatable.of("msg_err_command_disable"));
TopCommand(player, StringMgmt.remFirstArg(split));
} else if (split[0].equalsIgnoreCase("tree")) {
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_TREE.getNode(split[0].toLowerCase())))
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_TREE.getNode()))
throw new TownyException(Translatable.of("msg_err_command_disable"));
consoleUseOnly(player);
} else if (split[0].equalsIgnoreCase("time")) {
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_TIME.getNode(split[0].toLowerCase())))
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_TIME.getNode()))
throw new TownyException(Translatable.of("msg_err_command_disable"));
TownyMessaging.sendMsg(player, Translatable.of("msg_time_until_a_new_day").append(TimeMgmt.formatCountdownTime(TownyTimerHandler.townyTime())));
} else if (split[0].equalsIgnoreCase("universe")) {
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_UNIVERSE.getNode(split[0].toLowerCase())))
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_UNIVERSE.getNode()))
throw new TownyException(Translatable.of("msg_err_command_disable"));
for (String line : getUniverseStats(Translation.getLocale(player)))
TownyMessaging.sendMessage(player, line);
} else if (split[0].equalsIgnoreCase("version") || split[0].equalsIgnoreCase("v")) {
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_VERSION.getNode(split[0].toLowerCase())))
if (!permSource.testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_VERSION.getNode()))
throw new TownyException(Translatable.of("msg_err_command_disable"));

if (TownyUpdateChecker.shouldShowNotification()) {
Expand Down Expand Up @@ -296,14 +294,19 @@ else if (split.length > 1 && split[1].equalsIgnoreCase("hud"))

}

private void TopCommand(Player player, String[] args) {
private void TopCommand(Player player, String[] args) throws TownyException {
TownyUniverse universe = TownyUniverse.getInstance();
if (args.length == 0 || args[0].equalsIgnoreCase("?")) {
towny_top.add(ChatTools.formatTitle("/towny top"));
towny_top.add(ChatTools.formatCommand("", "/towny top", "residents [all/town/nation]", ""));
towny_top.add(ChatTools.formatCommand("", "/towny top", "land [all/resident/town]", ""));
towny_top.add(ChatTools.formatCommand("", "/towny top", "balance [all/town/nation]", ""));
} else if (args[0].equalsIgnoreCase("residents"))
}

if (!TownyUniverse.getInstance().getPermissionSource().testPermission(player, PermissionNodes.TOWNY_COMMAND_TOWNY_TOP.getNode(args[1].toLowerCase())))
throw new TownyException(Translatable.of("msg_err_command_disable"));

if (args[0].equalsIgnoreCase("residents"))
if (args.length == 1 || args[1].equalsIgnoreCase("all")) {
List<ResidentList> list = new ArrayList<>(universe.getTowns());
list.addAll(universe.getNations());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ public enum PermissionNodes {
*/
TOWNY_COMMAND_TOWNY("towny.command.towny.*"),
TOWNY_COMMAND_TOWNY_MAP("towny.command.towny.map"),
TOWNY_COMMAND_TOWNY_TOP("towny.command.towny.top"),
TOWNY_COMMAND_TOWNY_TOP("towny.command.towny.top.*"),
TOWNY_COMMAND_TOWNY_TOP_RESIDENTS("towny.command.towny.top.residents"),
TOWNY_COMMAND_TOWNY_TOP_LAND("towny.command.towny.top.land"),
TOWNY_COMMAND_TOWNY_TOP_BALANCE("towny.command.towny.top.balance"),
TOWNY_COMMAND_TOWNY_TREE("towny.command.towny.tree"),
TOWNY_COMMAND_TOWNY_TIME("towny.command.towny.time"),
TOWNY_COMMAND_TOWNY_UNIVERSE("towny.command.towny.universe"),
Expand Down

0 comments on commit 403d2bd

Please sign in to comment.