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;
 }
 @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());
 }
  @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());
      }
    }
  }
 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);
     }
   }
 }
 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);
 }
 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 = {"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");
   }
 }
  @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);
  }
  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));
  }
  @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));
      }
    }
  }
Exemple #11
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;
  }
  @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);
    }
  }
 public static boolean sendMessage(ArenaPlayer player, String msg) {
   return MessageUtil.sendMessage(player, msg);
 }
 public static boolean sendMessage(CommandSender sender, String msg) {
   return MessageUtil.sendMessage(sender, msg);
 }
 public static boolean sendMessage(CommandSender p, String message) {
   return MessageUtil.sendMessage(p, message);
 }