Пример #1
0
 public void performAction(ArenaPlayer player) {
   if (mp.getJoinType() == JoinType.JOINPHASE) {
     performEventAction(player);
   } else {
     performMatchAction(player);
   }
 }
  private static ArenaLocation getArenaLocation(
      PlayerHolder am, ArenaTeam team, ArenaPlayer player, TransitionOptions mo, int teamIndex) {
    final MatchParams mp = am.getParams();
    final boolean randomRespawn = mo.hasOption(TransitionOption.RANDOMRESPAWN);
    Location l;
    final boolean teleportWaitRoom = mo.shouldTeleportWaitRoom();
    final boolean teleportLobby = mo.shouldTeleportLobby();
    final boolean teleportSpectate = mo.shouldTeleportSpectate();
    final LocationType type;
    final PlayerHolder ph;
    if (Defaults.DEBUG_TRACE)
      Log.info(" teamindex = " + teamIndex + "   " + am.getClass().getSimpleName() + "  " + am);

    if (teleportWaitRoom) {
      if (mo.hasOption(TransitionOption.TELEPORTMAINWAITROOM)) {
        teamIndex = Defaults.MAIN_SPAWN;
      }
      ph = (am instanceof Match) ? ((Match) am).getArena().getWaitroom() : am;
      type = LocationType.WAITROOM;
      l = jitter(ph.getSpawn(teamIndex, randomRespawn), teamIndex);
    } else if (teleportLobby) {
      if (mo.hasOption(TransitionOption.TELEPORTMAINLOBBY)) {
        teamIndex = Defaults.MAIN_SPAWN;
      }
      ph = RoomController.getLobby(mp.getType());
      type = LocationType.LOBBY;
      l = jitter(RoomController.getLobbySpawn(teamIndex, mp.getType(), randomRespawn), 0);
    } else if (teleportSpectate) {
      ph = (am instanceof Match) ? ((Match) am).getArena().getSpectatorRoom() : am;
      type = LocationType.SPECTATE;
      l = jitter(ph.getSpawn(teamIndex, randomRespawn), teamIndex);
    } else { // They should teleportIn, aka to the Arena
      final Arena arena;
      if (am instanceof Arena) {
        arena = (Arena) am;
      } else if (am instanceof Match) {
        Match m = (Match) am;
        arena = m.getArena();
      } else {
        throw new IllegalStateException("[BA Error] Instance is " + am.getClass().getSimpleName());
      }
      ph = am;
      type = LocationType.ARENA;
      l = arena.getSpawn(teamIndex, false);
    }
    return new ArenaLocation(ph, l, type);
  }
Пример #3
0
 public boolean matches(ArenaPlayer player, MatchParams mp) {
   if (mp.getTransitionOptions()
       .hasOptionAt(MatchState.PREREQS, TransitionOption.WITHINDISTANCE)) {
     Double distance =
         mp.getTransitionOptions().getOptions(MatchState.PREREQS).getWithinDistance();
     if (options.containsKey(DuelOption.ARENA)) {
       Arena arena = (Arena) options.get(DuelOption.ARENA);
       return arena.withinDistance(player.getLocation(), distance);
     } else {
       for (Arena arena : BattleArena.getBAController().getArenas(mp)) {
         if (arena.withinDistance(player.getLocation(), distance)) return true;
       }
       return false;
     }
   }
   return true;
 }
  public static void teleport(
      PlayerHolder am, ArenaTeam team, ArenaPlayer player, TransitionOptions mo, int teamIndex) {
    player.markOldLocation();
    MatchParams mp = am.getParams();

    /// EnterWaitRoom is supposed to happen before the teleport in event, but it depends on the
    // result of a teleport
    /// Since we cant really tell the eventual result.. do our best guess
    ArenaLocation dest = getArenaLocation(am, team, player, mo, teamIndex);
    ArenaLocation src = player.getCurLocation();
    src.setLocation(player.getLocation());
    if (Defaults.DEBUG_TRACE)
      Log.info(" ########### @@ " + player.getCurLocation() + "  -->  " + am.getTeam(player));

    TeleportDirection td = calcTeleportDirection(player, src, dest);
    ArenaPlayerTeleportEvent apte =
        new ArenaPlayerTeleportEvent(mp.getType(), player, team, src, dest, td);

    movePlayer(player, apte, mp);
  }
Пример #5
0
 public String optionsString(MatchParams mp) {
   StringBuilder sb = new StringBuilder();
   sb.append("rated=" + mp.isRated() + " ");
   for (DuelOption op : options.keySet()) {
     sb.append(op.getName());
     if (op.needsValue) {
       sb.append("=" + options.get(op));
     }
     sb.append(" ");
   }
   return sb.toString();
 }
Пример #6
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);
    }
  }
Пример #7
0
  public static DuelOptions parseOptions(MatchParams params, ArenaPlayer challenger, String[] args)
      throws InvalidOptionException {
    DuelOptions dop = new DuelOptions();
    dop.options.putAll(defaultOptions.options);
    Map<DuelOption, Object> ops = dop.options;

    for (int i = 0; i < args.length; i++) {
      String op = args[i];
      Player p = ServerUtil.findPlayer(op);
      if (p != null) {
        if (!p.isOnline())
          throw new InvalidOptionException(
              "&cPlayer &6" + p.getDisplayName() + "&c is not online!");
        if (challenger != null && p.getName().equals(challenger.getName()))
          throw new InvalidOptionException("&cYou can't challenge yourself!");
        if (p.hasPermission(Permissions.DUEL_EXEMPT) && !Defaults.DUEL_CHALLENGE_ADMINS) {
          throw new InvalidOptionException("&cThis player can not be challenged!");
        }
        dop.challengedPlayers.add(BattleArena.toArenaPlayer(p));
        continue;
      }
      Object obj = null;

      DuelOption to = null;
      String val;
      if (op.contains("=")) {
        String[] split = op.split("=");
        op = split[0];
        val = split[1];
      } else {
        val = i + 1 < args.length ? args[i + 1] : null;
      }
      to = parseOp(op, val);
      switch (to) {
        case RATED:
          if (!Defaults.DUEL_ALLOW_RATED)
            throw new InvalidOptionException("&cRated formingDuels are not allowed!");
          break;
        default:
          break;
      }

      if (!to.needsValue) {
        ops.put(to, null);
        continue;
      }
      i++; /// another increment to get past the value
      switch (to) {
        case MONEY:
          Double money = null;
          try {
            money = Double.valueOf(val);
          } catch (Exception e) {
            throw new InvalidOptionException("&cmoney needs to be a number! Example: &6money=100");
          }
          if (!MoneyController.hasEconomy()) {
            if (challenger != null)
              MessageUtil.sendMessage(
                  challenger, "&cignoring duel option money as there is no economy!");
            Log.warn("[BA Error] ignoring duel option money as there is no economy!");
            continue;
          }
          obj = money;
          break;
        case ARENA:
          Arena a = BattleArena.getBAController().getArena(val);
          if (a == null) {
            throw new InvalidOptionException("&cCouldnt find the arena &6" + val);
          }
          if (params != null && !a.getArenaType().matches(params.getType())) {
            throw new InvalidOptionException("&cThe arena is used for a different type!");
          }
          obj = a;
        default:
          break;
      }
      ops.put(to, obj);
    }
    if (challenger != null && dop.challengedPlayers.isEmpty()) {
      throw new InvalidOptionException("&cYou need to challenge at least one player!");
    }
    return dop;
  }
  private static void movePlayer(
      ArenaPlayer player, ArenaPlayerTeleportEvent apte, MatchParams mp) {
    PlayerHolder src = apte.getSrcLocation().getPlayerHolder();
    PlayerHolder dest = apte.getDestLocation().getPlayerHolder();
    TeleportDirection td = apte.getDirection();
    if (Defaults.DEBUG_TRACE)
      Log.info(" ###########  " + player.getCurLocation() + "  -->  " + dest.getLocationType());
    if (Defaults.DEBUG_TRACE)
      Log.info(
          " ---- << -- " + player.getName() + "   src=" + src + "   dest=" + dest + "    td=" + td);

    switch (td) {
      case RESPAWN:
        break;
      case FIRSTIN:
        mp.getGameManager().onPreJoin(player, apte);
        dest.onPreJoin(player, apte);
      case IN:
        src.onPreLeave(player, apte);
        dest.onPreEnter(player, apte);
        break;
      case OUT:
        mp.getGameManager().onPreQuit(player, apte);
        src.onPreQuit(player, apte);
        dest.onPreJoin(player, apte);
        break;
      default:
        break;
    }
    dest.callEvent(apte);
    if (!TeleportController.teleport(player.getPlayer(), apte.getDestLocation().getLocation(), true)
        && player.isOnline()
        && !player.isDead()) {
      Log.err(
          "[BA Warning] couldn't teleport "
              + player.getName()
              + " srcLoc="
              + apte.getSrcLocation()
              + " destLoc="
              + apte.getDestLocation());
    }
    player.setCurLocation(apte.getDestLocation());
    switch (td) {
      case RESPAWN:
        break;
      case FIRSTIN:
        mp.getGameManager().onPostJoin(player, apte);
        dest.onPostJoin(player, apte);
      case IN:
        src.onPostLeave(player, apte);
        dest.onPostEnter(player, apte);
        break;
      case OUT:
        mp.getGameManager().onPostQuit(player, apte);
        src.onPostQuit(player, apte);
        dest.onPostJoin(player, apte);
        break;
      default:
        break;
    }
  }
Пример #9
0
 public static ArenaStat loadRecord(MatchParams mp, ArenaPlayer ap) {
   if (!enabled) return BLANK_STAT;
   return BTInterface.loadRecord(mp.getDBName(), ap);
 }
Пример #10
0
 public static ArenaStat loadRecord(MatchParams mp, ArenaTeam t) {
   if (!enabled || mp == null) return BLANK_STAT;
   return BTInterface.loadRecord(mp.getDBName(), t);
 }
Пример #11
0
 public int getMinTeams() {
   return mp.getMinTeams();
 }