Ejemplo n.º 1
0
 @Command(aliases = "clear", usage = "[player]", desc = "Clears your inventory", min = 0, max = 1)
 @CommandPermissions("vanilla.command.clear")
 public void clear(CommandContext args, CommandSource source) throws CommandException {
   if (args.length() == 0) {
     if (!(source instanceof Player)) {
       throw new CommandException("You must be a player to clear your own inventory.");
     }
     PlayerInventory inv = ((Player) source).get(PlayerInventory.class);
     if (inv == null) {
       source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "You have no inventory!");
       return;
     }
     inv.clear();
   }
   if (args.length() == 1) {
     Player player = args.getPlayer(0, false);
     if (player == null) {
       source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player is not online!");
       return;
     }
     PlayerInventory inv = player.get(PlayerInventory.class);
     if (inv == null) {
       source.sendMessage(plugin.getPrefix(), ChatStyle.RED, "Player has no inventory!");
       return;
     }
     player.sendMessage(
         plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Your inventory has been cleared.");
     if (source instanceof Player && source.equals(player)) {
       return;
     }
   }
   source.sendMessage(plugin.getPrefix(), ChatStyle.BRIGHT_GREEN, "Inventory cleared.");
 }