Trust API
HuskClaims provides API for trusting users in claims and registering trust tags.
Table of Contents
- 1. Getting the list of trust levels
- 2. Getting UserGroups
- 3. Trusting Trustables in a claim
- 4. TrustTags
1. Getting the list of trust levels
- You can get a list of registered trust levels using
HuskClaimsAPI#getTrustLevels()
. - Within the
TrustLevel
object, you can get the various privileges and their associatedTrustLevel.Privilege
s using#getPrivileges()
, and allowedOperationType
s using#getFlags()
.
Example — Getting the list of TrustLevels
void showTrustLevels(org.bukkit.command.CommandSender sender) {
sender.sendMessage("Registered trust levels: " + huskClaims.getTrustLevels().stream()
.map(TrustLevel::getName).collect(Collectors.joining(", ")));
}
2. Getting UserGroups
- You can get a list of a user's created
UserGroup
s usingHuskClaimsAPI#getUserGroups(User user)
. - You can get a
UserGroup
by name usingHuskClaimsAPI#getUserGroupByName(User owner, String name)
.
Example — Getting a user's created User Groups
void showUserGroups(org.bukkit.Player player) {
final OnlineUser user = huskClaims.getOnlineUser(player);
player.sendMessage("Registered user groups for " + user.getName() + ": " + huskClaims.getUserGroups(user).stream()
.map(UserGroup::getName).collect(Collectors.joining(", ")));
}
3. Trusting Trustables in a claim
- You can use the
HuskClaimsAPI#setTrustLevel(Claim claim, ClaimWorld claimWorld, Trustable trustable, TrustLevel trustLevel)
method to set a user's trust level in a claim.- Check the Claims API documentation for getting a
Claim
andClaimWorld
from aPosition
- Also check the Claims API page for getting a user's trust level in any given claim.
- Check the Claims API documentation for getting a
- Valid
Trustables
include aUser
(or extending classes, such as anOnlineUser
), aTrustTag
, or aUserGroup
.
Example — Trusting a user in a claim
void trustUserInClaim(Claim claim, ClaimWorld claimWorld, User user) {
huskClaims.setTrustLevel(claim, claimWorld, user, TrustLevel.BUILD);
}
4. TrustTags
- A
TrustTag
is a tag that can be trusted on claims that represents a set ofUsers
. - HuskClaims provides a
TrustTag
abstract class which you can extend to create your own trust tag, which you can then provide via theHuskClaimsAPI#registerTrustTag(TrustTag)
method. - Users can then trust users in your tag on claims using the relevant trust command, followed by your
#(tag)
. - You can check which trust tags are registered in-game in the
/huskclaims status
menu.
4.1 Getting TrustTags
- You can get a list of registered trust tags using
HuskClaimsAPI#getTrustTags()
. - You can get a
TrustTag
by name usingHuskClaimsAPI#getTrustTagByName(String name)
.- For example, use
#getTrustTagByName("public")
to get the built-inPublicTrustTag
which you can use to grant public trust on aClaim
.
- For example, use
Example — Getting the list of registered TrustTags
void showTrustTags(org.bukkit.command.CommandSender sender) {
sender.sendMessage("Registered trust tags: " + huskClaims.getTrustTags().stream()
.map(TrustTag::getName).collect(Collectors.joining(", ")));
}
4.2 Extending the TrustTag class
Note:Check the built-inLuckPermsTrustTag
class for an example of a trust tag implementation.
TrustTag
is a simple abstract class. In the constructor, you must pass a tagname
anddescription
, and you must implement one method:boolean includes(@NotNull User trustable);
- This method should return
true
if the suppliedUser
is included in the tag, andfalse
otherwise. - Tag names should not contain spaces or non-alphanumeric (a-z, A-Z, 0-9) characters!
- This method should return
- Additionally, you may override the
boolean canUse(@NotNull User user);
method to returntrue
if the suppliedUser
is allowed to trust others with the tag, orfalse
otherwise (e.g. to restrict the tag behind a permission node).
Example Trust Tag
public class MyTrustTag extends TrustTag {
public TrustTag() {
// Name / description
super("mytag", "Grants access to upside-down people.");
}
@Override
public boolean includes(@NotNull User trustable) {
// Return true if the supplied user is included in the tag, false otherwise
return user.getName().equals("Dinnerbone") || user.getName().equals("Grumm"); // Include Dinnerbone or Grumm!
}
@Override
public boolean canUse(@NotNull User user) {
// Return true if the supplied user is allowed to trust others with the tag, false otherwise
return true; // Let everyone trust others with this tag in their claims
}
}
4.3 Registering your TrustTag
You can register your trust tag by calling HuskClaimsAPI#registerTrustTag(TrustTag)
with your created trust tag instance.
void onEnable() {
huskClaims.registerTrustTag(new MyTrustTag());
}
And users will be able to use /(trust_level_command) #mytag
to trust the tag in their claims!