Ejemplo n.º 1
0
 /**
  * A safe version of <code>execute</code> which catches and logs all errors that occur. Returns
  * whether the command handler should print usage or not.
  *
  * @see #execute(Command, String[], CommandSender, Object...)
  * @return Whether further usage should be printed
  */
 public boolean executeSafe(
     org.bukkit.command.Command command,
     String[] args,
     CommandSender sender,
     Object... methodArgs) {
   try {
     try {
       execute(command, args, sender, methodArgs);
     } catch (ServerCommandException ex) {
       Messaging.sendTr(sender, CommandMessages.MUST_BE_INGAME);
     } catch (CommandUsageException ex) {
       Messaging.sendError(sender, ex.getMessage());
       Messaging.sendError(sender, ex.getUsage());
     } catch (UnhandledCommandException ex) {
       return false;
     } catch (WrappedCommandException ex) {
       throw ex.getCause();
     } catch (CommandException ex) {
       Messaging.sendError(sender, ex.getMessage());
     } catch (NumberFormatException ex) {
       Messaging.sendErrorTr(sender, CommandMessages.INVALID_NUMBER);
     }
   } catch (Throwable ex) {
     ex.printStackTrace();
     if (sender instanceof Player) {
       Messaging.sendErrorTr(sender, CommandMessages.REPORT_ERROR);
       Messaging.sendError(sender, ex.getClass().getName() + ": " + ex.getMessage());
     }
   }
   return true;
 }
 @Override
 protected Prompt acceptValidatedInput(ConversationContext context, Number input) {
   boolean found = false;
   for (NPC npc : choices) {
     if (input.intValue() == npc.getId()) {
       found = true;
       break;
     }
   }
   CommandSender sender = (CommandSender) context.getForWhom();
   if (!found) {
     Messaging.sendErrorTr(sender, Messages.SELECTION_PROMPT_INVALID_CHOICE, input);
     return this;
   }
   NPC toSelect = CitizensAPI.getNPCRegistry().getById(input.intValue());
   try {
     callback.run(toSelect);
   } catch (ServerCommandException ex) {
     Messaging.sendTr(sender, CommandMessages.MUST_BE_INGAME);
   } catch (CommandUsageException ex) {
     Messaging.sendError(sender, ex.getMessage());
     Messaging.sendError(sender, ex.getUsage());
   } catch (UnhandledCommandException ex) {
     ex.printStackTrace();
   } catch (WrappedCommandException ex) {
     ex.getCause().printStackTrace();
   } catch (CommandException ex) {
     Messaging.sendError(sender, ex.getMessage());
   } catch (NumberFormatException ex) {
     Messaging.sendErrorTr(sender, CommandMessages.INVALID_NUMBER);
   }
   return null;
 }