-
-
Notifications
You must be signed in to change notification settings - Fork 43
Claims API
github-actions[bot] edited this page Feb 5, 2024
·
3 revisions
HuskTowns provides API for getting, creating, changing the type of, & deleting claims and admin claims.
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.
- Getting if a location is claimed
- Checking what a user can do at a location
- Creating a claim
- Highlighting a claim
- On the Bukkit platform, get a
Position
object using#getPosition(org.bukkit.Location location)
- Use
#isClaimAt(Position position)
to check if the location has been claimed - Or, use
#getClaimAt(Position position)
to get theOptional<TownClaim>
at the location- With an
Optional<TownClaim>
, you can useOptional#isPresent()
to check if a claim exists at the location - With a
TownClaim
object, you can get the associatedTown
object (see Towns API) using#town()
, and theClaim
itself using#claim()
- The
Claim
object has a range of properties describing the claim.
- With an
Example — Getting if a location is claimed
void showTownWhoHasClaimedAt(org.bukkit.Location location) {
Position position = huskTowns.getPosition(location);
Optional<TownClaim> claim = huskTowns.getClaimAt(position);
if (claim.isPresent()) {
System.out.println("This location is claimed by " + claim.get().town().getName());
}
}
- Claims exist within a
ClaimWorld
in HuskTowns.World
s withoutClaimWorld
s are not protected by HuskTowns. - On the Bukkit platform, get a
World
object from a Bukkit World using#getWorld(org.bukkit.World)
(or call#getWorld()
on aPosition
object) - You can then get the
ClaimWorld
for a world using#getClaimWorld(World world)
which will return anOptional<ClaimWorld>
Example — Getting the claim world for a world
void showClaimWorld(org.bukkit.World world) {
Optional<ClaimWorld> claimWorld = huskTowns.getClaimWorld(world);
if (claimWorld.isPresent()) {
System.out.println("This world is protected by HuskTowns, and contains " + claimWorld.get().getClaimCount() + " claims!");
}
}
- On the Bukkit platform, get an
OnlineUser
object using#getOnlineUser(@NotNull org.bukkit.Player player)
- Use
#getPosition()
to get thePosition
of anOnlineUser
to check if there's a claim where they stand (see #1)
- Use
- Check if a user can perform
OperationTypes
using#isOperationAllowed(OnlineUser user, OperationType type, Position position)
- Use the
#isOperationAllowed
method that accepts and build anOperation
viaOperation.builder()
for more complex operation checks!
- Use the
Example — Checking what a user can do at a location
void checkUserAccessAt(org.bukkit.Player player, org.bukkit.Location location) {
OnlineUser user = huskTowns.getOnlineUser(player);
Position position = huskTowns.getPosition(location);
if (huskTowns.isOperationAllowed(user, OperationType.BREAK_BLOCKS, position)) {
System.out.println("User can build here!");
} else {
System.out.println("User can't build here!");
}
}
- You can create a claim using
#createClaimAt(OnlineUser actor, Town town, Chunk chunk, World world)
- You may also create an admin claim using
#createAdminClaimAt(OnlineUser actor, Chunk chunk, World world)
- You may also create an admin claim using
- This will create a claim at that position. You can then use
#getClaimAt(Position position)
to get theTownClaim
object for the claim you just created (see #1) - You can also create a claim at the chunk at a position using
#createClaimAt(OnlineUser actor, Town town, Position position)
Example — Creating a claim
void createClaimAt(org.bukkit.Player player, org.bukkit.Chunk chunk, org.bukkit.World world) {
OnlineUser user = huskTowns.getOnlineUser(player);
Town town = huskTowns.getTown("townName").get();
huskTowns.createClaimAt(user, town, chunk, world);
}
- You can edit a claim using
#editClaimAt(Chunk chunk, World world, Consumer<TownClaim> editor)
- This will allow you to edit the claim at the given chunk and world using the
Consumer<TownClaim>
to modify theTownClaim
object- For example, you can do
townClaim.claim().setType(Claim.Type type)
to change the type of the claim
- For example, you can do
Example — Editing a claim
void editClaimAt(org.bukkit.Chunk chunk, org.bukkit.World world) {
huskTowns.editClaimAt(chunk, world, townClaim -> {
townClaim.claim().setType(Claim.Type.FARM);
});
}
- You can delete a claim using
#deleteClaimAt(OnlineUser actor, Position position)
- A method that accepts a
Chunk
and aWorld
is also available
- A method that accepts a
Example — Deleting a claim
void deleteClaimAt(org.bukkit.Player player, org.bukkit.Location location) {
OnlineUser user = huskTowns.getOnlineUser(player);
Position position = huskTowns.getPosition(location);
huskTowns.deleteClaimAt(user, position);
}
- You can "highlight" a claim for an
OnlineUser
(displaying the outline particle effect) using#highlightClaim(OnlineUser actor, TownClaim claim)
- You may additionally specify the duration, and use
#highlightClaimAt
to attempt to highlight a claim at a specifiedPosition
Example — Highlighting a claim
void highlightClaimAt(org.bukkit.Player player, org.bukkit.Location location) {
OnlineUser user = huskTowns.getOnlineUser(player);
Position position = huskTowns.getPosition(location);
Optional<TownClaim> claim = huskTowns.getClaimAt(position);
if (claim.isPresent()) {
huskTowns.highlightClaim(user, claim.get());
}
}
This documentation is available via william278.net |
---|
- 📚 Setup
- 📦 Legacy Migration
- 📁 Database
- ⛅ Redis Support
- 📄 Config Files
- 📝 Translations
- 🔌 Hooks
- 🖥️ Commands
- 🏙️ Towns
- 🏠 Claims
- 🔨 Roles
- 🌟 Advancements
- ☯️ Relations
- ⚔️ Wars
- 🚫 Inactive Town Pruning
- 📦 API v3
- 🧡 Towns API
- ⚙️ Claims API
- ❗ API Events
- 🕸️ API v1 (Legacy)