All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.event.server.ServerCommandEvent Maven / Gradle / Ivy

package org.bukkit.event.server;

import org.bukkit.command.CommandSender;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;

/**
 * This event is called when a command is run from the server console. It is
 * called early in the command handling process, and modifications in this
 * event (via {@link #setCommand(String)}) will be shown in the behavior.
 * 

* Many plugins will have no use for this event, and you should * attempt to avoid using it if it is not necessary. *

* Some examples of valid uses for this event are: *

    *
  • Logging executed commands to a separate file *
  • Variable substitution. For example, replacing ${ip:Steve} * with the connection IP of the player named Steve, or simulating the * @a and @p decorators used by Command Blocks * for plugins that do not handle it. *
  • Conditionally blocking commands belonging to other plugins. *
  • Per-sender command aliases. For example, after the console runs the * command /calias cr gamemode creative, the next time they * run /cr, it gets replaced into * /gamemode creative. (Global command aliases should be * done by registering the alias.) *
*

* Examples of incorrect uses are: *

    *
  • Using this event to run command logic *
*

* If the event is cancelled, processing of the command will halt. *

* The state of whether or not there is a slash (/) at the * beginning of the message should be preserved. If a slash is added or * removed, unexpected behavior may result. */ public class ServerCommandEvent extends ServerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final CommandSender sender; private String command; private boolean cancel = false; public ServerCommandEvent(final CommandSender sender, final String command) { this.command = command; this.sender = sender; } public static HandlerList getHandlerList() { return handlers; } /** * Gets the command that the user is attempting to execute from the * console * * @return Command the user is attempting to execute */ public String getCommand() { return command; } /** * Sets the command that the server will execute * * @param message New message that the server will execute */ public void setCommand(String message) { this.command = message; } /** * Get the command sender. * * @return The sender */ public CommandSender getSender() { return sender; } @Override public HandlerList getHandlers() { return handlers; } @Override public boolean isCancelled() { return cancel; } @Override public void setCancelled(boolean cancel) { this.cancel = cancel; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy