Package org.mctourney.autoreferee

Examples of org.mctourney.autoreferee.AutoRefMatch


  public void playerJoin(PlayerJoinEvent event)
  {
    Player player = event.getPlayer();

    // get the match for the world the player is logging into
    AutoRefMatch match = plugin.getMatch(player.getWorld());

    // if there is no match here, or they aren't meant to play in this world,
    // check if there is a world they are expected in
    if (match == null || !match.isPlayer(player))
      for (AutoRefMatch m : plugin.getMatches())
        if (m.isPlayerExpected(player)) match = m;

    if (match != null)
    {
      // if we are logging in to the wrong world, teleport to the correct world
      if (player.getWorld() != match.getWorld()) match.joinMatch(player);
      else match.checkTeamsReady();

      if (!match.getCurrentState().inProgress() || match.isPlayer(player))
        match.broadcast(match.colorMessage(event.getJoinMessage()));
      event.setJoinMessage(null);

      match.sendMatchInfo(player);
      match.setupSpectators(player);

      // only clear inventories and give books if before match or not a player
      if (match.getCurrentState().isBeforeMatch() || !match.isPlayer(player))
      {
        // give them a book with info about the match
        PlayerUtil.clearInventory(player);
        match.giveMatchInfoBook(player);
      }

      if (match.isReferee(player))
        match.updateReferee(player);

      if (!player.hasPlayedBefore())
        player.teleport(match.getPlayerSpawn(player));
    }
  }
View Full Code Here


  }

  @EventHandler
  public void playerQuit(PlayerQuitEvent event)
  {
    AutoRefMatch match = plugin.getMatch(event.getPlayer().getWorld());
    if (match != null)
    {
      if (!match.getCurrentState().inProgress() || match.isPlayer(event.getPlayer()))
        match.broadcast(match.colorMessage(event.getQuitMessage()));
      event.setQuitMessage(null);

      // set the player back to the main scoreboard
      event.getPlayer().setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
    }
View Full Code Here

  @EventHandler
  public void worldJoin(PlayerChangedWorldEvent event)
  {
    // update team ready information for both worlds
    AutoRefMatch matchFm = plugin.getMatch(event.getFrom());
    if (matchFm != null) matchFm.checkTeamsReady();

    Player player = event.getPlayer();
    AutoRefMatch matchTo = plugin.getMatch(player.getWorld());

    if (matchTo != null)
    {
      matchTo.checkTeamsReady();
      matchTo.sendMatchInfo(player);
      matchTo.setupSpectators(player);

      if (matchTo.isReferee(player))
        matchTo.updateReferee(player);

      // give them a book with info about the match
      PlayerUtil.clearInventory(player);
      matchTo.giveMatchInfoBook(player);
    }

    // if this is leaving a match, leave its team
    if (matchFm != null)
      matchFm.leaveTeam(player, false);
View Full Code Here

  }

  @EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
  public void worldUnload(WorldUnloadEvent event)
  {
    AutoRefMatch match = plugin.getMatch(event.getWorld());
    if (match == null) return;

    match.saveWorldConfiguration();
    plugin.clearMatch(match);
  }
View Full Code Here

  @EventHandler
  public void blockForm(BlockFormEvent event)
  {
    // we are really only interested in stopping ice from forming here
    AutoRefMatch match = plugin.getMatch(event.getBlock().getWorld());
    if (match != null && !match.getCurrentState().inProgress()
      && event.getNewState().getType() == Material.ICE)
    { event.setCancelled(true); return; }
  }
View Full Code Here

  }

  @EventHandler
  public void blockGrow(BlockGrowEvent event)
  {
    AutoRefMatch match = plugin.getMatch(event.getBlock().getWorld());
    if (match != null && !match.getCurrentState().inProgress())
    { event.setCancelled(true); return; }
  }
View Full Code Here

  }

  @EventHandler(priority=EventPriority.HIGHEST)
  public void playerDeath(PlayerDeathEvent event)
  {
    AutoRefMatch match = plugin.getMatch(event.getEntity().getWorld());
    if (match != null)
    {
      // get victim, and killer (maybe null) of this player
      Player victim = event.getEntity();
      AutoRefPlayer vapl = match.getPlayer(victim);

      Player killer = victim.getKiller();
      AutoRefPlayer kapl = match.getPlayer(killer);

      String dmsg = event.getDeathMessage();
      EntityDamageEvent lastDmg = victim.getLastDamageCause();

      // if the death was due to intervention by the plugin
      // let's change the death message to reflect this fact
      if (lastDmg == AutoRefPlayer.VOID_DEATH)
      {
        dmsg = victim.getName() + " entered the void lane";
        event.getDrops().clear();
      }

      Location locKiller = null;
      if (lastDmg instanceof EntityDamageByEntityEvent)
      {
        EntityDamageByEntityEvent ed = (EntityDamageByEntityEvent) lastDmg;
        switch (ed.getDamager().getType())
        {
          case CREEPER:
            dmsg = victim.getName() + " was blown up by Creeper";
            break;
          case PRIMED_TNT:
            dmsg = victim.getName() + " was blown up by TNT";
            if (plugin.getTNTOwner(ed.getDamager()) != vapl)
            {
              kapl = plugin.getTNTOwner(ed.getDamager());
              if (kapl != null)
                dmsg = victim.getName() + " was blown up by " + kapl.getName();
            }
            break;
          default:
            // noop
            break;
        }

        if (ed.getDamager() instanceof Projectile)
          locKiller = shotArrows.get(ed.getDamager());
      }

      // update the death message with the changes
      event.setDeathMessage(dmsg);

      if (match.getCurrentState().inProgress())
      {
        // register the death and kill
        if (vapl != null) vapl.registerDeath(event, locKiller);
        if (kapl != null && kapl != vapl) kapl.registerKill(event);
      }

      // handle respawn modes
      if (vapl != null && match.getCurrentState().inProgress())
      {
        respawn: switch (match.getRespawnMode())
        {
          case BEDS_ONLY:
            // INTENTIONAL FALL-THROUGH HERE!
            if (vapl.getTeam() != null)
              for (AutoRefPlayer mate : vapl.getTeam().getPlayers())
            {
              if (mate == vapl) continue;
              boolean couldRespawn = mate.isOnline() &&
                mate.getPlayer().getBedSpawnLocation() != null;
              if (!mate.isDead() || couldRespawn) break respawn;
            }
            if (victim.getBedSpawnLocation() != null) break respawn;

          case DISALLOW:
          case ALLOW:
            if (match.getCurrentState().inProgress() && !vapl.hasLives())
              match.eliminatePlayer(event.getEntity());
            break;

          // typically, no action should be taken
          default: break;
        }
View Full Code Here

  @EventHandler(priority=EventPriority.HIGHEST)
  public void chatMessage(AsyncPlayerChatEvent event)
  {
    // typical chat message format, swap out with colored version
    Player speaker = event.getPlayer();
    AutoRefMatch match = plugin.getMatch(speaker.getWorld());

    // restrict listeners to being in the same match (not world).
    // this should avoid messing up multi-world chat on multipurpose servers
    Iterator<Player> iter = event.getRecipients().iterator();
    while (iter.hasNext())
    {
      Player listener = iter.next();

      if (plugin.getMatch(listener.getWorld()) != match)
      { iter.remove(); continue; }
    }

    // if the speaker isn't in a match, that's all we can do
    if (match == null) return;

    AutoRefTeam speakerTeam = match.getPlayerTeam(speaker);
    if (speakerTeam != null)
    {
      ChatColor teamColor = speakerTeam.getColor();
      event.setFormat("<" + teamColor + "%s" + ChatColor.RESET + "> %s");
    }
View Full Code Here

  @EventHandler
  public void playerRespawn(PlayerRespawnEvent event)
  {
    World world = event.getPlayer().getWorld();
    AutoRefMatch match = plugin.getMatch(world);

    if (match != null && match.isPlayer(event.getPlayer()))
    {
      // does this player have a bed spawn?
      boolean hasBed = event.getPlayer().getBedSpawnLocation() != null;

      // if the player attempts to respawn in a different world, bring them back
      Location respawnLocation = event.getRespawnLocation();
      boolean changeRespawn = !hasBed || respawnLocation.getWorld() != match.getWorld() ||
        match.inStartRegion(respawnLocation);
      if (changeRespawn) event.setRespawnLocation(match.getPlayerSpawn(event.getPlayer()));

      // setup respawn for the player
      match.getPlayer(event.getPlayer()).respawn();
    }
  }
View Full Code Here

  {
    Player player = event.getPlayer();

    // if this player needs to be in a specific world, put them there
    AutoRefTeam team = plugin.getExpectedTeam(player);
    AutoRefMatch match = plugin.getMatch(player.getWorld());

    if (team != null)
    {
      team.join(player, PlayerTeamJoinEvent.Reason.EXPECTED);
      match = team.getMatch();
    }

    if (match != null && match.isPlayer(player))
      match.messageReferees("player", player.getName(), "login");
  }
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.