本文整理匯總了Java中org.bukkit.command.CommandException類的典型用法代碼示例。如果您正苦於以下問題:Java CommandException類的具體用法?Java CommandException怎麽用?Java CommandException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CommandException類屬於org.bukkit.command包,在下文中一共展示了CommandException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
boolean success = false;
if (!owningPlugin.isEnabled()) {
return false;
}
if (!testPermission(sender)) {
return true;
}
try {
success = executor.onCommand(sender, this, commandLabel, args);
} catch (Throwable ex) {
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + owningPlugin.getDescription().getFullName(), ex);
}
if (!success && usageMessage.length() > 0) {
for (String line : usageMessage.replace("<command>", commandLabel).split("\n")) {
sender.sendMessage(line);
}
}
return success;
}
示例2: protectedDispatch
import org.bukkit.command.CommandException; //導入依賴的package包/類
private void protectedDispatch(CommandSender sender, String command) {
boolean player = (sender instanceof Player);
try {
sender.sendMessage((player ? ChatColor.GOLD : "") + "[ConditionalCommands] > Dispatching command \"" + command + "\"");
this.getServer().dispatchCommand(sender, command);
} catch (CommandException ex) {
if (getConfig().getBoolean("dev")) {
sender.sendMessage((player ? ChatColor.GOLD : "") + "[ConditionalCommands] > An error occured whilst executing the command. The stack trace has been printed to the console.");
this.getLogger().warning("ConditionalCommands executed this command on the main thread through the sender " + sender);
this.getLogger().warning("The command string is: " + command);
this.getLogger().warning("Stack trace follows: ");
ex.printStackTrace();
} else {
sender.sendMessage((player ? ChatColor.GOLD : "") + "[ConditionalCommands] > There was a problem trying to run the command.");
}
}
}
示例3: execute
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override public boolean execute(BaseCommand command, RegisteredCommand registeredCommand, CommandIssuer sender,
List<String> args, Throwable t) {
if (t instanceof InvocationTargetException) { // ACF doesnt pass actual exception in 0.5.0
t = t.getCause();
}
if (t instanceof NumberFormatException) {
final Matcher matcher = numberFormat.matcher(t.getMessage());
if (matcher.matches()) {
sender.sendMessage(ChatColor.RED + "Number expected; string \"" + matcher.group(1) + "\" given.");
return true;
} else {
sender.sendMessage(ChatColor.RED + "Number expected; string given.");
return true;
}
} else if (t instanceof CommonException) {
sender.sendMessage(ChatColor.RED + t.getMessage());
t.printStackTrace();
return true;
} else if (t instanceof CommandException) {
sender.sendMessage(ChatColor.RED + t.getMessage());
return true;
}
return false;
}
示例4: tabCompleteCommand
import org.bukkit.command.CommandException; //導入依賴的package包/類
public List<String> tabCompleteCommand(Player player, String message) {
// Spigot Start
if ( (org.spigotmc.SpigotConfig.tabComplete < 0 || message.length() <= org.spigotmc.SpigotConfig.tabComplete) && !message.contains( " " ) )
{
return ImmutableList.of();
}
// Spigot End
List<String> completions = null;
try {
completions = getCommandMap().tabComplete(player, message.substring(1));
} catch (CommandException ex) {
player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command");
getLogger().log(Level.SEVERE, "Exception when " + player.getName() + " attempted to tab complete " + message, ex);
}
return completions == null ? ImmutableList.<String>of() : completions;
}
示例5: tabCompleteCommand
import org.bukkit.command.CommandException; //導入依賴的package包/類
public List<String> tabCompleteCommand(Player player, String message) {
// Spigot Start
if ( !org.spigotmc.SpigotConfig.tabComplete && !message.contains( " " ) )
{
return ImmutableList.of();
}
// Spigot End
// Spigot Start
List<String> completions = new ArrayList<String>();
try {
message = message.substring( 1 );
List<String> bukkitCompletions = getCommandMap().tabComplete( player, message );
if ( bukkitCompletions != null )
{
completions.addAll( bukkitCompletions );
}
List<String> vanillaCompletions = org.spigotmc.VanillaCommandWrapper.complete( player, message );
if ( vanillaCompletions != null )
{
completions.addAll( vanillaCompletions );
}
// Spigot End
} catch (CommandException ex) {
player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command");
getLogger().log(Level.SEVERE, "Exception when " + player.getName() + " attempted to tab complete " + message, ex);
}
return completions; // Spigot
}
示例6: execute
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
boolean success;
if (!this.owningPlugin.isEnabled()) {
return false;
}
if (!testPermission(sender)) {
return true;
}
try {
success = this.executor.onCommand(sender, this, commandLabel, args);
}
catch (Throwable ex) {
throw new CommandException("Unhandled exception executing command '" + commandLabel + "' in plugin " + this.owningPlugin.getDescription().getFullName(), ex);
}
if (!success && this.usageMessage.length() > 0) {
for (String line : this.usageMessage.replace("<command>", commandLabel).split("\n")) {
sender.sendMessage(line);
}
}
return success;
}
示例7: tabComplete
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (this.completer != null) {
completions = this.completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && this.executor instanceof TabCompleter) {
completions = ((TabCompleter) this.executor).onTabComplete(sender, this, alias, args);
}
}
catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ").append(this.owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
示例8: tabComplete
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public java.util.List<String> tabComplete(CommandSender sender, String alias, String[] args) throws CommandException, IllegalArgumentException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(args, "Arguments cannot be null");
Validate.notNull(alias, "Alias cannot be null");
List<String> completions = null;
try {
if (completer != null) {
completions = completer.onTabComplete(sender, this, alias, args);
}
if (completions == null && executor instanceof TabCompleter) {
completions = ((TabCompleter) executor).onTabComplete(sender, this, alias, args);
}
} catch (Throwable ex) {
StringBuilder message = new StringBuilder();
message.append("Unhandled exception during tab completion for command '/").append(alias).append(' ');
for (String arg : args) {
message.append(arg).append(' ');
}
message.deleteCharAt(message.length() - 1).append("' in plugin ")
.append(owningPlugin.getDescription().getFullName());
throw new CommandException(message.toString(), ex);
}
if (completions == null) {
return super.tabComplete(sender, alias, args);
}
return completions;
}
示例9: execute
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public boolean execute( CommandSender commandSender, String commandLabel, String[] args ) {
checkNotNull( commandSender );
checkNotNull( commandLabel );
checkNotNull( args );
boolean success;
if ( !plugin.isEnabled() ) {
return false;
}
if ( !testPermission( commandSender ) ) {
return true;
}
//execute
try {
success = executor.onCommand( commandSender, this, commandLabel, args );
} catch ( Throwable ex ) {
throw new CommandException( "Unhandled exception executing command '" + commandLabel + "' in plugin "
+ plugin.getDescription().getFullName(), ex );
}
// print usage
if ( !success && usageMessage.length() > 0 ) {
for ( String line : usageMessage.replace( "<command>", commandLabel ).split( "\n" ) ) {
commandSender.sendMessage( line );
}
}
return success;
}
示例10: tabComplete
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public List<String> tabComplete( CommandSender sender, String alias, String[] args )
throws CommandException, IllegalArgumentException {
checkNotNull( sender );
checkNotNull( alias );
checkNotNull( args );
List<String> completions = null;
try {
// if we have a completer, get the completions from it
if ( completer != null ) {
completions = completer.onTabComplete( sender, this, alias, args );
}
// if not succeeded, try bukkits completer
if ( completions == null && executor instanceof TabCompleter ) {
completions = ( (TabCompleter) executor ).onTabComplete( sender, this, alias, args );
}
} catch ( Throwable ex ) {
StringBuilder message = new StringBuilder();
message.append( "Unhandled exception during tab completion for command '/" ).append( alias ).append( ' ' );
for ( String arg : args ) {
message.append( arg ).append( ' ' );
}
message.deleteCharAt( message.length() - 1 ).append( "' in plugin " )
.append( plugin.getDescription().getFullName() );
throw new CommandException( message.toString(), ex );
}
if ( completions == null ) {
return super.tabComplete( sender, alias, args );
}
return completions;
}
示例11: dispatchCommand
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) throws CommandException {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(commandLine, "CommandLine cannot be null");
if (commandMap.dispatch(sender, commandLine)) {
return true;
}
sender.sendMessage("Unknown command. Type \"/help\" for help.");
return false;
}
示例12: tabCompleteCommand
import org.bukkit.command.CommandException; //導入依賴的package包/類
public List<String> tabCompleteCommand(Player player, String message) {
List<String> completions = null;
try {
completions = getCommandMap().tabComplete(player, message.substring(1));
} catch (CommandException ex) {
player.sendMessage(ChatColor.RED + "An internal error occurred while attempting to tab-complete this command");
getLogger().log(Level.SEVERE, "Exception when " + player.getName() + " attempted to tab complete " + message, ex);
}
return completions == null ? ImmutableList.<String>of() : completions;
}
示例13: execute
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public boolean execute(CommandSender sender, String commandLabel,
String[] args) {
boolean success = false;
if (!owningPlugin.isEnabled()) {
return false;
}
if (!testPermission(sender)) {
return true;
}
try {
success = executor.onCommand(sender, this, commandLabel, args);
} catch (Throwable ex) {
throw new CommandException(
"Unhandled exception executing command '"
+ commandLabel + "' in plugin "
+ owningPlugin.getDescription().getFullName(),
ex);
}
if (!success && usageMessage.length() > 0) {
for (String line : usageMessage.replace("<command>",
commandLabel).split("\n")) {
sender.sendMessage(line);
}
}
return success;
}
示例14: onCommand
import org.bukkit.command.CommandException; //導入依賴的package包/類
@Override
public boolean onCommand(CommandSender paramCommandSender, Command paramCommand, String paramString,
String[] paramArrayOfString) {
try {
doExecute(paramCommandSender, paramArrayOfString);
} catch (Throwable e) {
paramCommandSender.sendMessage(ChatColor.RED
+ ExceptionHelper.getExceptionMessage(e, getErrorMessageHead()));
throw new CommandException(e.getMessage() == null ? "" : e.getMessage(), e);
}
return true;
}
示例15: execute
import org.bukkit.command.CommandException; //導入依賴的package包/類
/**
* Executes a command
*
* @param command command enum
* @param sender sender instance
* @param args command arguments
*/
public void execute(CommandWrapper command, CommandSender sender, String[] args) {
CommandExecutor executor = getExecutor(command);
if(command.getPermission() != null && !command.hasPermission(sender)) {
Message.CHAT_NOPERMISSIONS.send(sender);
return;
}
if(!command.allowedSender(sender)) {
Message.CHAT_CMDFROMCONSOLE.send(sender);
return;
}
NovaPlayer nPlayer = PlayerManager.getPlayer(sender);
if((sender instanceof Player) && (command.hasFlag(CommandWrapper.Flag.CONFIRM) && !Permission.NOVAGUILDS_ADMIN_NOCONFIRM.has(sender) && (nPlayer.getCommandExecutorHandler() == null || nPlayer.getCommandExecutorHandler().getState() != CommandExecutorHandler.State.CONFIRMED))) {
nPlayer.newCommandExecutorHandler(command, args);
nPlayer.getCommandExecutorHandler().executorVariable(command.getExecutorVariable());
}
else {
if(executor instanceof CommandExecutor.Reversed) {
((CommandExecutor.Reversed) executor).set(command.getExecutorVariable());
command.executorVariable(null);
}
try {
executor.execute(sender, args);
}
catch(Exception e) {
LoggerUtils.exception(new CommandException("Unhandled exception executing command '" + command.getName() + "' in plugin NovaGuilds", e));
}
}
}