cn.nukkit.event.server.ServerCommandEvent Java Examples

The following examples show how to use cn.nukkit.event.server.ServerCommandEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NukkitConsole.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void runCommand(String command) {
    if (executingCommands.get()) {
        Timings.serverCommandTimer.startTiming();
        ServerCommandEvent event = new ServerCommandEvent(server.getConsoleSender(), command);
        if (server.getPluginManager() != null) {
            server.getPluginManager().callEvent(event);
        }
        if (!event.isCancelled()) {
            Server.getInstance().getScheduler().scheduleTask(() -> server.dispatchCommand(event.getSender(), event.getCommand()));
        }
        Timings.serverCommandTimer.stopTiming();
    } else {
        consoleQueue.add(command);
    }
}
 
Example #2
Source File: NukkitCommandExecutor.java    From LuckPerms with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsoleCommand(ServerCommandEvent e) {
    if (!(e.getSender() instanceof ConsoleCommandSender)) {
        return;
    }

    String buffer = e.getCommand();
    if (buffer.isEmpty() || buffer.charAt(0) != '/') {
        return;
    }

    buffer = buffer.substring(1);

    String commandLabel;
    int firstSpace = buffer.indexOf(' ');
    if (firstSpace == -1) {
        commandLabel = buffer;
    } else {
        commandLabel = buffer.substring(0, firstSpace);
    }

    Command command = this.plugin.getBootstrap().getServer().getCommandMap().getCommand(commandLabel);
    if (command != this.command) {
        return;
    }

    e.setCommand(buffer);
}
 
Example #3
Source File: NukkitPlatformListener.java    From LuckPerms with MIT License 4 votes vote down vote up
@EventHandler
public void onServerCommand(ServerCommandEvent e) {
    handleCommand(e.getSender(), e.getCommand().toLowerCase(), e);
}