From e94a80b6195bd4984312f632e9f22a006d5f7d89 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Fri, 2 Apr 2021 23:31:03 -0300 Subject: [PATCH 01/21] Trying out eclipse --- resources/chinese.yml | 2 ++ resources/english.yml | 2 ++ resources/es-419.yml | 4 ++- resources/french.yml | 2 ++ resources/german.yml | 2 ++ resources/italian.yml | 2 ++ resources/korean.yml | 2 ++ resources/norwegian.yml | 2 ++ resources/polish.yml | 2 ++ resources/pt-br.yml | 2 ++ resources/russian.yml | 2 ++ resources/se-SV.yml | 2 ++ resources/spanish.yml | 2 ++ resources/zh-TW.yml | 2 ++ .../bukkit/config/ConfigNodes.java | 16 ++++++++++++ .../bukkit/towny/TownySettings.java | 8 ++++++ .../towny/listeners/TownyPlayerListener.java | 25 +++++++++++++++++++ 17 files changed, 78 insertions(+), 1 deletion(-) diff --git a/resources/chinese.yml b/resources/chinese.yml index 6711c1914d..79933ae23c 100644 --- a/resources/chinese.yml +++ b/resources/chinese.yml @@ -1374,3 +1374,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file diff --git a/resources/english.yml b/resources/english.yml index 7862787189..15406947df 100644 --- a/resources/english.yml +++ b/resources/english.yml @@ -1372,3 +1372,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file diff --git a/resources/es-419.yml b/resources/es-419.yml index 334f205b9c..27367b3193 100644 --- a/resources/es-419.yml +++ b/resources/es-419.yml @@ -1391,4 +1391,6 @@ msg_ta_allies_enemies_updated: '&bSe actualizaron los aliados/enemigos de %s.' # Añadido en la versión 0.102 towny_map_detailed_information: '&2Clic para ver información detallada del terreno.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' -msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' \ No newline at end of file +msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/french.yml b/resources/french.yml index d2380419b3..f0f387d4b7 100644 --- a/resources/french.yml +++ b/resources/french.yml @@ -1374,3 +1374,5 @@ msg_ta_allies_enemies_updated: "&bAlliés / Ennemis mis à jour pour %s." towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/german.yml b/resources/german.yml index ddce5e4b4d..2c02832830 100644 --- a/resources/german.yml +++ b/resources/german.yml @@ -1376,3 +1376,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/italian.yml b/resources/italian.yml index c46edc5cae..1bb8d8ef1b 100644 --- a/resources/italian.yml +++ b/resources/italian.yml @@ -1375,3 +1375,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/korean.yml b/resources/korean.yml index a99eba1bae..3c434e6734 100644 --- a/resources/korean.yml +++ b/resources/korean.yml @@ -1286,3 +1286,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file diff --git a/resources/norwegian.yml b/resources/norwegian.yml index 311aeda60f..d6fe929580 100644 --- a/resources/norwegian.yml +++ b/resources/norwegian.yml @@ -1373,3 +1373,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/polish.yml b/resources/polish.yml index f695bfc82f..c07d2565b5 100644 --- a/resources/polish.yml +++ b/resources/polish.yml @@ -1372,3 +1372,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/pt-br.yml b/resources/pt-br.yml index 3becf93201..10cff50fef 100644 --- a/resources/pt-br.yml +++ b/resources/pt-br.yml @@ -1377,3 +1377,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file diff --git a/resources/russian.yml b/resources/russian.yml index e6002ac018..950b61c97d 100644 --- a/resources/russian.yml +++ b/resources/russian.yml @@ -1373,3 +1373,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/se-SV.yml b/resources/se-SV.yml index a0cd1b390d..dfa0f7739a 100644 --- a/resources/se-SV.yml +++ b/resources/se-SV.yml @@ -1371,3 +1371,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/spanish.yml b/resources/spanish.yml index 1a69da5994..416d7df8b7 100644 --- a/resources/spanish.yml +++ b/resources/spanish.yml @@ -1374,3 +1374,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/resources/zh-TW.yml b/resources/zh-TW.yml index 613a4457c1..e1c42acf3f 100644 --- a/resources/zh-TW.yml +++ b/resources/zh-TW.yml @@ -1372,3 +1372,5 @@ msg_ta_allies_enemies_updated: '&bAllies/Enemies updated for %s.' towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' + +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' diff --git a/src/com/palmergames/bukkit/config/ConfigNodes.java b/src/com/palmergames/bukkit/config/ConfigNodes.java index f36f6cace8..2dc7565daa 100644 --- a/src/com/palmergames/bukkit/config/ConfigNodes.java +++ b/src/com/palmergames/bukkit/config/ConfigNodes.java @@ -761,6 +761,22 @@ public enum ConfigNodes { "# For example, to give a `visemayor` preference over an `assistant`, change this parameter to `visemayor,assistant`." ), + GTOWN_SETTINGS_ENABLE_COMMAND_BLACKLISTING( + "global_town_settings.allow_town_command_blacklisting", + "true", + "", + "# Allows blocking commands inside towns through the town_blacklisted_commands setting.", + "# This boolean allows you to disable this feature altogether if you don't need it" + ), + + GTOWN_TOWN_BLACKLISTED_COMMANDS( + "global_town_settings.town_blacklisted_commands", + "somecommandhere", + "", + "# Similar to the jail command blacklist feature, but allows blocking commands inside towns.", + "# This can be useful if you want to block sethome/home commands while inside any town." + ), + GNATION_SETTINGS( "global_nation_settings", "", diff --git a/src/com/palmergames/bukkit/towny/TownySettings.java b/src/com/palmergames/bukkit/towny/TownySettings.java index 2df5f24c4f..4bf41bd421 100644 --- a/src/com/palmergames/bukkit/towny/TownySettings.java +++ b/src/com/palmergames/bukkit/towny/TownySettings.java @@ -3048,5 +3048,13 @@ public static boolean doesFrostWalkerRequireBuildPerms() { public static boolean isNotificationsAppearingOnBossbar() { return getBoolean(ConfigNodes.NOTIFICATION_NOTIFICATIONS_APPEAR_ON_BOSSBAR); } + + public static boolean allowTownCommandBlacklisting() { + return getBoolean(ConfigNodes.GTOWN_SETTINGS_ENABLE_COMMAND_BLACKLISTING); + } + + public static List getTownBlacklistedCommands() { + return getStrArr(ConfigNodes.GTOWN_TOWN_BLACKLISTED_COMMANDS); + } } diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 042cfc1c68..bcb8ff425b 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1003,6 +1003,31 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { } } + /** + * Allows restricting commands while being on an town. + * Works almost the same way as jail command blacklisting. + * @param event + */ + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { + if (plugin.isError()) + return; + + if (!TownySettings.allowTownCommandBlacklisting()) + return; + + Resident res = TownyUniverse.getInstance().getResident(event.getPlayer().getUniqueId()); + + if (res == null) + return; + + String[] split = event.getMessage().substring(1).split(" "); + if (TownySettings.getTownBlacklistedCommands().contains(split[0])) { + TownyMessaging.sendErrorMsg(event.getPlayer(), Translation.of("msg_command_blocked_inside_towns")); + event.setCancelled(true); + } + } + /* * Handles AdminTool use on Blocks */ From 7a76983a6450a77852f946deff4487e1f0f650d2 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Sat, 3 Apr 2021 12:14:38 -0300 Subject: [PATCH 02/21] Implement perm node for bypassing this --- src/com/palmergames/bukkit/config/ConfigNodes.java | 2 +- .../bukkit/towny/listeners/TownyPlayerListener.java | 3 ++- .../palmergames/bukkit/towny/permissions/PermissionNodes.java | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/com/palmergames/bukkit/config/ConfigNodes.java b/src/com/palmergames/bukkit/config/ConfigNodes.java index 2dc7565daa..ef8f0bd3e0 100644 --- a/src/com/palmergames/bukkit/config/ConfigNodes.java +++ b/src/com/palmergames/bukkit/config/ConfigNodes.java @@ -771,7 +771,7 @@ public enum ConfigNodes { GTOWN_TOWN_BLACKLISTED_COMMANDS( "global_town_settings.town_blacklisted_commands", - "somecommandhere", + "somecommandhere, someothercommandhere", "", "# Similar to the jail command blacklist feature, but allows blocking commands inside towns.", "# This can be useful if you want to block sethome/home commands while inside any town." diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index bcb8ff425b..b5b6c3bf26 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1018,7 +1018,8 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { Resident res = TownyUniverse.getInstance().getResident(event.getPlayer().getUniqueId()); - if (res == null) + if (res == null || TownyAPI.getInstance().isWilderness(event.getPlayer().getLocation()) || + event.getPlayer().hasPermission(PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) return; String[] split = event.getMessage().substring(1).split(" "); diff --git a/src/com/palmergames/bukkit/towny/permissions/PermissionNodes.java b/src/com/palmergames/bukkit/towny/permissions/PermissionNodes.java index dbfc260da9..7bcb755914 100644 --- a/src/com/palmergames/bukkit/towny/permissions/PermissionNodes.java +++ b/src/com/palmergames/bukkit/towny/permissions/PermissionNodes.java @@ -8,6 +8,8 @@ public enum PermissionNodes { TOWNY_ADMIN("towny.admin"), TOWNY_ADMIN_NATION_ZONE("towny.admin.nation_zone"), TOWNY_ADMIN_OUTLAW_TELEPORT_BYPASS("towny.admin.outlaw.teleport_bypass"), + TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS("towny.admin.town_commands.blacklist_bypass"), + /* * Nation command permissions */ From b6724f555a64d2dd2f7ea55eb4616f2c83c7a051 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Sat, 3 Apr 2021 12:44:30 -0300 Subject: [PATCH 03/21] tweaks and adds limited commands --- resources/chinese.yml | 3 ++- resources/english.yml | 3 ++- resources/es-419.yml | 1 + resources/french.yml | 3 ++- resources/german.yml | 3 ++- resources/italian.yml | 1 + resources/korean.yml | 3 ++- resources/norwegian.yml | 3 ++- resources/polish.yml | 3 ++- resources/pt-br.yml | 3 ++- resources/russian.yml | 3 ++- resources/se-SV.yml | 1 + resources/spanish.yml | 3 ++- resources/zh-TW.yml | 3 ++- .../bukkit/config/ConfigNodes.java | 23 +++++++++++++++---- .../bukkit/towny/TownySettings.java | 4 ++++ .../towny/listeners/TownyPlayerListener.java | 7 ++++++ 17 files changed, 54 insertions(+), 16 deletions(-) diff --git a/resources/chinese.yml b/resources/chinese.yml index 79933ae23c..400aae7181 100644 --- a/resources/chinese.yml +++ b/resources/chinese.yml @@ -1375,4 +1375,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/english.yml b/resources/english.yml index 15406947df..e3b10ed9ac 100644 --- a/resources/english.yml +++ b/resources/english.yml @@ -1373,4 +1373,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/es-419.yml b/resources/es-419.yml index 27367b3193..3af74896c7 100644 --- a/resources/es-419.yml +++ b/resources/es-419.yml @@ -1394,3 +1394,4 @@ msg_err_nation_capital_too_many_residents: '&cThe current capital city has too m msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/french.yml b/resources/french.yml index f0f387d4b7..3733be4e26 100644 --- a/resources/french.yml +++ b/resources/french.yml @@ -1375,4 +1375,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/german.yml b/resources/german.yml index 2c02832830..2dea14f29e 100644 --- a/resources/german.yml +++ b/resources/german.yml @@ -1377,4 +1377,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/italian.yml b/resources/italian.yml index 1bb8d8ef1b..cc7cf24f7b 100644 --- a/resources/italian.yml +++ b/resources/italian.yml @@ -1377,3 +1377,4 @@ msg_err_nation_capital_too_many_residents: '&cThe current capital city has too m msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/korean.yml b/resources/korean.yml index 3c434e6734..8e5fd7f832 100644 --- a/resources/korean.yml +++ b/resources/korean.yml @@ -1287,4 +1287,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/norwegian.yml b/resources/norwegian.yml index d6fe929580..f2f6e83629 100644 --- a/resources/norwegian.yml +++ b/resources/norwegian.yml @@ -1374,4 +1374,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/polish.yml b/resources/polish.yml index c07d2565b5..1ab691f7c9 100644 --- a/resources/polish.yml +++ b/resources/polish.yml @@ -1373,4 +1373,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/pt-br.yml b/resources/pt-br.yml index 10cff50fef..c49ed1dabd 100644 --- a/resources/pt-br.yml +++ b/resources/pt-br.yml @@ -1378,4 +1378,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' \ No newline at end of file +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/russian.yml b/resources/russian.yml index 950b61c97d..82c67ecb01 100644 --- a/resources/russian.yml +++ b/resources/russian.yml @@ -1374,4 +1374,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/se-SV.yml b/resources/se-SV.yml index dfa0f7739a..ba48abba2f 100644 --- a/resources/se-SV.yml +++ b/resources/se-SV.yml @@ -1373,3 +1373,4 @@ msg_err_nation_capital_too_many_residents: '&cThe current capital city has too m msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/spanish.yml b/resources/spanish.yml index 416d7df8b7..c59816db4d 100644 --- a/resources/spanish.yml +++ b/resources/spanish.yml @@ -1375,4 +1375,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/resources/zh-TW.yml b/resources/zh-TW.yml index e1c42acf3f..1c7aa4a577 100644 --- a/resources/zh-TW.yml +++ b/resources/zh-TW.yml @@ -1373,4 +1373,5 @@ towny_map_detailed_information: '&2Click to see detailed plot information.' msg_err_nation_capital_too_many_residents: '&cThe current capital city has too many residents to be replaced by %s.' msg_deleting_nation_will_result_in_losing_residents: '&cWarning: Deleting your nation will mean your town is over the population limit of %d, resulting in the removal of %d residents.' -msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_blocked_inside_towns: '&cYou cannot use that command inside towns.' +msg_command_limited: 'You can only use that command inside your own plots.' diff --git a/src/com/palmergames/bukkit/config/ConfigNodes.java b/src/com/palmergames/bukkit/config/ConfigNodes.java index ef8f0bd3e0..9ed32158e7 100644 --- a/src/com/palmergames/bukkit/config/ConfigNodes.java +++ b/src/com/palmergames/bukkit/config/ConfigNodes.java @@ -761,8 +761,15 @@ public enum ConfigNodes { "# For example, to give a `visemayor` preference over an `assistant`, change this parameter to `visemayor,assistant`." ), + GTOWN_SETTINGS_COMMAND_BLACKLISTING( + "global_town_settings.town_command_blacklisting", + "", + "", + "# Allows blocking commands inside towns and limiting them to plots owned by the players only.", + "# Useful for limiting sethome/home commands to plots owned by the players themselves and not someone else." + ), GTOWN_SETTINGS_ENABLE_COMMAND_BLACKLISTING( - "global_town_settings.allow_town_command_blacklisting", + "global_town_settings.town_command_blacklisting.enabled", "true", "", "# Allows blocking commands inside towns through the town_blacklisted_commands setting.", @@ -770,11 +777,17 @@ public enum ConfigNodes { ), GTOWN_TOWN_BLACKLISTED_COMMANDS( - "global_town_settings.town_blacklisted_commands", - "somecommandhere, someothercommandhere", + "global_town_settings.town_command_blacklisting.blacklisted_commands", + "somecommandhere,othercommandhere", + "", + "# Comma separated list of commands to block inside towns." + ), + + GTOWN_TOWN_LIMITED_COMMANDS( + "global_town_settings.town_command_blacklisting.limited_commands", + "sethome,home", "", - "# Similar to the jail command blacklist feature, but allows blocking commands inside towns.", - "# This can be useful if you want to block sethome/home commands while inside any town." + "# This allows the usage of blacklisted commands only in plots owned by the player." ), GNATION_SETTINGS( diff --git a/src/com/palmergames/bukkit/towny/TownySettings.java b/src/com/palmergames/bukkit/towny/TownySettings.java index 4bf41bd421..679371a55c 100644 --- a/src/com/palmergames/bukkit/towny/TownySettings.java +++ b/src/com/palmergames/bukkit/towny/TownySettings.java @@ -3056,5 +3056,9 @@ public static boolean allowTownCommandBlacklisting() { public static List getTownBlacklistedCommands() { return getStrArr(ConfigNodes.GTOWN_TOWN_BLACKLISTED_COMMANDS); } + + public static List getTownLimitedCommands() { + return getStrArr(ConfigNodes.GTOWN_TOWN_LIMITED_COMMANDS); + } } diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index b5b6c3bf26..5189ce4a01 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1018,12 +1018,19 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { Resident res = TownyUniverse.getInstance().getResident(event.getPlayer().getUniqueId()); + if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) + return; + if (res == null || TownyAPI.getInstance().isWilderness(event.getPlayer().getLocation()) || event.getPlayer().hasPermission(PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) return; String[] split = event.getMessage().substring(1).split(" "); if (TownySettings.getTownBlacklistedCommands().contains(split[0])) { + if (TownySettings.getTownLimitedCommands().contains(split[0])) { + + } + TownyMessaging.sendErrorMsg(event.getPlayer(), Translation.of("msg_command_blocked_inside_towns")); event.setCancelled(true); } From 51bb57bd93e693490349e626f56938aad04bc168 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Sat, 3 Apr 2021 12:48:14 -0300 Subject: [PATCH 04/21] adds perm node to plugin.yml --- resources/plugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/plugin.yml b/resources/plugin.yml index a78eb8d6b4..b34c78e01c 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -60,6 +60,7 @@ permissions: towny.admin.nation_zone: true towny.admin.outlaw.teleport_bypass: true towny.admin.spawn: true + towny.admin.town_commands.blacklist_bypass: true towny.outlaw.jailer: description: Node given in townyperms.yml to mayors, assistants and sheriffs by default. Required to jail outlaws that are killed in a town. From 98d9135bf203a197463af330a7a012ecf3a9e624 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 10:55:35 -0400 Subject: [PATCH 05/21] try to get this to work --- .../towny/listeners/TownyPlayerListener.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 5189ce4a01..8e72de8b7b 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -77,6 +77,7 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.scheduler.BukkitRunnable; +import java.awt.image.RescaleOp; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -1005,8 +1006,9 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { /** * Allows restricting commands while being on an town. + * Also allows limiting commands to self owned plots only. * Works almost the same way as jail command blacklisting. - * @param event + * @param event PlayerCommandPreprocessEvent */ @EventHandler(priority = EventPriority.NORMAL) public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { @@ -1016,22 +1018,35 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { if (!TownySettings.allowTownCommandBlacklisting()) return; - Resident res = TownyUniverse.getInstance().getResident(event.getPlayer().getUniqueId()); + Player player = event.getPlayer(); + Resident res = TownyUniverse.getInstance().getResident(player.getUniqueId()); if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) return; - if (res == null || TownyAPI.getInstance().isWilderness(event.getPlayer().getLocation()) || + if (res == null || TownyAPI.getInstance().isWilderness(player.getLocation()) || event.getPlayer().hasPermission(PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) return; String[] split = event.getMessage().substring(1).split(" "); - if (TownySettings.getTownBlacklistedCommands().contains(split[0])) { - if (TownySettings.getTownLimitedCommands().contains(split[0])) { + + if (TownySettings.getTownLimitedCommands().contains(split[0])) { + WorldCoord worldCoord = WorldCoord.parseWorldCoord(player.getLocation()); + + if (worldCoord.hasTownBlock()) { + TownBlock tb = worldCoord.getTownBlock(); + if (tb.hasResident()) { + if (tb.getResident().getName() != player.getName()) { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); + event.setCancelled(true); + } + } } - - TownyMessaging.sendErrorMsg(event.getPlayer(), Translation.of("msg_command_blocked_inside_towns")); + } + + if (TownySettings.getTownBlacklistedCommands().contains(split[0])) { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_blocked_inside_towns")); event.setCancelled(true); } } From 2c6d2556346dc80824906bfbf0d34018b3fd9452 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 11:04:09 -0400 Subject: [PATCH 06/21] fix maven crying a river because nre was not caught --- .../bukkit/towny/listeners/TownyPlayerListener.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 8e72de8b7b..0d736b1312 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1009,9 +1009,10 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { * Also allows limiting commands to self owned plots only. * Works almost the same way as jail command blacklisting. * @param event PlayerCommandPreprocessEvent + * @throws exception NotRegisteredException */ @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { + public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) throws NotRegisteredException { if (plugin.isError()) return; From 8dea99703ad0d825f321a2639aeb993b85ae9fac Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 11:10:56 -0400 Subject: [PATCH 07/21] why are u crying about the javadocs --- .../towny/listeners/TownyPlayerListener.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 0d736b1312..c8135703b5 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1009,10 +1009,9 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { * Also allows limiting commands to self owned plots only. * Works almost the same way as jail command blacklisting. * @param event PlayerCommandPreprocessEvent - * @throws exception NotRegisteredException */ @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) throws NotRegisteredException { + public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { if (plugin.isError()) return; @@ -1035,10 +1034,24 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) th WorldCoord worldCoord = WorldCoord.parseWorldCoord(player.getLocation()); if (worldCoord.hasTownBlock()) { - TownBlock tb = worldCoord.getTownBlock(); + TownBlock tb; + + try { + tb = worldCoord.getTownBlock(); + } catch(NotRegisteredException nre) { + return; + } if (tb.hasResident()) { - if (tb.getResident().getName() != player.getName()) { + + Resident owner; + try { + owner = tb.getResident(); + } catch(NotRegisteredException nre) { + return; + } + + if (owner.getName() != player.getName()) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); } From f187e218952005f5685951baf4e0fa4ef1206b87 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 11:47:46 -0400 Subject: [PATCH 08/21] add fixes made by llmdl --- .../towny/listeners/TownyPlayerListener.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index c8135703b5..16dcd19b33 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1024,13 +1024,18 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) return; - if (res == null || TownyAPI.getInstance().isWilderness(player.getLocation()) || - event.getPlayer().hasPermission(PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) + if (res == null || event.getPlayer().hasPermission(PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) return; String[] split = event.getMessage().substring(1).split(" "); if (TownySettings.getTownLimitedCommands().contains(split[0])) { + if (TownyAPI.getInstance().isWilderness(player.getLocation())) { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); + event.setCancelled(true); + return; + } + WorldCoord worldCoord = WorldCoord.parseWorldCoord(player.getLocation()); if (worldCoord.hasTownBlock()) { @@ -1043,23 +1048,22 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { } if (tb.hasResident()) { + Resident owner = null; - Resident owner; try { owner = tb.getResident(); - } catch(NotRegisteredException nre) { - return; - } + } catch(NotRegisteredException nre) {} if (owner.getName() != player.getName()) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); + return; } - } + } } } - if (TownySettings.getTownBlacklistedCommands().contains(split[0])) { + if (TownySettings.getTownBlacklistedCommands().contains(split[0]) && !TownyAPI.getInstance().isWilderness(player.getLocation())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_blocked_inside_towns")); event.setCancelled(true); } From f40bbfe2462830b5b0e4f2d48d1e76799a8f858d Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 11:57:19 -0400 Subject: [PATCH 09/21] adds checks that were missing --- .../towny/listeners/TownyPlayerListener.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 16dcd19b33..93491ea375 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1012,10 +1012,8 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { */ @EventHandler(priority = EventPriority.NORMAL) public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { - if (plugin.isError()) - return; - - if (!TownySettings.allowTownCommandBlacklisting()) + if (plugin.isError() || !TownySettings.allowTownCommandBlacklisting() || + !TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) return; Player player = event.getPlayer(); @@ -1024,7 +1022,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) return; - if (res == null || event.getPlayer().hasPermission(PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) + if (res == null || TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) return; String[] split = event.getMessage().substring(1).split(" "); @@ -1039,7 +1037,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { WorldCoord worldCoord = WorldCoord.parseWorldCoord(player.getLocation()); if (worldCoord.hasTownBlock()) { - TownBlock tb; + TownBlock tb = null; try { tb = worldCoord.getTownBlock(); @@ -1058,6 +1056,10 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); return; + } else { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); + event.setCancelled(true); + return; } } } From a5679b02039b74e169ec766e28aabc0a406cc9bb Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 12:21:43 -0400 Subject: [PATCH 10/21] Change getTownLimitedCommands() to getPlayerOwnedPlotLimdCommands --- src/com/palmergames/bukkit/towny/TownySettings.java | 2 +- .../palmergames/bukkit/towny/listeners/TownyPlayerListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/TownySettings.java b/src/com/palmergames/bukkit/towny/TownySettings.java index 679371a55c..4559947072 100644 --- a/src/com/palmergames/bukkit/towny/TownySettings.java +++ b/src/com/palmergames/bukkit/towny/TownySettings.java @@ -3057,7 +3057,7 @@ public static List getTownBlacklistedCommands() { return getStrArr(ConfigNodes.GTOWN_TOWN_BLACKLISTED_COMMANDS); } - public static List getTownLimitedCommands() { + public static List getPlayerOwnedPlotLimitedCommands() { return getStrArr(ConfigNodes.GTOWN_TOWN_LIMITED_COMMANDS); } } diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 93491ea375..1d68b0c341 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1027,7 +1027,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { String[] split = event.getMessage().substring(1).split(" "); - if (TownySettings.getTownLimitedCommands().contains(split[0])) { + if (TownySettings.getPlayerOwnedPlotLimitedCommands().contains(split[0])) { if (TownyAPI.getInstance().isWilderness(player.getLocation())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); From c748fa069678f9b4e672d1a5c1a30b683cdb1a2e Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 12:29:51 -0400 Subject: [PATCH 11/21] remove unused import --- .../palmergames/bukkit/towny/listeners/TownyPlayerListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 1d68b0c341..543c0feecc 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -77,7 +77,6 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.scheduler.BukkitRunnable; -import java.awt.image.RescaleOp; import java.util.Arrays; import java.util.HashMap; import java.util.Map; From 6bc6d1e38dae1d471d17f5c71428f93d8e6e254a Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 12:35:55 -0400 Subject: [PATCH 12/21] add tests for owntown and townowned nodes --- .../bukkit/towny/listeners/TownyPlayerListener.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 543c0feecc..713373076f 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1051,7 +1051,8 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { owner = tb.getResident(); } catch(NotRegisteredException nre) {} - if (owner.getName() != player.getName()) { + if (owner.getName() != player.getName() || + !TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.owntown.*")) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); return; @@ -1060,7 +1061,13 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { event.setCancelled(true); return; } - } + } else { + if (!TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.townowned.*")) { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); + event.setCancelled(true); + return; + } + } } } From bbbab69781a5a0af74380e86d59f7770d71aaead Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 6 Apr 2021 13:11:24 -0400 Subject: [PATCH 13/21] fix commands being blocked even if they shouldn't --- .../palmergames/bukkit/towny/listeners/TownyPlayerListener.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 713373076f..58c298a438 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1057,8 +1057,6 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { event.setCancelled(true); return; } else { - TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); - event.setCancelled(true); return; } } else { From c9cb8383646be64cd24f60b4a12e92484dedeca2 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:15:48 -0400 Subject: [PATCH 14/21] limited cmds actually work now lol --- .../bukkit/towny/listeners/TownyPlayerListener.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 58c298a438..4861395676 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1006,7 +1006,7 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { /** * Allows restricting commands while being on an town. * Also allows limiting commands to self owned plots only. - * Works almost the same way as jail command blacklisting. + * Works almost the same way as jail command blacklisting, except has more stuff * @param event PlayerCommandPreprocessEvent */ @EventHandler(priority = EventPriority.NORMAL) @@ -1049,10 +1049,14 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { try { owner = tb.getResident(); - } catch(NotRegisteredException nre) {} + } catch(NotRegisteredException nre) { return; } - if (owner.getName() != player.getName() || - !TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.owntown.*")) { + if (TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.owntown.*")) return; + + TownyMessaging.sendMsg("OwnerName: " + owner.getName()); + TownyMessaging.sendMsg("PlayerName: " + player.getName()); + + if (!owner.getName().equals(player.getName())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); return; @@ -1072,6 +1076,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { if (TownySettings.getTownBlacklistedCommands().contains(split[0]) && !TownyAPI.getInstance().isWilderness(player.getLocation())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_blocked_inside_towns")); event.setCancelled(true); + return; } } From 0c6e59e40cf3f1385786d50ec6d6a6719761aeb9 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Mon, 19 Apr 2021 08:59:30 -0400 Subject: [PATCH 15/21] requested changes (#1) --- src/com/palmergames/bukkit/config/ConfigNodes.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/palmergames/bukkit/config/ConfigNodes.java b/src/com/palmergames/bukkit/config/ConfigNodes.java index 9ed32158e7..dcdc8ee206 100644 --- a/src/com/palmergames/bukkit/config/ConfigNodes.java +++ b/src/com/palmergames/bukkit/config/ConfigNodes.java @@ -770,7 +770,7 @@ public enum ConfigNodes { ), GTOWN_SETTINGS_ENABLE_COMMAND_BLACKLISTING( "global_town_settings.town_command_blacklisting.enabled", - "true", + "false", "", "# Allows blocking commands inside towns through the town_blacklisted_commands setting.", "# This boolean allows you to disable this feature altogether if you don't need it" From 6263ef555b7f1de13e589bed078f8875c8949b14 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Mon, 19 Apr 2021 09:00:16 -0400 Subject: [PATCH 16/21] requested changes (#2) --- .../bukkit/towny/listeners/TownyPlayerListener.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 4861395676..b09f3692bf 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1052,10 +1052,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { } catch(NotRegisteredException nre) { return; } if (TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.owntown.*")) return; - - TownyMessaging.sendMsg("OwnerName: " + owner.getName()); - TownyMessaging.sendMsg("PlayerName: " + player.getName()); - + if (!owner.getName().equals(player.getName())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); From d8b7a26f028b08f767dd07c7b6136a4d58d65e1e Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Mon, 19 Apr 2021 09:02:47 -0400 Subject: [PATCH 17/21] fix bypass not checking for res township (req. changes) --- .../palmergames/bukkit/towny/listeners/TownyPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index b09f3692bf..1b40d650c8 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1061,7 +1061,7 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { return; } } else { - if (!TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.townowned.*")) { + if (!TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.townowned.*") && tb.getTown().hasResident(player.getName())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); return; From a37b855bab7fd13c94d28fa90bc5f7a856b9d045 Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Mon, 19 Apr 2021 09:03:46 -0400 Subject: [PATCH 18/21] remove repeated check left from older commits (req changes) --- .../bukkit/towny/listeners/TownyPlayerListener.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 1b40d650c8..96c4781149 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1018,9 +1018,6 @@ public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); Resident res = TownyUniverse.getInstance().getResident(player.getUniqueId()); - if (!TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) - return; - if (res == null || TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) return; From 817f063d8b00aaef855527ab2b2fb584e0d0bf1b Mon Sep 17 00:00:00 2001 From: EuGNosii <65878291+GNosii@users.noreply.github.com> Date: Mon, 19 Apr 2021 09:08:56 -0400 Subject: [PATCH 19/21] mvn exception not caught --- .../palmergames/bukkit/towny/listeners/TownyPlayerListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 96c4781149..28aeeaab25 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1010,7 +1010,7 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { * @param event PlayerCommandPreprocessEvent */ @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { + public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) throws NotRegisteredException { if (plugin.isError() || !TownySettings.allowTownCommandBlacklisting() || !TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) return; From a3bc47b486e676690635fd7978d8d96d41499f11 Mon Sep 17 00:00:00 2001 From: Llm Dl Date: Mon, 19 Apr 2021 09:37:54 -0500 Subject: [PATCH 20/21] Rebase off master and make a couple polishing changes. --- .../bukkit/towny/listeners/TownyPlayerListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 28aeeaab25..86347c32dc 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1004,8 +1004,8 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { } /** - * Allows restricting commands while being on an town. - * Also allows limiting commands to self owned plots only. + * Allows restricting commands while being in a town. + * Also allows limiting commands to personally-owned plots only. * Works almost the same way as jail command blacklisting, except has more stuff * @param event PlayerCommandPreprocessEvent */ From 52123b25ce301771d5538404968eca92f000ca84 Mon Sep 17 00:00:00 2001 From: Llm Dl Date: Thu, 22 Apr 2021 07:24:24 -0500 Subject: [PATCH 21/21] Cleanup Commit & Requested Changes. - Requests from Warriorrrr are made. - Moves town-blocked commands above the personally-owned commands test to reduce the required returns later on. - Switches to the PermissionSource hasOwnTown and hasTownOwned permission tests. --- .../bukkit/config/ConfigNodes.java | 15 ++- .../towny/listeners/TownyPlayerListener.java | 103 +++++++++++------- 2 files changed, 72 insertions(+), 46 deletions(-) diff --git a/src/com/palmergames/bukkit/config/ConfigNodes.java b/src/com/palmergames/bukkit/config/ConfigNodes.java index dcdc8ee206..2b6b19241e 100644 --- a/src/com/palmergames/bukkit/config/ConfigNodes.java +++ b/src/com/palmergames/bukkit/config/ConfigNodes.java @@ -766,7 +766,8 @@ public enum ConfigNodes { "", "", "# Allows blocking commands inside towns and limiting them to plots owned by the players only.", - "# Useful for limiting sethome/home commands to plots owned by the players themselves and not someone else." + "# Useful for limiting sethome/home commands to plots owned by the players themselves and not someone else.", + "# Admins and players with the towny.admin.town_commands.blacklist_bypass permission node will not be hindered." ), GTOWN_SETTINGS_ENABLE_COMMAND_BLACKLISTING( "global_town_settings.town_command_blacklisting.enabled", @@ -777,17 +778,21 @@ public enum ConfigNodes { ), GTOWN_TOWN_BLACKLISTED_COMMANDS( - "global_town_settings.town_command_blacklisting.blacklisted_commands", + "global_town_settings.town_command_blacklisting.town_blacklisted_commands", "somecommandhere,othercommandhere", "", - "# Comma separated list of commands to block inside towns." + "# Comma separated list of commands which cannot be run inside of any town." ), GTOWN_TOWN_LIMITED_COMMANDS( - "global_town_settings.town_command_blacklisting.limited_commands", + "global_town_settings.town_command_blacklisting.player_owned_plot_limited_commands", "sethome,home", "", - "# This allows the usage of blacklisted commands only in plots owned by the player." + "# This allows the usage of blacklisted commands only in plots personally-owned by the player.", + "# Players with the towny.claimed.townowned.* permission node will be able to run these commands", + "# inside of town-owned land. This would include mayors, assistants and possibly a builder rank.", + "# Players with the towny.claimed.owntown.* permission node (given to mayors/assistants usually,)", + "# will also not be limited by this command blacklist." ), GNATION_SETTINGS( diff --git a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java index 86347c32dc..aed01de31a 100644 --- a/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java +++ b/src/com/palmergames/bukkit/towny/listeners/TownyPlayerListener.java @@ -1009,69 +1009,90 @@ public void onJailedPlayerUsesCommand(PlayerCommandPreprocessEvent event) { * Works almost the same way as jail command blacklisting, except has more stuff * @param event PlayerCommandPreprocessEvent */ - @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) throws NotRegisteredException { - if (plugin.isError() || !TownySettings.allowTownCommandBlacklisting() || - !TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerUsesCommandInsideTown(PlayerCommandPreprocessEvent event) { + if (plugin.isError() + || !TownySettings.allowTownCommandBlacklisting() + || !TownyAPI.getInstance().isTownyWorld(event.getPlayer().getWorld())) return; Player player = event.getPlayer(); Resident res = TownyUniverse.getInstance().getResident(player.getUniqueId()); - - if (res == null || TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) + if (res == null) return; - String[] split = event.getMessage().substring(1).split(" "); + String command = event.getMessage().substring(1).split(" ")[0]; + + /* + * Commands are sometimes blocked from being run inside any town. + */ + if (TownySettings.getTownBlacklistedCommands().contains(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; + + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_blocked_inside_towns")); + event.setCancelled(true); + return; + } - if (TownySettings.getPlayerOwnedPlotLimitedCommands().contains(split[0])) { + /* + * Commands are sometimes limited to only plots that players personally own. + */ + if (TownySettings.getPlayerOwnedPlotLimitedCommands().contains(command)) { + // Let admins run commands. + if (TownyUniverse.getInstance().getPermissionSource().has(player, PermissionNodes.TOWNY_ADMIN_TOWN_COMMAND_BLACKLIST_BYPASS.getNode())) + return; + + // Stop the command being run because this is in the wilderness. if (TownyAPI.getInstance().isWilderness(player.getLocation())) { TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); event.setCancelled(true); return; } - WorldCoord worldCoord = WorldCoord.parseWorldCoord(player.getLocation()); + TownBlock tb = TownyAPI.getInstance().getTownBlock(player.getLocation()); + Town town = TownyAPI.getInstance().getTown(player.getLocation()); + if (tb == null || town == null) + return; + + // If the player is in their own town and has towny.claimed.owntown.build.dirt + // (or more likely towny.claimed.owntown.*) then allow them to use the command. + // It is likely a mayor/assistant. + if (town.hasResident(res) && TownyUniverse.getInstance().getPermissionSource().hasOwnTownOverride(player, Material.DIRT, ActionType.BUILD)) + return; - if (worldCoord.hasTownBlock()) { - TownBlock tb = null; + if (tb.hasResident()) { + // This is a personally-owned plot, let's make sure the player is the plot owner. + Resident owner = null; try { - tb = worldCoord.getTownBlock(); - } catch(NotRegisteredException nre) { - return; + owner = tb.getResident(); + } catch(NotRegisteredException nre) { return; } + + // The owner and player are not the same, cancel the command. + if (!owner.getName().equals(player.getName())) { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); + event.setCancelled(true); } + // Player owns this plot personally, we won't limit their command-usage. + } else { + // This is not a personally-owned plot, but let's only block this command if the player isn't special to the town. - if (tb.hasResident()) { - Resident owner = null; - - try { - owner = tb.getResident(); - } catch(NotRegisteredException nre) { return; } + // If the player is in their own town and has towny.claimed.townowned.build.dirt + // (or more likely towny.claimed.townowned.*) then allow them to use the command. + // It is likely a assistant or town-ranked player. + if (town.hasResident(res) && TownyUniverse.getInstance().getPermissionSource().hasTownOwnedOverride(player, Material.DIRT, ActionType.BUILD)) { + return; - if (TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.owntown.*")) return; - - if (!owner.getName().equals(player.getName())) { - TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); - event.setCancelled(true); - return; - } else { - return; - } - } else { - if (!TownyUniverse.getInstance().getPermissionSource().has(player, "towny.claimed.townowned.*") && tb.getTown().hasResident(player.getName())) { - TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); - event.setCancelled(true); - return; - } + // Not a special person, and not in a personally-owned plot, cancel this command. + } else { + TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_limited")); + event.setCancelled(true); } } } - - if (TownySettings.getTownBlacklistedCommands().contains(split[0]) && !TownyAPI.getInstance().isWilderness(player.getLocation())) { - TownyMessaging.sendErrorMsg(player, Translation.of("msg_command_blocked_inside_towns")); - event.setCancelled(true); - return; - } + } /*