Skip to content

Commit

Permalink
- Fix command blacklists not handling casing well.
Browse files Browse the repository at this point in the history
    - Closes #5586.
  • Loading branch information
LlmDl committed Jan 2, 2022
1 parent 6ee623f commit 8bc8162
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
4 changes: 3 additions & 1 deletion resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7130,4 +7130,6 @@ v0.92.0.11:
- Add the ability to make a CommentedConfiguration from a File again.
0.97.5.8:
- Suppress deprecated JSONReader stuff, fix javadoc building.
- Fix ArrayIndexOutOfBoundException when using /towny top with no subcommand.
- Fix ArrayIndexOutOfBoundException when using /towny top with no subcommand.
- Fix command blacklists not handling casing well.
- Closes #5586.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -1051,7 +1052,7 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) {
return;

String[] split = event.getMessage().substring(1).split(" ");
if (TownySettings.getJailBlacklistedCommands().contains(split[0])) {
if (listContainsCommand(TownySettings.getJailBlacklistedCommands(), split[0])) {
TownyMessaging.sendErrorMsg(event.getPlayer(), Translatable.of("msg_you_cannot_use_that_command_while_jailed"));
event.setCancelled(true);
}
Expand Down Expand Up @@ -1079,7 +1080,7 @@ public void onOutlawedPlayerUsesCommand(PlayerCommandPreprocessEvent event) {

if (town != null && town.hasOutlaw(resident)) {
String[] split = event.getMessage().substring(1).split(" ");
if (TownySettings.getOutlawBlacklistedCommands().contains(split[0])) {
if (listContainsCommand(TownySettings.getOutlawBlacklistedCommands(), split[0])) {
TownyMessaging.sendErrorMsg(event.getPlayer(), Translatable.of("msg_err_you_cannot_use_command_while_in_outlaw_town"));
event.setCancelled(true);
}
Expand All @@ -1106,11 +1107,11 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) {
/*
* Commands are sometimes blocked from being run by outsiders on an town.
*/
if (TownySettings.getTownBlacklistedCommands().contains(command) && TownySettings.getTouristBlockedCommands().contains(command)) {
if (listContainsCommand(TownySettings.getTownBlacklistedCommands(), command) && listContainsCommand(TownySettings.getTouristBlockedCommands(), command)) {
// Let admins and globally welcomed players run commands.
if (TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())
|| TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOURIST_COMMAND_LIMITATION_BYPASS.getNode()))
return;
|| TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOURIST_COMMAND_LIMITATION_BYPASS.getNode()))
return;

Town town = TownyAPI.getInstance().getTown(player.getLocation());
if (town == null)
Expand All @@ -1133,7 +1134,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) {
/*
* Commands are sometimes blocked from being run inside any town.
*/
if (TownySettings.getTownBlacklistedCommands().contains(command) && !TownyAPI.getInstance().isWilderness(player.getLocation())) {
if (listContainsCommand(TownySettings.getTownBlacklistedCommands(), command) && !TownyAPI.getInstance().isWilderness(player.getLocation())) {
// Let admins run commands.
if (TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode()))
return;
Expand All @@ -1146,7 +1147,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) {
/*
* Commands are sometimes limited to only plots that players personally own.
*/
if (TownySettings.getPlayerOwnedPlotLimitedCommands().contains(command)) {
if (listContainsCommand(TownySettings.getPlayerOwnedPlotLimitedCommands(), command)) {
// Let admins run commands.
if (TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode()))
return;
Expand Down Expand Up @@ -1198,6 +1199,10 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) {
}

}

private boolean listContainsCommand(List<String> list, String command) {
return list.stream().anyMatch(command::equalsIgnoreCase);
}

/*
* Handles AdminTool use on Blocks
Expand Down

0 comments on commit 8bc8162

Please sign in to comment.