Beispiel #1
0
  public entryRow(int i, SpoutPlayer player) throws SQLException {
    this.idd = i;
    this.player = player;

    setLayout(ContainerType.HORIZONTAL);

    ModTRSSpout plugin = ModTRSSpout.getInstance();
    ModTRSRequest req = plugin.api.getRequestTable().getRequestFromId(i);
    id = new GenericLabel();
    id.setText(String.valueOf(i)).setMaxWidth(15);
    addChild(id);
    ModTRSUser user = plugin.api.getUserTable().getUserFromId(req.getUserId());
    boolean online = plugin.getServer().getPlayer(user.getName()).isOnline();
    name = new GenericLabel();
    if (online) {
      name.setText(ChatColor.GREEN + user.getName()).setMaxWidth(60);
    } else {
      name.setText(ChatColor.RED + user.getName()).setMaxWidth(60);
    }
    addChild(name);
    desc = new GenericLabel();
    String text = req.getText();
    if (text.length() >= 35) {
      text = text.substring(0, 35) + "...";
    }
    desc.setText(text).setMinWidth(200);
    addChild(desc);
    claim = new GenericLabel();
    if (req.getStatus() == 1) {

      claim.setText(plugin.api.getUserTable().getUserFromId(req.getModId()).getName());
    }
    claim.setMaxWidth(60);
    addChild(claim);
    done = new doneButton(i, this);
    addChild(done);
    stst = req.getStatus() != 0;
    claimb = new claimButton(i, this);
    addChild(claimb);
  }
Beispiel #2
0
  @Override
  public boolean onCommand(
      CommandSender sender, Command command, String commandLabel, String[] args) {

    // Default parameter values
    String[] parameters = this.getParameters(args);
    int page = Integer.parseInt(parameters[0]);
    String type = parameters[1];

    ModTRSCommandSender player = new ModTRSCommandSender(sender);

    if (!parameters[2].isEmpty()) {
      CheckIdCommand checkid = new CheckIdCommand(parent);

      if (ValidatorHandler.getInstance().hasValidator("check-id")) {
        if (!ValidatorHandler.getInstance()
            .getValidator("check-id")
            .isValid(new String[] {parameters[2].trim()})) {
          return false;
        }
      }
      return checkid.onCommand(sender, command, commandLabel, new String[] {parameters[2].trim()});
    }

    CommandCheckEvent event = new CommandCheckEvent(page, type, player);
    EventHandler.getInstance().dispatch(event);
    if (event.isCancelled()) {
      return true;
    }

    page = event.getPage();
    type = event.getRequestType();
    player = event.getSender();

    PagingList<ModTRSRequest> pager;
    boolean isModerator = true;

    try {

      if (!player.hasPerm("modtrs.command.check")) {
        if (!player.hasPerm("modtrs.command.check.self", false)) {
          player.sendMessage(Message.parse("general.error.permission"));
          return true;
        } else {
          isModerator = false;
          pager =
              parent
                  .getTableHandler()
                  .getRequest()
                  .getOpenRequestsFromUserPager(player.getName(), ModTRSSettings.reqsPerPage);
        }
      } else {
        pager =
            parent
                .getTableHandler()
                .getRequest()
                .getRequestsPager(type, ModTRSSettings.reqsPerPage);
      }

      String ucfirst = type.toUpperCase().substring(0, 1) + type.substring(1);
      player.sendMessage(Message.parse("check.intro", pager.getTotalRowCount(), ucfirst));

      if (pager.getTotalRowCount() == 0) {
        player.sendMessage(Message.parse("check.no_reqs"));
      }

      int count = 0;
      for (ModTRSRequest request : pager.getPage(page - 1).getList()) {
        count++;

        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat(CommandHandler.TIMEDATE_FORMAT);
        calendar.setTimeInMillis(request.getTstamp());

        String substring = request.getText();

        if (substring.length() >= 20) {
          substring = substring.substring(0, 20) + "...";
        }

        boolean online =
            ModTRSFunctions.isUserOnline(
                parent.getTableHandler().getUser().getUserFromId(request.getUserId()).getName(),
                player.getServer());
        if (request.getStatus() == 1) {
          player.sendMessage(
              Message.parse(
                  "check.item.claimed",
                  request.getId(),
                  sdf.format(calendar.getTime()),
                  (online) ? ChatColor.GREEN : ChatColor.RED,
                  parent.getTableHandler().getUser().getUserFromId(request.getUserId()).getName(),
                  parent.getTableHandler().getUser().getUserFromId(request.getModId()).getName()));
        } else {
          player.sendMessage(
              Message.parse(
                  "check.item.unclaimed",
                  request.getId(),
                  sdf.format(calendar.getTime()),
                  (online) ? ChatColor.GREEN : ChatColor.RED,
                  parent.getTableHandler().getUser().getUserFromId(request.getUserId()).getName(),
                  substring));
        }
      }

      if (!isModerator) {
        return true;
      }
      int reqs_left = pager.getTotalRowCount() - (page) * pager.getPageSize();
      if (reqs_left > 0) {
        player.sendMessage(Message.parse("check.more", reqs_left, page + 1));
      }

    } catch (Exception e) {
      e.printStackTrace();
      player.sendMessage(Message.parse("general.error.internal"));
    }

    return true;
  }