Esempio n. 1
0
 public void animatedTeleport() {
   Task.Builder builder = MoseCraft.getPlugin().getGame().getScheduler().createTaskBuilder();
   builder.intervalTicks(20);
   builder.async();
   builder.name(POS1.getBlockX() + "," + POS1.getBlockY() + "," + POS1.getBlockZ());
   builder.execute(new TeleportTask()).submit(MoseCraft.getPlugin().getGame());
 }
  @Listener
  public void onStart(MinigameStartedEvent event) {
    if (event.getMinigame().equals(this)) {
      for (Player player : players()) {
        player.sendMessage(
            Text.of(
                TextColors.BLUE, "[UltimateGames]: ", TextColors.GREEN, "Deathmatch starting..."));
      }

      for (Player player : this.teamA) {
        player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
        player.setScoreboard(scoreboard);
        this.teamAScoreboardTeam.addMember(player.getTeamRepresentation());

        if (this.arena.getTeamALoadout() != null)
          UltimateGames.game
              .getCommandManager()
              .process(
                  Sponge.getServer().getConsole(),
                  "kit " + this.arena.getTeamALoadout() + " " + player.getName());

        if (player
            .getWorld()
            .getUniqueId()
            .equals(this.arena.getTeamASpawn().getLocation().getExtent().getUniqueId())) {
          player.setLocation(this.arena.getTeamASpawn().getLocation());
        } else {
          player.transferToWorld(
              this.arena.getTeamASpawn().getLocation().getExtent().getUniqueId(),
              this.arena.getTeamASpawn().getLocation().getPosition());
        }

        player.sendMessage(
            Text.of(TextColors.BLUE, "[UltimateGames]: ", TextColors.GOLD, "May the games begin!"));
      }

      for (Player player : this.teamB) {
        player.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
        player.setScoreboard(scoreboard);
        this.teamBScoreboardTeam.addMember(player.getTeamRepresentation());

        if (this.arena.getTeamBLoadout() != null)
          UltimateGames.game
              .getCommandManager()
              .process(
                  Sponge.getServer().getConsole(),
                  "kit " + this.arena.getTeamBLoadout() + " " + player.getName());

        if (player
            .getWorld()
            .getUniqueId()
            .equals(this.arena.getTeamBSpawn().getLocation().getExtent().getUniqueId())) {
          player.setLocation(this.arena.getTeamBSpawn().getLocation());
        } else {
          player.transferToWorld(
              this.arena.getTeamBSpawn().getLocation().getExtent().getUniqueId(),
              this.arena.getTeamBSpawn().getLocation().getPosition());
        }

        player.sendMessage(
            Text.of(TextColors.BLUE, "[UltimateGames]: ", TextColors.GOLD, "May the games begin!"));
      }

      Scheduler scheduler = UltimateGames.game.getScheduler();
      Task.Builder taskBuilder = scheduler.createTaskBuilder();

      taskBuilder
          .execute(
              () -> {
                try {
                  Ember.unregister(this.arena);
                } catch (Exception e) {
                  System.out.println(
                      "[UltimateGames]: Error when ending deathmatch in arena " + arena.getName());
                }
              })
          .delay(this.arena.getLength(), TimeUnit.MINUTES)
          .name("UltimateGames - End Deathmatch")
          .submit(
              UltimateGames.game
                  .getPluginManager()
                  .getPlugin("io.github.hsyyid.ultimategames")
                  .get()
                  .getInstance()
                  .get());
    }
  }