@EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockPlace(BlockPlaceEvent event) {
   if (event.getBlock().equals(place.getBlock())) {
     if (event.getBlock().getType().equals(Material.WOOL)) {
       if (((Wool) event.getBlock().getState().getData()).getColor().equals(color)) {
         if (Teams.getTeamByPlayer(event.getPlayer()).orNull() == team) {
           this.complete = true;
           if (this.show)
             ChatUtil.getGlobalChannel()
                 .sendLocalizedMessage(
                     new UnlocalizedChatMessage(
                         ChatColor.WHITE + "{0}",
                         new LocalizedChatMessage(
                             ChatConstant.UI_OBJECTIVE_PLACED,
                             team.getColor() + event.getPlayer().getName() + ChatColor.WHITE,
                             team.getCompleteName() + ChatColor.WHITE,
                             MiscUtil.convertDyeColorToChatColor(color)
                                 + name.toUpperCase().replaceAll("_", " ")
                                 + ChatColor.WHITE)));
           Fireworks.spawnFirework(
               event.getPlayer().getLocation(),
               event.getPlayer().getWorld(),
               MiscUtil.convertChatColorToColor(MiscUtil.convertDyeColorToChatColor(color)));
           ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer());
           Bukkit.getServer().getPluginManager().callEvent(compEvent);
           event.setCancelled(false);
         } else {
           event.setCancelled(true);
           if (this.show)
             ChatUtil.sendWarningMessage(
                 event.getPlayer(), "You may not complete the other team's objective.");
         }
       } else {
         event.setCancelled(true);
         if (this.show)
           ChatUtil.sendWarningMessage(
               event.getPlayer(),
               new LocalizedChatMessage(
                   ChatConstant.ERROR_BLOCK_PLACE,
                   MiscUtil.convertDyeColorToChatColor(color)
                       + color.name().toUpperCase().replaceAll("_", " ")
                       + " WOOL"
                       + ChatColor.RED));
       }
     } else {
       event.setCancelled(true);
       if (this.show)
         ChatUtil.sendWarningMessage(
             event.getPlayer(),
             new LocalizedChatMessage(
                 ChatConstant.ERROR_BLOCK_PLACE,
                 MiscUtil.convertDyeColorToChatColor(color)
                     + color.name().toUpperCase().replaceAll("_", " ")
                     + " WOOL"
                     + ChatColor.RED));
     }
   }
 }
 @Override
 public void run() {
   if (GameHandler.getGameHandler().getMatch().isRunning()) {
     if (timesBroadcasted < count) {
       if (MatchTimer.getTimeInSeconds() >= (timeAfter + (every * timesBroadcasted))) {
         if (type.equals(BroadcastType.TIP))
           ChatUtil.getGlobalChannel()
               .sendLocalizedMessage(
                   new UnlocalizedChatMessage(
                       ChatColor.GRAY
                           + ""
                           + ChatColor.BOLD
                           + "["
                           + ChatColor.BLUE
                           + ""
                           + ChatColor.BOLD
                           + "Tip"
                           + ChatColor.GRAY
                           + ""
                           + ChatColor.BOLD
                           + "] "
                           + ChatColor.AQUA
                           + ""
                           + ChatColor.ITALIC
                           + message));
         else if (type.equals(BroadcastType.ALERT))
           ChatUtil.getGlobalChannel()
               .sendLocalizedMessage(
                   new UnlocalizedChatMessage(
                       ChatColor.GRAY
                           + ""
                           + ChatColor.BOLD
                           + "["
                           + ChatColor.YELLOW
                           + ""
                           + ChatColor.BOLD
                           + "Alert"
                           + ChatColor.GRAY
                           + ""
                           + ChatColor.BOLD
                           + "] "
                           + ChatColor.GREEN
                           + ""
                           + ChatColor.ITALIC
                           + message));
         timesBroadcasted++;
       }
     }
   }
 }
 @Command(
     aliases = {"join", "play"},
     desc = "Join a team.",
     usage = "[team]")
 public static void join(final CommandContext cmd, CommandSender sender) throws CommandException {
   if (!(sender instanceof Player)) {
     throw new CommandException(
         ChatConstant.ERROR_CONSOLE_NO_USE.getMessage(ChatUtil.getLocale(sender)));
   }
   if (GameHandler.getGameHandler().getMatch().getState().equals(MatchState.ENDED)
       || GameHandler.getGameHandler().getMatch().getState().equals(MatchState.CYCLING)) {
     throw new CommandException(
         ChatUtil.getWarningMessage(
             new LocalizedChatMessage(ChatConstant.ERROR_MATCH_OVER)
                 .getMessage(((Player) sender).getLocale())));
   }
   Optional<TeamModule> originalTeam = Teams.getTeamByPlayer((Player) sender);
   if (cmd.argsLength() == 0 && originalTeam.isPresent() && !originalTeam.get().isObserver()) {
     throw new CommandException(
         ChatUtil.getWarningMessage(
             ChatColor.RED
                 + new LocalizedChatMessage(
                         ChatConstant.ERROR_ALREADY_JOINED,
                         Teams.getTeamByPlayer((Player) sender).get().getCompleteName()
                             + ChatColor.RED)
                     .getMessage(((Player) sender).getLocale())));
   }
   Optional<TeamModule> destinationTeam = Optional.absent();
   if (cmd.argsLength() > 0) {
     for (TeamModule teamModule :
         GameHandler.getGameHandler().getMatch().getModules().getModules(TeamModule.class)) {
       if (teamModule.getName().toLowerCase().startsWith(cmd.getJoinedStrings(0).toLowerCase())) {
         destinationTeam = Optional.of(teamModule);
         break;
       }
     }
     if (!destinationTeam.isPresent()) {
       throw new CommandException(
           ChatConstant.ERROR_NO_TEAM_MATCH.getMessage(ChatUtil.getLocale(sender)));
     }
     if (destinationTeam.get().contains(sender)) {
       throw new CommandException(
           ChatUtil.getWarningMessage(
               ChatColor.RED
                   + new LocalizedChatMessage(
                           ChatConstant.ERROR_ALREADY_JOINED,
                           destinationTeam.get().getCompleteName() + ChatColor.RED)
                       .getMessage(ChatUtil.getLocale(sender))));
     }
     destinationTeam.get().add((Player) sender, false);
   } else {
     destinationTeam = Teams.getTeamWithFewestPlayers(GameHandler.getGameHandler().getMatch());
     if (destinationTeam.isPresent()) {
       destinationTeam.get().add((Player) sender, false);
     } else {
       throw new CommandException(
           ChatConstant.ERROR_TEAMS_FULL.getMessage(ChatUtil.getLocale(sender)));
     }
   }
 }
Exemple #4
0
 @Command(
     aliases = {"cancel"},
     desc = "Cancels the current countdown.")
 @CommandPermissions("cardinal.cancel")
 public static void cancel(final CommandContext cmd, CommandSender sender) {
   GameHandler handler = GameHandler.getGameHandler();
   if (GameHandler.getGameHandler().getMatch().getState() == MatchState.CYCLING) BossBar.delete();
   if (GameHandler.getGameHandler().getMatch().getState() == MatchState.STARTING) BossBar.delete();
   if (!handler.getMatch().getModules().getModule(CycleTimerModule.class).isCancelled())
     handler.getMatch().getModules().getModule(CycleTimerModule.class).setCancelled(true);
   if (!handler.getMatch().getModules().getModule(StartTimer.class).isCancelled())
     handler.getMatch().getModules().getModule(StartTimer.class).setCancelled(true);
   if (handler.getMatch().getState().equals(MatchState.STARTING))
     handler.getMatch().setState(MatchState.WAITING);
   if (handler.getMatch().getState().equals(MatchState.CYCLING))
     handler.getMatch().setState(MatchState.ENDED);
   ChatUtil.getGlobalChannel()
       .sendLocalizedMessage(
           new UnlocalizedChatMessage(
               ChatColor.GREEN + "{0}",
               new LocalizedChatMessage(ChatConstant.GENERIC_COUNTDOWN_CANELLED)));
 }
 @Override
 public void run() {
   if (GameHandler.getGameHandler().getMatch().isRunning()) {
     double time = MatchTimer.getTimeInSeconds();
     double timeRemaining;
     if (TimeLimit.getMatchTimeLimit() == 0) {
       if (time >= nextTimeMessage) {
         ChatUtil.getGlobalChannel()
             .sendLocalizedMessage(
                 new UnlocalizedChatMessage(
                     ChatColor.AQUA + "{0}",
                     new LocalizedChatMessage(
                         ChatConstant.UI_TIME_ELAPSED,
                         new UnlocalizedChatMessage(
                             ChatColor.GREEN + Strings.formatTime(nextTimeMessage)))));
         nextTimeMessage += 300;
       }
       return;
     }
     timeRemaining = TimeLimit.getMatchTimeLimit() - time;
     if (GameHandler.getGameHandler().getMatch().getModules().getModule(MonumentModes.class)
         != null) {
       ModuleCollection<MonumentModes> modes =
           GameHandler.getGameHandler().getMatch().getModules().getModules(MonumentModes.class);
       HashMap<MonumentModes, Integer> modesWithTime = new HashMap<>();
       for (MonumentModes modeForTime : modes) {
         modesWithTime.put(modeForTime, modeForTime.getTimeAfter());
       }
       List<MonumentModes> sortedModes = MiscUtil.getSortedHashMapKeyset(modesWithTime);
       int timeBeforeMode = 1;
       int showBefore = 60;
       String name = MonumentModes.getModeName();
       for (MonumentModes mode : sortedModes) {
         if (!mode.hasRan()) {
           timeBeforeMode = mode.getTimeAfter() - (int) MatchTimer.getTimeInSeconds();
           name = mode.getName();
           showBefore = mode.getShowBefore();
         }
       }
       int timeLeft = TimeLimit.getMatchTimeLimit() - (int) MatchTimer.getTimeInSeconds();
       if (((timeBeforeMode > showBefore) || (name == null))
           && (TimeLimit.getMatchTimeLimit() > 0)) {
         int percent = (int) ((100F * timeLeft) / TimeLimit.getMatchTimeLimit());
         BossBar.sendGlobalBossBar(
             new UnlocalizedChatMessage(
                 ChatColor.AQUA + "{0} " + ChatUtil.getTimerColor(timeRemaining) + "{1}",
                 new LocalizedChatMessage(ChatConstant.UI_TIMER),
                 new UnlocalizedChatMessage(Strings.formatTime(timeRemaining + 1))),
             percent);
       }
       if (timeBeforeMode == showBefore || timeBeforeMode <= 0) {
         BossBar.delete();
       }
     } else if (TimeLimit.getMatchTimeLimit() > 0) {
       int timeLeft = ((TimeLimit.getMatchTimeLimit() - (int) MatchTimer.getTimeInSeconds()));
       int percent = (int) ((100F * timeLeft) / TimeLimit.getMatchTimeLimit());
       BossBar.sendGlobalBossBar(
           new UnlocalizedChatMessage(
               ChatColor.AQUA + "{0} " + ChatUtil.getTimerColor(timeRemaining) + "{1}",
               new LocalizedChatMessage(ChatConstant.UI_TIMER),
               new UnlocalizedChatMessage(Strings.formatTime(timeRemaining + 1))),
           percent);
     }
     if (nextTimeMessage >= timeRemaining) {
       if (nextTimeMessage <= 5) {
         ChatUtil.getGlobalChannel()
             .sendLocalizedMessage(
                 new UnlocalizedChatMessage(
                     ChatColor.AQUA
                         + "{0} "
                         + ChatColor.DARK_RED
                         + Strings.formatTime(nextTimeMessage),
                     new LocalizedChatMessage(ChatConstant.UI_TIMER)));
         nextTimeMessage--;
       } else if (nextTimeMessage <= 30) {
         ChatUtil.getGlobalChannel()
             .sendLocalizedMessage(
                 new UnlocalizedChatMessage(
                     ChatColor.AQUA
                         + "{0} "
                         + ChatColor.GOLD
                         + Strings.formatTime(nextTimeMessage),
                     new LocalizedChatMessage(ChatConstant.UI_TIMER)));
         nextTimeMessage -= 5;
       } else if (nextTimeMessage <= 60) {
         ChatUtil.getGlobalChannel()
             .sendLocalizedMessage(
                 new UnlocalizedChatMessage(
                     ChatColor.AQUA
                         + "{0} "
                         + ChatColor.YELLOW
                         + Strings.formatTime(nextTimeMessage),
                     new LocalizedChatMessage(ChatConstant.UI_TIMER)));
         nextTimeMessage -= 15;
       } else {
         ChatUtil.getGlobalChannel()
             .sendLocalizedMessage(
                 new UnlocalizedChatMessage(
                     ChatColor.AQUA
                         + "{0} "
                         + ChatColor.GREEN
                         + Strings.formatTime(nextTimeMessage),
                     new LocalizedChatMessage(ChatConstant.UI_TIMER)));
         if ((nextTimeMessage / 60) % 5 == 0 && nextTimeMessage != 300) {
           nextTimeMessage -= 300;
         } else if (nextTimeMessage % 60 == 0 && nextTimeMessage <= 300) {
           nextTimeMessage -= 60;
         } else {
           nextTimeMessage = (nextTimeMessage / 300) * 300;
         }
       }
     }
   }
 }