Package org.mctourney.autoreferee

Examples of org.mctourney.autoreferee.AutoRefPlayer


      {
        // player teleport target (optional)
        String target = options.getOptionValue('t');
        if (target != null && !target.isEmpty())
        {
          AutoRefPlayer apl = match.getPlayer(target);
          if (apl != null) player.teleport(apl.getLocation());
        }
        // if no player is specified, show teleport menu
        else showPlayerTeleportMenu(player);
      }
      // if no options are given, show practice menu
View Full Code Here


    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

    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())
      {
View Full Code Here

    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() &&
View Full Code Here

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

      AutoRefPlayer apl = match.getPlayer(damager);
      if (apl != null)
      {
        Location loc = event.getVehicle().getLocation();
        if (!apl.isInsideLane() || apl.getTeam().hasFlag(loc, Flag.NO_ACCESS))
        { event.setCancelled(true); return; }
      }
    }
  }
View Full Code Here

    if (match == null || !match.getCurrentState().inProgress()) return;

    // save player data if the damaged entity was a player
    if (event.getEntityType() == EntityType.PLAYER)
    {
      AutoRefPlayer pdata = match.getPlayer((Player) event.getEntity());
      if (pdata != null)
      {
        Player damager = (event instanceof EntityDamageByEntityEvent) ?
          entityToPlayer(((EntityDamageByEntityEvent) event).getDamager()) : null;
        pdata.registerDamage(event, damager);
      }
    }
  }
View Full Code Here

    Player player = (Player) event.getEntity();
    AutoRefMatch match = plugin.getMatch(player.getWorld());
    if (match == null || !match.getCurrentState().inProgress()) return;

    AutoRefPlayer apl = match.getPlayer(player);
    if (apl != null) apl.incrementShotsFired();

    shotArrows.put((Projectile) event.getProjectile(),
      event.getEntity().getLocation().clone());
  }
View Full Code Here

    if (!SportBukkitUtil.hasSportBukkitApi() || match == null) return;

    if (event.getEntityType() == EntityType.PRIMED_TNT)
    {
      Location tntLocation = event.getEntity().getLocation().getBlock().getLocation();
      AutoRefPlayer apl = tntPropagation.remove(tntLocation);

      // if there was no propagation chain
      if (apl == null)
      {
        // try to determine if this was the first tnt in a chain
        if ((apl = match.getNearestPlayer(tntLocation)) == null) return;

        Location plLocation = apl.getLocation();
        if (plLocation.distanceSquared(tntLocation) > TNT_PRIME_RANGE * TNT_PRIME_RANGE) return;
      }

      // add an owner for this tnt object
      if (apl != null) plugin.setTNTOwner(event.getEntity(), apl);
View Full Code Here

  @EventHandler(priority=EventPriority.MONITOR)
  public void entityExplode(EntityExplodeEvent event)
  {
    // remove this entity from the table if present
    AutoRefPlayer apl = plugin.clearTNTOwner(event.getEntity());

    if (apl != null) for (Block b : event.blockList())
      if (b.getType() == Material.TNT) tntPropagation.put(b.getLocation(), apl);
  }
View Full Code Here

TOP

Related Classes of org.mctourney.autoreferee.AutoRefPlayer

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.