Skip to content
This repository was archived by the owner on Aug 10, 2023. It is now read-only.

Commands

Findlay Richardson edited this page Jun 23, 2023 · 4 revisions

The command

The @Command annotation is used to indicate that there is a command

package net.zenoc.gallium.test.commands;

import net.zenoc.gallium.api.annotations.Command;
import net.zenoc.gallium.api.chat.ChatMessage;
import net.zenoc.gallium.commandsys.CommandContext;

public class TestCommand {
    @Command(aliases = {"test"}, description = "A test command for testing")
    public void testCommand(CommandContext ctx) {
        ctx.getCaller().sendMessage(ChatMessage.from("Hey"));
    }
}

Registering in the plugin

Commands have to be registered in your plugin!

package net.zenoc.gallium.test;

import net.zenoc.gallium.api.annotations.PluginLifecycleListener;
import net.zenoc.gallium.plugin.PluginLifecycleState;
import net.zenoc.gallium.plugin.java.JavaPlugin;

public class GalliumPlugin extends JavaPlugin {
    @PluginLifecycleListener(PluginLifecycleState.ENABLED)
    public void onPluginEnable() {
        Gallium.getCommandManager().registerCommand(new TestCommand(), this);
    }
}

ifPlayer and ifConsole

@Command(aliases = {"whatami"}, description = "Find out what type of command caller you are")
public void whatamiCommand(CommandContext ctx) {
    ctx.ifPlayer(player -> {
        player.sendMessage(ChatMessage.from("Hello, you're a player!"));
    }).ifConsole(caller -> {
        caller.sendMessage(ChatMessage.from("Hello, you're the console!"));
    });
}

Clone this wiki locally