Ejemplo n.º 1
0
  public static void useJailStick(Player player) {
    Boolean enabled = Jail.jailStickToggle.get(player);
    if (enabled == null || !enabled) return;

    if (!InputOutput.global.getBoolean(Setting.EnableJailStick.getString(), false)
        || !InputOutput.jailStickParameters.containsKey(player.getItemInHand().getTypeId())) return;
    if (!Util.permission(
        player,
        "jail.usejailstick." + String.valueOf(player.getItemInHand().getTypeId()),
        PermissionDefault.OP)) return;
    String[] param = InputOutput.jailStickParameters.get(player.getItemInHand().getTypeId());

    List<Block> targets = player.getLineOfSight(null, Integer.parseInt(param[1]));
    for (Block b : targets) {
      for (Player p : Bukkit.getServer().getOnlinePlayers()) {
        if (p == player) continue;
        if ((b.getLocation().equals(p.getLocation().getBlock().getLocation())
                || b.getLocation().equals(p.getEyeLocation().getBlock().getLocation()))
            && Util.permission(player, "jail.canbestickjailed", PermissionDefault.TRUE)) {
          String args[] = new String[4];
          args[0] = p.getName();
          args[1] = param[2];
          args[2] = param[3];
          args[3] = param[4];
          PrisonerManager.PrepareJail((CommandSender) player, args);
        }
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Initiate release procedure. If player is online, he will be released instantly, otherwise he
   * will be released when he logs in.
   */
  public void release() {
    Player player = Jail.instance.getServer().getPlayerExact(getName());

    if (player == null) {

      setOfflinePending(true);
      setRemainingTime(0);
      update();
    } else {
      PrisonerManager.UnJail(this, player);
    }
  }
Ejemplo n.º 3
0
  /**
   * Transfer prisoner to specified jail. If player is online, he will be transfered instantly,
   * otherwise he will be transfered when he logs in.
   *
   * @param targetjail Name of the destination jail zone
   */
  public void transfer(String targetjail) {
    if (targetjail == null) targetjail = "find nearest";

    setTransferDestination(targetjail);
    Player player = Jail.instance.getServer().getPlayerExact(getName());

    if (player == null) {
      setOfflinePending(true);
      update();
      Jail.prisoners.put(getName(), this);
    } else {
      PrisonerManager.Transfer(this, player);
    }
  }
Ejemplo n.º 4
0
  public static void PrepareJail(CommandSender sender, String args[]) {
    String playername;
    int time = InputOutput.global.getInt(Setting.DefaultJailTime.getString());
    String jailname = "";
    if (args.length < 1
        || (args.length > 1 && (!Util.isInteger(args[1])))
        || args[0].trim().equals("?")) {
      if (sender != null)
        Util.Message("Usage: /jail [Name] (Time) (Jail Name:Cell Name) (Reason)", sender);
      return;
    }
    if (Jail.zones.size() < 1) {
      if (sender != null)
        Util.Message("There is no jail available. Build one, before you can jail anyone!", sender);
      return;
    }
    if (Jail.prisoners.containsKey(args[0].toLowerCase())) {
      JailPrisoner prisoner = Jail.prisoners.get(args[0].toLowerCase());
      Player player = Jail.instance.getServer().getPlayer(prisoner.getName());
      if (player != null) {
        player.teleport(prisoner.getTeleportLocation());
        if (sender != null) Util.Message("Player was teleported back to his jail!", sender);

      } else {
        if (sender != null) Util.Message("That player is already jailed!", sender);
      }
      return;
    }
    playername = args[0];

    Player player = Jail.instance.getServer().getPlayerExact(playername);
    if (player == null) player = Jail.instance.getServer().getPlayer(playername);
    if (player != null) playername = player.getName().toLowerCase();
    else if (sender != null) {
      Boolean exist = false;
      for (OfflinePlayer p : Bukkit.getServer().getOfflinePlayers())
        if (p.getName().toLowerCase().equals(playername.toLowerCase())) {
          exist = true;
          break;
        }
      if (!exist) {
        Util.Message("Player " + playername + " was never on this server!", sender);
        return;
      }
    }

    if (args.length > 2) time = (int) PrisonerManager.parseTimeSpec(args[1], args[2]);
    String reason = "";
    if (args.length > 3) {
      for (int i = 3; i < args.length; i++) {
        reason += " " + args[i];
      }
      if (reason.length() > 250) {
        if (sender != null) Util.Message("Reason is too long!", sender);
        return;
      }
    }

    if (jailname.equals(InputOutput.global.getString(Setting.NearestJailCode.getString())))
      jailname = "";
    Util.debug("[Jailing " + playername + "] Requested jail: " + jailname);
    String cellname = null;
    if (jailname.contains(":")) {
      cellname = jailname.split(":")[1];
      jailname = jailname.split(":")[0];
      Util.debug("[Jailing " + playername + "] Requested cell: " + cellname);
    }
    String jailer;
    if (sender instanceof Player) jailer = ((Player) sender).getName();
    else if (sender == null) jailer = "other plugin";
    else jailer = "console";

    if (player == null) {
      JailPrisoner prisoner =
          new JailPrisoner(
              playername,
              time * 6,
              jailname,
              cellname,
              true,
              "",
              reason,
              InputOutput.global.getBoolean(Setting.AutomaticMute.getString(), false),
              "",
              jailer,
              "");
      if (prisoner.getJail() != null) {
        Util.debug("[Jailing " + playername + "] Searching for requested cell");
        JailCell cell = prisoner.getJail().getRequestedCell(prisoner);
        if (cell != null
            && (cell.getPlayerName() == null || cell.getPlayerName().trim().equals(""))) {
          Util.debug("[Jailing " + playername + "] Found requested cell");
          cell.setPlayerName(prisoner.getName());
          cell.update();
        }
      }

      InputOutput.InsertPrisoner(prisoner);
      Jail.prisoners.put(prisoner.getName(), prisoner);

      Util.Message(
          ChatColor.YELLOW
              + "Player is offline. He will be automatically jailed when he connnects.",
          sender);
      Jail.instance
          .getServer()
          .broadcastMessage(
              ChatColor.YELLOW
                  + "Player "
                  + ChatColor.GOLD
                  + playername
                  + ChatColor.YELLOW
                  + " was jailed by "
                  + ChatColor.GOLD
                  + jailer
                  + ChatColor.YELLOW
                  + ", Reason:"
                  + ChatColor.GOLD
                  + reason);

    } else {
      playername = player.getName().toLowerCase();
      JailPrisoner prisoner =
          new JailPrisoner(
              playername,
              time * 6,
              jailname,
              cellname,
              false,
              "",
              reason,
              InputOutput.global.getBoolean(Setting.AutomaticMute.getString(), false),
              "",
              jailer,
              "");
      Jail(prisoner, player);
      Util.Message("Player jailed.", sender);
      Jail.instance
          .getServer()
          .broadcastMessage(
              ChatColor.YELLOW
                  + "Player "
                  + ChatColor.GOLD
                  + playername
                  + ChatColor.YELLOW
                  + " was jailed by "
                  + ChatColor.GOLD
                  + jailer
                  + ChatColor.YELLOW
                  + ", Reason:"
                  + ChatColor.GOLD
                  + reason);
    }

    // Log jailing into console
    if (InputOutput.global.getBoolean(Setting.LogJailingIntoConsole.getString(), false)) {
      String times;
      if (time < 0) times = "forever";
      else times = "for " + String.valueOf(time) + "minutes";

      Jail.log.info("Player " + playername + " was jailed by " + jailer + " " + times);
    }
  }
Ejemplo n.º 5
0
  public Boolean run(CommandSender sender, String[] args) {
    if (args.length < 1) {
      Util.Message("Usage: /jail [Name] (time) (j:Jail name) (c:Cell name) (r:Reason) (m)", sender);
      return true;
    }

    if (Jail.zones.size() < 1) {
      Util.Message(Settings.getGlobalString(Setting.MessageNoJail), sender);
      return true;
    }

    // Initialize defaults
    String playerName = args[0].toLowerCase();
    int time = Settings.getGlobalInt(Setting.DefaultJailTime);
    String jailname = "";
    String cellname = "";
    String reason = "";
    Boolean muted = Settings.getGlobalBoolean(Setting.AutomaticMute);

    // Parse command line
    for (int i = 1; i < args.length; i++) {
      String line = args[i];

      if (Util.isInteger(line)) time = Integer.parseInt(line);
      else if (line.startsWith("j:")) jailname = line.substring(2);
      else if (line.startsWith("c:")) cellname = line.substring(2);
      else if (line.equals("m")) muted = !muted;
      else if (line.startsWith("r:")) {
        if (line.startsWith("r:\"")) {
          reason = line.substring(3);
          while (!line.endsWith("\"")) {
            i++;
            if (i >= args.length) {
              Util.Message(
                  "Usage: /jail [Name] (t:time) (j:Jail name) (c:Cell name) (r:Reason) (m)",
                  sender);
              return true;
            }

            line = args[i];
            if (line.endsWith("\"")) reason += " " + line.substring(0, line.length() - 1);
            else reason += " " + line;
          }
        } else reason = line.substring(2);

        int maxReason = Settings.getGlobalInt(Setting.MaximumReasonLength);
        if (maxReason > 250) maxReason = 250; // DB Limit

        if (reason.length() > maxReason) {
          Util.Message(Settings.getGlobalString(Setting.MessageTooLongReason), sender);
          return true;
        }
      }
    }

    Player player = Util.getPlayer(playerName, true);

    if (player == null && !Util.playerExists(playerName)) {
      Util.Message(
          Settings.getGlobalString(Setting.MessageNeverOnThisServer)
              .replace("<Player>", playerName),
          sender);
      return true;
    } else if (player != null) playerName = player.getName().toLowerCase();

    JailPrisoner prisoner =
        new JailPrisoner(
            playerName,
            time * 6,
            jailname,
            cellname,
            false,
            "",
            reason,
            muted,
            "",
            sender instanceof Player ? ((Player) sender).getName() : "console",
            "");
    PrisonerManager.PrepareJail(prisoner, player);

    String message;
    if (player == null) message = Settings.getGlobalString(Setting.MessagePrisonerOffline);
    else message = Settings.getGlobalString(Setting.MessagePrisonerJailed);
    message = prisoner.parseTags(message);
    Util.Message(message, sender);
    return true;
  }