Esempio n. 1
0
  @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
  public void onEntityExplode(final EntityExplodeEvent event) {
    if (arena == null) {
      return;
    }

    boolean contains = false;

    for (final ArenaRegion region : arena.getRegionsByType(RegionType.BATTLE)) {
      if (region.getShape().contains(new PABlockLocation(event.getLocation()))) {
        contains = true;
        break;
      }
    }

    if (!contains) {
      return;
    }

    final Set<PABlock> blocks = SpawnManager.getPABlocksContaining(arena, "block");

    // final Set<PABlockLocation>

    for (final Block b : event.blockList()) {
      final PABlockLocation loc = new PABlockLocation(b.getLocation());
      for (final PABlock pb : blocks) {
        if (pb.getLocation().getDistanceSquared(loc) < 1) {
          final String blockTeam = pb.getName().split("block")[0];

          try {
            arena.broadcast(
                Language.parse(
                    arena,
                    MSG.GOAL_BLOCKDESTROY_SCORE,
                    Language.parse(arena, MSG.DEATHCAUSE_BLOCK_EXPLOSION) + ChatColor.YELLOW,
                    arena.getTeam(blockTeam).getColoredName() + ChatColor.YELLOW,
                    String.valueOf(getLifeMap().get(blockTeam) - 1)));
          } catch (final Exception e) {
            Bukkit.getLogger().severe("[PVP Arena] team unknown/no lives: " + blockTeam);
            e.printStackTrace();
          }
          takeBlock(arena.getTeam(blockTeam).getColor().name(), pb.getLocation());

          reduceLivesCheckEndAndCommit(arena, blockTeam);
        }
      }
    }
  }
Esempio n. 2
0
  @Override
  public boolean overlapsWith(final ArenaRegion paRegion) {
    if (paRegion.getShape() instanceof CuboidRegion) {
      // compare 2 cuboids
      if (getMinimumLocation().getX() > paRegion.locs[1].getX()
          || getMinimumLocation().getY() > paRegion.locs[1].getY()
          || getMinimumLocation().getZ() > paRegion.locs[1].getZ()) {
        return false;
      }
      if (paRegion.locs[0].getX() > getMaximumLocation().getX()
          || paRegion.locs[0].getY() > getMaximumLocation().getY()
          || paRegion.locs[0].getZ() > getMaximumLocation().getZ()) {
        return false;
      }
      return true;
    } else if (paRegion.getShape() instanceof SphericRegion) {
      // we are cube and search for intersecting sphere

      final PABlockLocation thisCenter = getMaximumLocation().getMidpoint(getMinimumLocation());
      final PABlockLocation thatCenter = paRegion.locs[1].getMidpoint(paRegion.locs[0]);

      final Double thatRadius = paRegion.locs[0].getDistance(paRegion.locs[1]) / 2;

      if (contains(thatCenter)) {
        return true; // the sphere is inside!
      }

      final PABlockLocation offset = thatCenter.pointTo(thisCenter, thatRadius);
      // offset is pointing from that to this

      return this.contains(offset);
    } else if (paRegion.getShape() instanceof CylindricRegion) {
      // we are cube and search for intersecting cylinder

      final PABlockLocation thisCenter = getMaximumLocation().getMidpoint(getMinimumLocation());
      final PABlockLocation thatCenter = paRegion.locs[1].getMidpoint(paRegion.locs[0]);

      if (getMaximumLocation().getY() < paRegion.locs[0].getY()) {
        return false;
      }
      if (getMinimumLocation().getY() > paRegion.locs[1].getY()) {
        return false;
      }

      thisCenter.setY(thatCenter.getY());

      if (contains(thatCenter)) {
        return true; // the sphere is inside!
      }

      final Double thatRadius = paRegion.locs[0].getDistance(paRegion.locs[1]) / 2;

      final PABlockLocation offset = thatCenter.pointTo(thisCenter, thatRadius);
      // offset is pointing from that to this

      return this.contains(offset);
    } else {
      PVPArena.instance
          .getLogger()
          .warning("Region Shape not supported: " + paRegion.getShape().getName());
    }
    return false;
  }