Get Started
Documentation
- 🖥️ Commands
- 🏙️ Towns
- 🏠 Claims
- 🔨 Roles
- 🌟 Advancements
- ☯️ Relations
- ⚔️ Wars
- 🚫 Inactive Town Pruning
Developers
- 📦 API v3
- 🧡 Towns API
- ⚙️ Claims API
- ❗ API Events
- 🕸️ API v1 (Legacy)
HuskTowns provides an API for getting, creating, and editing Towns. Note that actions carried out through the API will not fire API Events.
This page assumes you have read the general API introduction and that you have both imported HuskTowns into your project and added it as a dependency.
#getTown(String name)
Optional<Town>
; a town wrapped with an Optional (that will be empty if no town exists with the supplied name
)Town
object has a range of properties and methods for interacting with the town.Town
from a TownClaim
object - see the Claims API for more information.void getTownByName(String townName) {
Optional<Town> town = huskTowns.getTown(townName);
if (town.isPresent()) {
// Do something with the town
Town townObject = town.get();
System.out.println("Town name: " + townObject.getName());
} else {
System.out.println("No town found with the name " + townName);
}
}
#getUserTown(User user)
, which will return an Optional<Member>
for the town the user is in.
Member
is present, you can use Member#town()
to get the Town
objectOnlineUser
is not in a town, the Optional
will be empty (Optional#isEmpty()
)Role
via Member#role()
void showUserTownAndRole(org.bukkit.Player player) {
OnlineUser user = huskTowns.getOnlineUser(player);
Optional<Member> member = huskTowns.getUserTown(user);
if (member.isPresent()) {
Town town = member.get().town();
Role role = member.get().role();
System.out.println("User " + player.getName() + " is in the town " + town.getName() + " with the role " + role.getName());
} else {
System.out.println("User " + player.getName() + " is not in a town");
}
}
Privilege
s a Member
can perform with HuskTownsAPI#isPrivilegeAllowed(Privilege privilege, User user)
true
if the user has the privilege, and false
if they do not.void showCanCreateTownClaims(org.bukkit.Player player) {
boolean allowed = huskTowns.isPrivilegeAllowed(Privilege.CLAIM, huskTowns.getOnlineUser(player));
if (allowed) {
System.out.println("User " + player.getName() + " can create claims");
} else {
System.out.println("User " + player.getName() + " cannot create claims");
}
}
Town
object, then save it with #updateTown(Town town, OnlineUser user)
OnlineUser
actor to network town changes in cases where the server is using Plugin Message networking in cross-server mode.
OnlineUser
object, use the platform modules — on the Bukkit platform, use #getOnlineUser(org.bukkit.Player player)
.#editTown(OnlineUser actor, String townName, Consumer<Town> editor)
provides a way to modify a town in a single action using a Consumer<Town>
.
Town#addMember(UUID, role)
— just be sure to make sure you don't add users to multiple towns!void editTown(String townName, org.bukkit.Player player) {
OnlineUser online = huskTowns.getOnlineUser(player);
huskTowns.editTown(online, townName, town -> {
town.setGreeting("Welcome to our town!");
town.setFarewell("Goodbye!");
});
}
#createTown(String name, OnlineUser user)
CompletableFuture<Town>
which will be completed with the new town if it was created successfully.void createTown(String townName, org.bukkit.Player player) {
OnlineUser online = huskTowns.getOnlineUser(player);
CompletableFuture<Town> future = huskTowns.createTown(townName, online);
future.thenAccept(town -> {
System.out.println("Town created: " + town.getName());
}).exceptionally(throwable -> {
System.out.println("Failed to create town: " + throwable.getMessage());
return null;
});
}
#deleteTown(String name, OnlineUser user)
void deleteTown(String townName, org.bukkit.Player player) {
OnlineUser online = huskTowns.getOnlineUser(player);
huskTowns.deleteTown(townName, online);
}