@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)));
     }
   }
 }
Beispiel #2
0
 @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()));
   }
 }
Beispiel #3
0
 @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));
     }
   }
 }
 @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);
       }
     }
   }
 }
Beispiel #5
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onPlayerChangeTeam(PlayerChangeTeamEvent event) {
   if (team.equals(event.getNewTeam())) addMember(event.getPlayer());
   else removeMember(event.getPlayer());
 }
Beispiel #6
0
 public TeamChannel(TeamModule team, PermissionModule permissionModule) {
   super(new Permission("cardinal." + team.getId()), permissionModule);
   this.team = team;
 }
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onEntityExplode(EntityExplodeEvent event) {
   if (!event.isCancelled()) {
     List<Block> objectiveBlownUp = new ArrayList<>();
     for (Block block : event.blockList()) {
       if (getBlocks().contains(block)) {
         objectiveBlownUp.add(block);
       }
     }
     boolean oldState = this.isTouched();
     boolean blownUp = false;
     Player eventPlayer = null;
     int originalPercent = getPercent();
     boolean touchMessage = false;
     for (Block block : objectiveBlownUp) {
       boolean blockDestroyed = false;
       if (TntTracker.getWhoPlaced(event.getEntity()) != null) {
         UUID player = TntTracker.getWhoPlaced(event.getEntity());
         if (Bukkit.getOfflinePlayer(player).isOnline()) {
           if (TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player)) == team) {
             event.blockList().remove(block);
           } else {
             if (!playersTouched.contains(player)) {
               playersTouched.add(player);
               TeamModule teamModule = TeamUtils.getTeamByPlayer(Bukkit.getPlayer(player));
               if (this.show && !this.completed) {
                 TeamUtils.getTeamChannel(teamModule)
                     .sendLocalizedMessage(
                         new LocalizedChatMessage(
                             ChatConstant.UI_OBJECTIVE_DAMAGED_FOR,
                             teamModule.getColor()
                                 + Bukkit.getPlayer(player).getName()
                                 + ChatColor.WHITE,
                             ChatColor.AQUA + name + ChatColor.WHITE,
                             teamModule.getCompleteName() + ChatColor.WHITE));
                 for (Player player1 : Bukkit.getOnlinePlayers()) {
                   if (TeamUtils.getTeamByPlayer(player1) != null
                       && TeamUtils.getTeamByPlayer(player1).isObserver()) {
                     player1.sendMessage(
                         new LocalizedChatMessage(
                                 ChatConstant.UI_OBJECTIVE_DAMAGED_FOR,
                                 teamModule.getColor()
                                     + Bukkit.getPlayer(player).getName()
                                     + ChatColor.WHITE,
                                 ChatColor.AQUA + name + ChatColor.WHITE,
                                 teamModule.getCompleteName() + ChatColor.WHITE)
                             .getMessage(player1.getLocale()));
                   }
                   if (Settings.getSettingByName("Sounds") != null
                       && Settings.getSettingByName("Sounds")
                           .getValueByPlayer(player1)
                           .getValue()
                           .equalsIgnoreCase("on")) {
                     player1.playSound(player1.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1);
                   }
                 }
                 touchMessage = true;
               }
             }
             blockDestroyed = true;
             blownUp = true;
             eventPlayer = Bukkit.getPlayer(player);
           }
         } else {
           if (!playersTouched.contains(player)) {
             playersTouched.add(player);
           }
           blockDestroyed = true;
           blownUp = true;
         }
       } else {
         blockDestroyed = true;
         blownUp = true;
       }
       if (blockDestroyed) {
         this.complete++;
         if (eventPlayer != null)
           this.playersCompleted.put(
               eventPlayer.getUniqueId(),
               (playersCompleted.containsKey(eventPlayer.getUniqueId())
                   ? playersCompleted.get(eventPlayer.getUniqueId()) + 1
                   : 1));
         if ((this.complete / size) >= this.required && !this.completed) {
           this.completed = true;
           if (this.show) {
             for (Player player : Bukkit.getOnlinePlayers())
               player.sendMessage(
                   ChatColor.GRAY
                       + new UnlocalizedChatMessage(
                               "{0}",
                               new LocalizedChatMessage(
                                   ChatConstant.UI_OBJECTIVE_DESTROYED,
                                   team.getCompleteName() + ChatColor.GRAY,
                                   ChatColor.AQUA + name + ChatColor.GRAY,
                                   getWhoDestroyed(player.getLocale())))
                           .getMessage(player.getLocale()));
             Bukkit.getLogger()
                 .info(
                     ChatColor.GRAY
                         + new UnlocalizedChatMessage(
                                 "{0}",
                                 new LocalizedChatMessage(
                                     ChatConstant.UI_OBJECTIVE_DESTROYED,
                                     team.getCompleteName() + ChatColor.GRAY,
                                     ChatColor.AQUA + name + ChatColor.GRAY,
                                     getWhoDestroyed(Locale.getDefault().toString())))
                             .getMessage(Locale.getDefault().toString()));
           }
           ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, eventPlayer);
           Bukkit.getServer().getPluginManager().callEvent(compEvent);
         }
       }
     }
     if (!this.completed && blownUp) {
       ObjectiveTouchEvent touchEvent =
           new ObjectiveTouchEvent(
               this, eventPlayer, !oldState || (getPercent() != originalPercent), touchMessage);
       Bukkit.getServer().getPluginManager().callEvent(touchEvent);
     }
   }
 }
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockBreak(BlockBreakEvent event) {
   if (!event.isCancelled()) {
     if (getBlocks().contains(event.getBlock())) {
       if (TeamUtils.getTeamByPlayer(event.getPlayer()) != team) {
         boolean touchMessage = false;
         if (!playersTouched.contains(event.getPlayer().getUniqueId())) {
           playersTouched.add(event.getPlayer().getUniqueId());
           TeamModule teamModule = TeamUtils.getTeamByPlayer(event.getPlayer());
           if (this.show && !this.completed) {
             TeamUtils.getTeamChannel(teamModule)
                 .sendLocalizedMessage(
                     new LocalizedChatMessage(
                         ChatConstant.UI_OBJECTIVE_DAMAGED_FOR,
                         teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE,
                         ChatColor.AQUA + name + ChatColor.WHITE,
                         teamModule.getCompleteName() + ChatColor.WHITE));
             for (Player player : Bukkit.getOnlinePlayers()) {
               if (TeamUtils.getTeamByPlayer(player) != null
                   && TeamUtils.getTeamByPlayer(player).isObserver()) {
                 player.sendMessage(
                     new LocalizedChatMessage(
                             ChatConstant.UI_OBJECTIVE_DAMAGED_FOR,
                             teamModule.getColor() + event.getPlayer().getName() + ChatColor.WHITE,
                             ChatColor.AQUA + name + ChatColor.WHITE,
                             teamModule.getCompleteName() + ChatColor.WHITE)
                         .getMessage(player.getLocale()));
               }
               if (Settings.getSettingByName("Sounds") != null
                   && Settings.getSettingByName("Sounds")
                       .getValueByPlayer(player)
                       .getValue()
                       .equalsIgnoreCase("on")) {
                 player.playSound(player.getLocation(), Sound.FIREWORK_TWINKLE, 1, 1);
               }
             }
           }
         }
         boolean oldState = this.isTouched();
         this.complete++;
         this.playersCompleted.put(
             event.getPlayer().getUniqueId(),
             (playersCompleted.containsKey(event.getPlayer().getUniqueId())
                 ? playersCompleted.get(event.getPlayer().getUniqueId()) + 1
                 : 1));
         if ((this.complete / size) >= this.required && !this.completed) {
           this.completed = true;
           event.setCancelled(false);
           if (this.show) {
             for (Player player : Bukkit.getOnlinePlayers())
               player.sendMessage(
                   ChatColor.GRAY
                       + new UnlocalizedChatMessage(
                               "{0}",
                               new LocalizedChatMessage(
                                   ChatConstant.UI_OBJECTIVE_DESTROYED,
                                   team.getCompleteName() + ChatColor.GRAY,
                                   ChatColor.AQUA + name + ChatColor.GRAY,
                                   getWhoDestroyed(player.getLocale())))
                           .getMessage(player.getLocale()));
           }
           FireworkUtil.spawnFirework(
               event.getPlayer().getLocation(),
               event.getPlayer().getWorld(),
               MiscUtils.convertChatColorToColor(team.getColor()));
           ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer());
           Bukkit.getServer().getPluginManager().callEvent(compEvent);
         } else if (!this.completed) {
           ObjectiveTouchEvent touchEvent =
               new ObjectiveTouchEvent(
                   this, event.getPlayer(), !oldState || showPercent, touchMessage);
           Bukkit.getServer().getPluginManager().callEvent(touchEvent);
         }
       } else {
         event.setCancelled(true);
         if (this.show)
           ChatUtils.sendWarningMessage(
               event.getPlayer(), new LocalizedChatMessage(ChatConstant.ERROR_OWN_OBJECTIVE));
       }
     }
   }
 }
 @Command(
     aliases = {"team"},
     desc = "Manage the teams in the match.",
     usage = "<force, alias, shuffle> [player, old team] [force team, new team]",
     min = 1)
 public static void team(final CommandContext cmd, CommandSender sender) throws CommandException {
   if (cmd.getString(0).equalsIgnoreCase("force")) {
     if (sender.hasPermission("cardinal.team.force")) {
       if (cmd.argsLength() >= 3) {
         if (Bukkit.getPlayer(cmd.getString(1)) != null) {
           String msg = "";
           for (int i = 2; i < cmd.argsLength(); i++) {
             msg += cmd.getString(i) + " ";
           }
           msg = msg.trim();
           if (TeamUtils.getTeamByName(msg) != null) {
             TeamModule team = TeamUtils.getTeamByName(msg);
             if (!team.contains(Bukkit.getPlayer(cmd.getString(1)))) {
               team.add(Bukkit.getPlayer(cmd.getString(1)), true, false);
               sender.sendMessage(
                   team.getColor()
                       + Bukkit.getPlayer(cmd.getString(1)).getName()
                       + ChatColor.GRAY
                       + " forced to "
                       + team.getCompleteName());
             } else
               throw new CommandException(
                   new LocalizedChatMessage(
                           ChatConstant.ERROR_ALREADY_JOINED,
                           TeamUtils.getTeamByPlayer((Player) sender).getCompleteName()
                               + ChatColor.RED)
                       .getMessage(((Player) sender).getLocale()));
           } else {
             throw new CommandException(
                 new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH)
                     .getMessage(ChatUtils.getLocale(sender)));
           }
         } else {
           throw new CommandException(
               new LocalizedChatMessage(ChatConstant.ERROR_NO_PLAYER_MATCH)
                   .getMessage(ChatUtils.getLocale(sender)));
         }
       } else {
         throw new CommandUsageException(
             "Too few arguments.", "/team <force> <player> <force team>");
       }
     } else {
       throw new CommandPermissionsException();
     }
   } else if (cmd.getString(0).equalsIgnoreCase("alias")) {
     if (sender.hasPermission("cardinal.team.alias")) {
       if (cmd.argsLength() >= 3) {
         TeamModule team = TeamUtils.getTeamByName(cmd.getString(1));
         if (team != null) {
           String msg = "";
           for (int i = 2; i < cmd.argsLength(); i++) {
             msg += cmd.getString(i) + " ";
           }
           msg = msg.trim();
           String locale = ChatUtils.getLocale(sender);
           sender.sendMessage(
               ChatColor.GRAY
                   + new LocalizedChatMessage(
                           ChatConstant.GENERIC_TEAM_ALIAS,
                           team.getCompleteName() + ChatColor.GRAY,
                           team.getColor() + msg + ChatColor.GRAY)
                       .getMessage(locale));
           team.setName(msg);
           Bukkit.getServer().getPluginManager().callEvent(new TeamNameChangeEvent(team));
         } else {
           throw new CommandException(
               new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH)
                   .getMessage(ChatUtils.getLocale(sender)));
         }
       } else {
         throw new CommandUsageException(
             "Too few arguments!", "/team <alias> <old team> <new team>");
       }
     } else {
       throw new CommandPermissionsException();
     }
   } else if (cmd.getString(0).equalsIgnoreCase("shuffle")) {
     if (sender.hasPermission("cardinal.team.shuffle")) {
       List<Player> playersToShuffle = new ArrayList<>();
       for (Player player : Bukkit.getOnlinePlayers()) {
         if (TeamUtils.getTeamByPlayer(player) != null) {
           if (!TeamUtils.getTeamByPlayer(player).isObserver()) {
             playersToShuffle.add(player);
             TeamModule observers = TeamUtils.getTeamById("observers");
             observers.add(player, true, false);
           }
         }
       }
       while (playersToShuffle.size() > 0) {
         Player player = playersToShuffle.get(new Random().nextInt(playersToShuffle.size()));
         TeamModule team =
             TeamUtils.getTeamWithFewestPlayers(GameHandler.getGameHandler().getMatch());
         team.add(player, true);
         playersToShuffle.remove(player);
       }
       String locale = ChatUtils.getLocale(sender);
       sender.sendMessage(
           ChatColor.GREEN
               + new LocalizedChatMessage(ChatConstant.GENERIC_TEAM_SHUFFLE).getMessage(locale));
     } else {
       throw new CommandPermissionsException();
     }
   } else if (cmd.getString(0).equalsIgnoreCase("size")) {
     if (sender.hasPermission("cardinal.team.size")) {
       TeamModule team = TeamUtils.getTeamByName(cmd.getString(1));
       if (team == null) {
         throw new CommandException(
             new LocalizedChatMessage(ChatConstant.ERROR_NO_TEAM_MATCH)
                 .getMessage(ChatUtils.getLocale(sender)));
       }
       team.setMax(cmd.getInteger(1));
       team.setMaxOverfill(cmd.getInteger(1));
       sender.sendMessage(
           new LocalizedChatMessage(
                   ChatConstant.GENERIC_TEAM_SIZE_UPDATE,
                   team.getCompleteName() + ChatColor.YELLOW,
                   cmd.getInteger(1) + "")
               .getMessage(ChatUtils.getLocale(sender)));
     } else {
       throw new CommandPermissionsException();
     }
   } else {
     throw new CommandUsageException(
         "Invalid arguments.",
         "/team <force, alias, shuffle, size> [player, old team] [force team, new team, size]");
   }
 }
Beispiel #10
0
 @EventHandler
 public void onWoolPickup(PlayerPickupItemEvent event) {
   Player player = event.getPlayer();
   if (!this.complete && GameHandler.getGameHandler().getMatch().isRunning()) {
     try {
       if (event.getItem().getItemStack().getType() == Material.WOOL
           && event.getItem().getItemStack().getData().getData() == color.getData()) {
         if (Teams.getTeamByPlayer(player).orNull() == team) {
           boolean touchMessage = false;
           if (!this.playersTouched.contains(player.getUniqueId())) {
             this.playersTouched.add(player.getUniqueId());
             if (this.show && !this.complete) {
               Teams.getTeamChannel(Optional.of(team))
                   .sendLocalizedMessage(
                       new UnlocalizedChatMessage(
                           ChatColor.WHITE + "{0}",
                           new LocalizedChatMessage(
                               ChatConstant.UI_OBJECTIVE_PICKED,
                               team.getColor() + player.getName() + ChatColor.WHITE,
                               MiscUtil.convertDyeColorToChatColor(color)
                                   + name.toUpperCase().replaceAll("_", " ")
                                   + ChatColor.WHITE,
                               team.getCompleteName() + ChatColor.WHITE)));
               for (Player player1 : Bukkit.getOnlinePlayers()) {
                 if (Teams.getTeamByPlayer(player1).isPresent()
                     && Teams.getTeamByPlayer(player1).get().isObserver()) {
                   player1.sendMessage(
                       new UnlocalizedChatMessage(
                               ChatColor.GRAY + "{0}",
                               new LocalizedChatMessage(
                                   ChatConstant.UI_OBJECTIVE_PICKED_FOR,
                                   team.getColor() + player.getName() + ChatColor.GRAY,
                                   MiscUtil.convertDyeColorToChatColor(color)
                                       + name.toUpperCase().replaceAll("_", " ")
                                       + ChatColor.GRAY,
                                   team.getCompleteName() + ChatColor.GRAY))
                           .getMessage(player1.getLocale()));
                 }
               }
               touchMessage = true;
             }
           }
           boolean oldState = this.touched;
           this.touched = true;
           if (touchMessage) {
             double newProx;
             if (location != null) {
               newProx = location.distance(place.getVector());
             } else {
               newProx = player.getLocation().toVector().distance(place.getVector());
             }
             if (!oldState || newProx < proximity) {
               proximity = newProx;
             }
           }
           ObjectiveTouchEvent touchEvent =
               new ObjectiveTouchEvent(this, player, !oldState, touchMessage);
           Bukkit.getServer().getPluginManager().callEvent(touchEvent);
         }
       }
     } catch (NullPointerException e) {
     }
   }
 }