@Listener
  public void onPlayerRespawn(RespawnPlayerEvent event) {
    Player player = event.getTargetEntity();

    if (this.teamA.contains(player)) {
      event.setToTransform(
          event.getToTransform().setLocation(this.arena.getTeamASpawn().getLocation()));

      Sponge.getScheduler()
          .createTaskBuilder()
          .execute(
              () -> {
                if (this.arena.getTeamALoadout() != null)
                  UltimateGames.game
                      .getCommandManager()
                      .process(
                          Sponge.getServer().getConsole(),
                          "kit " + this.arena.getTeamALoadout() + " " + player.getName());
              })
          .delayTicks(10)
          .name("UltimateGames - Give Player Loadout")
          .submit(
              UltimateGames.game
                  .getPluginManager()
                  .getPlugin("io.github.hsyyid.ultimategames")
                  .get()
                  .getInstance()
                  .get());
    } else if (this.teamB.contains(player)) {
      event.setToTransform(
          event.getToTransform().setLocation(this.arena.getTeamBSpawn().getLocation()));

      Sponge.getScheduler()
          .createTaskBuilder()
          .execute(
              () -> {
                if (this.arena.getTeamBLoadout() != null)
                  UltimateGames.game
                      .getCommandManager()
                      .process(
                          Sponge.getServer().getConsole(),
                          "kit " + this.arena.getTeamBLoadout() + " " + player.getName());
              })
          .delayTicks(10)
          .name("UltimateGames - Give Player Loadout")
          .submit(
              UltimateGames.game
                  .getPluginManager()
                  .getPlugin("io.github.hsyyid.ultimategames")
                  .get()
                  .getInstance()
                  .get());
    }
  }
Beispiel #2
0
  @Listener(order = Order.POST)
  public void onAffectSlotEvent(AffectSlotEvent event, @Root Player player) {
    for (SlotTransaction transaction : event.getTransactions()) {
      ItemStack itemStack = transaction.getFinal().createStack();

      BigDecimal amount = WalletDrop.getValue(itemStack);

      if (amount.compareTo(BigDecimal.ZERO) == 0) {
        continue;
      }

      WorldSettings settings = WorldSettings.get(player.getWorld());

      if (player.gameMode().get().equals(GameModes.CREATIVE) && !settings.isCreativeModeAllowed()) {
        event.setCancelled(true);
        return;
      }

      if (settings.isUsePermissions()) {
        if (!player.hasPermission("walletdrop.enable")) {
          return;
        }
      }

      WalletPickupEvent moneyPickupEvent =
          new WalletPickupEvent(itemStack, amount, Cause.of(NamedCause.source(player)));

      if (!Sponge.getEventManager().post(moneyPickupEvent)) {
        Sponge.getScheduler()
            .createTaskBuilder()
            .delayTicks(2)
            .execute(
                c -> {
                  player.getInventory().query(itemStack).clear();
                })
            .submit(Main.getPlugin());

        WalletDrop.depositOrWithdraw(player, moneyPickupEvent.getAmount());

        WalletDrop.sendPickupMessage(player, amount);
      }
    }
  }
  /**
   * Creates a new DeathmatchMinigame instance.
   *
   * @param arena the arena to be played.
   * @param teamA the players on team A.
   * @param teamB the players on team B.
   * @throws Exception If the match failed to register.
   */
  public DeathmatchMinigame(UltimateGamesArena arena, List<Player> teamA, List<Player> teamB)
      throws Exception {
    this.teamA = teamA;
    this.teamB = teamB;
    this.arena = arena;

    Objective.Builder objectiveBuilder =
        Sponge.getRegistry().createBuilder(Objective.Builder.class);

    Text title = Text.of(TextColors.AQUA, "UltimateGames");
    final Objective mainObjective =
        objectiveBuilder.name("<Arena>").criterion(Criteria.DUMMY).displayName(title).build();

    Score teamAName =
        mainObjective.getOrCreateScore(Text.of(TextColors.BLUE, TextStyles.BOLD, "Team A"));
    teamAName.setScore(4);

    this.teamAScoreboardTeam =
        Team.builder()
            .name("TeamA")
            .displayName(Text.of("TeamA"))
            .prefix(Text.of(TextColors.BLUE))
            .nameTagVisibility(Visibilities.ALL)
            .canSeeFriendlyInvisibles(true)
            .allowFriendlyFire(false)
            .members(Sets.newHashSet(Text.of(TextColors.BLUE, TextStyles.BOLD, "Team A")))
            .build();

    Score teamAScore = mainObjective.getOrCreateScore(Text.of(TextColors.BLUE, "Kills: "));
    teamAScore.setScore(3);

    Team teamAScoreTeam =
        Team.builder()
            .name("TeamAScore")
            .displayName(Text.of("TeamAScore"))
            .members(Sets.newHashSet(Text.of(TextColors.BLUE, "Kills: ")))
            .build();

    Score teamBName =
        mainObjective.getOrCreateScore(Text.of(TextColors.RED, TextStyles.BOLD, "Team B"));
    teamBName.setScore(2);

    this.teamBScoreboardTeam =
        Team.builder()
            .name("TeamB")
            .displayName(Text.of("TeamB"))
            .prefix(Text.of(TextColors.RED))
            .nameTagVisibility(Visibilities.ALL)
            .canSeeFriendlyInvisibles(true)
            .allowFriendlyFire(false)
            .members(Sets.newHashSet(Text.of(TextColors.RED, TextStyles.BOLD, "Team B")))
            .build();

    Score teamBScore = mainObjective.getOrCreateScore(Text.of(TextColors.RED, "Kills: "));
    teamBScore.setScore(1);

    Team teamBScoreTeam =
        Team.builder()
            .name("TeamBScore")
            .displayName(Text.of("TeamBScore"))
            .members(Sets.newHashSet(Text.of(TextColors.RED, "Kills: ")))
            .build();

    List<Objective> objectives = new ArrayList<Objective>();
    objectives.add(mainObjective);

    scoreboard = Scoreboard.builder().objectives(objectives).build();
    scoreboard.registerTeam(this.teamAScoreboardTeam);
    scoreboard.registerTeam(teamAScoreTeam);
    scoreboard.registerTeam(this.teamBScoreboardTeam);
    scoreboard.registerTeam(teamBScoreTeam);
    scoreboard.updateDisplaySlot(mainObjective, DisplaySlots.SIDEBAR);

    Scheduler scheduler = Sponge.getScheduler();

    scheduler
        .createTaskBuilder()
        .execute(
            () -> {
              try {
                teamAScoreTeam.setSuffix(Text.of(TextColors.GRAY, teamAPoints));
                teamBScoreTeam.setSuffix(Text.of(TextColors.GRAY, teamBPoints));
              } catch (Exception e) {
                e.printStackTrace();
              }
            })
        .interval(1, TimeUnit.MILLISECONDS)
        .name("UltimateGames - Update scoreboard")
        .submit(
            Sponge.getPluginManager()
                .getPlugin("io.github.hsyyid.ultimategames")
                .get()
                .getInstance()
                .get());

    Ember.register(arena, this);
  }