Skip to content

Add /town nearby command#8040

Merged
LlmDl merged 9 commits intoTownyAdvanced:masterfrom
Nrleryx:feature/town-nearby-command
Dec 13, 2025
Merged

Add /town nearby command#8040
LlmDl merged 9 commits intoTownyAdvanced:masterfrom
Nrleryx:feature/town-nearby-command

Conversation

@Nrleryx
Copy link
Copy Markdown
Contributor

@Nrleryx Nrleryx commented Dec 13, 2025

Description
Adds a new /town nearby command that lists the 10 nearest towns sorted by distance from the player's current location.

Changes

  • Added TOWNY_COMMAND_TOWN_NEARBY permission node
  • Added parseTownNearbyCommand() method in TownCommand.java
  • Added command case handler for "nearby"
  • Added permission definition in plugin.yml
  • Added translation strings in en-US.yml

Features

  • Lists up to 10 nearest towns
  • Shows distance in blocks
  • Displays nation information if town is in a nation
  • Filters towns by same world
  • Handles edge cases (no towns found, world not using Towny)

Testing

  • Tested with towns in same world
  • Tested with towns in different worlds
  • Tested with no towns nearby

  • I have tested this pull request for defects on a server.

By making this pull request, I represent that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the TownyAdvanced organization has the copyright to use and modify my contribution under the Towny License for perpetuity.

Copy link
Copy Markdown
Member

@LlmDl LlmDl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found some things to change.

I've also tested the jar and I cannot get it to list any towns, it just says "No towns found nearby." so you should probably retest it.

Thanks for the pull request.

@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Thanks for the review! I've addressed all the feedback:

  • Moved "nearby" to alphabetical order (just above "new")
  • Added town.hasWorld() check before accessing town.getWorld()
  • Added help menu entry using town_help_11 in HelpMenu class
  • Moved hardcoded strings to lang file (msg_nearby_town_format and msg_nearby_town_nation)
  • Changed empty check to throw exception instead of returning
  • Added permission to townyperms.yml in nomad section
  • Added entry to config-migration.json using TOWNYPERMS_ADD
  • Switched from Stream API to for loop for better reliability

I've also fixed the issue where no towns were showing - the problem was with the stream filtering. The for loop approach should work correctly now.

Please let me know if there's anything else that needs to be changed!

…ssages, help menu, townyperms, config migration
@Nrleryx Nrleryx force-pushed the feature/town-nearby-command branch from b4b4801 to ad21f3f Compare December 13, 2025 16:08
@Nrleryx Nrleryx force-pushed the feature/town-nearby-command branch from df4ea28 to a129cf3 Compare December 13, 2025 16:55
@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

All review comments addressed:

  • Using town_help_36 instead of town_help_11
  • Added version section 0.102.0.2 in config-migration.json
  • Removed BASIT_OZELLIKLER.md
  • Fixed TownCommand.java formatting - only new code added

Ready for review!

Copy link
Copy Markdown
Member

@LlmDl LlmDl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple more things to clean up.

I am pretty sure this command will be able to do some harm to larger servers. If players spam this command it's going to cause a lot of math over and over again.

I had at first thought that this could go in as a /t list by nearby command so that it would use our Comparator caches. Then I realized that it wouldn't work well because the list would be different for each player.

Although I like the idea here, I don't think we can add it without some sort of cache and having this done on its own thread.

@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Fixed:

  • Removed duplicate town_help entries from en-US.yml
  • Fixed HelpMenu to use town_help_11
  • Made nearby command async for better performance

@Nrleryx Nrleryx requested a review from LlmDl December 13, 2025 17:22
…ssary scheduler, fix exception handling, move language strings to end of file
@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Addressed all review comments: optimized distance calculation with Map, removed unnecessary scheduler and exception handling, moved language strings to end of file.

@Nrleryx Nrleryx requested a review from LlmDl December 13, 2025 17:33
Copy link
Copy Markdown
Member

@LlmDl LlmDl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good now, we'll see what Warrior thinks.

@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Thanks! Waiting.

@Nrleryx Nrleryx requested a review from LlmDl December 13, 2025 18:02
@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Optimizations applied. Thanks!

Copy link
Copy Markdown
Member

@Warriorrrr Warriorrrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final thing I noticed, the rest looks good.

@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Updated to use minimessage colors. Thanks!

@Nrleryx Nrleryx requested a review from Warriorrrr December 13, 2025 18:28
Copy link
Copy Markdown
Member

@LlmDl LlmDl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the jar and it is working now, thanks.

@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Thanks for testing! Will this be merged soon? @LlmDl @Warriorrrr

@LlmDl LlmDl added this to the 0.102.1.0 milestone Dec 13, 2025
@LlmDl
Copy link
Copy Markdown
Member

LlmDl commented Dec 13, 2025

Thanks for testing! Will this be merged soon? @LlmDl @Warriorrrr

It'll get merged before the next pre-release

@Nrleryx
Copy link
Copy Markdown
Contributor Author

Nrleryx commented Dec 13, 2025

Thanks for the update! Do you have an approximate ETA for the next pre-release?

@Warriorrrr Warriorrrr removed their request for review December 13, 2025 20:18
@LlmDl LlmDl merged commit 362fbb6 into TownyAdvanced:master Dec 13, 2025
1 check passed
LlmDl added a commit that referenced this pull request Dec 13, 2025
    - Adds a configurable system based on town age and size limits, to
refund recently-made, "small" towns their full cost.
    - Closes #7974.
  - New Config Option:
economy.refund_deleted_new_towns.allow_refund_on_deletion
    - Default: false
    - Will towns that are recently created allow for a refund when the
town is deleted by using the /t delete command?
    - This allows a player who has founded their town in the wrong place
to delete their town and move it.
    - Towns must be less than the age specified below and have a
configuable number of townblocks.
  - New Config Option:
economy.refund_deleted_new_towns.max_town_age_in_hours
    - Default: 1
    - How many hours old is a town allowed to be in order to get the
refund when being deleted.
  - New Config Option: economy.refund_deleted_new_towns.max_townblocks
    - Default: 8
    - How many townblocks is a town allowed to have in order to qualify
for the refund.
  - Fix exception when attempting to query NPC perms through LuckPerms,
courtesy of Warrior with PR #8033.
  - Future proof minecraft version parsing, courtesy of Warrior with
PR #8034.
  - Fix 2 points where permission node tests bypass the adminbypass
mode.
  - Add /town nearby command, courtesy of Nrleryx with PR #8040.
(First-Time Contributor!)
  - New Permission Node: towny.command.town.nearby
    - Will be automatically added to your nomads in the townyperms.yml.
  - New Command: /town nearby
    - Shows a player up to 10 towns that are nearest to the player in
the order of closest to furthest.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants