コード例 #1
0
ファイル: InfoModule.java プロジェクト: pyrodogg/LWC
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("i", "info")) {
      return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    if (!(sender instanceof Player)) {
      return;
    }

    event.setCancelled(true);

    if (!lwc.hasPlayerPermission(sender, "lwc.info")) {
      lwc.sendLocale(sender, "protection.accessdenied");
      return;
    }

    LWCPlayer player = lwc.wrapPlayer(sender);
    String type = "info";

    if (args.length > 0) {
      type = args[0].toLowerCase();
    }

    if (type.equals("info")) {
      Action action = new Action();
      action.setName("info");
      action.setPlayer(player);

      player.removeAllActions();
      player.addAction(action);

      lwc.sendLocale(player, "protection.info.finalize");
    }
  }
コード例 #2
0
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (event.isCancelled()) {
      return;
    }

    if (!event.hasFlag("c", "create")) {
      return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    if (!(sender instanceof Player)) {
      return;
    }

    if (args.length == 0) {
      lwc.sendLocale(sender, "help.creation");
      return;
    }

    LWCPlayer player = lwc.wrapPlayer(sender);

    String full = StringUtil.join(args, 0).trim();
    String type = args[0].toLowerCase();
    String data = StringUtil.join(args, 1);
    event.setCancelled(true);

    /**
     * Allow individual enforcements with e.g lwc.create.private, or just the umbrella lwc.create
     * for all
     */
    if (!lwc.hasPermission(sender, "lwc.create." + type, "lwc.create", "lwc.protect")) {
      lwc.sendLocale(sender, "protection.accessdenied");
      return;
    }

    try {
      switch (Protection.Type.matchType(type)) {
        case PASSWORD:
          if (args.length < 2) {
            lwc.sendSimpleUsage(player, "/lwc -c password <Password>");
            return;
          }

          String hiddenPass = StringUtil.transform(data, '*');
          lwc.sendLocale(player, "protection.create.password", "password", hiddenPass);
          break;
      }
    } catch (IllegalArgumentException e) {
      // Invalid protection type!
      lwc.sendLocale(player, "help.creation");
      return;
    }

    Action action = new Action();
    action.setName("create");
    action.setPlayer(player);
    action.setData(full);

    player.removeAllActions();
    player.addAction(action);

    lwc.sendLocale(
        player,
        "protection.create.finalize",
        "type",
        lwc.getPlugin().getMessageParser().parseMessage(type));
  }
コード例 #3
0
ファイル: DropTransferModule.java プロジェクト: Carpeeet/LWC
  @Override
  public void onCommand(LWCCommandEvent event) {
    if (!event.hasFlag("p", "mode")) {
      return;
    }

    if (event.isCancelled()) {
      return;
    }

    LWC lwc = event.getLWC();
    CommandSender sender = event.getSender();
    String[] args = event.getArgs();

    LWCPlayer player = lwc.wrapPlayer(sender);
    String mode = args[0].toLowerCase();

    if (!mode.equals("droptransfer")) {
      return;
    }

    event.setCancelled(true);

    // internal name
    mode = "dropTransfer";

    if (args.length < 2) {
      lwc.sendLocale(player, "protection.modes.dropxfer.help");
      return;
    }

    String action = args[1].toLowerCase();
    String playerName = player.getName();

    if (action.equals("select")) {
      if (isPlayerDropTransferring(player)) {
        lwc.sendLocale(player, "protection.modes.dropxfer.select.error");
        return;
      }

      player.disableMode(player.getMode(mode));

      Action temp = new Action();
      temp.setName("dropTransferSelect");
      temp.setPlayer(player);

      player.addAction(temp);
      lwc.sendLocale(player, "protection.modes.dropxfer.select.finalize");
    } else if (action.equals("on")) {
      int target = getPlayerDropTransferTarget(player);

      if (target == -1) {
        lwc.sendLocale(player, "protection.modes.dropxfer.selectchest");
        return;
      }

      Mode temp = new Mode();
      temp.setName("+dropTransfer");
      temp.setPlayer(player.getBukkitPlayer());

      player.enableMode(temp);
      lwc.sendLocale(player, "protection.modes.dropxfer.on.finalize");
    } else if (action.equals("off")) {
      int target = getPlayerDropTransferTarget(player);

      if (target == -1) {
        lwc.sendLocale(player, "protection.modes.dropxfer.selectchest");
        return;
      }

      player.disableMode(player.getMode("+dropTransfer"));
      lwc.sendLocale(player, "protection.modes.dropxfer.off.finalize");
    } else if (action.equals("status")) {
      if (getPlayerDropTransferTarget(player) == -1) {
        lwc.sendLocale(player, "protection.modes.dropxfer.status.off");
      } else {
        if (isPlayerDropTransferring(player)) {
          lwc.sendLocale(player, "protection.modes.dropxfer.status.active");
        } else {
          lwc.sendLocale(player, "protection.modes.dropxfer.status.inactive");
        }
      }
    }
  }