Developer APIs

General player data

We provide you with a class named /api/user/User.java that gives you general player data, including the list of friends, the list of blocked players, mailbox, and more… You can use 2 methods provided from public class FriendAPI to get the player data:

Optional<User> FriendAPI.findUser(UUID);
Optional<User> FriendAPI.findUser(OfflinePlayer);

List of friends

To get the list of all your friends:

List<Friend> getList();

List of online friends

To get the list of online friends:

List<Friend> getOnlineFriends();

List of blocked players

To get the list of blocked players:

BlockedList getBlockedList();

Blocking a player

To block a player you are hating:

void block(UUID target);

Unblocking a player

To unblock a player:

void unblock(UUID target);

Friend request

To send a friend request to a player:

void sendRequest(UUID target);

Find pending friend request

To find a friend request you received recently but are waiting for response:

Optional<Request> findWaitingRequest(UUID target, boolean checkExpire);

Add new friend

To immediately add a player to your friend list:

void addFriend(UUID target);

Unfriend a player

To remove a player from your friend list:

void unfriend(UUID target);

Allow the player’s friends to teleport to them

Before teleporting to your friend, you should check whether your friend allows you to teleport to them by using the method below:

boolean canTeleportTo();

To check whether your friend can teleport to you, use this method:

boolean canTeleport();

To allow/disallow your friend to teleport to you, use this method:

boolean setCanTeleport(boolean canTeleport);

Allow to receive mail from friends

boolean canMail(); // Checks whether the player can receive the mail of their friend or not.
void setCanMail(boolean canMail); // Sets whether the player can receive the mail of their friend or not.

Mailbox

This mailbox will contain all mails, including mails you have sent and mails you have received from your friends. It can be invoked from the User class:

Mailbox getMailbox();

Send new mail

To send a mail to your friend:

Mail mail = new MailImpl(UUID sender, UUID target, String content, ItemStack... items);
mail.send();

Attached items

To get attached items from a letter:

List<ItemStack> getAttachedItem();

Sender - revoke items from mail

There are 2 methods that allow you to revoke your items from the letter:

boolean revokeItem(ItemStack item); // Revoke the specified item.
boolean revokeAllItems(); // Revoke all items contained in the letter.

Receiver - take items from mail

Same as revoke items, there are 2 methods that allow you to take items from the letter:

boolean takeItem(ItemStack item); // Take the specified item.
boolean takeAllItems(); // Take all items contained in the letter.

Events

We also provide you with some event classes, see details at: Events API.

Subsections of Developer APIs

Events

PreFriendRequestSendEvent

Called before a friend request is sent

public final class PreFriendRequestSendEvent extends BaseEvent implements Cancellable {
    private final Request request;
    private boolean cancelled;

    public PreFriendRequestSendEvent(Request request) {
        this.request = request;
        this.cancelled = false;
    }

    public Request getRequest() {
        return request;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}

PreFriendRequestRespondEvent

Called when a friend request is ready to respond (accept/decline/cancel)

public final class PreFriendRequestRespondEvent extends BaseEvent implements Cancellable {
    private final Request request;
    private Request.Status status;
    private boolean cancelled;

    public PreFriendRequestRespondEvent(Request request, Request.Status status) {
        this.request = request;
        this.status = status;
        this.cancelled = false;
    }

    public Request getRequest() {
        return request;
    }

    public Request.Status getStatus() {
        return status;
    }

    public void setStatus(Request.Status status) {
        this.status = status;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}

FriendTeleportEvent

Called before your friend teleports to you

public final class FriendTeleportEvent extends BaseEvent implements Cancellable {
    private final User user, target;
    private boolean cancelled;

    public FriendTeleportEvent(User user, User target) {
        this.user = user;
        this.target = target;
        this.cancelled = false;
    }

    public User getUser() {
        return user;
    }

    public User getTarget() {
        return target;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}

AttachingItemToMailEvent

Called before attaching items to your mail

public final class AttachingItemToMailEvent extends BaseEvent implements Cancellable {
    private ItemStack item;
    private boolean cancelled;

    public AttachingItemToMailEvent(ItemStack item) {
        this.item = item;
        this.cancelled = false;
    }

    public ItemStack getAttachedItem() {
        return item;
    }

    public void setAttachedItem(ItemStack item) {
        this.item = item;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}

PreMailSendEvent

Called before your mail is sent

public final class PreMailSendEvent extends BaseEvent implements Cancellable {
    private final Mail mail;
    private boolean cancelled;

    public PreMailSendEvent(Mail mail) {
        this.mail = mail;
        this.cancelled = false;
    }

    public Mail getMail() {
        return mail;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}

PreMailRespondEvent

Called when a mail is ready to respond (read/cancel)

public final class PreMailRespondEvent extends BaseEvent implements Cancellable {
    private final Mail mail;
    private Mail.Status status;
    private boolean cancelled;

    public PreMailRespondEvent(Mail mail, Mail.Status status) {
        this.mail = mail;
        this.status = status;
        this.cancelled = false;
    }

    public Mail getMail() {
        return mail;
    }

    public Mail.Status getStatus() {
        return status;
    }

    public void setStatus(Mail.Status status) {
        this.status = status;
    }

    @Override
    public boolean isCancelled() {
        return cancelled;
    }

    @Override
    public void setCancelled(boolean cancel) {
        this.cancelled = cancel;
    }
}