private boolean checkWager(Duel d) {
   Double wager = (Double) d.getDuelOptionValue(DuelOption.MONEY);
   if (wager == null) return true;
   HashSet<ArenaPlayer> players = new HashSet<ArenaPlayer>(d.getChallengedPlayers());
   players.addAll(d.getChallengerTeam().getPlayers());
   for (ArenaPlayer ap : players) {
     if (MoneyController.balance(ap.getName()) < wager) {
       MessageUtil.sendMessage(ap, "&4[Duel] &cYou don't have enough money to accept the wager!");
       cancelFormingDuel(
           d, "&4[Duel]&6" + ap.getDisplayName() + " didn't have enough money for the wager");
       return false;
     }
   }
   for (ArenaPlayer ap : players) {
     MessageUtil.sendMessage(
         ap,
         "&4[Duel] &6"
             + wager
             + " "
             + Defaults.MONEY_STR
             + "&e has been subtracted from your account");
     MoneyController.subtract(ap.getName(), wager);
   }
   d.setTotalMoney((wager) * players.size());
   return true;
 }
Esempio n. 2
0
 @Override
 public void broadcast(String msg) {
   if (msg == null || msg.isEmpty()) return;
   try {
     MessageUtil.broadcastMessage(MessageUtil.colorChat(msg));
   } catch (Throwable e) {
     /// getting this a lot of concurrency and null pointer errors from bukkit when stress
     // testing...
     /// so ignore errors from bukkit
     if (!Defaults.DEBUG_STRESS) {
       Log.printStackTrace(e);
     }
   }
 }
  @ArenaEventHandler
  public void matchComplete(MatchCompletedEvent event) {
    Match match = event.getMatch();
    Matchup matchup = matchups.remove(match);
    if (matchup == null) return;
    Duel d = ongoingDuels.remove(matchup);
    if (d == null) return;
    MatchResult mr = match.getResult();

    Double money = (Double) d.getDuelOptionValue(DuelOption.MONEY);
    if (money != null) {
      if (mr.hasVictor()) {
        Collection<ArenaTeam> winningTeams = mr.getVictors();
        int winningSize = 0;
        for (ArenaTeam winTeam : winningTeams) {
          winningSize += winTeam.size();
        }
        final double split = d.getTotalMoney() / winningSize;
        for (ArenaTeam winTeam : winningTeams) {
          for (ArenaPlayer ap : winTeam.getPlayers()) {
            MessageUtil.sendMessage(
                ap,
                "&4[Duel] &eYou have won &6"
                    + split
                    + " "
                    + Defaults.MONEY_STR
                    + "&e for your victory!");
            MoneyController.add(ap.getName(), split);
          }
        }
      } else {
        refundMoney(money, mr.getDrawers());
      }
    }
  }
 @MCCommand(
     cmds = {"select", "sel"},
     admin = true)
 public boolean arenaSelect(CommandSender sender, Arena arena) {
   aac.setCurrentArena(sender, arena);
   return MessageUtil.sendMessage(sender, "&2You have selected arena &6" + arena.getName());
 }
Esempio n. 5
0
  public static void signClick(PlayerInteractEvent event, PlayerHolder am) {
    /// Get our sign
    final Sign sign = (Sign) event.getClickedBlock().getState();
    /// Check to see if sign has correct format (is more efficient than doing string manipulation )
    if (!sign.getLine(0).matches("^.[0-9a-fA-F]\\*.*$") && !sign.getLine(0).matches("^\\[.*$")) {
      return;
    }

    final Action action = event.getAction();
    if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) {
      return;
    }
    if (action == Action.LEFT_CLICK_BLOCK) { // / Dont let them break the sign
      event.setCancelled(true);
    }

    final ArenaClass ac =
        ArenaClassController.getClass(
            MessageUtil.decolorChat(sign.getLine(0))
                .replace('*', ' ')
                .replace('[', ' ')
                .replace(']', ' ')
                .trim());
    ArenaClassController.changeClass(event.getPlayer(), am, ac);
  }
Esempio n. 6
0
 public AllKills(Match match) {
   super(match);
   kills = new ArenaObjective("allkills", "All Kills", 5);
   kills.setDisplayName(MessageUtil.colorChat("&4All Kills"));
   boolean isRated = match.getParams().isRated();
   boolean soloRating = !match.getParams().isTeamRating();
   sc = (isRated && soloRating) ? new StatController(match.getParams()) : null;
 }
 public void cancelFormingDuel(Duel d, String msg) {
   formingDuels.remove(d);
   Collection<ArenaPlayer> players = d.getChallengedPlayers();
   for (ArenaPlayer p : players) {
     MessageUtil.sendMessage(p, msg);
   }
   ArenaTeam t = d.getChallengerTeam();
   t.sendMessage(msg);
 }
Esempio n. 8
0
  @Override
  public void startEvent() {
    super.startEvent();
    Server server = Bukkit.getServer();

    int osize = teams.size();
    nrounds = getNRounds(osize);
    int nteams = (int) Math.pow(2, nrounds);
    server.broadcastMessage(
        Log.colorChat(
            eventParams.getPrefix()
                + "&e The "
                + eventParams.toPrettyString()
                + oParms.getName()
                + " tournament is starting!"));

    preliminary_round = teams.size() != nteams;
    if (preliminary_round) nrounds++;

    TreeMap<Double, Team> sortTeams = new TreeMap<Double, Team>(Collections.reverseOrder());
    BTInterface bti = new BTInterface(eventParams);
    //		System.out.println("startEvent:: bti=" + bti);
    for (Team t : teams) {
      Double elo = Defaults.DEFAULT_ELO;
      if (bti.isValid()) {
        elo = (double) bti.getElo(t);
      }
      while (sortTeams.containsKey(elo)) {
        elo += 0.0001;
      }
      sortTeams.put(elo, t);
    }
    competingTeams.addAll(teams);
    teams.clear();
    aliveTeams.clear();
    ArrayList<Team> ts = new ArrayList<Team>(sortTeams.values());
    for (Team t : ts) {
      teams.add(t);
      aliveTeams.add(t);
    }
    server.broadcastMessage(
        Log.colorChat(
            eventParams.getPrefix()
                + "&6 "
                + teams.size()
                + " &e"
                + MessageUtil.getTeamsOrPlayers(teams.size())
                + " will compete in a &6"
                + nrounds
                + "&e round tournament"));
    if (preliminary_round) {
      makePreliminaryRound();
    } else {
      makeNextRound();
    }
    startRound();
  }
 private void refundMoney(Double money, Collection<ArenaTeam> teams) {
   for (ArenaTeam t : teams) {
     for (ArenaPlayer ap : t.getPlayers()) {
       MessageUtil.sendMessage(
           ap, "&4[Duel] &6" + money + " " + Defaults.MONEY_STR + "&e has been refunded");
       MoneyController.add(ap.getName(), money);
     }
   }
 }
Esempio n. 10
0
 private void handlePreprocess(PlayerCommandPreprocessEvent event) {
   if (CommandUtil.shouldCancel(event, disabledCommands)) {
     event.setCancelled(true);
     event
         .getPlayer()
         .sendMessage(ChatColor.RED + "You cannot use that command when you are in a match");
     if (PermissionsUtil.isAdmin(event.getPlayer())) {
       MessageUtil.sendMessage(
           event.getPlayer(), "&cYou can set &6/bad allowAdminCommands true: &c to change");
     }
   }
 }
  @MCCommand(
      cmds = {"as", "addspawn"},
      selection = true,
      inGame = true,
      admin = true,
      min = 2,
      usage =
          "/aa addspawn <mob/item/block/spawnGroup> [buffs or effects] [number] [fs=first spawn time] [rt=respawn time] [trigger=<trigger type>]")
  public boolean arenaAddSpawn(Player sender, String[] args) {
    Long number = -1L;
    try {
      number = Long.parseLong(args[args.length - 1].toString());
    } catch (Exception e) {
      return MessageUtil.sendMessage(
          sender, "&cYou need to specify an index as the final value. &61-10000");
    }
    if (number == -1) {
      number = 1L;
    }
    if (number <= 0 || number > 10000) {
      return MessageUtil.sendMessage(
          sender, "&cYou need to specify an index within the range &61-10000");
    }

    Arena a = aac.getArena(sender);
    SpawnInstance spawn = parseSpawn(Arrays.copyOfRange(args, 0, args.length - 1));
    if (spawn == null) {
      return MessageUtil.sendMessage(sender, "Couldnt recognize spawn " + args[1]);
    }
    Location l = sender.getLocation();
    spawn.setLocation(l);
    TimedSpawn ts = new TimedSpawn(0, 30, 0, spawn);

    a.addTimedSpawn(number, ts);
    ac.updateArena(a);
    BattleArena.saveArenas();
    return MessageUtil.sendMessage(
        sender, "&6" + a.getName() + "&e now has spawn &6" + spawn + "&2  index=&4" + number);
  }
 @MCCommand(
     cmds = {"ds", "deletespawn"},
     selection = true,
     admin = true,
     usage = "/aa deleteSpawn <index>")
 public boolean arenaDeleteSpawn(CommandSender sender, Integer number) {
   if (number <= 0 || number > 10000) {
     return MessageUtil.sendMessage(
         sender, "&cYou need to specify an index within the range &61-10000");
   }
   Arena a = aac.getArena(sender);
   TimedSpawn ts = a.deleteTimedSpawn(new Long(number));
   if (ts != null) {
     ac.updateArena(a);
     BattleArena.saveArenas();
     return MessageUtil.sendMessage(
         sender,
         "&6" + a.getName() + "&e has deleted index=&4" + number + "&e that had spawn=" + ts);
   } else {
     return MessageUtil.sendMessage(sender, "&cThere was no spawn at that index");
   }
 }
Esempio n. 13
0
  private void announceRound() {
    Round tr = rounds.get(round);

    String strround =
        preliminary_round && round == 0 ? "PreliminaryRound" : ("Round " + (round + 1));
    if (round + 1 == nrounds) {
      strround = "Final Round";
    }
    if (preliminary_round) {
      preliminary_round = false;
      int nprelims = tr.getMatchups().size() * eventParams.getMinTeams();
      for (int i = 0; i < aliveTeams.size() - nprelims; i++) {
        Team t = aliveTeams.get(i);
        t.sendMessage("&4[" + strround + "]&e You have a &5bye&e this round");
      }
    }
    BTInterface bti = new BTInterface(eventParams);
    final String prefix = eventParams.getPrefix();
    if (tr.getMatchups().size() <= 8) {
      for (Matchup m : tr.getMatchups()) {
        List<String> names = new ArrayList<String>();
        for (Team t : m.getTeams()) {
          names.add("&8" + t.getDisplayName() + "&6[" + bti.getElo(t) + "]");
        }
        String msg = "&e" + strround + ": " + StringUtils.join(names, " vs ");
        if (ChatPaginator.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH > msg.length() + prefix.length()) {
          broadcastAlive(prefix + " " + msg);
        } else {
          broadcastAlive(msg);
        }
      }
    } else {
      broadcastAlive(
          prefix
              + "&e Round "
              + strround
              + " has "
              + tr.getMatchups().size()
              + " "
              + MessageUtil.teamsOrPlayers(eventParams.getMinTeamSize())
              + " competing. &6/tourney status:&e for updates");
    }
    if (round != nrounds)
      broadcast(
          prefix + "&e " + strround + " will start in &4" + timeBetweenRounds + " &eseconds!");
    else
      broadcast(
          prefix + "&e The " + strround + " will start in &4" + timeBetweenRounds + " &eseconds!");
  }
Esempio n. 14
0
  private void readyClick(PlayerInteractEvent event) {
    if (!Defaults.ENABLE_PLAYER_READY_BLOCK) return;
    final ArenaPlayer ap = BattleArena.toArenaPlayer(event.getPlayer());
    if (!isInWaitRoomState()) {
      return;
    }
    final Action action = event.getAction();
    if (action == Action.LEFT_CLICK_BLOCK) { // / Dont let them break the block
      event.setCancelled(true);
    }

    if (ap.isReady()) return;
    ap.setReady(true);
    MessageUtil.sendMessage(ap, "&2You ready yourself for the arena");
    callEvent(new ArenaPlayerReadyEvent(ap, true));
  }
Esempio n. 15
0
 @Override
 public void addTeam(Team t) {
   super.addTeam(t);
   int size = teams.size();
   int nrounds = getNRounds(size);
   int idealteam = (int) Math.pow(2, nrounds);
   if (size > 2 && size % idealteam == 0) {
     Bukkit.broadcastMessage(
         Log.colorChat(
             eventParams.getPrefix()
                 + "&6"
                 + size
                 + " "
                 + MessageUtil.getTeamsOrPlayers(teams.size())
                 + "&e have joined, Current tournament will have &6"
                 + nrounds
                 + "&e rounds"));
   }
 }
Esempio n. 16
0
 private void announceTourneySize() {
   int size = 0;
   for (Team t : teams) {
     if (t.size() > 0) size++;
   }
   int nrounds = getNRounds(size);
   int idealteam = (int) Math.pow(eventParams.getMinTeams(), nrounds);
   if (nrounds > 1 && size % idealteam == 0) {
     Bukkit.broadcastMessage(
         Log.colorChat(
             eventParams.getPrefix()
                 + "&6"
                 + size
                 + " "
                 + MessageUtil.getTeamsOrPlayers(teams.size())
                 + "&e have joined, Current tournament will have &6"
                 + nrounds
                 + "&e rounds"));
   }
 }
Esempio n. 17
0
 @Override
 public void openEvent(EventParams mp) throws NeverWouldJoinException {
   aliveTeams.clear();
   competingTeams.clear();
   rounds.clear();
   round = -1;
   nrounds = -1;
   timeBetweenRounds = oParms.getTimeBetweenRounds();
   ChatColor color = MessageUtil.getFirstColor(mp.getPrefix());
   mp.setTransitionOptions(mp.getTransitionOptions());
   mp.setPrefix(color + "[" + mp.getName() + " " + oParms.getName() + "]");
   mp.setCommand(oParms.getCommand());
   mp.setName(mp.getName() + " " + oParms.getName());
   mp.setTimeBetweenRounds(oParms.getTimeBetweenRounds());
   mp.setSecondsTillMatch(oParms.getSecondsTillMatch());
   mp.setSecondsToLoot(oParms.getSecondsToLoot());
   TimeUtil.testClock();
   super.openEvent(mp);
   EventParams copy = new EventParams(mp);
   copy.setMaxTeams(CompetitionSize.MAX);
   this.setTeamJoinHandler(TeamJoinFactory.createTeamJoinHandler(copy, this));
 }
Esempio n. 18
0
  @ArenaEventHandler(
      suppressCastWarnings = true,
      bukkitPriority = org.bukkit.event.EventPriority.MONITOR)
  public void onPlayerDeath(PlayerDeathEvent event, final ArenaPlayer target) {
    if (Defaults.DEBUG_TRACE)
      MessageUtil.sendMessage(target, " -onPlayerDeath  t=" + target.getTeam());
    if (state == MatchState.ONCANCEL || state == MatchState.ONCOMPLETE) {
      return;
    }
    final ArenaTeam t = getTeam(target);
    if (t == null) return;

    ArenaPlayerDeathEvent apde = new ArenaPlayerDeathEvent(target, t);
    apde.setPlayerDeathEvent(event);
    callEvent(apde);
    ArenaPlayer killer = DmgDeathUtil.getPlayerCause(event);
    if (killer != null) {
      ArenaTeam killT = getTeam(killer);
      if (killT != null) { // / they must be in the same match for this to count
        killT.addKill(killer);
        callEvent(new ArenaPlayerKillEvent(killer, killT, target));
      }
    }
  }
Esempio n. 19
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;
  }
Esempio n. 20
0
 public String getOtherChallengedString(ArenaPlayer ap) {
   List<ArenaPlayer> players = new ArrayList<ArenaPlayer>(challengedPlayers);
   players.remove(ap);
   return MessageUtil.joinPlayers(players, ", ");
 }
Esempio n. 21
0
 public String getChallengedTeamString() {
   return MessageUtil.joinPlayers(getChallengedPlayers(), ", ");
 }
Esempio n. 22
0
 public static boolean sendMessage(CommandSender sender, String msg) {
   return MessageUtil.sendMessage(sender, msg);
 }
Esempio n. 23
0
 public static boolean sendMessage(ArenaPlayer player, String msg) {
   return MessageUtil.sendMessage(player, msg);
 }
Esempio n. 24
0
  @ArenaEventHandler(priority = EventPriority.HIGH)
  public void onPlayerRespawn(PlayerRespawnEvent event, final ArenaPlayer p) {
    if (Defaults.DEBUG_TRACE) MessageUtil.sendMessage(p, " -onPlayerRespawn  t=" + p.getTeam());

    if (isWon()) {
      return;
    }
    final TransitionOptions mo = tops.getOptions(MatchState.ONDEATH);

    if (mo == null) return;

    if (respawns) {
      final boolean randomRespawn = mo.randomRespawn();
      /// Lets cancel our death respawn timer
      Integer timer = deathTimer.get(p.getName());
      if (timer != null) {
        Bukkit.getScheduler().cancelTask(timer);
      }
      final Location loc;
      final ArenaTeam t = getTeam(p);
      if (mo.hasAnyOption(
          TransitionOption.TELEPORTLOBBY,
          TransitionOption.TELEPORTMAINLOBBY,
          TransitionOption.TELEPORTWAITROOM,
          TransitionOption.TELEPORTMAINWAITROOM)) {
        final int index = t.getIndex();
        if (mo.hasOption(TransitionOption.TELEPORTLOBBY)) {
          loc = RoomController.getLobbySpawn(index, getParams().getType(), randomRespawn);
        } else if (mo.hasOption(TransitionOption.TELEPORTMAINLOBBY)) {
          loc =
              RoomController.getLobbySpawn(
                  Defaults.MAIN_SPAWN, getParams().getType(), randomRespawn);
        } else if (mo.hasOption(TransitionOption.TELEPORTMAINWAITROOM)) {
          loc = this.getWaitRoomSpawn(Defaults.MAIN_SPAWN, randomRespawn);
        } else {
          loc = this.getWaitRoomSpawn(index, randomRespawn);
        }
        /// Should we respawn the player to the team spawn after a certain amount of time
        if (mo.hasOption(TransitionOption.RESPAWNTIME)) {
          int id =
              Bukkit.getScheduler()
                  .scheduleSyncDelayedTask(
                      BattleArena.getSelf(),
                      new Runnable() {
                        @Override
                        public void run() {
                          Integer id = respawnTimer.remove(p.getName());
                          Bukkit.getScheduler().cancelTask(id);
                          Location loc =
                              getTeamSpawn(
                                  index,
                                  tops.hasOptionAt(
                                      MatchState.ONSPAWN, TransitionOption.RANDOMRESPAWN));
                          TeleportController.teleport(p.getPlayer(), loc);
                        }
                      },
                      mo.getRespawnTime() * 20);
          respawnTimer.put(p.getName(), id);
        }
      } else {
        loc = getTeamSpawn(getTeam(p), randomRespawn);
      }

      event.setRespawnLocation(loc);
      /// For some reason, the player from onPlayerRespawn Event isnt the one in the main thread, so
      // we need to
      /// resync before doing any effects
      final Match am = this;
      Bukkit.getScheduler()
          .scheduleSyncDelayedTask(
              BattleArena.getSelf(),
              new Runnable() {
                public void run() {
                  ArenaTeam t = getTeam(p);
                  PerformTransition.transition(am, MatchState.ONDEATH, p, t, false);
                  PerformTransition.transition(am, MatchState.ONSPAWN, p, t, false);
                  if (respawnsWithClass) {
                    ArenaClass ac = null;
                    if (p.getPreferredClass() != null) {
                      ac = p.getPreferredClass();
                    } else if (p.getCurrentClass() != null) {
                      ac = p.getCurrentClass();
                    }
                    if (ac != null) {
                      ArenaClassController.giveClass(p, ac);
                    }
                  }
                  if (keepsInventory) {
                    psc.restoreMatchItems(p);
                  }
                  if (woolTeams) {
                    TeamUtil.setTeamHead(t.getIndex(), p);
                  }
                }
              });
    } else { /// This player is now out of the system now that we have given the ondeath effects
      Location l =
          tops.hasOptionAt(MatchState.ONLEAVE, TransitionOption.TELEPORTTO)
              ? tops.getOptions(MatchState.ONLEAVE).getTeleportToLoc()
              : oldlocs.get(p.getName());
      if (l != null) event.setRespawnLocation(l);
    }
  }
Esempio n. 25
0
 public static boolean sendMultilineMessage(CommandSender p, String message) {
   return MessageUtil.sendMultilineMessage(p, message);
 }