Package org.mctourney.autoreferee

Examples of org.mctourney.autoreferee.AutoRefMatch


      {
        dropSkipPlayers.remove(pl);
      }
    });

    AutoRefMatch match = plugin.getMatch(pl.getWorld());
    AutoRefPlayer apl = match == null ? null : match.getPlayer(pl);

    if (match == null || apl == null)
    { return; }
    if (apl.getTeam() == null)
    { return; }

    GoalsInventorySnapshot snapshot = GoalsInventorySnapshot
        .fromItemsAndGoals(ev.getDrops(), apl.getTeam().getObjectives());

    if (snapshot.isEmpty())
    { return; }

    match.addEvent(new TranscriptEvent(
            match,
            TranscriptEvent.EventType.OBJECTIVE_DETAIL,
            // {player} has dropped {snap} when dying (@ {loc})
            String.format("%s has dropped %s when dying (@ %s)",
                apl.getDisplayName(), snapshot, LocationUtil.toBlockCoords(
View Full Code Here


    if (event.getItem().getItemStack() == null)
    { return; }

    BlockData item = new BlockData(event.getItem().getItemStack());

    AutoRefMatch match = plugin.getMatch(pl.getWorld());
    AutoRefPlayer apl = match == null ? null : match.getPlayer(pl);

    if (match == null || apl == null)
    { return; }
    if (apl.getTeam() == null)
    { return; }

    for (BlockData b : apl.getTeam().getObjectives())
    {
      if (b.equals(item))
      {
        GoalsInventorySnapshot pickupItems = new GoalsInventorySnapshot(event.getItem().getItemStack(), b);
        match.addEvent(new TranscriptEvent(match,
            TranscriptEvent.EventType.OBJECTIVE_DETAIL, String.format(
              // {player} has picked up {snap} (@ {loc})
              "%s has picked up %s (@ %s)", apl.getDisplayName(),
              pickupItems, LocationUtil.toBlockCoords(pl.getLocation())),
            pl.getLocation(), apl, b
View Full Code Here

  }

  @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
  public void matchLoad(MatchLoadEvent event)
  {
    AutoRefMatch match = event.getMatch();
    if (match.getWorld().getName().equals(this.currentMatchName))
    {
      // update the current match BEFORE we unload
      AutoRefMatch prev = this.currentMatch;
      this.currentMatch = match;

      // if there was a match previously loaded, unload it
      if (prev != null)
      {
        for (Player player : prev.getWorld().getPlayers())
          player.teleport(match.getPlayerSpawn(player));
        prev.destroy(MatchUnloadEvent.Reason.COMPLETE);
      }
    }
  }
View Full Code Here

  {
    List<Block> blocks = event.blockList();
    if (blocks.isEmpty()) return;
    // remember, event entity can be null
    Entity cause = event.getEntity();
    AutoRefMatch match = plugin.getMatch(blocks.get(0).getWorld());
    Location loc = event.getLocation();

    if (match == null)
    { return; }

    Set<AutoRefTeam> teams = match.getTeams();
    Set<BlockData> goals = Sets.newHashSet();
    for (AutoRefTeam te : teams)
      goals.addAll(te.getObjectives());

    if (goals.isEmpty()) return; // not an objective match

    String causeStr;

    if (currentResponsibleTntPlayer != null)
    {
      causeStr = currentResponsibleTntPlayer.getDisplayName();
    }
    else if (cause != null)
    {
      causeStr = "A " + StringUtils.capitalize(cause.getType().toString().toLowerCase());
    }
    else
    {
      causeStr = "An explosion";
    }

    for (Block b : blocks)
      checkContainerBreak(b, goals, match, causeStr, "exploded");

    GoalsInventorySnapshot snap = new GoalsInventorySnapshot(blocks, goals);
    if (snap.isEmpty()) return;

    if (currentResponsibleTntPlayer != null)
    {
      // TranscriptEvent.ObjectiveDetailType.BREAK_PLAYER
      match.addEvent(new TranscriptEvent(
          match,
          TranscriptEvent.EventType.OBJECTIVE_DETAIL,
          // {entity} has exploded {snap} block(s) in {area} (@ {loc})
          String.format("%s has exploded %s block(s) in %s (@ %s)", causeStr, snap,
              getLocationDescription(loc, match), LocationUtil.toBlockCoords(loc)),
          loc, unpack(snap, currentResponsibleTntPlayer)
      ));
    }
    else
    {
      // TranscriptEvent.ObjectiveDetailType.BREAK_NONPLAYER
      match.addEvent(new TranscriptEvent(
          match,
          TranscriptEvent.EventType.OBJECTIVE_DETAIL,
          // {entity} has exploded {snap} block(s) in {area} (@ {loc})
          String.format("%s has exploded %s block(s) in %s (@ %s)", causeStr, snap,
              getLocationDescription(loc, match), LocationUtil.toBlockCoords(loc)),
View Full Code Here

  @EventHandler(priority = EventPriority.MONITOR)
  public void traceChange(EntityChangeBlockEvent event)
  {
    Block block = event.getBlock();
    AutoRefMatch match = plugin.getMatch(block.getWorld());
    if (match == null)
    { return; }

    Entity entity = event.getEntity();
    Location loc = block.getLocation();

    Set<AutoRefTeam> teams = teamsWithAccess(block.getLocation(), match, 0.1);
    Set<BlockData> goals = Sets.newHashSet();
    for (AutoRefTeam te : teams)
      goals.addAll(te.getObjectives());
    if (goals.isEmpty()) return; // not a block objectives match

    BlockData former = BlockData.fromBlock(block);
    BlockData after = new BlockData(event.getTo(), event.getData());

    String causeStr = "A " + StringUtils.capitalize(entity.getType().toString().toLowerCase());

    for (BlockData goal : goals)
    {
      if (goal.equals(former))
      {
        // process break
        // TranscriptEvent.ObjectiveDetailType.BREAK_NONPLAYER
        match.addEvent(new TranscriptEvent(match,
            TranscriptEvent.EventType.OBJECTIVE_DETAIL, String.format(
            // {entity} has broken a {goal} in {area} (@ {loc})
            "%s has broken a %s in %s (@ %s)", causeStr, goal,
            getLocationDescription(loc, match),
            LocationUtil.toBlockCoords(loc)), entity.getLocation(), goal
        ));
      }
      else if (goal.equals(after))
      {
        // process place
        // TranscriptEvent.ObjectiveDetailType.PLACE
        match.addEvent(new TranscriptEvent(match,
            TranscriptEvent.EventType.OBJECTIVE_DETAIL, String.format(
            // {entity} has placed a {goal} in {area} (@ {loc})
            "%s has placed a %s in %s (@ %s)", causeStr, goal,
            getLocationDescription(loc, match),
            LocationUtil.toBlockCoords(loc)), entity.getLocation(), goal
View Full Code Here

    if (event.getEntity().getItemStack() == null)
    { return; }

    Location loc = event.getEntity().getLocation();

    AutoRefMatch match = plugin.getMatch(loc.getWorld());

    if (match == null)
    { return; }

    Set<AutoRefTeam> teams = match.getTeams();
    Set<BlockData> goals = Sets.newHashSet();
    for (AutoRefTeam te : teams)
      goals.addAll(te.getObjectives());

    if (goals.isEmpty())
    { return; }

    GoalsInventorySnapshot snap = new GoalsInventorySnapshot(event.getEntity().getItemStack(), goals);

    match.addEvent(new TranscriptEvent(match,
        TranscriptEvent.EventType.OBJECTIVE_DETAIL, String.format(
          // "A {snap} item entity has EXPIRED in {area} (@ {loc})"
          "A %s item entity has EXPIRED in %s (@ %s)",
          snap, getLocationDescription(loc, match), LocationUtil.toBlockCoords(loc)
        ), loc, unpack(snap)
View Full Code Here

  }

  @Override
  protected void lobbyLoadMap(Player player, AutoRefMap map)
  {
    AutoRefMatch match = findSuitableMatch(map);
    if (match != null) match.joinMatch(player);
    else _loadMap(player, map, null);
  }
View Full Code Here

  @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=false)
  public void practiceMenuClick(InventoryClickEvent event)
  {
    Player player = (Player) event.getWhoClicked();
    AutoRefMatch match = plugin.getMatch(player.getWorld());

    if (match == null || !match.isPracticeMode()) return;
    if (!event.getInventory().getTitle().endsWith(PRACTICE_MENU_IDENTIFIER)
      || !practiceMenu.getViewers().contains(player)) return;

    event.setCancelled(true);

    AutoRefPlayer apl = match.getPlayer(player);
    if (apl != null && PracticeMenuOption.fromSlot(event.getSlot()) != null)
      switch (PracticeMenuOption.fromSlot(event.getSlot()))
    {
      case ADVANCE_TIME:
        player.getWorld().setFullTime(player.getWorld().getFullTime() + 1000L);
        match.broadcast(ChatColor.DARK_GRAY + "[" + apl.getDisplayName() +
          ChatColor.DARK_GRAY + "] Advanced time by one hour");
        break;

      case SET_TIME_SUNRISE:
        player.getWorld().setTime(0L);
        match.broadcast(ChatColor.DARK_GRAY + "[" + apl.getDisplayName() +
          ChatColor.DARK_GRAY + "] Set time to 7am");
        break;

      case SET_TIME_SUNSET:
        player.getWorld().setTime(13000L);
        match.broadcast(ChatColor.DARK_GRAY + "[" + apl.getDisplayName() +
          ChatColor.DARK_GRAY + "] Set time to 9pm");
        break;

      case NIGHT_VISION:
        player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 8 * 60 * 20, 1));
        break;

      case CLEAR_POTION_EFFECTS:
        player.sendMessage(ChatColor.GRAY + "-- Potion effects cleared");
        PlayerUtil.removeStatusEffects(player);
        break;

      case BUTCHER:
        match.clearEntities();
        break;

      case MODE_SURVIVAL: PlayerUtil.setGameMode(player, GameMode.SURVIVAL); break;
      case MODE_CREATIVE: PlayerUtil.setGameMode(player, GameMode.CREATIVE); break;

      case SET_WARP:
        warpPoints.put(player.getName(), player.getLocation());
        player.sendMessage(ChatColor.GRAY + "-- Set warp point");
        break;

      case GOTO_WARP:
        Location loc = warpPoints.get(player.getName());
        if (loc != null && loc.getWorld() == player.getWorld())
          player.teleport(loc);
        break;

      case TOGGLE_GODMODE:
        boolean b = !apl.isGodMode();
        apl.setGodMode(b);

        match.broadcast(ChatColor.DARK_GRAY + "[" + apl.getDisplayName() +
          ChatColor.DARK_GRAY + "] Toggled invulnerability " + ChatColor.RED + (b ? "ON" : "OFF"));
        break;

      case HEAL: PlayerUtil.heal(player); break;
      case FEED: PlayerUtil.feed(player); break;
View Full Code Here

        resultChecker.cancel();
      }
      // Schedule announce, return true
      Bukkit.getScheduler().runTask(plugin, new Runnable() { public void run()
      {
        AutoRefMatch match = team.getMatch();
        World world = match.getWorld();
        StringBuilder sb = new StringBuilder();
        sb.append(ChatColor.GREEN).append("Objective search for ").append(team.getDisplayName()).append(ChatColor.GREEN).append(" complete.");
        sb.append('\n');
        for (BlockData bd : originalSearch)
        {
          Location loc = results.get(bd).toLocation(world);
          sb.append(bd.getDisplayName()).append(ChatColor.GRAY).append(" is at ").append(ChatColor.RED).append(LocationUtil.toBlockCoords(loc));
          sb.append('\n');
        }
        String[] message = sb.toString().split("\n");
        for (Player p : match.getSpectators())
          p.sendMessage(message);
      } });
      return true;
    }
    return false;
View Full Code Here

  }

  @EventHandler(priority=EventPriority.HIGHEST)
  public void damageDealt(EntityDamageEvent event)
  {
    AutoRefMatch match = plugin.getMatch(event.getEntity().getWorld());
    if (match == null || !match.getCurrentState().inProgress()) return;

    if (event.getEntityType() == EntityType.PLAYER)
    {
      AutoRefPlayer apl = match.getPlayer((Player) event.getEntity());
      if (apl != null && apl.isGodMode()) { event.setDamage(0); return; }
    }

    if (match.getCurrentState().inProgress() &&
      event instanceof EntityDamageByEntityEvent)
    {
      EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) event;
      Player damaged = entityToPlayer(ed.getEntity());

      // enderpearls are a special case!
      if (ed.getDamager().getType() == EntityType.ENDER_PEARL) return;

      Player damager = entityToPlayer(ed.getDamager());
      if (null != damager && ed.getDamager() instanceof Arrow)
      {
        AutoRefPlayer apl = match.getPlayer(damager);
        if (apl != null) apl.incrementShotsHit();

        Arrow arrow = (Arrow) ed.getDamager();
        if (arrow.getShooter().getType() == EntityType.PLAYER)
        {
          AutoRefPlayer shooter = match.getPlayer((Player) arrow.getShooter());
          Location shotFrom = shotArrows.get(arrow);

          if (shooter != null && shotFrom != null)
            shooter.setFurthestShot(arrow.getLocation().distance(shotFrom));
        }
      }

      // spectators cannot cause damage to any entity
      if (match.getCurrentState().inProgress() &&
        null != damager && match.isSpectator(damager))
      { event.setCancelled(true); return; }

      if (null != damager && ed.getEntityType() == EntityType.PIG_ZOMBIE)
      {
        AutoRefPlayer apl = match.getPlayer(damager);
        Long lastAggro = lastPigmenAggro.get(apl);

        long currentTime = ManagementFactory.getRuntimeMXBean().getUptime();
        if (lastAggro == null || currentTime > PIGMEN_COOLDOWN_MS + lastAggro)
        {
          for (Player ref : match.getReferees(false))
            ref.sendMessage(apl.getDisplayName() + ChatColor.GRAY + " has angered the Zombie Pigmen");
          lastPigmenAggro.put(apl, currentTime);
        }
      }

      // if either of these aren't players, nothing to do here
      if (null == damager || null == damaged) return;

      AutoRefPlayer aapl = match.getPlayer(damager);
      AutoRefPlayer vapl = match.getPlayer(damaged);

      // FIXME - define behavior for when attacker or victim is not actually in the match
      // (and therefore aapl/vapl is null)

      if (!aapl.isInsideLane())
      { event.setCancelled(true); return; }

      // if the match is in progress and player is in start region
      // cancel any damage dealt to the player
      if (match.getCurrentState().inProgress() && vapl != null && !vapl.isActive())
      { event.setCancelled(true); return; }

      // if both players are not on a team, quit
      if (aapl.getTeam() == null && vapl.getTeam() == null) return;

      // if the attacked isn't on a team, or same team (w/ no FF), cancel
      if (vapl.getTeam() == null || (aapl.getTeam() == vapl.getTeam() && !match.allowFriendlyFire()))
      { event.setCancelled(true); return; }
    }

    // only allow damage before a match if it is a direct attack
    if (match.getCurrentState().isBeforeMatch() &&
      event.getCause() != DamageCause.ENTITY_ATTACK)
    { event.setCancelled(true); return; }
  }
View Full Code Here

TOP

Related Classes of org.mctourney.autoreferee.AutoRefMatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.