/**
   * drop an item at a powerup spawn point
   *
   * @param item the item to drop
   */
  protected void dropItemOnSpawn(Material item) {
    debug.i("calculating item spawn location");
    Location aim = SpawnManager.getCoords(arena, "powerup").add(0, 1, 0).toLocation();

    debug.i("dropping item on spawn: " + aim.toString());
    Bukkit.getWorld(arena.getWorld()).dropItem(aim, new ItemStack(item, 1));
  }
Exemplo n.º 2
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);
        }
      }
    }
  }
Exemplo n.º 3
0
  @Override
  public void parseStart() {
    getLifeMap().clear();
    for (final ArenaTeam team : arena.getTeams()) {
      if (!team.getTeamMembers().isEmpty()) {
        arena.getDebugger().i("adding team " + team.getName());
        // team is active
        getLifeMap()
            .put(team.getName(), arena.getArenaConfig().getInt(CFG.GOAL_BLOCKDESTROY_LIVES, 1));
      }
      final Set<PABlockLocation> blocks = SpawnManager.getBlocksContaining(arena, "block");

      for (final PABlockLocation block : blocks) {
        takeBlock(team.getColor().name(), block);
      }
    }
  }
Exemplo n.º 4
0
  @Override
  public void initate(final Player player) {
    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());
    final ArenaTeam team = aPlayer.getArenaTeam();
    if (!getLifeMap().containsKey(team.getName())) {
      getLifeMap()
          .put(
              aPlayer.getArenaTeam().getName(),
              arena.getArenaConfig().getInt(CFG.GOAL_BLOCKDESTROY_LIVES));

      final Set<PABlockLocation> blocks = SpawnManager.getBlocksContaining(arena, "block");

      for (final PABlockLocation block : blocks) {
        takeBlock(team.getColor().name(), block);
      }
    }
  }
Exemplo n.º 5
0
  @Override
  public boolean commitSetFlag(final Player player, final Block block) {

    arena.getDebugger().i("trying to set a block", player);

    // command : /pa redblock1
    // location: red1block:

    SpawnManager.setBlock(arena, new PABlockLocation(block.getLocation()), blockTeamName);

    arena.msg(player, Language.parse(arena, MSG.GOAL_BLOCKDESTROY_SET, blockTeamName));

    PAA_Region.activeSelections.remove(player.getName());
    blockTeamName = "";

    return true;
  }
Exemplo n.º 6
0
  @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = false)
  public void onBlockBreak(final BlockBreakEvent event) {
    final Player player = event.getPlayer();
    if (!arena.hasPlayer(event.getPlayer())
        || !event
            .getBlock()
            .getType()
            .name()
            .equals(arena.getArenaConfig().getString(CFG.GOAL_BLOCKDESTROY_BLOCKTYPE))) {

      arena.getDebugger().i("block destroy, ignoring", player);
      arena.getDebugger().i(String.valueOf(arena.hasPlayer(event.getPlayer())), player);
      arena.getDebugger().i(event.getBlock().getType().name(), player);
      return;
    }

    if (!arena.isFightInProgress()) {
      event.setCancelled(true);
      return;
    }

    final Block block = event.getBlock();

    arena.getDebugger().i("block destroy!", player);

    final ArenaPlayer aPlayer = ArenaPlayer.parsePlayer(player.getName());

    final ArenaTeam pTeam = aPlayer.getArenaTeam();
    if (pTeam == null) {
      return;
    }

    Vector vBlock = null;
    for (final ArenaTeam team : arena.getTeams()) {
      final String blockTeam = team.getName();

      if (team.getTeamMembers().size() < 1 && !"touchdown".equals(team.getName())) {
        arena.getDebugger().i("size!OUT! ", player);
        continue; // dont check for inactive teams
      }

      arena.getDebugger().i("checking for block of team " + blockTeam, player);
      Vector vLoc = block.getLocation().toVector();
      arena.getDebugger().i("block: " + vLoc, player);
      if (!SpawnManager.getBlocksStartingWith(arena, blockTeam + "block").isEmpty()) {
        vBlock =
            SpawnManager.getBlockNearest(
                    SpawnManager.getBlocksStartingWith(arena, blockTeam + "block"),
                    new PABlockLocation(player.getLocation()))
                .toLocation()
                .toVector();
      }
      if (vBlock != null && vLoc.distance(vBlock) < 2) {

        // ///////

        if (blockTeam.equals(pTeam.getName())) {
          arena.getDebugger().i("is own team! cancel and OUT! ", player);
          event.setCancelled(true);
          continue;
        }
        PAGoalEvent gEvent = new PAGoalEvent(arena, this, "trigger:" + player.getName());
        Bukkit.getPluginManager().callEvent(gEvent);
        final String sTeam = pTeam.getName();

        try {
          arena.broadcast(
              Language.parse(
                  arena,
                  MSG.GOAL_BLOCKDESTROY_SCORE,
                  arena.getTeam(sTeam).colorizePlayer(player) + 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();
        }

        gEvent =
            new PAGoalEvent(
                arena,
                this,
                "score:" + player.getName() + ':' + aPlayer.getArenaTeam().getName() + ":1");
        Bukkit.getPluginManager().callEvent(gEvent);
        class RunLater implements Runnable {
          String localColor;
          PABlockLocation localLoc;

          RunLater(final String color, final PABlockLocation loc) {
            localColor = color;
            localLoc = loc;
          }

          @Override
          public void run() {
            takeBlock(localColor, localLoc);
          }
        }

        if (getLifeMap().containsKey(blockTeam)
            && getLifeMap().get(blockTeam)
                > SpawnManager.getBlocksStartingWith(arena, blockTeam + "block").size()) {

          Bukkit.getScheduler()
              .runTaskLater(
                  PVPArena.instance,
                  new RunLater(
                      arena.getTeam(blockTeam).getColor().name(),
                      new PABlockLocation(event.getBlock().getLocation())),
                  5L);
        }
        reduceLivesCheckEndAndCommit(arena, blockTeam);

        return;
      }
    }
  }