コード例 #1
0
 /**
  * Retrieves an open height level by sifting through the mapping and attempting to retrieve the
  * lowest height level.
  *
  * @return the next lowest, open height level will be returned otherwise -1 will be returned. When
  *     -1 is returned it signifies that there are no heights open from 0 to {@link
  *     MAXIMUM_HEIGHT}.
  */
 public int getNextOpenHeight(Boundary boundary) {
   for (int height = 0; height < MAXIMUM_HEIGHT; height += 4) {
     if (active.containsKey(height)) {
       continue;
     }
     final int heightLevel = height;
     if (PlayerHandler.getPlayers()
         .stream()
         .anyMatch(p -> Boundary.isIn(p, boundary) && p.heightLevel == heightLevel)) {
       continue;
     }
     return height;
   }
   return -1;
 }
コード例 #2
0
ファイル: Jail.java プロジェクト: camdevgit/RSPS-Server
  @Override
  public void execute(Player c, String input) {
    try {
      String[] args = input.split("-");
      if (args.length != 3) {
        throw new IllegalArgumentException();
      }
      String name = args[0];
      int duration = Integer.parseInt(args[1]);
      long jailEnd = 0;
      if (duration == 0) {
        jailEnd = Long.MAX_VALUE;
      } else {
        jailEnd = System.currentTimeMillis() + duration * 1000 * 60;
      }
      String reason = args[2];

      Optional<Player> optionalPlayer = PlayerHandler.getOptionalPlayer(name);
      if (optionalPlayer.isPresent()) {
        Player c2 = optionalPlayer.get();
        if (Server.getMultiplayerSessionListener().inAnySession(c)) {
          c.sendMessage("The player is in a trade, or duel. You cannot do this at this time.");
          return;
        }
        c2.teleportToX = 2095;
        c2.teleportToY = 4428;
        c2.jailEnd = jailEnd;
        if (duration == 0) {
          c2.sendMessage("@red@You have been permanently jailed by " + c.playerName + " .");
          c.sendMessage("Permanently jailed " + c2.playerName + ".");
          new PunishmentHandler().punishOnlinePlayer(c2, c, "Jail (Permanent)", reason);

        } else {
          c2.sendMessage(
              "@red@You have been jailed by " + c.playerName + " for " + duration + " minutes.");
          c2.sendMessage("@red@Type ::unjail after having served your time to be unjailed.");
          c.sendMessage("Successfully jailed " + c2.playerName + " for " + duration + " minutes.");
          new PunishmentHandler().punishOnlinePlayer(c2, c, "Jail (" + duration + ")", reason);
        }
      } else {
        c.sendMessage(name + " is not online. You can only jail online players.");
      }
    } catch (Exception e) {
      c.sendMessage("Error. Correct syntax: ::jail-player-duration-reason");
    }
  }
コード例 #3
0
 /**
  * Updates a single global object with a new object id in the game world for every player within a
  * region.
  *
  * @param object the new global object
  * @param objectId the new object id
  */
 public void updateObject(final GlobalObject object, final int objectId) {
   List<Player> players =
       PlayerHandler.getPlayers()
           .stream()
           .filter(Objects::nonNull)
           .filter(
               player ->
                   player.distanceToPoint(object.getX(), object.getY()) <= 60
                       && player.heightLevel == object.getHeight())
           .collect(Collectors.toList());
   players.forEach(
       player ->
           player
               .getPA()
               .object(
                   objectId, object.getX(), object.getY(), object.getFace(), object.getType()));
 }