Here are the examples of the java api org.bukkit.command.Command taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
745 Examples
19
Source : NMSImpl.java
with MIT License
from TabooLib
with MIT License
from TabooLib
@Override
public Object getWrapper(Command command) {
return new BukkitCommandWrapper((CraftServer) Bukkit.getServer(), command);
}
19
Source : Commodore.java
with MIT License
from TabooLib
with MIT License
from TabooLib
/**
* 根据为{@code command}定义的所有别名,将提供的参数数据注册到调度程序。
*
* <p>另外,将CraftBukkit {@link SuggestionProvider}应用于节点内的所有参数,
* 因此ASK_SERVER建议可以继续对该命令起作用。</p>
*
* <p>只有玩家通过 {@code PermissionTest},才会向其发送参数数据.</p>
*
* @param command 从中读取别名的命令
* @param argumentBuilder 构造器形式的参数数据
* @param permissionTest Predicate,检查是否应向玩家发送参数数据
*/
public void register(Command command, LiteralArgumentBuilder<?> argumentBuilder, Predicate<? super Player> permissionTest) {
Objects.requireNonNull(command, "command");
Objects.requireNonNull(argumentBuilder, "argumentBuilder");
Objects.requireNonNull(permissionTest, "permissionTest");
register(command, argumentBuilder.build(), permissionTest);
}
19
Source : Commodore.java
with MIT License
from TabooLib
with MIT License
from TabooLib
/**
* 根据为{@code command}定义的所有别名,将提供的参数数据注册到调度程序。
*
* <p>另外,将CraftBukkit {@link SuggestionProvider}应用于节点内的所有参数,
* 因此ASK_SERVER建议可以继续对该命令起作用。</p>
*
* @param command 从中读取别名的命令
* @param argumentBuilder 构造器形式的参数数据
*/
public void register(Command command, LiteralArgumentBuilder<?> argumentBuilder) {
Objects.requireNonNull(command, "command");
Objects.requireNonNull(argumentBuilder, "argumentBuilder");
register(command, argumentBuilder.build());
}
19
Source : ServerMock.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
@Override
public PluginCommand getPluginCommand(String name) {
replacedertMainThread();
Command command = getCommandMap().getCommand(name);
return command instanceof PluginCommand ? (PluginCommand) command : null;
}
19
Source : ServerMock.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
/**
* Executes a command as the console.
*
* @param command The command to execute.
* @param args The arguments to preplaced to the commands.
* @return The value returned by {@link Command#execute}.
*/
public CommandResult executeConsole(Command command, String... args) {
replacedertMainThread();
return execute(command, getConsoleSender(), args);
}
19
Source : ServerMock.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
/**
* Executes a command as a player.
*
* @param command The command to execute.
* @param args The arguments to preplaced to the commands.
* @return The value returned by {@link Command#execute}.
*/
public CommandResult executePlayer(Command command, String... args) {
replacedertMainThread();
if (playerList.isSomeoneOnline())
return execute(command, getPlayer(0), args);
else
throw new IllegalStateException("Need at least one player to run the command");
}
19
Source : GenericCommandHelpTopic.java
with GNU General Public License v3.0
from Mohist-Community
with GNU General Public License v3.0
from Mohist-Community
/**
* Lacking an alternative, the help system will create instances of
* GenericCommandHelpTopic for each command in the server's CommandMap. You
* can use this clreplaced as a base clreplaced for custom help topics, or as an example
* for how to write your own.
*/
public clreplaced GenericCommandHelpTopic extends HelpTopic {
protected Command command;
public GenericCommandHelpTopic(@NotNull Command command) {
this.command = command;
if (command.getLabel().startsWith("/")) {
name = command.getLabel();
} else {
name = "/" + command.getLabel();
}
// The short text is the first line of the description
int i = command.getDescription().indexOf('\n');
if (i > 1) {
shortText = command.getDescription().substring(0, i - 1);
} else {
shortText = command.getDescription();
}
// Build full text
StringBuilder sb = new StringBuilder();
sb.append(ChatColor.GOLD);
sb.append("Description: ");
sb.append(ChatColor.WHITE);
sb.append(command.getDescription());
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Usage: ");
sb.append(ChatColor.WHITE);
sb.append(command.getUsage().replace("<command>", name.substring(1)));
if (command.getAliases().size() > 0) {
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Aliases: ");
sb.append(ChatColor.WHITE);
sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
}
fullText = sb.toString();
}
@Override
public boolean canSee(@NotNull CommandSender sender) {
if (!command.isRegistered()) {
// Unregistered commands should not show up in the help
return false;
}
if (sender instanceof ConsoleCommandSender) {
return true;
}
if (amendedPermission != null) {
return sender.hasPermission(amendedPermission);
} else {
return command.testPermissionSilent(sender);
}
}
}
19
Source : SimpleHelpMap.java
with GNU General Public License v3.0
from Mohist-Community
with GNU General Public License v3.0
from Mohist-Community
private String getCommandPluginName(Command command) {
if (command instanceof VanillaCommandWrapper) {
return "Minecraft";
}
if (command instanceof BukkitCommand) {
return "Bukkit";
}
if (command instanceof PluginIdentifiableCommand) {
return ((PluginIdentifiableCommand) command).getPlugin().getName();
}
return null;
}
19
Source : SimpleHelpMap.java
with GNU General Public License v3.0
from Mohist-Community
with GNU General Public License v3.0
from Mohist-Community
private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) {
if ((command instanceof BukkitCommand) && ignoredPlugins.contains("Bukkit")) {
return true;
}
if (command instanceof PluginIdentifiableCommand && ignoredPlugins.contains(((PluginIdentifiableCommand) command).getPlugin().getName())) {
return true;
}
return false;
}
19
Source : GenericCommandHelpTopic.java
with GNU Lesser General Public License v3.0
from Luohuayu
with GNU Lesser General Public License v3.0
from Luohuayu
/**
* Lacking an alternative, the help system will create instances of
* GenericCommandHelpTopic for each command in the server's CommandMap. You
* can use this clreplaced as a base clreplaced for custom help topics, or as an example
* for how to write your own.
*/
public clreplaced GenericCommandHelpTopic extends HelpTopic {
protected Command command;
public GenericCommandHelpTopic(Command command) {
this.command = command;
if (command.getLabel().startsWith("/")) {
name = command.getLabel();
} else {
name = "/" + command.getLabel();
}
// The short text is the first line of the description
int i = command.getDescription().indexOf('\n');
if (i > 1) {
shortText = command.getDescription().substring(0, i - 1);
} else {
shortText = command.getDescription();
}
// Build full text
StringBuilder sb = new StringBuilder();
sb.append(ChatColor.GOLD);
sb.append("Description: ");
sb.append(ChatColor.WHITE);
sb.append(command.getDescription());
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Usage: ");
sb.append(ChatColor.WHITE);
sb.append(command.getUsage().replace("<command>", name.substring(1)));
if (command.getAliases().size() > 0) {
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Aliases: ");
sb.append(ChatColor.WHITE);
sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
}
fullText = sb.toString();
}
public boolean canSee(CommandSender sender) {
if (!command.isRegistered()) {
// Unregistered commands should not show up in the help
return false;
}
if (sender instanceof ConsoleCommandSender) {
return true;
}
if (amendedPermission != null) {
return sender.hasPermission(amendedPermission);
} else {
return command.testPermissionSilent(sender);
}
}
}
19
Source : CommandButton.java
with GNU Lesser General Public License v3.0
from Jannyboy11
with GNU Lesser General Public License v3.0
from Jannyboy11
/**
* A button that executes a command when clicked.
* @param <MH> the menu holder type
*/
public clreplaced CommandButton<MH extends MenuHolder<?>> extends ItemButton<MH> {
private Command command;
private String[] arguments;
private CommandResultHandler<MH> resultHandler;
/**
* Protected constructor for command buttons that wish to use non-constant commands and arguments.
* Subclreplacedes that use this super constructor must override {@link #getArguments()} or {@link #getCommand} or their overloads.
* @param icon the icon
*/
protected CommandButton(ItemStack icon) {
super(icon);
}
/**
* Creates the CommandButton.
* @param icon the icon of the button
* @param command the command to be executed
* @param arguments the arguments used to execute the command
*/
public CommandButton(ItemStack icon, Command command, String... arguments) {
super(icon);
setCommand(command);
setArguments(arguments);
}
/**
* Creates the CommandButton.
* @param icon the icon of the button
* @param command the command to be executed
* @param arguments the arguments used to execute the command
* @param resultHandler the handler that is executed after the command has run
*/
public CommandButton(ItemStack icon, Command command, CommandResultHandler<MH> resultHandler, String... arguments) {
this(icon, command, arguments);
setResultHandler(resultHandler);
}
/**
* Executes the command obtained by {@link #getCommand()} using the arguments provided by {@link #getArguments()}.
* If a {@link CommandResultHandler} is present, then its {@link CommandResultHandler#afterCommand(HumanEnreplacedy, Command, String[], boolean, MenuHolder, InventoryClickEvent)} executed too.
* @param menuHolder the menu holder
* @param event the InventoryClickEvent
*/
@Override
public void onClick(MH menuHolder, InventoryClickEvent event) {
Command command = getCommand(menuHolder, event);
String[] arguments = getArguments(menuHolder, event);
HumanEnreplacedy player = event.getWhoClicked();
boolean success = command.execute(player, command.getLabel(), arguments);
getResultHandler().ifPresent(resultHandler -> resultHandler.afterCommand(player, command, arguments, success, menuHolder, event));
}
/**
* Set the command.
* @param command the command
*/
public void setCommand(Command command) {
this.command = Objects.requireNonNull(command, "Command cannot be null");
}
/**
* Set the arguments.
* @param arguments the arguments
*/
public void setArguments(String... arguments) {
this.arguments = Objects.requireNonNull(arguments, "Arguments cannot be null");
}
/**
* Set the result handler.
* @param resultHandler the result handler
*/
public void setResultHandler(CommandResultHandler<MH> resultHandler) {
this.resultHandler = resultHandler;
}
/**
* Computes the command to be used from the MenuHolder and InventoryClickEvent.
* This method is called by {@link #onClick(MenuHolder, InventoryClickEvent)}.
* The default implementation delegates to {@link #getCommand()}.
*
* @param menuHolder the menu holder
* @param event the InventoryClickEvent
* @return the command to be executed
*/
protected Command getCommand(MH menuHolder, InventoryClickEvent event) {
return getCommand();
}
/**
* Computes the arguments to be used from the MenuHolder and InventoryClickEvent.
* This method is called by {@link #onClick(MenuHolder, InventoryClickEvent)}.
* The default implementation delegates to {@link #getArguments()}.
*
* @param menuHolder the menu holder
* @param event the InventoryClickEvent
* @return the arguments with which to execute command
*/
protected String[] getArguments(MH menuHolder, InventoryClickEvent event) {
return getArguments();
}
/**
* Get the command.
* @return the command
*/
public Command getCommand() {
return command;
}
/**
* Get the arguments.
* @return the arguments
*/
public String[] getArguments() {
return arguments;
}
/**
* Get the result handler.
* @return an Optional containing the {@link CommandResultHandler} if one is present, otherwise the empty Optional.
*/
public Optional<? extends CommandResultHandler<MH>> getResultHandler() {
return Optional.ofNullable(resultHandler);
}
/**
* A callback that is executed after a command is run from the {@link #onClick(MenuHolder, InventoryClickEvent)} method.
* @param <MH> the menu holder type
*/
@FunctionalInterface
public static interface CommandResultHandler<MH extends MenuHolder<?>> {
/**
* The callback method.
* @param player the player that executed the command
* @param command the command that was executed
* @param arguments the arguments the command was executed with
* @param wasExecutedSuccessFully whether the command was executed successfully
* @param menuHolder the menu holder
* @param event the event that caused the command to execute
*/
public void afterCommand(HumanEnreplacedy player, Command command, String[] arguments, boolean wasExecutedSuccessFully, MH menuHolder, InventoryClickEvent event);
}
}
19
Source : CommandButton.java
with GNU Lesser General Public License v3.0
from Jannyboy11
with GNU Lesser General Public License v3.0
from Jannyboy11
/**
* Set the command.
* @param command the command
*/
public void setCommand(Command command) {
this.command = Objects.requireNonNull(command, "Command cannot be null");
}
19
Source : GenericCommandHelpTopic.java
with GNU General Public License v3.0
from CrucibleMC
with GNU General Public License v3.0
from CrucibleMC
/**
* Lacking an alternative, the help system will create instances of
* GenericCommandHelpTopic for each command in the server's CommandMap. You
* can use this clreplaced as a base clreplaced for custom help topics, or as an example
* for how to write your own.
*/
public clreplaced GenericCommandHelpTopic extends HelpTopic {
protected Command command;
public GenericCommandHelpTopic(Command command) {
this.command = command;
if (command.getLabel().startsWith("/")) {
name = command.getLabel();
} else {
name = "/" + command.getLabel();
}
// The short text is the first line of the description
int i = command.getDescription().indexOf("\n");
if (i > 1) {
shortText = command.getDescription().substring(0, i - 1);
} else {
shortText = command.getDescription();
}
// Build full text
StringBuffer sb = new StringBuffer();
sb.append(ChatColor.GOLD);
sb.append("Description: ");
sb.append(ChatColor.WHITE);
sb.append(command.getDescription());
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Usage: ");
sb.append(ChatColor.WHITE);
sb.append(command.getUsage().replace("<command>", name.substring(1)));
if (command.getAliases().size() > 0) {
sb.append("\n");
sb.append(ChatColor.GOLD);
sb.append("Aliases: ");
sb.append(ChatColor.WHITE);
sb.append(ChatColor.WHITE + StringUtils.join(command.getAliases(), ", "));
}
fullText = sb.toString();
}
public boolean canSee(CommandSender sender) {
if (!command.isRegistered() && !(command instanceof VanillaCommand)) {
// Unregistered commands should not show up in the help (ignore VanillaCommands)
return false;
}
if (sender instanceof ConsoleCommandSender) {
return true;
}
if (amendedPermission != null) {
return sender.hasPermission(amendedPermission);
} else {
return command.testPermissionSilent(sender);
}
}
}
19
Source : SimpleHelpMap.java
with GNU General Public License v3.0
from CardboardPowered
with GNU General Public License v3.0
from CardboardPowered
private boolean commandInIgnoredPlugin(Command command, Set<String> ignoredPlugins) {
return ((command instanceof BukkitCommand) && ignoredPlugins.contains("Bukkit")) || (command instanceof PluginIdentifiableCommand && ignoredPlugins.contains(((PluginIdentifiableCommand) command).getPlugin().getName()));
}
19
Source : SimpleHelpMap.java
with GNU General Public License v3.0
from CardboardPowered
with GNU General Public License v3.0
from CardboardPowered
private String getCommandPluginName(Command command) {
if (command instanceof MinecraftCommandWrapper)
return "Minecraft";
if (command instanceof BukkitCommand)
return "Bukkit";
return (command instanceof PluginIdentifiableCommand) ? ((PluginIdentifiableCommand) command).getPlugin().getName() : null;
}
19
Source : BukkitCommandWrapper.java
with GNU General Public License v3.0
from CardboardPowered
with GNU General Public License v3.0
from CardboardPowered
public clreplaced BukkitCommandWrapper implements com.mojang.brigadier.Command<ServerCommandSource>, Predicate<ServerCommandSource>, SuggestionProvider<ServerCommandSource> {
private final Command command;
public BukkitCommandWrapper(Command command) {
this.command = command;
}
public LiteralCommandNode<ServerCommandSource> register(CommandDispatcher<ServerCommandSource> dispatcher, String label) {
return dispatcher.register(LiteralArgumentBuilder.<ServerCommandSource>literal(label).requires(this).executes(this).then(RequiredArgumentBuilder.<ServerCommandSource, String>argument("args", StringArgumentType.greedyString()).suggests(this).executes(this)));
}
@Override
public boolean test(ServerCommandSource wrapper) {
// Let Bukkit handle permissions
return true;
}
@Override
public int run(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
try {
return Bukkit.getServer().dispatchCommand(getSender(context.getSource()), context.getInput()) ? 1 : 0;
} catch (Exception e) {
e.printStackTrace();
return 0;
}
}
public CommandSender getSender(ServerCommandSource source) {
try {
ServerPlayerEnreplacedy plr = source.getPlayer();
if (null != plr)
return ((IMixinCommandOutput) plr).getBukkitSender(source);
} catch (Exception ignored) {
// ex.printStackTrace();
}
Enreplacedy e = source.getEnreplacedy();
return (null != e) ? ((IMixinCommandOutput) e).getBukkitSender(source) : null;
}
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
List<String> results = ((CraftServer) Bukkit.getServer()).tabComplete(((IMixinServerCommandSource) context.getSource()).getBukkitSender(), builder.getInput(), context.getSource().getWorld(), context.getSource().getPosition(), true);
// Defaults to sub nodes, but we have just one giant args node, so offset accordingly
builder = builder.createOffset(builder.getInput().lastIndexOf(' ') + 1);
for (String s : results) builder.suggest(s);
return builder.buildFuture();
}
}
19
Source : BetterGUIAddon.java
with MIT License
from BetterGUI-MC
with MIT License
from BetterGUI-MC
/**
* Unregister the command
*
* @param command the Command object
*/
public final void unregisterCommand(Command command) {
((BetterGUI) getPlugin()).getCommandManager().unregister(command);
}
19
Source : BetterGUIAddon.java
with MIT License
from BetterGUI-MC
with MIT License
from BetterGUI-MC
/**
* Register the command
*
* @param command the Command object
*/
public final void registerCommand(Command command) {
((BetterGUI) getPlugin()).getCommandManager().register(command);
}
18
Source : ScriptBlockPlusCommand.java
with GNU General Public License v3.0
from yuttyann
with GNU General Public License v3.0
from yuttyann
@Override
public boolean runCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
int length = args.length;
if (length == 1) {
if (equals(args[0], "tool")) {
return doTool(sender);
} else if (equals(args[0], "reload")) {
return doReload(sender);
} else if (equals(args[0], "backup")) {
try {
return doBackup(sender);
} catch (IOException e) {
e.printStackTrace();
}
} else if (equals(args[0], "checkver")) {
return doCheckVer(sender);
} else if (equals(args[0], "datamigr")) {
return doDataMigr(sender);
}
}
if (length == 2) {
if (equals(args[0], ScriptKey.types()) && equals(args[1], "remove", "view")) {
return setAction(sender, args);
} else if (equals(args[0], "selector") && equals(args[1], "paste", "remove")) {
return doSelector(sender, args);
}
}
if (length == 3 && equals(args[0], ScriptKey.types()) && equals(args[1], "redstone") && equals(args[2], "false")) {
return setAction(sender, args);
}
if (length > 3 && equals(args[0], ScriptKey.types()) && equals(args[1], "redstone") && equals(args[2], "true")) {
return setAction(sender, args);
}
if (length > 2) {
if (length < 5 && equals(args[0], "selector") && equals(args[1], "paste")) {
return doSelector(sender, args);
} else if (equals(args[0], ScriptKey.types())) {
if (length == 6 && equals(args[1], "run")) {
return doRun(sender, args);
} else if (equals(args[1], "create", "add")) {
return setAction(sender, args);
}
}
}
return false;
}
18
Source : CommandPass.java
with Apache License 2.0
from Tradeshop
with Apache License 2.0
from Tradeshop
public clreplaced CommandPreplaced {
private CommandSender sender;
private Command cmd;
private String label;
private ArrayList<String> args;
public CommandPreplaced(CommandSender sender, Command cmd, String label, String[] args) {
this.sender = sender;
this.cmd = cmd;
this.label = label;
this.args = Lists.newArrayList(args);
}
public CommandSender getSender() {
return sender;
}
public Command getCmd() {
return cmd;
}
public String getLabel() {
return label;
}
public int argsSize() {
return args.size();
}
public boolean hasArgAt(int index) {
return index < argsSize();
}
public String getArgAt(int index) {
if (hasArgAt(index)) {
return args.get(index);
} else {
return null;
}
}
public ArrayList<String> getArgs() {
return args;
}
public boolean hasArgs() {
return argsSize() > 0;
}
}
18
Source : Head.java
with MIT License
from Thatsmusic99
with MIT License
from Thatsmusic99
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
return fire(args, sender);
}
18
Source : CommodoreImpl.java
with MIT License
from TabooLib
with MIT License
from TabooLib
@Override
public void register(Command command, LiteralCommandNode<?> node) {
Objects.requireNonNull(command, "command");
Objects.requireNonNull(node, "node");
register(command, node, command::testPermissionSilent);
}
18
Source : ServerMock.java
with MIT License
from seeseemelk
with MIT License
from seeseemelk
/**
* Executes a command.
*
* @param command The command to execute.
* @param sender The person that executed the command.
* @param args The arguments to preplaced to the commands.
* @return The value returned by {@link Command#execute}.
*/
public CommandResult execute(Command command, CommandSender sender, String... args) {
replacedertMainThread();
if (!(sender instanceof MessageTarget)) {
throw new IllegalArgumentException("Only a MessageTarget can be the sender of the command");
}
boolean status = command.execute(sender, command.getName(), args);
return new CommandResult(status, (MessageTarget) sender);
}
18
Source : SimpleHelpMap.java
with GNU General Public License v3.0
from Mohist-Community
with GNU General Public License v3.0
from Mohist-Community
private void fillPluginIndexes(Map<String, Set<HelpTopic>> pluginIndexes, Collection<? extends Command> commands) {
for (Command command : commands) {
String pluginName = getCommandPluginName(command);
if (pluginName != null) {
HelpTopic topic = getHelpTopic("/" + command.getLabel());
if (topic != null) {
if (!pluginIndexes.containsKey(pluginName)) {
// keep things in topic order
pluginIndexes.put(pluginName, new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance()));
}
pluginIndexes.get(pluginName).add(topic);
}
}
}
}
18
Source : BukkitCommandWrapper.java
with GNU General Public License v3.0
from Mohist-Community
with GNU General Public License v3.0
from Mohist-Community
public clreplaced BukkitCommandWrapper implements com.mojang.brigadier.Command<CommandSource>, Predicate<CommandSource>, SuggestionProvider<CommandSource> {
private final CraftServer server;
private final Command command;
public BukkitCommandWrapper(CraftServer server, Command command) {
this.server = server;
this.command = command;
}
public LiteralCommandNode<CommandSource> register(CommandDispatcher<CommandSource> dispatcher, String label) {
return dispatcher.register(LiteralArgumentBuilder.<CommandSource>literal(label).requires(this).executes(this).then(RequiredArgumentBuilder.<CommandSource, String>argument("args", StringArgumentType.greedyString()).suggests(this).executes(this)));
}
@Override
public boolean test(CommandSource wrapper) {
return command.testPermissionSilent(wrapper.getBukkitSender());
}
@Override
public int run(CommandContext<CommandSource> context) throws CommandSyntaxException {
return server.dispatchCommand(context.getSource().getBukkitSender(), context.getInput()) ? 1 : 0;
}
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException {
List<String> results = server.tabComplete(context.getSource().getBukkitSender(), builder.getInput(), context.getSource().getLevel(), context.getSource().getPosition(), true);
// Defaults to sub nodes, but we have just one giant args node, so offset accordingly
builder = builder.createOffset(builder.getInput().lastIndexOf(' ') + 1);
for (String s : results) {
builder.suggest(s);
}
return builder.buildFuture();
}
}
18
Source : BukkitCommandWrapper.java
with GNU Lesser General Public License v3.0
from Luohuayu
with GNU Lesser General Public License v3.0
from Luohuayu
public clreplaced BukkitCommandWrapper implements ICommand {
private final CommandSender bukkitSender;
private final String name;
private final Command command;
public BukkitCommandWrapper(CommandSender bukkitSender, String name, Command command) {
this.bukkitSender = bukkitSender;
this.command = command;
this.name = name;
}
@Override
public int compareTo(ICommand o) {
return 0;
}
@Override
public String getName() {
return this.command.getName();
}
@Override
public String getUsage(ICommandSender sender) {
return this.command.getDescription();
}
@Override
public List<String> getAliases() {
return this.command.getAliases();
}
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
try {
this.command.execute(bukkitSender, name, args);
} catch (Exception e) {
throw new CommandException(e.getMessage());
}
}
@Override
public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
return this.command.testPermission(bukkitSender);
}
@Override
public List<String> getTabCompletions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos targetPos) {
try {
return this.command.tabComplete(bukkitSender, name, args);
} catch (Exception e) {
e.printStackTrace();
return ImmutableList.of();
}
}
@Override
public boolean isUsernameIndex(String[] args, int index) {
return false;
}
@Nullable
public static BukkitCommandWrapper toNMSCommand(ICommandSender sender, String name) {
Command command = ((CraftServer) Bukkit.getServer()).getCommandMap().getCommand(name);
CommandSender bukkitSender;
try {
if (command != null && (bukkitSender = CommandBlockBaseLogic.unwrapSender(sender)) != null) {
return new BukkitCommandWrapper(bukkitSender, name, command);
}
} catch (RuntimeException ignored) {
}
return null;
}
}
18
Source : LevelledMobsCommand.java
with GNU Affero General Public License v3.0
from lokka30
with GNU Affero General Public License v3.0
from lokka30
public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
if (sender.hasPermission("levelledmobs.command")) {
if (args.length == 0) {
sendMainUsage(sender, label);
} else {
switch(args[0].toLowerCase()) {
case "kill":
killSubcommand.parseSubcommand(main, sender, label, args);
break;
case "reload":
reloadSubcommand.parseSubcommand(main, sender, label, args);
break;
case "summon":
summonSubcommand.parseSubcommand(main, sender, label, args);
break;
case "info":
infoSubcommand.parseSubcommand(main, sender, label, args);
break;
case "compatibility":
compatibilitySubcommand.parseSubcommand(main, sender, label, args);
break;
case "generatemobdata":
generateMobDataSubcommand.parseSubcommand(main, sender, label, args);
break;
default:
sendMainUsage(sender, label);
}
}
} else {
main.configUtils.sendNoPermissionMsg(sender);
}
return true;
}
18
Source : BukkitCommandWrapper.java
with GNU General Public License v3.0
from kmecpp
with GNU General Public License v3.0
from kmecpp
public clreplaced BukkitCommandWrapper implements com.mojang.brigadier.Command<CommandListenerWrapper>, Predicate<CommandListenerWrapper>, SuggestionProvider<CommandListenerWrapper> {
private final CraftServer server;
private final Command command;
public BukkitCommandWrapper(CraftServer server, Command command) {
this.server = server;
this.command = command;
}
public LiteralCommandNode<CommandListenerWrapper> register(CommandDispatcher<CommandListenerWrapper> dispatcher, String label) {
return dispatcher.register(LiteralArgumentBuilder.<CommandListenerWrapper>literal(label).requires(this).executes(this).then(RequiredArgumentBuilder.<CommandListenerWrapper, String>argument("args", StringArgumentType.greedyString()).suggests(this).executes(this)));
}
@Override
public boolean test(CommandListenerWrapper wrapper) {
return command.testPermissionSilent(wrapper.getBukkitSender());
}
@Override
public int run(CommandContext<CommandListenerWrapper> context) throws CommandSyntaxException {
return server.dispatchCommand(context.getSource().getBukkitSender(), context.getInput()) ? 1 : 0;
}
@Override
public CompletableFuture<Suggestions> getSuggestions(CommandContext<CommandListenerWrapper> context, SuggestionsBuilder builder) throws CommandSyntaxException {
List<String> results = server.tabComplete(context.getSource().getBukkitSender(), builder.getInput(), context.getSource().getWorld(), context.getSource().getPosition(), true);
// These are normally only set based on sub nodes, but we have just one giant args node
builder.start = builder.getInput().lastIndexOf(' ') + 1;
builder.remaining = builder.getInput().substring(builder.start);
for (String s : results) {
builder.suggest(s);
}
return builder.buildFuture();
}
}
18
Source : SubCommand.java
with GNU General Public License v3.0
from Jumper251
with GNU General Public License v3.0
from Jumper251
public List<String> onTab(CommandSender cs, Command cmd, String label, String[] args) {
return null;
}
18
Source : NMS_1_16_R3.java
with MIT License
from JorelAli
with MIT License
from JorelAli
@Override
public boolean isVanillaCommandWrapper(Command command) {
return command instanceof VanillaCommandWrapper;
}
18
Source : Enchantments_plus.java
with GNU General Public License v3.0
from Geolykt
with GNU General Public License v3.0
from Geolykt
// Sends commands over to the CommandProcessor for it to handle
public boolean onCommand(CommandSender sender, Command command, String commandlabel, String[] args) {
return CommandProcessor.onCommand(sender, command, commandlabel, args);
}
18
Source : CommandProcessor.java
with GNU General Public License v3.0
from Geolykt
with GNU General Public License v3.0
from Geolykt
// Control flow for the command processor
public static boolean onCommand(CommandSender sender, Command command, String commandlabel, String[] args) {
if (commandlabel.equalsIgnoreCase("ench")) {
String label = args.length == 0 ? "" : args[0].toLowerCase();
switch(label) {
case "reload":
return reload(sender);
case "give":
return give(sender, args);
case "list":
return listEnchantment(sender);
case "info":
return infoEnchantment(sender, args);
case "disable":
return disable(sender, args);
case "enable":
return enable(sender, args);
case "version":
return versionInfo(sender);
case "lasercol":
return setLaserColor(sender, args);
case "license":
return printLicense(sender, args);
case "help":
default:
return helpEnchantment(sender, label) || enchant(sender, args);
}
}
return true;
}
18
Source : TestPlugin.java
with GNU General Public License v3.0
from CrucibleMC
with GNU General Public License v3.0
from CrucibleMC
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
throw new UnsupportedOperationException("Not supported.");
}
18
Source : TestPlugin.java
with GNU General Public License v3.0
from CrucibleMC
with GNU General Public License v3.0
from CrucibleMC
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
throw new UnsupportedOperationException("Not supported.");
}
18
Source : SimpleHelpMap.java
with GNU General Public License v3.0
from CardboardPowered
with GNU General Public License v3.0
from CardboardPowered
private void fillPluginIndexes(Map<String, Set<HelpTopic>> pluginIndexes, Collection<? extends Command> commands) {
for (Command command : commands) {
String pluginName = getCommandPluginName(command);
if (pluginName != null) {
HelpTopic topic = getHelpTopic("/" + command.getLabel());
if (topic != null) {
if (!pluginIndexes.containsKey(pluginName))
// keep things in topic order
pluginIndexes.put(pluginName, new TreeSet<HelpTopic>(HelpTopicComparator.helpTopicComparatorInstance()));
pluginIndexes.get(pluginName).add(topic);
}
}
}
}
18
Source : VersionIncompatibleCommand.java
with GNU General Public License v3.0
from Arnuh
with GNU General Public License v3.0
from Arnuh
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
if (commandSender.hasPermission(this.perm)) {
commandSender.sendMessage(this.pluginPrefix + " " + this.msg);
} else {
commandSender.sendMessage(this.pluginPrefix + " " + this.permMsg);
}
return true;
}
17
Source : Main.java
with GNU General Public License v2.0
from ZombieStriker
with GNU General Public License v2.0
from ZombieStriker
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
if (args.length == 1) {
List<String> list = new ArrayList<>();
String[] commands = new String[] { "disableAutoSaver", "enableAutoSaver", "restore", "save", "stop", "toggleOptions" };
for (String f : commands) {
if (f.toLowerCase().startsWith(args[0].toLowerCase()))
list.add(f);
}
return list;
}
if (args.length > 1) {
if (args[0].equalsIgnoreCase("restore")) {
List<String> list = new ArrayList<>();
for (File f : getBackupFolder().listFiles()) {
if (f.getName().toLowerCase().startsWith(args[1].toLowerCase()))
list.add(f.getName());
}
return list;
}
}
return super.onTabComplete(sender, command, alias, args);
}
17
Source : PlayerCommand.java
with GNU General Public License v3.0
from zachbr
with GNU General Public License v3.0
from zachbr
@Override
protected boolean commandLogic(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;
return doReflectionLookups(sender, args, player);
}
17
Source : ItemCommand.java
with GNU General Public License v3.0
from zachbr
with GNU General Public License v3.0
from zachbr
@Override
protected boolean commandLogic(CommandSender sender, Command command, String label, String[] args) {
Player player = (Player) sender;
ItemStack itemStack = player.getInventory().gereplacedemInMainHand();
return doReflectionLookups(sender, args, itemStack);
}
17
Source : ScriptBlockPlusCommand.java
with GNU General Public License v3.0
from yuttyann
with GNU General Public License v3.0
from yuttyann
@Override
public void tabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, @NotNull List<String> empty) {
if (args.length == 1) {
var prefix = args[0].toLowerCase(Locale.ROOT);
var set = setCommandPermissions(sender, new LinkedHashSet<String>());
StreamUtils.fForEach(set, s -> StringUtils.isNotEmpty(s) && s.startsWith(prefix), empty::add);
} else if (args.length == 2) {
if (equals(args[0], "selector")) {
if (Permission.COMMAND_SELECTOR.has(sender)) {
var prefix = args[1].toLowerCase(Locale.ROOT);
var answers = new String[] { "paste", "remove" };
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
}
} else if (equals(args[0], ScriptKey.types())) {
if (Permission.has(sender, ScriptKey.valueOf(args[0]), true)) {
var prefix = args[1].toLowerCase(Locale.ROOT);
var answers = new String[] { "create", "add", "remove", "view", "run", "redstone" };
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
}
}
} else if (args.length > 2) {
if (args.length == 3 && equals(args[0], "selector") && equals(args[1], "paste")) {
if (Permission.COMMAND_SELECTOR.has(sender)) {
var prefix = args[2].toLowerCase(Locale.ROOT);
var answers = new String[] { "true", "false" };
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
}
} else if (args.length == 4 && equals(args[0], "selector") && equals(args[1], "paste")) {
if (Permission.COMMAND_SELECTOR.has(sender)) {
var prefix = args[3].toLowerCase(Locale.ROOT);
var answers = new String[] { "true", "false" };
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
}
} else if (equals(args[0], ScriptKey.types())) {
if (Permission.has(sender, ScriptKey.valueOf(args[0]), true)) {
if (args.length == 3 && equals(args[1], "run")) {
var worlds = Bukkit.getWorlds();
var prefix = args[args.length - 1].toLowerCase(Locale.ROOT);
var answers = StreamUtils.toArray(worlds, World::getName, String[]::new);
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
} else if (equals(args[1], "create", "add")) {
var prefix = args[args.length - 1].toLowerCase(Locale.ROOT);
var answers = OptionManager.getSyntaxs();
Arrays.sort(answers);
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), s -> empty.add(s.trim()));
} else if (args.length == 3 && equals(args[1], "redstone")) {
var prefix = args[2].toLowerCase(Locale.ROOT);
var answers = new String[] { "true", "false" };
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
} else if (args.length == 4 && equals(args[1], "redstone") && equals(args[2], "true")) {
var prefix = args[3].toLowerCase(Locale.ROOT);
var answers = Lists.newArrayList("@a", "@e", "@p", "@r");
StreamUtils.forEach(Filter.values(), f -> answers.add(Filter.getPrefix() + f.getSyntax() + "}"));
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
} else if (args.length == 5 && equals(args[1], "redstone") && equals(args[2], "true") && args[3].startsWith(Filter.getPrefix())) {
var prefix = args[4].toLowerCase(Locale.ROOT);
var answers = new String[] { "@a", "@e", "@p", "@r" };
StreamUtils.fForEach(answers, s -> s.startsWith(prefix), empty::add);
}
}
}
}
}
17
Source : XConomy.java
with GNU General Public License v3.0
from YiC200333
with GNU General Public License v3.0
from YiC200333
private void coveress(CommandMap commandMap) {
Command commanda = new EconomyCommand("economy");
commandMap.register("economy", commanda);
Command commandb = new EconomyCommand("eco");
commandMap.register("eco", commandb);
Command commandc = new EconomyCommand("ebalancetop");
commandMap.register("ebalancetop", commandc);
Command commandd = new EconomyCommand("ebaltop");
commandMap.register("ebaltop", commandd);
Command commande = new EconomyCommand("eeconomy");
commandMap.register("eeconomy", commande);
}
17
Source : AnnoCommandManager.java
with Apache License 2.0
from UnknownStudio
with Apache License 2.0
from UnknownStudio
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
CommandNode node = root;
int i, size;
for (i = 0, size = args.length; i < size; i++) {
CommandNode child = node.getChild(args[i]);
if (child == null)
break;
node = child;
}
while (node != null && !node.hasCommand()) {
node = node.getParent();
i--;
}
if (node == null || !node.hasCommand()) {
getResultHandler().onUnknownCommand(sender, args);
return true;
}
handleCommand(node, sender, Arrays.copyOfRange(args, i, args.length));
return true;
}
17
Source : WSCommands.java
with GNU General Public License v3.0
from trainerlord
with GNU General Public License v3.0
from trainerlord
public boolean confirmCommand(CommandSender sender, Command command, String label, String[] args) {
CommandSender cs = sender;
if (AutoUpdater.getInstance().confirmed()) {
cs.sendMessage(PluginConfig.getPrefix() + "§cAlready confirmed or no confirm needed");
return false;
}
AutoUpdater.getInstance().confirm();
cs.sendMessage(PluginConfig.getPrefix() + "§aAutoupdate confirmed, §crestart §ato apply changes");
return true;
}
17
Source : CMCommand.java
with GNU Lesser General Public License v3.0
from timtomtim7
with GNU Lesser General Public License v3.0
from timtomtim7
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player))
return true;
if (args.length > 0) {
String id = args[0];
if (id.equalsIgnoreCase("close")) {
ChatMenuAPI.setCurrentMenu((Player) sender, null);
return true;
} else if (args.length > 1) {
int element;
try {
element = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
return true;
}
String[] elementArgs = new String[args.length - 2];
System.arraycopy(args, 2, elementArgs, 0, elementArgs.length);
ChatMenu menu = ChatMenuAPI.getMenu(id);
if (menu == null || element < 0 || element >= menu.elements.size())
return true;
menu.edit((Player) sender, element, elementArgs);
}
}
return true;
}
17
Source : SellHead.java
with GNU General Public License v3.0
from Thatsmusic99
with GNU General Public License v3.0
from Thatsmusic99
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, @NotNull String[] args) {
return new ArrayList<>();
}
17
Source : InternalPlugin.java
with MIT License
from TabooLib
with MIT License
from TabooLib
@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
return null;
}
17
Source : InternalPlugin.java
with MIT License
from TabooLib
with MIT License
from TabooLib
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
return false;
}
17
Source : BetterRTP.java
with MIT License
from SuperRonanCraft
with MIT License
from SuperRonanCraft
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return this.cmd.onTabComplete(sender, args);
}
17
Source : BukkitCommandExecutor.java
with GNU Affero General Public License v3.0
from Spicord
with GNU Affero General Public License v3.0
from Spicord
@Override
public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) {
UniversalCommandSender commandSender;
if (sender instanceof Player) {
commandSender = new BukkitPlayer((Player) sender);
} else {
commandSender = new UniversalCommandSender() {
@Override
public boolean hasPermission(String permission) {
return isEmpty(permission) || sender.hasPermission(permission);
}
@Override
public void sendMessage(String message) {
sender.sendMessage(message);
}
private boolean isEmpty(String string) {
return string == null || string.isEmpty();
}
};
}
return command.onCommand(commandSender, args);
}
17
Source : SimplixQuickStart.java
with MIT License
from Simplix-Softworks
with MIT License
from Simplix-Softworks
public static void registerCommand(@NonNull final Command command) {
try {
final Field commandMapField = Bukkit.getServer().getClreplaced().getDeclaredField("commandMap");
commandMapField.setAccessible(true);
final CommandMap commandMap = (CommandMap) commandMapField.get(Bukkit.getServer());
commandMap.register(command.getLabel(), command);
} catch (final Throwable throwable) {
Bukkit.getLogger().log(Level.SEVERE, "Unable to register command", throwable);
}
}
See More Examples