@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())); } }
@Command( aliases = {"myteam", "mt"}, desc = "Shows what team you are on", min = 0, max = 0) public static void myTeam(final CommandContext cmd, CommandSender sender) throws CommandException { if (!(sender instanceof Player)) { return; } Player player = (Player) sender; player.sendMessage( new UnlocalizedChatMessage( ChatColor.GRAY + "{0}", new LocalizedChatMessage( ChatConstant.GENERIC_ON_TEAM, TeamUtils.getTeamByPlayer(player).getCompleteName())) .getMessage(player.getLocale())); }
@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)); } } } }
@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) { } } }