private static boolean addWorldGuardRegion(
      CommandSender sender, Arena arena, BattleArenaController ac, String value) {
    if (!checkWorldGuard(sender)) {
      return false;
    }
    Player p = (Player) sender;
    WorldEditPlugin wep = WorldEditUtil.getWorldEditPlugin();
    Selection sel = wep.getSelection(p);
    if (sel == null) {
      sendMessage(sender, "&cYou need to select a region to use this command.");
      return false;
    }

    String region = arena.getRegion();
    World w = sel.getWorld();
    try {
      String id = makeRegionName(arena);
      if (region != null) {
        WorldGuardInterface.updateProtectedRegion(p, id);
        sendMessage(sender, "&2Region updated! ");
      } else {
        WorldGuardInterface.createProtectedRegion(p, id);
        sendMessage(sender, "&2Region added! ");
      }
      arena.addRegion(w.getName(), id);
      WorldGuardInterface.saveSchematic(p, id);
    } catch (Exception e) {
      sendMessage(sender, "&cAdding WorldGuard region failed!");
      sendMessage(sender, "&c" + e.getMessage());
      e.printStackTrace();
    }
    return true;
  }
 @MCCommand(
     cmds = {"hidespawns"},
     admin = true,
     selection = true,
     usage = "hidespawns")
 public boolean arenaHideSpawns(Player sender) {
   Arena arena = aac.getArena(sender);
   ArenaDebugger ad = ArenaDebugger.getDebugger(arena);
   ad.hideSpawns(sender);
   ArenaDebugger.removeDebugger(ad);
   return sendMessage(sender, ChatColor.YELLOW + "You are hiding spawns for &6" + arena.getName());
 }
  @MCCommand(
      cmds = {"showspawns"},
      admin = true,
      selection = true,
      usage = "showspawns")
  public boolean arenaShowSpawns(Player sender) {
    Arena arena = aac.getArena(sender);

    ArenaDebugger ad = ArenaDebugger.getDebugger(arena);
    ad.hideSpawns(sender);
    ad.showSpawns(sender);
    return sendMessage(sender, ChatColor.GREEN + "You are showing spawns for &6" + arena.getName());
  }
 @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());
 }
  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);
  }
示例#6
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;
 }
 @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 static boolean changeTeamSize(
     CommandSender sender, Arena arena, BattleArenaController ac, String value) {
   try {
     final MinMax mm = MinMax.valueOf(value);
     ac.removeArena(arena);
     arena.getParameters().setTeamSizes(mm);
     ac.addArena(arena);
     return sendMessage(sender, "&2Altered arena team size to &6" + value);
   } catch (Exception e) {
     sendMessage(sender, "size " + value + " not found");
     return false;
   }
 }
 private static boolean changeType(
     CommandSender sender, Arena arena, BattleArenaController ac, String value) {
   ArenaType t = ArenaType.fromString(value);
   if (t == null) {
     sendMessage(
         sender, "&ctype &6" + value + "&c not found. valid types=&6" + ArenaType.getValidList());
     return false;
   }
   ac.removeArena(arena);
   arena.getParameters().setType(t);
   ac.addArena(arena);
   sendMessage(sender, "&2Altered arena type to &6" + value);
   return true;
 }
  private static boolean changeSpawn(
      CommandSender sender,
      Arena arena,
      BattleArenaController ac,
      String changetype,
      String value,
      String[] otherOptions) {
    if (!BAExecutor.checkPlayer(sender)) return false;
    int locindex = verifySpawnLocation(sender, changetype);
    if (locindex == -1) return false;

    Player p = (Player) sender;
    Location loc = null;
    ac.removeArena(arena);
    loc = parseLocation(p, value);
    if (loc == null) {
      loc = p.getLocation();
    }
    arena.setSpawnLoc(locindex - 1, loc);
    ac.addArena(arena);
    sendMessage(
        sender, "&2team &6" + changetype + "&2 spawn set to location=&6" + Util.getLocString(loc));
    return true;
  }
示例#12
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;
  }
  public static boolean alterArena(CommandSender sender, Arena arena, String[] args) {
    if (args.length < 3) {
      showAlterHelp(sender);
      //			sendMessage(sender,ChatColor.YELLOW+ "      or /arena alter MainArena spawnitem
      // <itemname>:<matchEndTime between spawn> ");
      return false;
    }
    BattleArenaController ac = BattleArena.getBAC();
    String arenaName = arena.getName();
    String changetype = args[2];
    String value = null;
    if (args.length > 3) value = args[3];
    String[] otherOptions = args.length > 4 ? Arrays.copyOfRange(args, 4, args.length) : null;
    if (Defaults.DEBUG)
      System.out.println("alterArena " + arenaName + ":" + changetype + ":" + value);

    boolean success = false;
    ChangeType ct = ChangeType.fromName(changetype);
    if (ct == null) {
      sendMessage(
          sender,
          ChatColor.RED
              + "Option: &6"
              + changetype
              + "&c does not exist. \n&cValid options are &6"
              + ChangeType.getValidList());
      showAlterHelp(sender);
      return false;
    }
    switch (ct) {
      case TEAMSIZE:
        success = changeTeamSize(sender, arena, ac, value);
        break;
      case NTEAMS:
        success = changeNTeams(sender, arena, ac, value);
        break;
      case TYPE:
        success = changeType(sender, arena, ac, value);
        break;
      case SPAWNLOC:
        success = changeSpawn(sender, arena, ac, changetype, value, otherOptions);
        break;
      case VLOC:
        success = changeVisitorSpawn(sender, arena, ac, changetype, value, otherOptions);
        break;
      case WAITROOM:
        success = changeWaitroomSpawn(sender, arena, ac, changetype, value, otherOptions);
        break;
      case ADDREGION:
        success = addWorldGuardRegion(sender, arena, ac, value);
        break;
      default:
        sendMessage(
            sender,
            ChatColor.RED
                + "Option: &6"
                + changetype
                + "&c does not exist. \n&cValid options are &6"
                + ChangeType.getValidList());
        break;
    }
    if (success) BattleArena.saveArenas();
    return success;
  }
 public static String makeRegionName(Arena arena) {
   return "ba-" + arena.getName().toLowerCase();
 }