Example #1
0
 @EventHandler
 public void onWoolPickup(PlayerPickupItemEvent event) {
   Player player = event.getPlayer();
   if (!this.complete && GameHandler.getGameHandler().getMatch().isRunning()) {
     try {
       if (event.getItem().getItemStack().getType() == Material.WOOL
           && event.getItem().getItemStack().getData().getData() == color.getData()) {
         if (Teams.getTeamByPlayer(player).orNull() == team) {
           boolean touchMessage = false;
           if (!this.playersTouched.contains(player.getUniqueId())) {
             this.playersTouched.add(player.getUniqueId());
             if (this.show && !this.complete) {
               Teams.getTeamChannel(Optional.of(team))
                   .sendLocalizedMessage(
                       new UnlocalizedChatMessage(
                           ChatColor.WHITE + "{0}",
                           new LocalizedChatMessage(
                               ChatConstant.UI_OBJECTIVE_PICKED,
                               team.getColor() + player.getName() + ChatColor.WHITE,
                               MiscUtil.convertDyeColorToChatColor(color)
                                   + name.toUpperCase().replaceAll("_", " ")
                                   + ChatColor.WHITE,
                               team.getCompleteName() + ChatColor.WHITE)));
               for (Player player1 : Bukkit.getOnlinePlayers()) {
                 if (Teams.getTeamByPlayer(player1).isPresent()
                     && Teams.getTeamByPlayer(player1).get().isObserver()) {
                   player1.sendMessage(
                       new UnlocalizedChatMessage(
                               ChatColor.GRAY + "{0}",
                               new LocalizedChatMessage(
                                   ChatConstant.UI_OBJECTIVE_PICKED_FOR,
                                   team.getColor() + player.getName() + ChatColor.GRAY,
                                   MiscUtil.convertDyeColorToChatColor(color)
                                       + name.toUpperCase().replaceAll("_", " ")
                                       + ChatColor.GRAY,
                                   team.getCompleteName() + ChatColor.GRAY))
                           .getMessage(player1.getLocale()));
                 }
               }
               touchMessage = true;
             }
           }
           boolean oldState = this.touched;
           this.touched = true;
           if (touchMessage) {
             double newProx;
             if (location != null) {
               newProx = location.distance(place.getVector());
             } else {
               newProx = player.getLocation().toVector().distance(place.getVector());
             }
             if (!oldState || newProx < proximity) {
               proximity = newProx;
             }
           }
           ObjectiveTouchEvent touchEvent =
               new ObjectiveTouchEvent(this, player, !oldState, touchMessage);
           Bukkit.getServer().getPluginManager().callEvent(touchEvent);
         }
       }
     } catch (NullPointerException e) {
     }
   }
 }
Example #2
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;
      }
    }
  }