public boolean execute() {
    if (this.player == null) {
      return false;
    }

    if ((Economy.getEconomy() != null) && (this.cmdBlock.getEconomyPrice() > 0)) {
      if (!this.player.hasPermission("commandsign.costs.bypass")) {
        if (Economy.getEconomy().has(this.player, this.cmdBlock.getEconomyPrice())) {
          Economy.getEconomy().withdrawPlayer(this.player, this.cmdBlock.getEconomyPrice());
          String msg = Messages.get("usage.you_paied");
          msg =
              msg.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice()));
          this.player.sendMessage(msg);
        } else {
          String err = Messages.get("usage.not_enough_money");
          err =
              err.replace("{PRICE}", Economy.getEconomy().format(this.cmdBlock.getEconomyPrice()));
          this.player.sendMessage(err);
          return false;
        }
      }
    }

    if (this.cmdBlock.getTimeBetweenPlayerUsage() > 0) {
      if (this.cmdBlock.hasPlayerRecentlyUsed(this.player)) {
        if (!player.hasPermission("commandsign.timer.bypass")) {
          this.player.sendMessage(Messages.get("usage.player_cooldown"));
          return false;
        }
      }
      this.cmdBlock.addUsage(this.player);
    }

    PermissionAttachment perms = Container.getContainer().getPlayerPermissions(this.player);
    for (String perm : this.cmdBlock.getPermissions()) {
      if (!this.player.hasPermission(perm)) {
        perms.setPermission(perm, true);
      }
    }

    for (String command : this.cmdBlock.getCommands()) {
      handleCommand(command);
    }

    for (String perm : this.cmdBlock.getPermissions()) {
      if (perms.getPermissions().containsKey(perm)) {
        perms.unsetPermission(perm);
      }
    }

    return true;
  }
Пример #2
0
  public boolean doExecute(
      JavaPlugin plugin, CommandSender sender, Player player, String command, String[] args)
      throws Throwable {
    boolean retval = true;

    StringBuilder commandLine = new StringBuilder(command);
    for (int i = 0; i < args.length; i++) {
      commandLine.append(" ");
      commandLine.append(args[i]);
    }

    boolean cmdret = false;
    PermissionAttachment attachment = null;
    try {
      PluginCommand cmd = plugin.getServer().getPluginCommand(command);
      attachment =
          player.addAttachment(
              plugin, cmd.getPermission(), true, 20); // we add the permission to the player...
      // we let this expire after 20 ticks (one second) to make sure that he doesn't get it forever
      // by accident
    } catch (Throwable t) {
      // t.printStackTrace(); //No stacktrace since this can happen

      // apparently this failed. last chance: give him all permissions
      attachment = player.addAttachment(plugin, 20);
      for (Permission p : plugin.getServer().getPluginManager().getPermissions()) {
        attachment.setPermission(p, true);
      }
    }

    try {
      cmdret =
          plugin
              .getServer()
              .dispatchCommand(player, commandLine.toString()); // ... execute the command ...
    } catch (Exception e) {
      e.printStackTrace();
      retval = false;
    }

    if (attachment != null) player.removeAttachment(attachment); // ... and remove the permission.

    if (retval) {
      if (cmdret) sender.sendMessage("Done.");
      else sender.sendMessage("Couldn't find the specified command.");
    }

    return retval;
  }
Пример #3
0
  protected boolean doExecute(
      JavaPlugin plugin, CommandSender sender, Player player, String command, String[] args)
      throws Throwable {
    StringBuilder commandLine = new StringBuilder(command);
    for (int i = 0; i < args.length; i++) {
      commandLine.append(" ");
      commandLine.append(args[i]);
    }

    PluginCommand cmd = null;
    PermissionAttachment attachment = null;
    try {
      cmd = plugin.getServer().getPluginCommand(command);
      attachment =
          player.addAttachment(
              plugin, cmd.getPermission(), true, 20); // we add the permission to the player...
      // we let this expire after 20 ticks (one second) to make sure that he doesn't get it forever
      // by accident
    } catch (Throwable t) {
      // t.printStackTrace(); //No stacktrace since this can happen

      // apparently this failed. last chance: give him all permissions
      attachment = player.addAttachment(plugin, 20);
      for (Permission p : plugin.getServer().getPluginManager().getPermissions()) {
        attachment.setPermission(p, true);
      }
    }

    player.performCommand(commandLine.toString()); // ... execute the command ...

    if (attachment != null) player.removeAttachment(attachment); // ... and remove the permission.

    sender.sendMessage("Done.");

    return true; // basically this just can't fail
  }