コード例 #1
0
ファイル: JailPrisoner.java プロジェクト: matejdro/Jail
  /** Delete prisoner from the database. No teleporting is involved. */
  public void delete() {
    SetBeingReleased(true);
    JailCell cell = getCell();
    InputOutput.DeletePrisoner(this);
    Jail.prisoners.remove(getName());
    if (cell != null) {
      for (Sign sign : cell.getSigns()) {
        sign.setLine(0, "");
        sign.setLine(1, "");
        sign.setLine(2, "");
        sign.setLine(3, "");
        sign.update();
      }
      if (cell.getChest() != null) cell.getChest().getInventory().clear();
      cell.setPlayerName("");
    }

    for (LivingEntity e : guards) {
      e.remove();
      Jail.guards.remove(e);
    }

    if (getJail() != null
        && jail.getSettings().getBoolean(Setting.EnableChangingPermissions)
        && jail.getSettings().getBoolean(Setting.RestorePermissionsToEscapedPrisoners)) {
      Util.setPermissionsGroups(
          getName(), getOldPermissions(), jail.getTeleportLocation().getWorld().getName());
    }
  }
コード例 #2
0
ファイル: PrisonerManager.java プロジェクト: ingimarsson/Jail
  /**
   * Initiate transfer of every prisoner in specified jail zone to another jail zone
   *
   * @param target Name of the destination jail zone
   */
  public static void PrepareTransferAll(JailZone zone, String target) {
    for (JailPrisoner prisoner : zone.getPrisoners()) {
      prisoner.setTransferDestination(target);
      Player player = Jail.instance.getServer().getPlayerExact(prisoner.getName());
      if (player == null) {

        prisoner.setOfflinePending(true);
        InputOutput.UpdatePrisoner(prisoner);
        Jail.prisoners.put(prisoner.getName(), prisoner);

      } else {
        Transfer(prisoner, player);
      }
    }
  }
コード例 #3
0
ファイル: PrisonerManager.java プロジェクト: ingimarsson/Jail
  /**
   * Performs transfer of specified JailPrisoner. If you just want to transfer someone, I recommend
   * using prisoner.transfer, because it supports offline transfer and it's easier to do.
   *
   * @param prisoner Prisoner that will be transfered
   * @param player Player that will be teleported
   */
  public static void Transfer(JailPrisoner prisoner, Player player) {
    if (prisoner.getTransferDestination() == "find nearest")
      prisoner.setTransferDestination(
          JailZoneManager.findNearestJail(player.getLocation(), prisoner.getJail().getName())
              .getName());

    if (prisoner.getCell() != null) {
      Inventory inventory = player.getInventory();
      JailCell cell = prisoner.getCell();
      cell.setPlayerName("");
      for (Sign sign : cell.getSigns()) {
        sign.setLine(0, "");
        sign.setLine(1, "");
        sign.setLine(2, "");
        sign.setLine(3, "");
        sign.update();
      }

      if (cell.getChest() != null) {
        for (ItemStack i : cell.getChest().getInventory().getContents()) {
          if (i == null || i.getType() == Material.AIR) continue;
          inventory.addItem(i);
        }
        cell.getChest().getInventory().clear();
      }
      if (cell.getSecondChest() != null) {
        for (ItemStack i : cell.getSecondChest().getInventory().getContents()) {
          if (i == null || i.getType() == Material.AIR) continue;
          inventory.addItem(i);
        }
        cell.getSecondChest().getInventory().clear();
      }
      prisoner.setCell(null);
    }

    prisoner.SetBeingReleased(true);

    String targetJail = prisoner.getTransferDestination();
    if (targetJail.contains(":")) {
      prisoner.setRequestedCell(targetJail.split(":")[1]);
      targetJail = targetJail.split(":")[0];
    }

    JailZone jail = Jail.zones.get(targetJail);
    prisoner.setJail(jail);
    prisoner.setTransferDestination("");
    prisoner.setOfflinePending(false);
    Util.Message(jail.getSettings().getString(Setting.MessageTransfer), player);
    Jail.prisoners.put(prisoner.getName(), prisoner);

    JailCell cell = jail.getRequestedCell(prisoner);
    if (cell == null
        || (cell.getPlayerName() != null
            && !cell.getPlayerName().equals("")
            && !cell.getPlayerName().equals(prisoner.getName()))) {
      cell = null;
      cell = jail.getEmptyCell();
    }
    if (cell != null) {
      cell.setPlayerName(player.getName());
      prisoner.setCell(cell);
      player.teleport(prisoner.getTeleportLocation());
      prisoner.updateSign();
      if (jail.getSettings().getBoolean(Setting.StoreInventory) && cell.getChest() != null) {
        Chest chest = cell.getChest();
        chest.getInventory().clear();
        for (int i = 0; i < 40; i++) {
          if (chest.getInventory().getSize()
              <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break;
          if (player.getInventory().getItem(i) == null
              || player.getInventory().getItem(i).getType() == Material.AIR) continue;
          chest.getInventory().addItem(player.getInventory().getItem(i));
          player.getInventory().clear(i);
        }

        if (cell.getSecondChest() != null) {
          chest = cell.getSecondChest();
          chest.getInventory().clear();
          for (int i = 0; i < 40; i++) {
            if (chest.getInventory().getSize()
                <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break;
            if (player.getInventory().getItem(i) == null
                || player.getInventory().getItem(i).getType() == Material.AIR) continue;
            chest.getInventory().addItem(player.getInventory().getItem(i));
            player.getInventory().clear(i);
          }
        }
      }
      cell.update();
    } else {
      player.teleport(prisoner.getTeleportLocation());
    }

    if (jail.getSettings().getBoolean(Setting.StoreInventory)) {
      prisoner.storeInventory(player.getInventory());
      player.getInventory().clear();
    }

    prisoner.SetBeingReleased(false);
    InputOutput.UpdatePrisoner(prisoner);
  }
コード例 #4
0
ファイル: PrisonerManager.java プロジェクト: ingimarsson/Jail
  /**
   * Performs releasing of specified JailPrisoner. If you just want to release someone, I recommend
   * using prisoner.release, because it supports offline release and it's easier to do.
   *
   * @param prisoner prisoner that will be released
   * @param player Player that will be teleported
   */
  public static void UnJail(JailPrisoner prisoner, Player player) {
    prisoner.SetBeingReleased(true);
    JailZone jail = prisoner.getJail();
    Util.Message(jail.getSettings().getString(Setting.MessageUnJail), player);

    Util.changeSkin(player, "");

    if (jail.getSettings().getBoolean(Setting.EnableChangingPermissions)
        && !jail.getSettings().getBoolean(Setting.RestorePermissionsToEscapedPrisoners)) {
      Util.setPermissionsGroups(
          player.getName(),
          prisoner.getOldPermissions(),
          jail.getTeleportLocation().getWorld().getName());
    }

    player.setSleepingIgnored(false);

    JailCell cell = prisoner.getCell();
    if (cell != null) {
      if (cell.getChest() != null) {
        Chest chest = cell.getChest();
        for (int i = 0; i < chest.getInventory().getSize(); i++) {
          if (chest.getInventory().getItem(i) == null
              || chest.getInventory().getItem(i).getType() == Material.AIR) continue;
          if (player.getInventory().firstEmpty() == -1)
            player.getWorld().dropItem(player.getLocation(), chest.getInventory().getItem(i));
          else player.getInventory().addItem(chest.getInventory().getItem(i));
        }
        chest.getInventory().clear();

        if (cell.getSecondChest() != null) {
          chest = cell.getSecondChest();
          for (int i = 0; i < chest.getInventory().getSize(); i++) {
            if (chest.getInventory().getItem(i) == null
                || chest.getInventory().getItem(i).getType() == Material.AIR) continue;
            if (player.getInventory().firstEmpty() == -1)
              player.getWorld().dropItem(player.getLocation(), chest.getInventory().getItem(i));
            else player.getInventory().addItem(chest.getInventory().getItem(i));
          }
          chest.getInventory().clear();
        }
      }
      for (Sign sign : cell.getSigns()) {
        sign.setLine(0, "");
        sign.setLine(1, "");
        sign.setLine(2, "");
        sign.setLine(3, "");
        sign.update();
      }
      cell.setPlayerName("");
      cell.update();
    }

    if (jail.getSettings().getBoolean(Setting.TeleportPrisonerOnRelease))
      player.teleport(prisoner.getReleaseTeleportLocation());

    prisoner.restoreInventory(player);
    InputOutput.LogJail(prisoner, "unjail");
    prisoner.delete();

    for (Object o : jail.getSettings().getList(Setting.ExecutedCommandsOnRelease)) {
      String s = (String) o;
      CraftServer cs = (CraftServer) Jail.instance.getServer();
      CommandSender coms = Jail.instance.getServer().getConsoleSender();
      cs.dispatchCommand(coms, prisoner.parseTags(s));
    }
  }
コード例 #5
0
ファイル: PrisonerManager.java プロジェクト: ingimarsson/Jail
  /**
   * Performs jailing of specified JailPrisoner. If you just want to jail someone, I recommend using
   * JailAPI.jailPlayer, because it supports offline jail and it's easier to do.
   *
   * @param prisoner JailPrisoner class of the new prisoner. Must be already inserted into database
   * @param player Player that will be teleported
   */
  public static void Jail(JailPrisoner prisoner, Player player) {
    if (!prisoner.getName().equals(player.getName().toLowerCase())) return;
    prisoner.SetBeingReleased(true);
    JailZone jail = prisoner.getJail();
    if (jail == null) {
      Util.debug(prisoner, "searching for nearest jail");
      jail = JailZoneManager.findNearestJail(player.getLocation());
      prisoner.setJail(jail);
    }
    if (jail == null) {
      Util.Message("You are lucky! Server admin was too lazy to set up jail. Go now!", player);
      Jail.log.info(
          "[Jail] There is no jail to pick! Make sure, you have build at least one jail and at least one jail is set to automatic!");
      return;
    }
    prisoner.setOfflinePending(false);
    if (prisoner.getReason().isEmpty())
      Util.Message(jail.getSettings().getString(Setting.MessageJail), player);
    else
      Util.Message(
          jail.getSettings()
              .getString(Setting.MessageJailReason)
              .replace("<Reason>", prisoner.getReason()),
          player);

    if (jail.getSettings().getBoolean(Setting.DeleteInventoryOnJail)) player.getInventory().clear();

    prisoner.setPreviousPosition(player.getLocation());

    JailCell cell = jail.getRequestedCell(prisoner);
    if (cell == null
        || (cell.getPlayerName() != null
            && !cell.getPlayerName().equals("")
            && !cell.getPlayerName().equals(prisoner.getName()))) {
      Util.debug(prisoner, "No requested cell. searching for empty cell");
      cell = null;
      cell = jail.getEmptyCell();
    }
    if (cell != null) {
      Util.debug(prisoner, "Found cell!");
      cell.setPlayerName(player.getName());
      prisoner.setCell(cell);
      player.teleport(prisoner.getTeleportLocation());
      prisoner.updateSign();
      if (jail.getSettings().getBoolean(Setting.StoreInventory) && cell.getChest() != null) {
        Chest chest = cell.getChest();
        chest.getInventory().clear();
        for (int i = 0; i < 40; i++) {
          if (chest.getInventory().getSize()
              <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break;
          if (player.getInventory().getItem(i) == null
              || player.getInventory().getItem(i).getType() == Material.AIR) continue;
          chest.getInventory().addItem(player.getInventory().getItem(i));
          player.getInventory().clear(i);
        }

        if (cell.getSecondChest() != null) {
          chest = cell.getSecondChest();
          chest.getInventory().clear();
          for (int i = 0; i < 40; i++) {
            if (chest.getInventory().getSize()
                <= Util.getNumberOfOccupiedItemSlots(chest.getInventory().getContents())) break;
            if (player.getInventory().getItem(i) == null
                || player.getInventory().getItem(i).getType() == Material.AIR) continue;
            chest.getInventory().addItem(player.getInventory().getItem(i));
            player.getInventory().clear(i);
          }
        }
      }
      cell.update();
    } else {
      player.teleport(prisoner.getTeleportLocation());
    }

    if (jail.getSettings().getBoolean(Setting.StoreInventory)) {
      prisoner.storeInventory(player.getInventory());
      for (int i = 0; i < 40; i++) {
        player.getInventory().clear(i);
      }
    }

    if (jail.getSettings().getBoolean(Setting.SpoutChangeSkin))
      Util.changeSkin(player, jail.getSettings().getString(Setting.SpoutSkinChangeURL));

    if (jail.getSettings().getBoolean(Setting.EnableChangingPermissions)) {
      prisoner.setOldPermissions(
          Util.getPermissionsGroups(
              player.getName(), jail.getTeleportLocation().getWorld().getName()));
      Util.setPermissionsGroups(
          player.getName(),
          (ArrayList<String>) jail.getSettings().getList(Setting.PrisonersPermissionsGroups),
          jail.getTeleportLocation().getWorld().getName());
    }

    if (prisoner.getJail().getSettings().getBoolean(Setting.IgnorePrisonersSleepingState))
      player.setSleepingIgnored(true);

    if (Jail.prisoners.containsKey(prisoner.getName())) InputOutput.UpdatePrisoner(prisoner);
    else InputOutput.InsertPrisoner(prisoner);
    InputOutput.LogJail(prisoner, "jail");

    Jail.prisoners.put(prisoner.getName(), prisoner);
    prisoner.SetBeingReleased(false);

    for (Object o : jail.getSettings().getList(Setting.ExecutedCommandsOnJail)) {
      String s = (String) o;
      CraftServer cs = (CraftServer) Jail.instance.getServer();
      CommandSender coms = Jail.instance.getServer().getConsoleSender();
      cs.dispatchCommand(coms, prisoner.parseTags(s));
    }
  }
コード例 #6
0
ファイル: JailPrisoner.java プロジェクト: matejdro/Jail
  /**
   * Spawn guard wolves to this prisoner to kill him
   *
   * @param num Number of guards to spawn
   * @param location Spawning location
   * @param player Player, associated with this JailPrisoner
   */
  public void spawnGuards(int num, Location location, Player player) {
    List<BlockFace> checkedCorners = new ArrayList<BlockFace>();
    for (int i = 0; i < num; i++) {
      Location spawn = null;
      for (int ci = 0; ci < 4; ci++) {
        Block block = location.getBlock().getRelative(BlockFace.values()[ci]);
        if (!checkedCorners.contains(BlockFace.values()[ci])
            && (block.getType() == Material.AIR
                || block.getType() == Material.STATIONARY_WATER
                || block.getType() == Material.WATER)) {
          spawn = block.getLocation();
          checkedCorners.add(BlockFace.values()[ci]);
          break;
        }
      }
      if (spawn == null) {
        checkedCorners.clear();
        for (int ci = 0; ci < 3; ci++) {
          if (!checkedCorners.contains(BlockFace.values()[ci])
                  && location.getBlock().getRelative(BlockFace.values()[ci]).getType()
                      == Material.AIR
              || location.getBlock().getRelative(BlockFace.values()[ci]).getType()
                  == Material.STATIONARY_WATER) {
            spawn = location.getBlock().getRelative(BlockFace.NORTH).getLocation();
            checkedCorners.add(BlockFace.values()[ci]);
          }
        }
        if (spawn == null) spawn = location;
      }

      List<String> guardTypes = (List<String>) jail.getSettings().getList(Setting.GuardTypes);
      String pickedType = guardTypes.get(new Random().nextInt(guardTypes.size()));

      EntityType type = EntityType.fromName(pickedType);

      if (type == null
          || !type.isSpawnable()
          || !Creature.class.isAssignableFrom(type.getEntityClass())) {
        Jail.log.severe("[Jail] Invalid GuardTypes config! " + pickedType + " cannot be spawned.");
        type = EntityType.CHICKEN;
      }

      Creature guard = (Creature) location.getWorld().spawn(spawn, type.getEntityClass());

      if (!(guard.getWorld().getEntities().contains(guard))) {
        canSpawnGuards = false;
        return;
      }

      int health = getJail().getSettings().getInt(Setting.GuardHealth);
      if (health > guard.getMaxHealth()) {
        Jail.log.warning(
            "[Jail] Guard health cannot be more than "
                + guard.getMaxHealth()
                + "! Use Armor to increase toughness of your guards!");
        health = guard.getMaxHealth();
      }

      guardTargets.add(player);

      guard.setHealth(health);

      guard.setTarget(player);

      getGuards().add(guard);
      Jail.guards.put(guard, this);
    }
  }