Пример #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
 public boolean showProximity() {
   return GameHandler.getGameHandler()
               .getMatch()
               .getModules()
               .getModule(TimeLimit.class)
               .getTimeLimit()
           != 0
       && GameHandler.getGameHandler()
           .getMatch()
           .getModules()
           .getModule(TimeLimit.class)
           .getResult()
           .equals(TimeLimit.Result.MOST_OBJECTIVES);
 }
Пример #3
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerMove(PlayerMoveEvent event) {
   if (region.contains(event.getTo().toVector()) && !region.contains(event.getFrom().toVector())) {
     if ((filter == null || filter.evaluate(event.getPlayer()).equals(FilterState.ALLOW))
         || (TeamUtils.getTeamByPlayer(event.getPlayer()) != null
             && TeamUtils.getTeamByPlayer(event.getPlayer()).isObserver())
         || !GameHandler.getGameHandler().getMatch().isRunning()) {
       if (destination != null) {
         event.getPlayer().teleport(destination.getRandomPoint().getLocation());
         if (sound)
           event
               .getPlayer()
               .playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 0.2F, 1);
       } else {
         Location newLocation = event.getTo();
         if (xRelative) newLocation.setX(newLocation.getX() + location.getX());
         else newLocation.setX(location.getX());
         if (yRelative) newLocation.setY(newLocation.getY() + location.getY());
         else newLocation.setY(location.getY());
         if (zRelative) newLocation.setZ(newLocation.getZ() + location.getZ());
         else newLocation.setZ(location.getZ());
         if (yawRelative) newLocation.setYaw(newLocation.getYaw() + yaw);
         else newLocation.setYaw(yaw);
         if (pitchRelative) newLocation.setPitch(newLocation.getPitch() + pitch);
         else newLocation.setPitch(pitch);
         event.getPlayer().teleport(newLocation);
         if (sound)
           event
               .getPlayer()
               .playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 0.2F, 1);
       }
     }
   }
   if (destination != null
       && destination.contains(event.getTo().toVector())
       && !destination.contains(event.getFrom().toVector())
       && this.bidirectional) {
     if (filter == null
         || filter.evaluate(event.getPlayer()).equals(FilterState.ALLOW)
         || (TeamUtils.getTeamByPlayer(event.getPlayer()) != null
             && TeamUtils.getTeamByPlayer(event.getPlayer()).isObserver())
         || !GameHandler.getGameHandler().getMatch().isRunning()) {
       event.getPlayer().teleport(region.getRandomPoint().getLocation());
       if (sound)
         event
             .getPlayer()
             .playSound(event.getPlayer().getLocation(), Sound.ENDERMAN_TELEPORT, 0.2F, 1);
     }
   }
 }
Пример #4
0
 public static boolean isMapAuthor(UUID uuid) {
   if (!Bukkit.getOfflinePlayer(uuid).isOnline()) return false;
   for (Contributor author : GameHandler.getGameHandler().getMatch().getLoadedMap().getAuthors()) {
     if (author.getUniqueId() != null && author.getUniqueId().equals(uuid)) {
       return true;
     }
   }
   return false;
 }
Пример #5
0
 @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++;
       }
     }
   }
 }
Пример #6
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));
     }
   }
 }
Пример #7
0
 @EventHandler
 public void onPlayerMove(PlayerMoveEvent event) {
   if (GameHandler.getGameHandler().getMatch().isRunning()
       && !this.isTouched()
       && TeamUtils.getTeamByPlayer(event.getPlayer()) != null
       && !TeamUtils.getTeamByPlayer(event.getPlayer()).isObserver()
       && TeamUtils.getTeamByPlayer(event.getPlayer()) != this.team) {
     if (event.getPlayer().getLocation().toVector().distance(region.getCenterBlock().getVector())
         < proximity) {
       double old = proximity;
       proximity =
           event
               .getPlayer()
               .getLocation()
               .toVector()
               .distance(region.getCenterBlock().getVector());
       Bukkit.getServer()
           .getPluginManager()
           .callEvent(new ObjectiveProximityEvent(this, event.getPlayer(), old, proximity));
     }
   }
 }
Пример #8
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)));
 }
Пример #9
0
 @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]");
   }
 }
Пример #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) {
     }
   }
 }
Пример #11
0
 @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;
         }
       }
     }
   }
 }