This document provides comprehensive documentation for plugin developers who want to integrate with the Mailboxes plugin.
The Mailboxes API allows your plugin to send persistent messages to players programmatically. This is useful for notifications, rewards, alerts, or any other plugin-to-player communication needs.
- Send messages from your plugin to any player
- Messages persist across server restarts
- Messages are delivered even if the player is offline
- Access player mailboxes and messages
Note: The plugin messaging API methods (e.g., sendPluginMessageToPlayer) currently accept only String content and do not support item attachments. Item attachments are a feature available through the main plugin interface for player-to-player messages.
First, add the Mailboxes JAR to your local Maven repository or use a local file dependency:
Using a local file dependency:
<dependencies>
<dependency>
<groupId>dansplugins</groupId>
<artifactId>Mailboxes</artifactId>
<version>1.2.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/Mailboxes-1.2.0.jar</systemPath>
</dependency>
</dependencies>Or install to local Maven repository:
mvn install:install-file \
-Dfile=Mailboxes-1.2.0.jar \
-DgroupId=dansplugins \
-DartifactId=Mailboxes \
-Dversion=1.2.0 \
-Dpackaging=jarThen add to your pom.xml:
<dependencies>
<dependency>
<groupId>dansplugins</groupId>
<artifactId>Mailboxes</artifactId>
<version>1.2.0</version>
<scope>provided</scope>
</dependency>
</dependencies>dependencies {
compileOnly files('libs/Mailboxes-1.2.0.jar')
}Add Mailboxes as a dependency in your plugin.yml:
name: YourPlugin
version: 1.0
main: com.example.yourplugin.YourPlugin
depend: [Mailboxes]Or as a soft dependency if Mailboxes is optional:
softdepend: [Mailboxes]import dansplugins.mailboxes.Mailboxes;
import dansplugins.mailboxes.externalapi.MailboxesAPI;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class YourPlugin extends JavaPlugin {
private MailboxesAPI mailboxesAPI;
@Override
public void onEnable() {
// Get the Mailboxes plugin instance
Plugin plugin = getServer().getPluginManager().getPlugin("Mailboxes");
if (plugin != null && plugin instanceof Mailboxes) {
// Get the API instance
mailboxesAPI = ((Mailboxes) plugin).getAPI();
getLogger().info("Successfully hooked into Mailboxes API v" + mailboxesAPI.getAPIVersion());
} else {
getLogger().warning("Mailboxes plugin not found!");
return;
}
}
public MailboxesAPI getMailboxesAPI() {
return mailboxesAPI;
}
}If you're using a soft dependency, check if Mailboxes is available:
@Override
public void onEnable() {
if (getServer().getPluginManager().isPluginEnabled("Mailboxes")) {
Plugin plugin = getServer().getPluginManager().getPlugin("Mailboxes");
mailboxesAPI = ((Mailboxes) plugin).getAPI();
getLogger().info("Mailboxes integration enabled!");
} else {
getLogger().info("Mailboxes not found - mail features disabled");
}
}The main API class providing methods to interact with the Mailboxes plugin.
Returns the current API version string.
Returns: String - The API version (e.g., "v0.0.3")
Example:
String apiVersion = mailboxesAPI.getAPIVersion();
System.out.println("Using Mailboxes API: " + apiVersion);Returns the Mailboxes plugin version.
Returns: String - The plugin version (e.g., "v1.2.0")
Example:
String pluginVersion = mailboxesAPI.getVersion();Sends a message from your plugin to a player.
Parameters:
pluginName(String) - The name of your plugin (used as the sender)player(Player) - The player to send the message tocontent(String) - The message content
Returns: boolean - true if the message was sent successfully, false otherwise
Example:
Player player = Bukkit.getPlayer("Steve");
if (player != null) {
boolean success = mailboxesAPI.sendPluginMessageToPlayer(
"MyPlugin",
player,
"Congratulations! You've earned a reward!"
);
if (success) {
getLogger().info("Message sent successfully!");
}
}Sends a message from your plugin to a player using their UUID. This is useful when the player is offline.
Parameters:
pluginName(String) - The name of your plugin (used as the sender)playerUUID(UUID) - The UUID of the player to send the message tocontent(String) - The message content
Returns: boolean - true if the message was sent successfully, false otherwise
Example:
UUID playerUUID = UUID.fromString("f47ac10b-58cc-4372-a567-0e02b2c3d479");
boolean success = mailboxesAPI.sendPluginMessageToPlayer(
"MyPlugin",
playerUUID,
"This message will be waiting when you log in!"
);Retrieves a player's mailbox.
Parameters:
player(Player) - The player whose mailbox to retrieve
Returns: M_Mailbox - The player's mailbox wrapper object
Example:
Player player = Bukkit.getPlayer("Steve");
if (player != null) {
M_Mailbox mailbox = mailboxesAPI.getMailbox(player);
ArrayList<Message> activeMessages = mailbox.getActiveMessages();
player.sendMessage("You have " + activeMessages.size() + " active messages.");
}Retrieves a specific message by its ID.
Parameters:
ID(int) - The unique ID of the message
Returns: M_Message - The message wrapper object, or null if not found
Example:
M_Message message = mailboxesAPI.getMessage(123);
if (message != null) {
String content = message.getContent();
String sender = message.getSender();
}A wrapper class representing a player's mailbox.
Returns: int - The unique mailbox ID
Returns: UUID - The UUID of the mailbox owner
Returns: Message - A specific message by ID (searches both active and archived messages)
Returns: ArrayList<Message> - List of unarchived messages
Returns: Message - A specific active message by ID
Returns: ArrayList<Message> - List of archived messages
Returns: Message - A specific archived message by ID
Sends a formatted list of active messages to the player.
Parameters:
player(Player) - The player to send the list to
Sends a formatted list of archived messages to the player.
Parameters:
player(Player) - The player to send the list to
A wrapper class representing a message.
Returns: int - The unique message ID
Returns: String - The name/identifier of the message sender
Returns: String - The name of the message recipient
Returns: String - The message content/text
Returns: Date - The date when the message was created
Returns: int - The ID of the mailbox this message belongs to
Returns: boolean - Whether the message is archived
Returns: boolean - Whether the message has item attachments
Returns: List<ItemStack> - List of attached items (empty list if none)
Sends a formatted display of the message content to the player.
Parameters:
player(Player) - The player to send the message to
Send a notification to a player when they complete a quest:
import dansplugins.mailboxes.Mailboxes;
import dansplugins.mailboxes.externalapi.MailboxesAPI;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
public class QuestPlugin extends JavaPlugin {
private MailboxesAPI mailboxesAPI;
@Override
public void onEnable() {
setupMailboxesAPI();
}
private void setupMailboxesAPI() {
Plugin plugin = getServer().getPluginManager().getPlugin("Mailboxes");
if (plugin instanceof Mailboxes) {
mailboxesAPI = ((Mailboxes) plugin).getAPI();
}
}
public void onQuestComplete(Player player, String questName) {
if (mailboxesAPI != null) {
String message = String.format(
"Congratulations! You've completed the '%s' quest! Your reward has been added to your account.",
questName
);
mailboxesAPI.sendPluginMessageToPlayer("QuestPlugin", player, message);
}
}
}Send messages to offline players that they'll receive when they log in:
import dansplugins.mailboxes.externalapi.MailboxesAPI;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
public class EconomyPlugin extends JavaPlugin {
private MailboxesAPI mailboxesAPI;
public void notifyPlayerOfPayment(UUID playerUUID, double amount, String reason) {
if (mailboxesAPI == null) return;
String message = String.format(
"You received $%.2f! Reason: %s",
amount,
reason
);
boolean sent = mailboxesAPI.sendPluginMessageToPlayer(
"EconomyPlugin",
playerUUID,
message
);
if (sent) {
getLogger().info("Payment notification sent to player " + playerUUID);
}
}
}Read a player's messages and perform actions based on them:
import dansplugins.mailboxes.externalapi.M_Mailbox;
import dansplugins.mailboxes.objects.Message;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.ArrayList;
public void checkPlayerMessages(Player player) {
if (mailboxesAPI == null) return;
M_Mailbox mailbox = mailboxesAPI.getMailbox(player);
ArrayList<Message> messages = mailbox.getActiveMessages();
int messageCount = messages.size();
if (messageCount > 0) {
player.sendMessage(ChatColor.YELLOW + "You have " + messageCount + " active messages!");
player.sendMessage(ChatColor.YELLOW + "Use /m list to view them.");
}
}Notify players of important events:
import dansplugins.mailboxes.externalapi.MailboxesAPI;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
public class DeathNotifierListener implements Listener {
private final MailboxesAPI mailboxesAPI;
public DeathNotifierListener(MailboxesAPI mailboxesAPI) {
this.mailboxesAPI = mailboxesAPI;
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
Location deathLocation = player.getLocation();
if (mailboxesAPI != null) {
String message = String.format(
"You died at coordinates: X=%.0f, Y=%.0f, Z=%.0f. Your items may still be there!",
deathLocation.getX(),
deathLocation.getY(),
deathLocation.getZ()
);
// Send notification using UUID for reliable delivery
mailboxesAPI.sendPluginMessageToPlayer("DeathNotifier", player.getUniqueId(), message);
}
}
}Send messages to multiple players:
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public void sendServerAnnouncement(String announcement) {
if (mailboxesAPI == null) return;
// Send to all online players
for (Player player : Bukkit.getOnlinePlayers()) {
mailboxesAPI.sendPluginMessageToPlayer(
"AdminPlugin",
player,
"Server Announcement: " + announcement
);
}
// For offline players, maintain a list of UUIDs to notify
// Note: Avoid using Bukkit.getOfflinePlayers() as it loads all player data
// Instead, keep track of specific players you want to notify
// Create a set of online player UUIDs for efficient lookup
Set<UUID> onlineUUIDs = Bukkit.getOnlinePlayers().stream()
.map(Player::getUniqueId)
.collect(Collectors.toSet());
// Note: getTrackedPlayerUUIDs() is a placeholder method that must be implemented
// by the developer in their own plugin code. It is not provided by the Mailboxes API.
// Implement this method to return the list of player UUIDs you want to notify
// (e.g., from a database, config file, or cached list of players)
List<UUID> playersToNotify = getTrackedPlayerUUIDs();
for (UUID playerUUID : playersToNotify) {
// Check if player is not online using the set
if (!onlineUUIDs.contains(playerUUID)) {
mailboxesAPI.sendPluginMessageToPlayer(
"AdminPlugin",
playerUUID,
"Server Announcement: " + announcement
);
}
}
}Send different messages based on player permissions or states:
public void sendRewardNotification(Player player, String rewardType, int amount) {
if (mailboxesAPI == null) return;
String message;
if (player.hasPermission("vip.rewards")) {
// VIP players get bonus information
message = String.format(
"VIP Reward! You've received %d %s! (2x bonus applied)",
amount * 2,
rewardType
);
} else {
message = String.format(
"Reward! You've received %d %s!",
amount,
rewardType
);
}
mailboxesAPI.sendPluginMessageToPlayer("RewardPlugin", player, message);
}Always check if the API is available before using it:
if (mailboxesAPI != null) {
// Use the API
} else {
// Handle gracefully
getLogger().warning("Mailboxes API not available");
}Check the return value of sendPluginMessageToPlayer():
boolean success = mailboxesAPI.sendPluginMessageToPlayer(pluginName, player, message);
if (!success) {
getLogger().warning("Failed to send message to player");
// Consider alternative notification methods
}Use a clear, identifiable name for your plugin when sending messages:
// Good
mailboxesAPI.sendPluginMessageToPlayer("QuestSystem", player, message);
// Less clear
mailboxesAPI.sendPluginMessageToPlayer("Plugin", player, message);Messages should be clear and not too long:
// Good
"Quest completed! Reward: 100 gold"
// Too verbose
"Congratulations on completing the quest! As a reward for your efforts and dedication..."When you need to send messages to players who might be offline, use the UUID variant:
// Better for offline players
mailboxesAPI.sendPluginMessageToPlayer("MyPlugin", playerUUID, message);Check the API version if you need specific features:
String apiVersion = mailboxesAPI.getAPIVersion();
// Note: Basic lexicographical string comparison only works reliably for
// consistently formatted versions (e.g., zero-padded). For example,
// "v0.0.10" would incorrectly compare as less than "v0.0.3" with string comparison.
// For proper semantic version comparison, use a dedicated version parsing library.
if (apiVersion.compareTo("v0.0.3") >= 0) {
// Use features available in v0.0.3 and later
// (only works if all versions follow the same padding scheme)
}Wrap API calls in try-catch blocks for production code:
import java.util.logging.Level;
try {
mailboxesAPI.sendPluginMessageToPlayer("MyPlugin", player, message);
} catch (Exception e) {
getLogger().log(Level.WARNING, "Error sending Mailboxes message", e);
}Avoid sending too many messages in quick succession:
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
// Consider batching or rate-limiting per player
// Note: This is a simplified example showing the concept
// For production use, implement proper per-player cooldown tracking
// Using ConcurrentHashMap for thread safety in a multi-threaded Bukkit environment
private Map<UUID, Long> lastMessageTimes = new ConcurrentHashMap<>();
private static final long MESSAGE_COOLDOWN = 60000; // 1 minute
public void sendNotification(Player player, String message) {
UUID playerUUID = player.getUniqueId();
long currentTime = System.currentTimeMillis();
Long lastTime = lastMessageTimes.get(playerUUID);
if (lastTime != null && currentTime - lastTime < MESSAGE_COOLDOWN) {
return; // Skip if too soon
}
mailboxesAPI.sendPluginMessageToPlayer("MyPlugin", player, message);
lastMessageTimes.put(playerUUID, currentTime);
}Problem: getAPI() returns null or the plugin isn't found.
Solutions:
- Ensure Mailboxes is installed on the server
- Check that Mailboxes is listed in
dependorsoftdependin yourplugin.yml - Verify you're accessing the API after
onEnable()
Problem: sendPluginMessageToPlayer() returns false.
Solutions:
- Verify the player/UUID exists
- Check server logs for Mailboxes errors
- Ensure the message content is not empty
- Verify Mailboxes plugin is enabled
Problem: Cannot import Mailboxes classes.
Solutions:
- Verify the Mailboxes JAR is in your build path
- Check your Maven/Gradle configuration
- Ensure you're using the correct version
- Try rebuilding your project
For additional help:
- v0.0.3 - Current API version
- Support for plugin messages with UUID
- Access to mailboxes and messages
- Attachment support in messages
The Mailboxes plugin and API are licensed under GPL-3.0. When integrating with Mailboxes, ensure your plugin complies with the license terms.