/** * 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); }
@Listener public void onSendCommandEvent(SendCommandEvent event, @First CommandSource src) { String command = event.getCommand(); if (!command.equalsIgnoreCase("say")) { return; } if (Sponge.getPluginManager().isLoaded("simplechat")) { return; } String message = event.getArguments(); if (message == null || message.equals("")) { return; } MutableMessageChannel channel = MessageChannel.TO_ALL.asMutable(); if (message.startsWith("@")) { channel = MessageChannel.TO_NONE.asMutable(); String selector = message.substring(0, message.indexOf(" ")); for (Entity entity : Selector.parse(selector).resolve(src)) { if (entity instanceof Player) { channel.addMember((MessageReceiver) entity); } } if (channel.getMembers().size() == 0) { src.sendMessage(Text.of(TextColors.RED, "Selector returned no players")); return; } channel.addMember(Sponge.getServer().getConsole()); message = message.replace(selector, ""); } Text text = TextSerializers.FORMATTING_CODE.deserialize(message); if (src instanceof Player) { Player player = (Player) src; Optional<PlayerTag> optionalPlayerTag = PlayerTag.get(player); if (optionalPlayerTag.isPresent()) { text = Text.join(optionalPlayerTag.get().getTag(), Text.of(" "), text); } else { text = Text.join(PlayerTag.getDefault(player), Text.of(" "), text); } } else { Optional<SingleTag> optionalTag = SingleTag.get("simpletags", "console"); if (optionalTag.isPresent()) { text = Text.join(optionalTag.get().getTag(), Text.of(" "), text); } } channel.send(text); event.setCancelled(true); }