Пример #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);
    }
  }
Пример #2
0
 public static ChangeType fromName(String str) {
   str = str.toUpperCase();
   ChangeType ct = null;
   try {
     ct = ChangeType.valueOf(str);
   } catch (Exception e) {
   }
   if (ct != null) return ct;
   try {
     if (Integer.valueOf(str) != null) return SPAWNLOC;
   } catch (Exception e) {
   }
   if (TeamUtil.getTeamIndex(str) != null) {
     return SPAWNLOC;
   }
   if (str.equalsIgnoreCase("wr")) return WAITROOM;
   if (str.equalsIgnoreCase("v")) return VLOC;
   return null;
 }
Пример #3
0
 private static int verifySpawnLocation(CommandSender sender, String value) {
   if (!(sender instanceof Player)) {
     sendMessage(sender, "&cYou need to be in game to use this command");
     return -1;
   }
   Integer locindex = -1;
   try {
     locindex = Integer.parseInt(value);
   } catch (Exception e) {
   }
   if (locindex == -1) {
     locindex = TeamUtil.getTeamIndex(value);
     if (locindex != null) locindex++;
   }
   if (locindex == null || locindex <= 0 || locindex > 100) {
     sendMessage(sender, "&cspawn number must be in the range [1-100]");
     return -1;
   }
   return locindex;
 }
Пример #4
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);
    }
  }