@Override
 protected Optional<FireworkEffect> buildContent(DataView container) throws InvalidDataException {
   if (container.contains(
       DataQueries.FIREWORK_SHAPE,
       DataQueries.FIREWORK_COLORS,
       DataQueries.FIREWORK_FADE_COLORS,
       DataQueries.FIREWORK_FLICKERS,
       DataQueries.FIREWORK_TRAILS)) {
     final String fireworkShapeId =
         DataUtil.getData(container, DataQueries.FIREWORK_SHAPE, String.class);
     final Optional<FireworkShape> shapeOptional =
         Sponge.getRegistry().getType(FireworkShape.class, fireworkShapeId);
     if (!shapeOptional.isPresent()) {
       throw new InvalidDataException(
           "Could not find the FireworkShape for the provided id: " + fireworkShapeId);
     }
     final FireworkShape shape = shapeOptional.get();
     final boolean trails =
         DataUtil.getData(container, DataQueries.FIREWORK_TRAILS, Boolean.class);
     final boolean flickers =
         DataUtil.getData(container, DataQueries.FIREWORK_FLICKERS, Boolean.class);
     final List<Color> colors =
         container.getSerializableList(DataQueries.FIREWORK_COLORS, Color.class).get();
     final List<Color> fadeColors =
         container.getSerializableList(DataQueries.FIREWORK_FADE_COLORS, Color.class).get();
     return Optional.of(
         FireworkEffect.builder()
             .colors(colors)
             .flicker(flickers)
             .fades(fadeColors)
             .trail(trails)
             .shape(shape)
             .build());
   }
   return Optional.empty();
 }
Exemplo n.º 2
0
  /**
   * 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);
  }
 static Builder builder() {
   return Sponge.getRegistry().createBuilder(Builder.class);
 }
Exemplo n.º 4
0
 @Override
 protected MapValue<K, V> getValueGetter() {
   return Sponge.getRegistry()
       .getValueFactory()
       .createMapValue((Key<MapValue<K, V>>) this.usedKey, this.getValue());
 }