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
TrustLevelobject, you can get the various privileges and their associatedTrustLevel.Privileges using#getPrivileges(), and allowedOperationTypes 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
UserGroups usingHuskClaimsAPI#getUserGroups(User user). - You can get a
UserGroupby 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
ClaimandClaimWorldfrom 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
Trustablesinclude 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
TrustTagis a tag that can be trusted on claims that represents a set ofUsers. - HuskClaims provides a
TrustTagabstract 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 statusmenu.
4.1 Getting TrustTags
- You can get a list of registered trust tags using
HuskClaimsAPI#getTrustTags(). - You can get a
TrustTagby name usingHuskClaimsAPI#getTrustTagByName(String name).- For example, use
#getTrustTagByName("public")to get the built-inPublicTrustTagwhich 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
Check the built-in LuckPermsTrustTag class for an example of a trust tag implementation.
TrustTagis a simple abstract class. In the constructor, you must pass a tagnameanddescription, and you must implement one method:boolean includes(@NotNull User trustable);- This method should return
trueif the suppliedUseris included in the tag, andfalseotherwise. - 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 returntrueif the suppliedUseris allowed to trust others with the tag, orfalseotherwise (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!