示例#1
0
  /**
   * Get a player's data file
   *
   * @param playerName
   * @return
   */
  public PlayerEntry getPlayerEntry(String playerName) {
    PlayerEntry data = players.get(playerName.toLowerCase());

    if (data == null) {
      data = new PlayerEntry();
      data.setName(playerName);
      players.put(playerName.toLowerCase(), data);
    }

    return data;
  }
  /**
   * Get a player's last known location outside of an entry field
   *
   * @param player
   * @return
   */
  public Location getOutsideLocation(Player player) {
    PlayerEntry data = getPlayerEntry(player);
    Location loc = data.getOutsideLocation();

    if (loc != null) {
      loc =
          new Location(
              loc.getWorld(),
              ((double) loc.getBlockX()) + .5,
              ((double) loc.getBlockY()),
              ((double) loc.getBlockZ()) + .5,
              loc.getYaw(),
              loc.getPitch());
    }

    return loc;
  }
  /**
   * Get a player's data file, will look up by UUID first, then name.
   *
   * @param player
   * @return
   */
  public PlayerEntry getPlayerEntry(Player player) {
    // look for player in memory
    String playerName = player.getName();
    PlayerEntry data = players.get(playerName.toLowerCase());

    // otherwise look in database
    if (data == null) {
      UUID uuid = player.getUniqueId();

      data = plugin.getStorageManager().extractPlayer(uuid);
      if (data == null) {
        data = plugin.getStorageManager().extractPlayer(player.getName());
      } else if (!playerName.equalsIgnoreCase(data.getName())) {
        plugin.getStorageManager().migrate(data.getName(), playerName);
        data.setName(playerName);
      }
      if (data == null) {
        data = plugin.getStorageManager().createPlayer(playerName, uuid);
      }
      players.put(playerName.toLowerCase(), data);
    }

    return data;
  }
 /**
  * Set player as offline
  *
  * @param player
  */
 public void playerLogoff(Player player) {
   PlayerEntry data = getPlayerEntry(player);
   data.setOnline(false);
   data.setOutsideLocation(null);
 }
  /**
   * Player entry operations to do when player logs in
   *
   * @param player
   */
  public void playerLogin(Player player) {
    // set online

    PlayerEntry data = getPlayerEntry(player);
    data.setOnline(true);
  }
 /**
  * Updates a player's last known location outside an entry field
  *
  * @param player
  */
 public void updateOutsideLocation(Player player) {
   PlayerEntry data = getPlayerEntry(player);
   data.setOutsideLocation(player.getLocation());
 }
  public boolean teleport(List<TeleportEntry> entries) {
    for (TeleportEntry entry : entries) {
      Entity entity = entry.getEntity();
      Location destination = entry.getDestination();
      Field sourceField = entry.getSourceField();
      Vec currentPosition = null;

      if (entity instanceof Player) {
        Player player = (Player) entity;

        plugin.getPlayerManager().getPlayerEntry(player.getName()).setTeleporting(false);

        // done teleport players with bypass permission

        if (plugin.getPermissionsManager().has(player, "preciousstones.bypass.teleport")) {
          continue;
        }

        // don't teleport if sneaking bypasses

        if (sourceField.hasFlag(FieldFlag.SNEAKING_BYPASS)
            && !sourceField.hasFlag(FieldFlag.TELEPORT_ON_SNEAK)) {
          if (player.isSneaking()) {
            continue;
          }
        }

        currentPosition = new Vec(player.getLocation());
      }

      // prepare teleport destination

      World world = destination.getWorld();

      Vec safe = findSafeLocation(destination);
      double x = safe.getX() + .5D;
      double y = safe.getY();
      double z = safe.getZ() + .5D;

      if (y == -1) {
        continue;
      }

      if (!world.isChunkLoaded(destination.getBlockX() >> 4, destination.getBlockZ() >> 4)) {
        world.loadChunk(destination.getBlockX() >> 4, destination.getBlockZ() >> 4);
      }

      Location loc =
          new Location(
              world, x, y, z, entity.getLocation().getYaw(), entity.getLocation().getPitch());

      // teleport the player

      if (sourceField.hasFlag(FieldFlag.TELEPORT_EXPLOSION_EFFECT)) {
        world.createExplosion(entity.getLocation(), -1);
      }

      entity.teleport(loc);

      if (sourceField.hasFlag(FieldFlag.TELEPORT_EXPLOSION_EFFECT)) {
        world.createExplosion(loc, -1);
      }

      if (entity instanceof Player) {
        Player player = (Player) entity;

        if (sourceField.hasFlag(FieldFlag.TELEPORT_ANNOUNCE)) {
          if (!entry.getAnnounce().isEmpty()) {
            ChatBlock.send(player, entry.getAnnounce());
          }
        }

        // start teleport back countdown

        if (sourceField.getSettings().getTeleportBackAfterSeconds() > 0) {
          if (sourceField.hasFlag(FieldFlag.TELEPORT_ANNOUNCE)) {
            ChatBlock.send(
                player,
                "teleportAnnounceBack",
                sourceField.getSettings().getTeleportBackAfterSeconds());
          }

          PlayerEntry playerEntry = plugin.getPlayerManager().getPlayerEntry(player.getName());

          playerEntry.setTeleportSecondsRemaining(
              sourceField.getSettings().getTeleportBackAfterSeconds());
          playerEntry.setTeleportVec(currentPosition);
          playerEntry.startTeleportCountDown();
          plugin.getStorageManager().offerPlayer(player.getName());
        }
      }
    }

    return true;
  }
  /**
   * Adds a fields perimeter to a player's visualization buffer
   *
   * @param player
   * @param field
   */
  public void addVisualizationField(Player player, Field field) {
    Visualization vis = visualizations.get(player.getName());

    if (vis == null) {
      vis = new Visualization();
    }

    if (plugin.getCuboidManager().hasOpenCuboid(player)) {
      return;
    }

    PlayerEntry data = plugin.getPlayerManager().getPlayerEntry(player.getName());

    if (data.getDensity() == 0) {
      return;
    }

    vis.addField(field);

    int visualizationType =
        field.hasFlag(FieldFlag.CUBOID)
            ? plugin.getSettingsManager().getCuboidVisualizationType()
            : plugin.getSettingsManager().getVisualizeBlock();
    int frameType = plugin.getSettingsManager().getVisualizeFrameBlock();

    int minx = field.getX() - field.getRadius() - 1;
    int maxx = field.getX() + field.getRadius() + 1;
    int minz = field.getZ() - field.getRadius() - 1;
    int maxz = field.getZ() + field.getRadius() + 1;
    int miny = field.getY() - (Math.max(field.getHeight() - 1, 0) / 2) - 1;
    int maxy = field.getY() + (Math.max(field.getHeight() - 1, 0) / 2) + 1;

    if (field.hasFlag(FieldFlag.CUBOID)) {
      minx = field.getMinx() - 1;
      maxx = field.getMaxx() + 1;
      minz = field.getMinz() - 1;
      maxz = field.getMaxz() + 1;
      miny = field.getMiny() - 1;
      maxy = field.getMaxy() + 1;
    }

    Location loc = null;

    for (int x = minx; x <= maxx; x++) {
      int frame = (x == minx || x == maxx) ? 89 : frameType;

      loc = new Location(player.getWorld(), x, miny, maxz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }

      loc = new Location(player.getWorld(), x, maxy, minz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }

      loc = new Location(player.getWorld(), x, miny, minz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }

      loc = new Location(player.getWorld(), x, maxy, maxz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }
    }

    for (int y = miny; y <= maxy; y++) {
      loc = new Location(player.getWorld(), minx, y, maxz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, 89, (byte) 0);
      }

      loc = new Location(player.getWorld(), maxx, y, minz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, 89, (byte) 0);
      }

      loc = new Location(player.getWorld(), minx, y, minz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, 89, (byte) 0);
      }

      loc = new Location(player.getWorld(), maxx, y, maxz);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, 89, (byte) 0);
      }
    }

    for (int z = minz; z <= maxz; z++) {
      int frame = (z == minz || z == maxz) ? 89 : frameType;

      loc = new Location(player.getWorld(), minx, maxy, z);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }

      loc = new Location(player.getWorld(), maxx, miny, z);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }

      loc = new Location(player.getWorld(), minx, miny, z);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }

      loc = new Location(player.getWorld(), maxx, maxy, z);
      if (Helper.isAirOrWater(loc)) {
        vis.addBlock(loc, frame, (byte) 0);
      }
    }

    visualizations.put(player.getName(), vis);
  }
  /**
   * Adds a fields outline to a player's visualization buffer
   *
   * @param player
   * @param ce
   */
  public void displayFieldOutline(Player player, CuboidEntry ce) {
    Visualization vis = visualizations.get(player.getName());

    if (vis == null) {
      vis = new Visualization();
    }

    // save current outline and clear out the visualization

    List<BlockEntry> oldBlocks = new ArrayList<BlockEntry>(vis.getOutlineBlocks());
    List<BlockEntry> newBlocks = new ArrayList<BlockEntry>();

    int frameType = plugin.getSettingsManager().getVisualizeFrameBlock();

    int offset = ce.selectedCount() > 1 ? 1 : 0;

    int minx = ce.getMinx() - offset;
    int miny = ce.getMiny() - offset;
    int minz = ce.getMinz() - offset;
    int maxx = ce.getMaxx() + offset;
    int maxy = ce.getMaxy() + offset;
    int maxz = ce.getMaxz() + offset;

    // add  the blocks for the new outline

    if (plugin.getSettingsManager().isVisualizationNewStyle()) {
      PlayerEntry data = plugin.getPlayerManager().getPlayerEntry(player.getName());
      int spacing =
          ((Math.max(Math.max((maxx - minx), (maxy - miny)), (maxz - minz)) + 2)
                  / data.getDensity())
              + 1;

      for (int x = minx; x <= maxx; x++) {
        int frame = (x == minx || x == maxx) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), x, miny, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), x, maxy, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), x, miny, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
        loc = new Location(player.getWorld(), x, maxy, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
      }

      for (int y = miny; y <= maxy; y++) {
        int frame = (y == miny || y == maxy) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, y, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, y, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), minx, y, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, y, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
      }

      for (int z = minz; z <= maxz; z++) {
        int frame = (z == minz || z == maxz) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, maxy, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, miny, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), minx, miny, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, maxy, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
      }
    } else {
      for (int x = minx; x <= maxx; x++) {
        int frame = (x == minx || x == maxx) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), x, miny, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), x, maxy, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), x, miny, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), x, maxy, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
      }

      for (int y = miny; y <= maxy; y++) {
        int frame = (y == miny || y == maxy) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, y, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, y, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), minx, y, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, y, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
      }

      for (int z = minz; z <= maxz; z++) {
        int frame = (z == minz || z == maxz) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, maxy, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, miny, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), minx, miny, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, maxy, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
      }
    }

    // revert the blocks that are no longer in the new set and should be reverted

    List<BlockEntry> revertible = new ArrayList<BlockEntry>(oldBlocks);
    revertible.removeAll(newBlocks);

    Visualize revert =
        new Visualize(
            revertible, player, true, false, plugin.getSettingsManager().getVisualizeSeconds());

    // visualize all the new blocks that are left to visualize

    List<BlockEntry> missing = new ArrayList<BlockEntry>(newBlocks);
    missing.removeAll(oldBlocks);

    Visualize visualize =
        new Visualize(
            missing, player, false, true, plugin.getSettingsManager().getVisualizeSeconds());

    vis.setOutlineBlocks(newBlocks);
    visualizations.put(player.getName(), vis);
  }
  /**
   * Visualizes a single field's outline
   *
   * @param player
   * @param field
   */
  public void visualizeSingleOutline(Player player, Field field, boolean revert) {
    Visualization vis = visualizations.get(player.getName());

    if (vis == null) {
      vis = new Visualization();
    }

    // save current outline and clear out the visualization

    List<BlockEntry> newBlocks = new ArrayList<BlockEntry>();

    int frameType = plugin.getSettingsManager().getVisualizeFrameBlock();

    int minx = field.getX() - field.getRadius() - 1;
    int maxx = field.getX() + field.getRadius() + 1;
    int minz = field.getZ() - field.getRadius() - 1;
    int maxz = field.getZ() + field.getRadius() + 1;
    int miny = field.getY() - (Math.max(field.getHeight() - 1, 0) / 2) - 1;
    int maxy = field.getY() + (Math.max(field.getHeight() - 1, 0) / 2) + 1;

    if (field.hasFlag(FieldFlag.CUBOID)) {
      minx = field.getMinx() - 1;
      maxx = field.getMaxx() + 1;
      minz = field.getMinz() - 1;
      maxz = field.getMaxz() + 1;
      miny = field.getMiny() - 1;
      maxy = field.getMaxy() + 1;
    }

    // add  the blocks for the new outline

    if (plugin.getSettingsManager().isVisualizationNewStyle()) {
      PlayerEntry data = plugin.getPlayerManager().getPlayerEntry(player.getName());
      int spacing =
          ((Math.max(Math.max((maxx - minx), (maxy - miny)), (maxz - minz)) + 2)
                  / data.getDensity())
              + 1;

      for (int x = minx; x <= maxx; x++) {
        int frame = (x == minx || x == maxx) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), x, miny, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), x, maxy, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), x, miny, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), x, maxy, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
      }

      for (int y = miny; y <= maxy; y++) {
        int frame = (y == miny || y == maxy) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, y, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, y, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), minx, y, minz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, y, maxz);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
      }

      for (int z = minz; z <= maxz; z++) {
        int frame = (z == minz || z == maxz) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, maxy, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, miny, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), minx, miny, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }

        loc = new Location(player.getWorld(), maxx, maxy, z);
        if (Helper.isAirOrWater(loc)) {
          newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
        }
      }
    } else {
      for (int x = minx; x <= maxx; x++) {
        int frame = (x == minx || x == maxx) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), x, miny, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), x, maxy, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), x, miny, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), x, maxy, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
      }

      for (int y = miny; y <= maxy; y++) {
        int frame = (y == miny || y == maxy) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, y, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, y, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), minx, y, minz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, y, maxz);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
      }

      for (int z = minz; z <= maxz; z++) {
        int frame = (z == minz || z == maxz) ? 89 : frameType;

        Location loc = new Location(player.getWorld(), minx, maxy, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, miny, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), minx, miny, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));

        loc = new Location(player.getWorld(), maxx, maxy, z);
        newBlocks.add(new BlockEntry(loc, frame, (byte) 0));
      }
    }

    // visualize all the new blocks that are left to visualize

    Visualize visualize =
        new Visualize(
            newBlocks, player, false, !revert, plugin.getSettingsManager().getVisualizeSeconds());
    visualizations.put(player.getName(), vis);
  }
示例#11
0
 /**
  * Set player as online
  *
  * @param player
  */
 public void playerLogin(Player player) {
   PlayerEntry data = getPlayerEntry(player.getName());
   data.setOnline(true);
 }