Example #1
0
  @Override
  public List getPossibleCommands(ICommandSender sender) {
    ArrayList arraylist = new ArrayList();
    Iterator iterator = super.getCommands().keySet().iterator();
    while (iterator.hasNext()) {
      Object next = iterator.next();

      if (true) {
        ICommand icommand = (ICommand) super.getCommands().get(next);

        if (FML.isModLoaded("fihgu's Permission Mod") && sender instanceof EntityPlayerMP) {
          Player player = new Player(sender.getCommandSenderName());
          fihgu.permission.element.PermissionOwner owner =
              new fihgu.permission.element.PermissionOwner(player);
          if (owner.canUse(new TryCommandEvent(sender, icommand.getCommandName())))
            if (!arraylist.contains(icommand)) arraylist.add(icommand);
        } else if (icommand.canCommandSenderUseCommand(sender)) {
          arraylist.add(icommand);
        }
      }
    }

    return arraylist;
  }
Example #2
0
  @Override
  public int executeCommand(ICommandSender par1ICommandSender, String par2Str) {
    par2Str = par2Str.trim();

    if (par2Str.startsWith("/")) {
      par2Str = par2Str.substring(1);
    }

    String[] astring = par2Str.split(" ");
    String s1 = astring[0];

    // astring = dropFirstString(astring);
    String[] var1 = new String[astring.length - 1];
    for (int var2 = 1; var2 < astring.length; ++var2) {
      var1[var2 - 1] = astring[var2];
    }

    astring = var1;
    /////////////////////////////////////

    ICommand icommand = (ICommand) super.getCommands().get(s1);

    // int i = this.getUsernameIndex(icommand, astring);
    int i;
    if (icommand == null) {
      i = -1;
    } else {
      for (int temp = 0; temp < astring.length; ++temp) {
        if (icommand.isUsernameIndex(astring, temp)
            && PlayerSelector.matchesMultiplePlayers(astring[temp])) {
          i = temp;
        }
      }

      i = -1;
    }
    //////////////////////////////////////////////////

    int j = 0;

    try {
      if (icommand == null) {
        throw new CommandNotFoundException();
      }

      if (!MinecraftForge.EVENT_BUS.post(new TryCommandEvent(par1ICommandSender, par2Str))
          && (icommand.canCommandSenderUseCommand(par1ICommandSender)
              || FML.isModLoaded("fihgu's Permission Mod"))) {
        CommandEvent event = new CommandEvent(icommand, par1ICommandSender, astring);
        if (MinecraftForge.EVENT_BUS.post(event)) {
          if (event.exception != null) {
            throw event.exception;
          }
          return 1;
        }

        if (i > -1) {
          EntityPlayerMP[] aentityplayermp =
              PlayerSelector.matchPlayers(par1ICommandSender, astring[i]);
          String s2 = astring[i];
          EntityPlayerMP[] aentityplayermp1 = aentityplayermp;
          int k = aentityplayermp.length;

          for (int l = 0; l < k; ++l) {
            EntityPlayerMP entityplayermp = aentityplayermp1[l];
            astring[i] = entityplayermp.getEntityName();

            try {
              icommand.processCommand(par1ICommandSender, astring);
              ++j;
            } catch (CommandException commandexception) {
              par1ICommandSender.sendChatToPlayer(
                  EnumChatFormatting.RED
                      + par1ICommandSender.translateString(
                          commandexception.getMessage(), commandexception.getErrorOjbects()));
            }
          }

          astring[i] = s2;
        } else {
          icommand.processCommand(par1ICommandSender, astring);
          ++j;
        }
      } else {
        if (!FML.isModLoaded("fihgu's Permission Mod"))
          par1ICommandSender.sendChatToPlayer(
              "" + EnumChatFormatting.RED + "You do not have permission to use this command.");
      }
    } catch (WrongUsageException wrongusageexception) {
      par1ICommandSender.sendChatToPlayer(
          EnumChatFormatting.RED
              + par1ICommandSender.translateString(
                  "commands.generic.usage",
                  new Object[] {
                    par1ICommandSender.translateString(
                        wrongusageexception.getMessage(), wrongusageexception.getErrorOjbects())
                  }));
    } catch (CommandException commandexception1) {
      par1ICommandSender.sendChatToPlayer(
          EnumChatFormatting.RED
              + par1ICommandSender.translateString(
                  commandexception1.getMessage(), commandexception1.getErrorOjbects()));
    } catch (Throwable throwable) {
      par1ICommandSender.sendChatToPlayer(
          EnumChatFormatting.RED
              + par1ICommandSender.translateString("commands.generic.exception", new Object[0]));
      throwable.printStackTrace();
    }

    return j;
  }