-
Notifications
You must be signed in to change notification settings - Fork 5
Your first menu
This example is written for the BungeeCord platform, but things are similar on Spigot.
Set up your project as described in Project setup. After that you will have a Maven (or Gradle) project and a plugin main class (and a plugin.yml file of course) annotated with SimplixApplication
. Just like that:
import dev.simplix.cirrus.bungeecord.CirrusBungeeCord;
import dev.simplix.cirrus.bungeecord.example.commands.TestCommand;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.plugin.Plugin;
public class CirrusExamplePlugin extends Plugin {
@Override
public void onEnable() {
CirrusBungeeCord.init(this);
ProxyServer.getInstance().getPluginManager().registerCommand(this, new TestCommand());
}
}
Let's create our menu class from scratch. Our menu will be a simple single-page menu that will be configurable. We will add an ActionHandler
called tnt
. To learn more about ActionHandler
s check out: Action Handlers.
The class should look like this:
import dev.simplix.cirrus.common.business.PlayerWrapper;
import dev.simplix.cirrus.common.configuration.MenuConfiguration;
import dev.simplix.cirrus.common.menus.SimpleMenu;
import dev.simplix.cirrus.common.model.CallResult;
import java.util.Locale;
public class ExampleMenu extends SimpleMenu {
public ExampleMenu(PlayerWrapper player, MenuConfiguration configuration) {
super(player, configuration, Locale.ENGLISH);
registerActionHandler("tnt", click -> {
topContainer().itemMap().remove(click.slot());
title("Hello, {viewer}");
build();
player().sendMessage("It simply works :)");
});
}
}
We will use a command to show our new menu. We need to obtain an instance of ConfigurationFactory
. Our class should look like this:
import dev.simplix.cirrus.bungeecord.example.menus.ExampleMenu;
import dev.simplix.cirrus.common.Cirrus;
import dev.simplix.cirrus.common.business.PlayerWrapper;
import dev.simplix.cirrus.common.converter.Converters;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
public class TestCommand extends Command {
public TestCommand() {
super("test");
}
@Override
public void execute(CommandSender sender, String[] args) {
if (sender instanceof ProxiedPlayer) {
ProxiedPlayer proxy = (ProxiedPlayer) sender;
PlayerWrapper wrapper = Converters.convert(proxy, PlayerWrapper.class);
new ExampleMenu(,
Cirrus.configurationFactory().loadFile("plugins/Cirrus/example.json")).open();
}
}
}
After that, you can compile and package your plugin to test it on the server. When executing the /test
command on your server, you will see the generated default configuration of the menu. Close the menu and let's get started to configure the menu.
Due to the way Spigot is internally built you will need to change the way your Player
is converted to a PlayerWrapper
final PlayerWrapper wrapper = Converters.getConverter(Player.class, PlayerWrapper.class).convert(player);
Open the freshly created plugins/Cirrus/example.json in IntelliJ or any other text editor. If you are using the Cirrus Tooling plugin for IntelliJ, this will look like that:
Let's move to the items
section of the json file. Let's change the default item to a TNT block by setting its itemType
to TNT
. After that, we will also set the actionHandler
to tnt
. The item should now look like this:
{
"itemType": "TNT",
"displayName": {
"en": "§6Example Item",
"de": "§6Beispielitem"
},
"lore": {
"en": [
"§7Hello §6{viewer}§7,",
"§7this is an example item to show",
"§7how Cirrus menus and items are configured."
],
"de": [
"§7Hallo §6{viewer}§7,",
"§7das ist ein Beispiel, um zu zeigen",
"§7wie man Cirrus Menüs und Items konfiguriert."
]
},
"amount": 1,
"actionHandler": "tnt",
"actionArguments": [],
"slots": [13],
"nbt": {
"SkullOwner": "Exceptionflug"
}
}
After saving the file reopen the menu ingame. You will see that our skull is now a TNT block. By clicking the TNT block, our menu title changes to greet you.
Congratulations. You have created your first own menu using Cirrus.