Guides

Here I'll be showing a bit of what I have learned that I believe every rsps should have. I am by no means an expert, but I would like to share useful features I have implemented in my own server. Right now I will only be focusing on Discord implementation, I may expand later on.

Discord

I really don't like forums, they are way too static and dated, and Discord is a fantastic tool to replace it (for most scenarios). The Java Discord API is very well documented and easy to implement. If you're already familiar with it the only upgrade I would recommend if you haven't done so yet, is to update to JDA 5. It's a bit of work, but in the end it is worth it for interactions and slash commands.

I highly suggest that you read the interactions documentation before implementing any of the code I provide below. This isn't a guide, but I am assuming that you have implemented the JDA already.

Slash Commands Overview

Slash commands are a really easy and straightforward solution to interact with Discord bots. They allow a variety of inputs, handle autocomplete/validation and also allow responses to be public or private.

Basic Setup

You'll need to create a class that extends the JDA ListenerAdapter. This will listen for a slash event and then you can handle the event in any way that you choose.

Slash command listener

public class CommandsListener extends ListenerAdapter {
    @Override
    public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
        //code to handle the event
    }
}

I've made a manager that handles all my slash commands, I will make a guide on how I did this in the future, but I built it off of a system that MenuDocs created a while back, you can watch the series here. Note that its outdated as it is JDA 4, but his system to handle commands can work in any application (I use it for my in-game commands too).


Player Count

Lets start with a simple command with no inputs that returns data from the game (Kronos). Anytime you create a Slash command you need to tell your Discord Bot that you've made one. We add it by sending the command in the updateCommands() method. In this case we're going to create a command /players

Adding the command

public static void updateCommands() {
    Discord.guild.updateCommands().addCommands(
        Commands.slash("players", "Displays how many players are in-game.")

Retrieving and sending the player count

public class Players implements SlashCommand { //implementation of my SlashCommand manager

    @Override
    public void handleSlashCommandInteraction(SlashCommandInteractionEvent event) {

        event.deferReply().setEphemeral(true).queue(); //more time to reply to the hook, visibiliy hidden

        int count = 0;
        count = World.players.count();
        event.getHook().sendMessageFormat("There are currently %s players online.", count).queue();
    }

    @Override
    public String getName() { //command name
        return "players";
    }

}

It's important to notice the line event.deferReply().setEphemeral(true).queue(). Discord requires you to respond to the command within 3 seconds, however, sometimes you need more time for handling. By defering the reply you have 15 minutes after the intial command was requested to reply. We also set the visibiliy here to hidden so that no one except the user who created the interaction can see the initial request or any replies after that.


Item Spawning

Coming soon...


Notifications

Coming soon...