Example #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)));
     }
   }
 }
Example #2
0
 @EventHandler
 public void onCardinalDeath(CardinalDeathEvent event) {
   if (event.getKiller() != null
       && location != null
       && GameHandler.getGameHandler().getMatch().isRunning()
       && !this.touched
       && Teams.getTeamByPlayer(event.getKiller()).isPresent()
       && Teams.getTeamByPlayer(event.getKiller()).get() == this.team) {
     if (event.getKiller().getLocation().toVector().distance(location) < proximity) {
       double old = proximity;
       proximity = event.getKiller().getLocation().toVector().distance(location);
       Bukkit.getServer()
           .getPluginManager()
           .callEvent(new ObjectiveProximityEvent(this, event.getKiller(), old, proximity));
     }
   }
 }
Example #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));
     }
   }
 }
Example #4
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onSafetyPlace(BlockPlaceEvent event) {
   if (!event.isCancelled() && this.touched) {
     if (event.getBlock().getType().equals(Material.WOOL)) {
       if (((Wool) event.getBlock().getState().getData()).getColor().equals(color)) {
         if (Teams.getTeamByPlayer(event.getPlayer()).orNull() == team) {
           if (event.getBlockPlaced().getLocation().distance(place.getLocation()) < proximity) {
             double old = proximity;
             proximity = event.getBlockPlaced().getLocation().distance(place.getLocation());
             Bukkit.getServer()
                 .getPluginManager()
                 .callEvent(new ObjectiveProximityEvent(this, event.getPlayer(), old, proximity));
           }
         }
       }
     }
   }
 }
Example #5
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) {
     }
   }
 }