Minecraft: Spigot Plugin - PrivateJoinMessage
 
            Creating a Custom Minecraft Plugin: PrivateJoinMessage with AI Integration
Minecraft plugins can be powerful tools to customise server experiences. In this post, I’ll walk you through the development of a custom plugin for Spigot that displays personalised join messages for players, including integration with AI for dynamic and witty messages.
The Idea
The basic idea behind the PrivateJoinMessage plugin is to send a special message to players when they join a Minecraft server. The twist? These messages are dynamic and can be customised through a simple JSON configuration file. Additionally, I integrated an AI-powered roast generator to provide a funny, cheeky, and mean-spirited roast about the player, tailored just for them.
Features of the Plugin
- Customisable Messages: You can add your own personalised join messages in a JSON configuration file.
- AI Integration: The plugin integrates with an external API to generate clever roasts of players each time they join.
- Command Interface: Admins can reload the messages or view the current list of join messages.
- Easy to Use: The plugin is lightweight and simple, making it easy to integrate into any server.
Development Process
The development of the PrivateJoinMessage plugin involved a few key steps:
1. Setting Up the Plugin
First, I created the basic structure of the plugin in Java using Spigot's API. The plugin listens for the PlayerJoinEvent and displays a custom message every time a player joins.
@EventHandler
public void onJoin(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    if (messages == null || messages.isEmpty()) return;
    String randomMessage = messages.get(random.nextInt(messages.size())).replace("%player%", player.getName());
    event.setJoinMessage(null);
    getServer().getScheduler().runTask(this, () -> player.sendMessage(randomMessage));
}
2. Using a Configuration File
Instead of hardcoding the messages in the plugin, I used a messages.json file. This allows server admins to edit the messages without needing to modify the plugin code. The plugin loads the messages from this file on startup.
[
  "Welcome back, %player%",
  "Hey %player%, great to see you",
  "Hope you brought snacks, %player%",
  "The adventure begins again, %player%",
  "Ready to roll, %player%"
]
3. Integrating with AI
One of the unique features of this plugin is the integration with an external API to roast the player. This is done by sending the player's username to the API and receiving a clever roast in return.
private String getRoastFromAPI(String playerName) {
    // Make a request to the API here, passing the player's name
    return roastMessage; // The response from the API
}
This way, each time a player joins, they get a personalised roast, ensuring that the server atmosphere remains fun and interactive.
4. Commands for Configuration
To make the plugin more user-friendly, I added two commands:
- /pjm reload: Reloads the list of join messages.
- /pjm list: Lists the current join messages.
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (args.length == 0) {
        sender.sendMessage("§cUsage: /pjm <reload|list>");
        return false;
    }
    switch(args[0].toLowerCase()) {
        case "reload":
            loadMessages();
            sender.sendMessage("§aPrivateJoinMessage reloaded.");
            break;
        case "list":
            for(String message : messages) {
                sender.sendMessage("§7- " + message);
            }
            break;
        default:
            sender.sendMessage("§cUnknown subcommand.");
            break;
    }
    return true;
}
5. Hosting the Roast Service
The roast generation uses an AI model hosted on a local server. In this case, I used LM Studio to host the model and expose the roast service through an API. This allows the plugin to call the service on player join and get a dynamic response each time.
Conclusion
The PrivateJoinMessage plugin is an interesting blend of Minecraft plugin development and AI integration. It’s lightweight, fun, and provides a lot of customisation for server admins. If you're looking to spice up your Minecraft server and bring in some fun, cheeky join messages, this plugin is a perfect addition!
Getting Started
To get started with the plugin, simply download it from GitHub, place it in the plugins folder of your Spigot server, and configure it with your preferred messages in the messages.json file. Don’t forget to set up the AI roast service to make the most of the personalised joins!