Beispiel #1
0
  /*
   * (non-Javadoc)
   *
   * @see
   * be.Balor.Manager.ACCommands#execute(org.bukkit.command.CommandSender,
   * java.lang.String[])
   */
  @Override
  public void execute(final CommandSender sender, final CommandArgs args)
      throws ActionNotPermitedException, PlayerNotFound {
    ACPluginManager.scheduleSyncTask(
        new Runnable() {

          @Override
          public void run() {
            try {
              setPlayerHealth(sender, args, Health.HEAL);
            } catch (final PlayerNotFound e) {
              e.getSender().sendMessage(e.getMessage());
            } catch (final ActionNotPermitedException e) {
              e.sendMessage();
            }
          }
        });
  }
Beispiel #2
0
  /*
   * (non-Javadoc)
   *
   * @see be.Balor.Manager.Commands.CoreCommand#execute(org.bukkit.command.
   * CommandSender, be.Balor.Manager.Commands.CommandArgs)
   */
  @Override
  public void execute(final CommandSender sender, final CommandArgs args)
      throws PlayerNotFound, ActionNotPermitedException {
    Player target;
    try {
      target = Users.getUser(sender, args, permNode);
    } catch (final PlayerNotFound e) {
      target = Users.getUserParam(sender, args, permNode);
    }

    if (args.length == 0) {
      sender.sendMessage(ChatColor.YELLOW + "Echantment list :");
      sender.sendMessage(ChatColor.GOLD + MaterialContainer.possibleEnchantment());
      return;
    }
    if (target == null) {
      return;
    }
    final HashMap<String, String> replace = new HashMap<String, String>();
    final ItemStack itemInHand = target.getItemInHand();
    if (itemInHand == null || (itemInHand != null && itemInHand.getType().equals(Material.AIR))) {
      LocaleHelper.ERROR_HOLD_ITEM.sendLocale(sender);
      return;
    }
    final MaterialContainer inHand = new MaterialContainer(itemInHand);
    Give.setEnchantements(sender, args, inHand, target.equals(sender) ? 0 : 1);
    final Player finalTarget = target;
    ACPluginManager.scheduleSyncTask(
        new Runnable() {

          @Override
          public void run() {
            finalTarget.setItemInHand(inHand.getItemStack());
          }
        });
    replace.put("item", itemInHand.getType().name());
    LocaleHelper.SUCCESS_ENCHANT.sendLocale(sender, replace);
    if (!sender.equals(target)) {
      LocaleHelper.SUCCESS_ENCHANT.sendLocale(target, replace);
    }
  }
Beispiel #3
0
  /*
   * (non-Javadoc)
   *
   * @see
   * be.Balor.Manager.ACCommands#execute(org.bukkit.command.CommandSender,
   * java.lang.String[])
   */
  @Override
  public void execute(final CommandSender sender, final CommandArgs args)
      throws ActionNotPermitedException, PlayerNotFound {
    final Player toBan = Utils.getPlayer(args.getString(0));
    final HashMap<String, String> replace = new HashMap<String, String>();
    String message = "";
    String banPlayerString;
    if (toBan != null) {
      banPlayerString = toBan.getName();
      if (!Utils.checkImmunity(sender, toBan)) {
        Utils.sI18n(sender, "insufficientLvl");
        return;
      }
    } else {
      banPlayerString = args.getString(0);
    }
    Integer tmpBan = null;
    if (args.length >= 2) {
      if (args.hasFlag('m')) {
        message =
            LocaleManager.getInstance()
                .get("kickMessages", args.getValueFlag('m'), "player", banPlayerString);
      }
      try {
        final int tmpIntTime = Utils.timeParser(args.getString(args.length - 1));
        if (tmpIntTime != -1) {
          tmpBan = tmpIntTime;
        }
      } catch (final NotANumberException e) {
        Utils.sI18n(sender, "NaN", "number", args.getString(args.length - 1));
        return;
      }
      if (message == null || (message != null && message.isEmpty())) {
        message = "";
        if (tmpBan == null) {
          for (int i = 1; i < args.length; i++) {
            message += args.getString(i) + " ";
          }
        } else {
          for (int i = 1; i < args.length - 1; i++) {
            message += args.getString(i) + " ";
          }
        }
      }
      if (message.isEmpty()) {
        message += " You have been banned ";
        if (!Utils.isPlayer(sender, false)) {
          message += "by Server Admin";
        } else {
          message += "by " + ChatColor.stripColor(Utils.getPlayerName((Player) sender));
        }
      }
    } else {
      if (message.isEmpty()) {
        message = "You have been banned ";
        if (!Utils.isPlayer(sender, false)) {
          message += "by Server Admin";
        } else {
          message += "by " + ChatColor.stripColor(Utils.getPlayerName((Player) sender));
        }
      }
    }
    message = message.trim();
    replace.put("player", banPlayerString);
    replace.put("reason", message);
    final Matcher ipv4 = Utils.REGEX_IP_V4.matcher(banPlayerString);
    final Matcher inaccurateIp = Utils.REGEX_INACCURATE_IP_V4.matcher(banPlayerString);
    if (tmpBan != null) {
      message += " (Banned for " + tmpBan + " minutes)";
      replace.put("reason", message);
      ITempBan ban;
      if (inaccurateIp.find()) {
        if (!ipv4.find()) {
          replace.clear();
          replace.put("ip", banPlayerString);
          LocaleHelper.INACC_IP.sendLocale(sender, replace);
          return;
        }
        ban = new TempBannedIP(banPlayerString, message, tmpBan * 60 * 1000);
        ACHelper.getInstance().banPlayer(ban);
      } else {
        ban = new TempBannedPlayer(banPlayerString, message, tmpBan * 60 * 1000);
        ACHelper.getInstance().banPlayer(ban);
      }
      ACPluginManager.getScheduler()
          .runTaskLaterAsynchronously(
              getPlugin(), new UnBanTask(ban, true), Utils.secInTick * 60 * tmpBan);
    } else {
      if (inaccurateIp.find()) {
        if (!ipv4.find()) {
          replace.clear();
          replace.put("ip", banPlayerString);
          LocaleHelper.INACC_IP.sendLocale(sender, replace);
          return;
        }
        ACHelper.getInstance().banPlayer(new BannedIP(banPlayerString, message));
      } else {
        ACHelper.getInstance().banPlayer(new BannedPlayer(banPlayerString, message));
      }
    }
    ACPlayer.getPlayer(toBan).setPower(Type.KICKED);
    if (toBan != null) {
      final String finalmsg = message;
      final Player finalToKick = toBan;
      ACPluginManager.scheduleSyncTask(
          new Runnable() {

            @Override
            public void run() {
              finalToKick.kickPlayer(finalmsg);
            }
          });
    }
    Utils.broadcastMessage(Utils.I18n("ban", replace));
  }