public UHProtocolLibIntegration(UHPlugin p) { // The plugin is available if this is called. PacketsListener packetsListener = new PacketsListener(p); if (p.getConfig().getBoolean("hardcore-hearts.display")) { ProtocolLibrary.getProtocolManager().addPacketListener(packetsListener); } if (p.getConfig().getBoolean("auto-respawn.do")) { p.getServer().getPluginManager().registerEvents(packetsListener, p); } p.getLogger().info("Successfully hooked into ProtocolLib."); }
/** * Imports the teams from the configuration. * * @return The number of teams imported. */ public int importTeamsFromConfig() { if (p.getConfig().getList("teams") != null) { int teamsCount = 0; for (Object teamRaw : p.getConfig().getList("teams")) { if (teamRaw instanceof String && teamRaw != null) { String[] teamRawSeparated = ((String) teamRaw).split(","); TeamColor color = TeamColor.fromString(teamRawSeparated[0]); if (color == null) { p.getLogger().warning(i.t("load.invalidTeam", (String) teamRaw)); } else { if (teamRawSeparated.length == 2) { // "color,name" UHTeam newTeam = addTeam(color, teamRawSeparated[1]); p.getLogger() .info( i.t("load.namedTeamAdded", newTeam.getName(), newTeam.getColor().toString())); teamsCount++; } else if (teamRawSeparated.length == 1) { // "color" UHTeam newTeam = addTeam(color, teamRawSeparated[0]); p.getLogger().info(i.t("load.teamAdded", newTeam.getColor().toString())); teamsCount++; } else { p.getLogger().warning(i.t("load.invalidTeam", (String) teamRaw)); } } } } return teamsCount; } return 0; }
/** * Sets the correct display name of a player, according to his team. * * @param player */ public void colorizePlayer(OfflinePlayer offlinePlayer) { if (!p.getConfig().getBoolean("colorizeChat")) { return; } if (!offlinePlayer.isOnline()) { return; } Player player = (Player) offlinePlayer; UHTeam team = getTeamForPlayer(player); if (team == null) { player.setDisplayName(player.getName()); } else { if (team.getColor() != null) { player.setDisplayName(team.getColor().toChatColor() + player.getName() + ChatColor.RESET); } else { player.setDisplayName(player.getName()); } } }
/** * Displays a chat-based GUI (using tellraw formatting) to player to select a team. * * <p>Nothing is displayed if the player cannot use the /join command. * * @param player The receiver of the chat-GUI. */ public void displayTeamChooserChatGUI(Player player) { if (!player.hasPermission("uh.player.join.self")) return; if (p.getGameManager().isGameRunning()) { if (!p.getGameManager().isGameWithTeams()) { return; } } player.sendMessage( ChatColor.GRAY + "⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅"); if (p.getTeamManager().getTeams().size() != 0) { player.sendMessage(i.t("team.gui.choose")); boolean displayPlayers = p.getConfig().getBoolean("teams-options.gui.displayPlayersInTeams"); for (UHTeam team : p.getTeamManager().getTeams()) { String text = "{\"text\":\"\",\"extra\":["; // Team count (something like "[2/5]”) text += "{"; if (maxPlayersPerTeam != 0) { text += "\"text\": \"" + i.t( "team.gui.playersCount", String.valueOf(team.getSize()), String.valueOf(maxPlayersPerTeam)) + "\", "; } else { text += "\"text\": \"" + i.t("team.gui.playersCountUnlimited", String.valueOf(team.getSize())) + "\", "; } String players = ""; if (displayPlayers) { String bullet = "\n - "; for (OfflinePlayer opl : team.getPlayers()) { if (!p.getGameManager().isGameRunning()) { players += bullet + i.t("team.list.itemPlayer", opl.getName()); } else { if (p.getGameManager().isPlayerDead(opl.getUniqueId())) { players += bullet + i.t("team.list.itemPlayerDead", opl.getName()); } else { players += bullet + i.t("team.list.itemPlayerAlive", opl.getName()); } } } } text += "\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + i.t("team.gui.tooltipCount", String.valueOf(team.getPlayers().size())) + players + "\"}"; text += "},"; text += "{\"text\":\" \"},{"; // Team name (click event is here) text += "\"text\":\"" + team.getName() + "\","; text += "\"color\":\"" + team.getColor().toString().toLowerCase() + "\","; text += "\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/join " + team.getName() + "\"},"; if (team.containsPlayer(player)) { text += "\"bold\":\"true\","; text += "\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + i.t("team.gui.tooltipJoinInside", team.getDisplayName()) + "\"}"; } else { text += "\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + i.t("team.gui.tooltipJoin", team.getDisplayName()) + "\"}"; } text += "}"; text += "]}"; UHUtils.sendJSONMessage(player, text); } if (p.getTeamManager().getTeamForPlayer(player) != null && player.hasPermission("uh.player.leave.self")) { String text = "{"; text += "\"text\":\"" + i.t("team.gui.leaveTeam") + "\","; text += "\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/leave\"}"; text += "}"; UHUtils.sendJSONMessage(player, text); } else { player.sendMessage(i.t("team.gui.howToDisplayAgain")); } } else { // No teams. player.sendMessage(i.t("team.gui.noTeams")); } player.sendMessage( ChatColor.GRAY + "⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅"); }
public TeamManager(UHPlugin plugin) { this.p = plugin; this.i = p.getI18n(); this.maxPlayersPerTeam = p.getConfig().getInt("teams-options.maxPlayersPerTeam"); }