Example #1
0
  public static void initTeam(ArenaTeam team, MatchParams params) {
    team.reset(); // / reset scores, set alive
    team.setCurrentParams(params);
    int index = team.getIndex();
    MatchParams teamParams = null;
    boolean isTeamParam = false;
    if (index != -1) {
      teamParams = params.getTeamParams(index);
    }
    if (teamParams == null) {
      teamParams = params;
    } else {
      isTeamParam = true;
    }

    team.setMinPlayers(teamParams.getMinTeamSize());
    team.setMaxPlayers(teamParams.getMaxTeamSize());

    boolean alwaysTeamNames = false;
    if (index != -1) {
      StateGraph tops = teamParams.getStateGraph();
      team.setTeamChatColor(TeamUtil.getTeamChatColor(index));
      if (tops != null) {
        if (tops.hasAnyOption(TransitionOption.WOOLTEAMS) && teamParams.getMaxTeamSize() > 1
            || tops.hasAnyOption(TransitionOption.ALWAYSWOOLTEAMS)) {
          team.setHeadItem(TeamUtil.getTeamHead(index));
        }
        alwaysTeamNames = tops.hasAnyOption(TransitionOption.ALWAYSTEAMNAMES);
      }

      final String name;
      if (!isTeamParam || teamParams.getThisDisplayName() == null) {
        name = TeamUtil.getTeamName(index);
        if (alwaysTeamNames
            || (!team.hasSetName()
                && team.getDisplayName().length() > Defaults.MAX_TEAM_NAME_APPEND)) {
          team.setDisplayName(name);
        }
      } else {
        name = teamParams.getThisDisplayName();
        team.setDisplayName(name);
      }
      team.setScoreboardDisplayName(
          name.length() > Defaults.MAX_SCOREBOARD_NAME_SIZE
              ? name.substring(0, Defaults.MAX_SCOREBOARD_NAME_SIZE)
              : name);
    }
  }
Example #2
0
  @ArenaEventHandler(bukkitPriority = org.bukkit.event.EventPriority.MONITOR)
  public void onPlayerDeath(ArenaPlayerDeathEvent event) {
    final ArenaPlayer target = event.getPlayer();
    if (state == MatchState.ONCANCEL || state == MatchState.ONCOMPLETE) {
      return;
    }
    final ArenaTeam t = event.getTeam();

    Integer nDeaths = t.addDeath(target);
    boolean exiting = event.isExiting() || !respawns || nDeaths >= nLivesPerPlayer;
    event.setExiting(exiting);
    final boolean trueDeath = event.getPlayerDeathEvent() != null;
    if (nLivesPerPlayer != ArenaSize.MAX) {
      int curLives = nLivesPerPlayer - nDeaths;
      SEntry e = scoreboard.getEntry(target.getPlayer());
      if (e != null) scoreboard.setEntryNameSuffix(e, curLives <= 1 ? "" : "&4(" + curLives + ")");
    }
    if (trueDeath) {
      PlayerDeathEvent pde = event.getPlayerDeathEvent();
      if (cancelExpLoss) pde.setKeepLevel(true);

      /// Handle Drops from bukkitEvent
      if (clearsInventoryOnDeath || keepsInventory) { // / clear the drops
        try {
          pde.getDrops().clear();
        } catch (Exception e) {
          if (!Defaults.DEBUG_VIRTUAL) Log.printStackTrace(e);
        }
      } else if (woolTeams) { /// Get rid of the wool from teams so it doesnt drop
        final int index = t.getIndex();
        ItemStack teamHead = TeamUtil.getTeamHead(index);
        List<ItemStack> items = pde.getDrops();
        for (ItemStack is : items) {
          if (is.getType() == teamHead.getType()
              && is.getDurability() == teamHead.getDurability()) {
            final int amt = is.getAmount();
            if (amt > 1) is.setAmount(amt - 1);
            else is.setType(Material.AIR);
            break;
          }
        }
      }
      /// If keepInventory is specified, but not restoreAll, then we have a case
      /// where we need to give them back the current Inventory they have on them
      /// even if they log out
      if (keepsInventory) {
        boolean restores =
            getParams().hasOptionAt(MatchState.ONLEAVE, TransitionOption.RESTOREITEMS);
        /// Restores and exiting, means clear their match inventory so they won't
        /// get their match and their already stored inventory
        if (restores && exiting) {
          psc.clearMatchItems(target);
        } else { /// keep their current inv
          psc.storeMatchItems(target);
        }
      }
      /// We can't let them just sit on the respawn screen... schedule them to lose
      /// We will cancel this onRespawn
      final ArenaMatch am = this;
      Integer timer = deathTimer.get(target.getName());
      if (timer != null) {
        Bukkit.getScheduler().cancelTask(timer);
      }
      timer =
          Bukkit.getScheduler()
              .scheduleSyncDelayedTask(
                  BattleArena.getSelf(),
                  new Runnable() {
                    @Override
                    public void run() {
                      PerformTransition.transition(am, MatchState.ONCOMPLETE, target, t, true);
                      checkAndHandleIfTeamDead(t);
                    }
                  },
                  15 * 20L);
      deathTimer.put(target.getName(), timer);
    }
    if (exiting) {
      PerformTransition.transition(this, MatchState.ONCOMPLETE, target, t, true);
      checkAndHandleIfTeamDead(t);
    }
  }