public void start() {
    game.setState(GameState.DEATHMATCH);

    List<Location> spawns = game.getCurrentArena().getDeathmatchSpawns();
    int i = 0;
    for (User user : game.getUsers()) {
      if (i >= spawns.size()) i = 0;
      user.getPlayer().teleport(spawns.get(i));
      i++;
    }

    Location suloc = spawns.get(0);
    for (SpectatorUser su : game.getSpecators()) {
      su.getPlayer().teleport(suloc);
      Vector v = new Vector(0, 2, 0);
      v.multiply(1.25);
      su.getPlayer().getLocation().setDirection(v);
    }

    task =
        Bukkit.getScheduler()
            .runTaskTimer(
                SurvivalGames.instance,
                new Runnable() {
                  public void run() {
                    if (time == 60) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout-warning"));
                    }

                    if (time % 60 == 0 && time != 0) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout")
                              .replace("%0%", Util.getFormatedTime(time)));
                    } else if (time % 10 == 0 && time < 60 && time > 10) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout")
                              .replace("%0%", Util.getFormatedTime(time)));
                    } else if (time <= 10 && time > 0) {
                      game.sendMessage(
                          MessageHandler.getMessage("game-deathmatch-timeout")
                              .replace("%0%", Util.getFormatedTime(time)));
                    } else if (time == 0) {

                      List<User> users = game.getUsers();
                      Collections.shuffle(users);

                      if (users.size() > 0) {
                        users
                            .get(0)
                            .getPlayer()
                            .addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 10000, 3));
                      }
                    }

                    game.updateBossBarMessage();
                    game.updateScoreboard();
                    time--;
                  }
                },
                0L,
                20L);
  }
Ejemplo n.º 2
0
 public void sendToSpectators(List<SpectatorUser> users) {
   for (final SpectatorUser su : users) {
     send(su.getPlayer());
   }
 }