コード例 #1
0
 @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)));
     }
   }
 }
コード例 #2
0
ファイル: TeamChannel.java プロジェクト: Prodigy4532/Toucans
 @Override
 public void sendLocalizedMessage(ChatMessage message) {
   for (Player player : Bukkit.getOnlinePlayers()) {
     if (player.hasPermission(permission))
       player.sendMessage(
           team.getColor() + "[" + team.getName() + "] " + message.getMessage(player.getLocale()));
   }
 }
コード例 #3
0
 @EventHandler
 public void onBlockPlace(BlockPlaceEvent event) {
   if (!repairable && !isComplete()) {
     if (region.contains(event.getBlock().getLocation()) && partOfObjective(event.getBlock())) {
       if (TeamUtils.getTeamByPlayer(event.getPlayer()).getName() != team.getName()) {
         ChatUtils.sendWarningMessage(
             event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_ENEMY_OBJECTIVE));
         event.setCancelled(true);
       } else {
         ChatUtils.sendWarningMessage(
             event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_REPAIR_OBJECTIVE));
         event.setCancelled(true);
       }
     }
   }
 }