From 050d95b5ab00b37b00b81af1e925a09468ea29cf Mon Sep 17 00:00:00 2001 From: Xitee Date: Wed, 20 Jul 2022 15:53:03 +0200 Subject: [PATCH] Rank API stuff added Added Rank API event but not fully finished yet - I need some way to either execute the event asynchronously or to wait for the sync task so the scoreboard %player_rank% placeholder will be replaced. Also did some other changes and improvements. --- src/de/xite/scoreboard/api/TeamSetEvent.java | 104 +++++++++---- .../scoreboard/depend/LuckPermsRanks.java | 2 +- src/de/xite/scoreboard/depend/VaultAPI.java | 2 +- .../listeners/ConditionListener.java | 19 ++- .../listeners/JoinQuitListener.java | 9 +- src/de/xite/scoreboard/main/Config.java | 24 ++- .../xite/scoreboard/main/ExternalPlugins.java | 12 +- src/de/xite/scoreboard/main/PowerBoard.java | 5 +- .../modules/board/ScoreboardManager.java | 2 +- .../modules/board/ScoreboardPlayer.java | 2 +- .../scoreboard/modules/ranks/RankManager.java | 147 ++++++++++-------- .../xite/scoreboard/utils/Placeholders.java | 4 +- src/de/xite/scoreboard/utils/Teams.java | 22 ++- 13 files changed, 217 insertions(+), 137 deletions(-) diff --git a/src/de/xite/scoreboard/api/TeamSetEvent.java b/src/de/xite/scoreboard/api/TeamSetEvent.java index 8b5bf73..a6bf3a1 100644 --- a/src/de/xite/scoreboard/api/TeamSetEvent.java +++ b/src/de/xite/scoreboard/api/TeamSetEvent.java @@ -17,16 +17,11 @@ public class TeamSetEvent extends Event implements Cancellable{ private ChatColor nameColor; private String chatPrefix; private String rankDisplayName; - private int weight; + private String playerListName; + private int weight = 0; public TeamSetEvent(Player p) { this.p = p; - this.prefix = ""; - this.suffix = ""; - this.nameColor = ChatColor.WHITE; - this.chatPrefix = ""; - this.rankDisplayName = ""; - this.weight = 0; } @Override @@ -53,40 +48,80 @@ public Player getPlayer() { return this.p; } public String getPrefix() { - Teams t = Teams.get(p); - if(t != null && this.prefix.length() == 0) - this.prefix = t.getPrefix(); - return this.prefix; + if(prefix == null) { + Teams t = Teams.get(p); + if(t != null) { + prefix = t.getPrefix(); + }else + prefix = "Not defined"; + } + + return prefix; } public String getSuffix() { - Teams t = Teams.get(p); - if(t != null && this.suffix.length() == 0) - this.suffix = t.getSuffix(); - return this.suffix; - } - public ChatColor getNameColorChar() { - Teams t = Teams.get(p); - if(t != null && this.nameColor == ChatColor.WHITE) - this.nameColor = t.getNameColor(); - return this.nameColor; + if(suffix == null) { + Teams t = Teams.get(p); + if(t != null) { + suffix = t.getSuffix(); + }else + suffix = "Not defined"; + } + + return suffix; + } + public ChatColor getNameColor() { + if(nameColor == null) { + Teams t = Teams.get(p); + if(t != null) { + nameColor = t.getNameColor(); + }else + nameColor = ChatColor.WHITE; + } + + return nameColor; } public String getChatPrefix() { - Teams t = Teams.get(p); - if(t != null && this.chatPrefix.length() == 0) - this.chatPrefix = t.getChatPrefix(); - return this.chatPrefix; + if(chatPrefix == null) { + Teams t = Teams.get(p); + if(t != null) { + chatPrefix = t.getChatPrefix(); + }else + chatPrefix = "Not defined"; + } + + return chatPrefix; } public String getRankDisplayName() { - Teams t = Teams.get(p); - if(t != null && this.rankDisplayName.length() == 0) - this.rankDisplayName = t.getRankDisplayName(); - return this.rankDisplayName; + if(rankDisplayName == null) { + Teams t = Teams.get(p); + if(t != null) { + rankDisplayName = t.getRankDisplayName(); + }else + rankDisplayName = "Not defined"; + } + + return rankDisplayName; + } + public String getPlayerListName() { + if(playerListName == null) { + Teams t = Teams.get(p); + if(t != null) + playerListName = t.getPlayerListName(); + // Not setting to "Not defined" because it can be null and is optional + } + + return playerListName; } public Integer getWeight() { - Teams t = Teams.get(p); - if(t != null && this.weight == 0) - this.weight = t.getWeight(); - return this.weight; + if(weight == 0) { + Teams t = Teams.get(p); + if(t != null) { + weight = t.getWeight(); + }else + weight = 0; + } + + return weight; } public void setPrefix(String prefix) { @@ -104,6 +139,9 @@ public void setChatPrefix(String chatPrefix) { public void setRankDisplayName(String rankDisplayName) { this.rankDisplayName = rankDisplayName; } + public void setPlayerListName(String playerListName) { + this.playerListName = playerListName; + } public void setWeight(int weight) { this.weight = weight; } diff --git a/src/de/xite/scoreboard/depend/LuckPermsRanks.java b/src/de/xite/scoreboard/depend/LuckPermsRanks.java index 1b7fe45..7b24b99 100644 --- a/src/de/xite/scoreboard/depend/LuckPermsRanks.java +++ b/src/de/xite/scoreboard/depend/LuckPermsRanks.java @@ -104,7 +104,7 @@ public static boolean registerLuckPermsAPIRank(Player p) { // Register the player with all the collected data try { - Teams.addPlayer(p, prefix, suffix, nameColor, chat, displayname, weight); + Teams.addPlayer(p, prefix, suffix, nameColor, chat, displayname, null, weight); return true; }catch (Exception e) { // If somehow something does no work, send a error message to configure the rank properly. diff --git a/src/de/xite/scoreboard/depend/VaultAPI.java b/src/de/xite/scoreboard/depend/VaultAPI.java index 5db9234..1548b70 100644 --- a/src/de/xite/scoreboard/depend/VaultAPI.java +++ b/src/de/xite/scoreboard/depend/VaultAPI.java @@ -16,7 +16,7 @@ public class VaultAPI { public static boolean setupEconomy() { RegisteredServiceProvider rsp = pl.getServer().getServicesManager().getRegistration(Economy.class); if(rsp == null) { - pl.getLogger().warning("Error hooking into Vault-Economy! <- Ignore if you don't have a economy plugin installed on your server, otherwise check, if your money system supports Vault."); + pl.getLogger().warning("Error hooking into Vault-Economy! <- Ignore if you don't need PB's %player_money% placeholder, otherwise check, if your money system supports Vault."); return false; } econ = rsp.getProvider(); diff --git a/src/de/xite/scoreboard/listeners/ConditionListener.java b/src/de/xite/scoreboard/listeners/ConditionListener.java index 8b660ef..af6ceb6 100644 --- a/src/de/xite/scoreboard/listeners/ConditionListener.java +++ b/src/de/xite/scoreboard/listeners/ConditionListener.java @@ -4,12 +4,14 @@ import java.util.List; import org.bukkit.Bukkit; +import org.bukkit.ChatColor; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; +import de.xite.scoreboard.api.TeamSetEvent; import de.xite.scoreboard.main.PowerBoard; import de.xite.scoreboard.modules.board.ScoreboardPlayer; import de.xite.scoreboard.modules.ranks.RankManager; @@ -43,8 +45,21 @@ public void run() { } }); } - - + /* + @EventHandler + public void onRankEvent(TeamSetEvent e) { + Player p = e.getPlayer(); + if(p.getName().equals("Xitecraft")) { + e.setChatPrefix("Chat Prefix : "); + e.setNameColor(ChatColor.BLUE); + e.setPrefix(ChatColor.RED+"[OWNER]"); + e.setSuffix(ChatColor.AQUA+"[SUFFIX]"); + e.setRankDisplayName("Owner's Displayname"); + e.setPlayerListName("HEY"); + e.setWeight(999); + } + } + */ public static boolean checkConditions(Player p, List conditions) { for(String condition : conditions) { // For all "OR" conditions (lines) ArrayList andConditions = new ArrayList<>(); diff --git a/src/de/xite/scoreboard/listeners/JoinQuitListener.java b/src/de/xite/scoreboard/listeners/JoinQuitListener.java index 5961741..41b4ec9 100644 --- a/src/de/xite/scoreboard/listeners/JoinQuitListener.java +++ b/src/de/xite/scoreboard/listeners/JoinQuitListener.java @@ -1,7 +1,5 @@ package de.xite.scoreboard.listeners; -import java.util.ArrayList; - import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; @@ -10,7 +8,6 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; -import de.xite.scoreboard.api.PowerBoardAPI; import de.xite.scoreboard.main.PowerBoard; import de.xite.scoreboard.modules.board.ScoreboardPlayer; import de.xite.scoreboard.modules.ranks.RankManager; @@ -43,7 +40,8 @@ public void run() { // Set a new scoreboard for the player to prevent bugs if(pl.getConfig().getBoolean("tablist.ranks") || pl.getConfig().getBoolean("scoreboard")) p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard()); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { + + Bukkit.getScheduler().runTaskLaterAsynchronously(pl, new Runnable() { @Override public void run() { // Register Teams if chat ranks or tablist ranks are used @@ -54,9 +52,6 @@ public void run() { if(pl.getConfig().getBoolean("scoreboard")) ScoreboardPlayer.setScoreboard(p, false, null); - if(pl.getConfig().getBoolean("tablist.ranks")) - RankManager.setTablistRanks(p); - if(pl.getConfig().getBoolean("tablist.text")) TablistPlayer.addPlayer(p, null); diff --git a/src/de/xite/scoreboard/main/Config.java b/src/de/xite/scoreboard/main/Config.java index bc43057..f66ee05 100644 --- a/src/de/xite/scoreboard/main/Config.java +++ b/src/de/xite/scoreboard/main/Config.java @@ -400,11 +400,15 @@ public void run() { } }, 40); // General config - s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"config"+ChatColor.GRAY+"..."); + sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"config"+ChatColor.GRAY+"..."); Config.loadConfig(); + // Load all external plugin APIs + sendConfigReloadMessage(s, ChatColor.YELLOW+"Initializing external plugins"+ChatColor.GRAY+"..."); + ExternalPlugins.initializePlugins(); + // Scoreboards - s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"scoreboards"+ChatColor.GRAY+"..."); + sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"scoreboards"+ChatColor.GRAY+"..."); ArrayList players = new ArrayList(); players.addAll(ScoreboardPlayer.players.keySet()); for(Player p : players) @@ -422,25 +426,29 @@ public void run() { } // Ranks - boolean tabRanks = pl.getConfig().getBoolean("tablist.ranks"); - if(tabRanks || PowerBoard.pl.getConfig().getBoolean("chat.ranks")) { + if(pl.getConfig().getBoolean("tablist.ranks") || PowerBoard.pl.getConfig().getBoolean("chat.ranks")) { + sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"ranks"+ChatColor.GRAY+"..."); for(Player all : Bukkit.getOnlinePlayers()) { Teams.removePlayer(all); RankManager.register(all); - if(tabRanks) - RankManager.setTablistRanks(all); } } if(PowerBoard.pl.getConfig().getBoolean("tablist.text")) { - s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"tablist"+ChatColor.GRAY+"..."); + sendConfigReloadMessage(s, ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"tablists"+ChatColor.GRAY+"..."); TablistManager.unregisterAllTablists(); TablistManager.registerAllTablists(); for(Player all : Bukkit.getOnlinePlayers()) TablistPlayer.addPlayer(all, null); } - s.sendMessage(PowerBoard.pr+ChatColor.GREEN+"Plugin reloaded!"); + + sendConfigReloadMessage(s, ChatColor.GREEN+"Plugin reloaded!"); } }); } + private static void sendConfigReloadMessage(CommandSender s, String message) { + if(s instanceof Player) + s.sendMessage(PowerBoard.pr+"Config Reload: "+message); + pl.getLogger().info("Config Reload: "+message); + } } diff --git a/src/de/xite/scoreboard/main/ExternalPlugins.java b/src/de/xite/scoreboard/main/ExternalPlugins.java index 37f6490..e3d9ffa 100644 --- a/src/de/xite/scoreboard/main/ExternalPlugins.java +++ b/src/de/xite/scoreboard/main/ExternalPlugins.java @@ -40,10 +40,14 @@ public static void initializePlugins() { if(Bukkit.getPluginManager().isPluginEnabled("LuckPerms")) { hasLuckPerms = true; - RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class); - if(provider != null) - luckPerms = provider.getProvider(); - new LuckPermsListener(pl, luckPerms); + if(pl.getConfig().getBoolean("ranks.luckperms-api.enable") || pl.getConfig().getString("ranks.permissionsystem").equalsIgnoreCase("luckperms")) { + RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class); + if(provider != null) + luckPerms = provider.getProvider(); + new LuckPermsListener(pl, luckPerms); + }else + if(luckPerms != null) + pl.getLogger().warning("You have changed the rank permissions system from LuckPerms to something different. LuckPerms cannot be completely disabled whith a PB reload. Please restart your server soon."); } // BStats analytics try { diff --git a/src/de/xite/scoreboard/main/PowerBoard.java b/src/de/xite/scoreboard/main/PowerBoard.java index 4ca778c..17d7617 100644 --- a/src/de/xite/scoreboard/main/PowerBoard.java +++ b/src/de/xite/scoreboard/main/PowerBoard.java @@ -1,7 +1,6 @@ package de.xite.scoreboard.main; import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; @@ -105,10 +104,10 @@ public void run() { Teams teams = Teams.get(all); if(teams == null) RankManager.register(all); - RankManager.startTablistRanksUpdateScheduler(); + } if(pl.getConfig().getBoolean("tablist.ranks")) - RankManager.setTablistRanks(all); + RankManager.startTablistRanksUpdateScheduler(); if(pl.getConfig().getBoolean("scoreboard")) ScoreboardPlayer.setScoreboard(all, false, null); diff --git a/src/de/xite/scoreboard/modules/board/ScoreboardManager.java b/src/de/xite/scoreboard/modules/board/ScoreboardManager.java index bfe4810..b8e31c1 100644 --- a/src/de/xite/scoreboard/modules/board/ScoreboardManager.java +++ b/src/de/xite/scoreboard/modules/board/ScoreboardManager.java @@ -260,7 +260,7 @@ public boolean accept(File f, String name) { } for(String board : boards) { ScoreboardManager.get(board); - pl.getLogger().info("Registered scoreboard "+board+"."); + pl.getLogger().info("Registered scoreboard '"+board+"'."); } } public static void unregisterAllScoreboards() { diff --git a/src/de/xite/scoreboard/modules/board/ScoreboardPlayer.java b/src/de/xite/scoreboard/modules/board/ScoreboardPlayer.java index f93e7ac..553ab09 100644 --- a/src/de/xite/scoreboard/modules/board/ScoreboardPlayer.java +++ b/src/de/xite/scoreboard/modules/board/ScoreboardPlayer.java @@ -60,7 +60,7 @@ public static void setScoreboard(Player p, boolean API, ScoreboardManager sm) { } obj.setDisplaySlot(DisplaySlot.SIDEBAR); - p.setScoreboard(board); // Set the scoreboard + //p.setScoreboard(board); // Set the scoreboard // Set the scores if the API isn't used if(!API) { diff --git a/src/de/xite/scoreboard/modules/ranks/RankManager.java b/src/de/xite/scoreboard/modules/ranks/RankManager.java index e2c4414..37178e9 100644 --- a/src/de/xite/scoreboard/modules/ranks/RankManager.java +++ b/src/de/xite/scoreboard/modules/ranks/RankManager.java @@ -20,68 +20,85 @@ public class RankManager { public static boolean register(Player p) { if(pl.getConfig().getBoolean("ranks.luckperms-api.enable")) { - return LuckPermsRanks.registerLuckPermsAPIRank(p); + //--- Perm System: LuckPerms API ---// + boolean b = LuckPermsRanks.registerLuckPermsAPIRank(p); + if(b) + if(pl.getConfig().getBoolean("tablist.ranks")) + RankManager.setTablistRanks(p); + return b; }else if(pl.getConfig().getString("ranks.permissionsystem").equalsIgnoreCase("api")) { - // Use PowerBoardAPI as perm system + //--- Perm System: PB API ---// + TeamSetEvent tse = new TeamSetEvent(p); - Bukkit.getPluginManager().callEvent(tse); - if(!tse.isCancelled()) { - Teams.addPlayer(p, tse.getPrefix(), tse.getSuffix(), tse.getNameColorChar(), tse.getChatPrefix(), tse.getRankDisplayName(), tse.getWeight()); - } + Bukkit.getScheduler().runTask(pl, new Runnable() { + @Override + public void run() { + Bukkit.getPluginManager().callEvent(tse); + if(!tse.isCancelled()) { + Teams.addPlayer(p, tse.getPrefix(), tse.getSuffix(), tse.getNameColor(), tse.getChatPrefix(), tse.getRankDisplayName(), tse.getPlayerListName(), tse.getWeight()); + if(pl.getConfig().getBoolean("tablist.ranks")) + RankManager.setTablistRanks(p); + if(PowerBoard.debug) { + pl.getLogger().info("------------------------------------------------------"); + pl.getLogger().info("(PB API) The player "+p.getName()+" has now the rank:"); + pl.getLogger().info("Prefix: "+tse.getPrefix()); + pl.getLogger().info("ChatPrefix: "+tse.getChatPrefix()); + pl.getLogger().info("Suffix: "+tse.getSuffix()); + pl.getLogger().info("NameColor: "+tse.getNameColor()+"(Example Text)"); + pl.getLogger().info("RankDisplayName: "+tse.getRankDisplayName()); + pl.getLogger().info("PlayerListName: "+tse.getPlayerListName()); + pl.getLogger().info("Weight: "+tse.getWeight()); + pl.getLogger().info("------------------------------------------------------"); + } + }else + if(PowerBoard.debug) + pl.getLogger().info("TeamSetEvent cancelled for player: "+p.getName()); + } + }); return true; }else { - //--- Other PermSystems ---// + //--- Perm System: None ---// int weight = 0; for(String line : pl.getConfig().getConfigurationSection("ranks.list").getValues(false).keySet()) { if(!line.contains(".")) { String permission = pl.getConfig().getString("ranks.list."+line+".permission"); - //--- LuckPerms (without API) ---// - if(ExternalPlugins.luckPerms != null && pl.getConfig().getString("ranks.permissionsystem").equalsIgnoreCase("luckperms")) { - if(LuckPermsRanks.isPlayerInGroup(p, permission)) { - String prefix = pl.getConfig().getString("ranks.list."+line+".prefix"); - String suffix = pl.getConfig().getString("ranks.list."+line+".suffix"); - String chatPrefix = pl.getConfig().getString("ranks.list."+line+".chatPrefix"); - String placeholderName = pl.getConfig().getString("ranks.list."+line+".placeholder-name"); - String nameColor = ChatColor.getLastColors(ChatColor.translateAlternateColorCodes('&', prefix)); - - Teams.addPlayer(p, prefix, suffix, nameColor, chatPrefix, placeholderName, weight); - Teams t = Teams.get(p); - t.setRankDisplayName(t.getNameColor()+t.getRankDisplayName()); - - if(PowerBoard.debug) - pl.getLogger().info("The player "+p.getName()+" has now the rank (luckperms): Prefix: "+prefix+"; Suffix: "+suffix+"; Group: "+permission); - return true; - } - }else { - //---None---// - if(p.hasPermission(permission)) { - String prefix = pl.getConfig().getString("ranks.list."+line+".prefix"); - String suffix = pl.getConfig().getString("ranks.list."+line+".suffix"); - String chatPrefix = pl.getConfig().getString("ranks.list."+line+".chatPrefix"); - String placeholderName = pl.getConfig().getString("ranks.list."+line+".placeholder-name"); - String nameColor = ChatColor.getLastColors(ChatColor.translateAlternateColorCodes('&', prefix)); + + boolean luckperms = false; + if(ExternalPlugins.luckPerms != null && pl.getConfig().getString("ranks.permissionsystem").equalsIgnoreCase("luckperms")) + if(LuckPermsRanks.isPlayerInGroup(p, permission)) + luckperms = true; + + if(luckperms || p.hasPermission(permission)) { + String prefix = pl.getConfig().getString("ranks.list."+line+".prefix"); + String suffix = pl.getConfig().getString("ranks.list."+line+".suffix"); + String chatPrefix = pl.getConfig().getString("ranks.list."+line+".chatPrefix"); + String placeholderName = pl.getConfig().getString("ranks.list."+line+".placeholder-name"); + String nameColor = ChatColor.getLastColors(ChatColor.translateAlternateColorCodes('&', prefix)); - Teams.addPlayer(p, prefix, suffix, nameColor, chatPrefix, placeholderName, weight); - Teams t = Teams.get(p); - t.setRankDisplayName(t.getNameColor()+t.getRankDisplayName()); - - if(PowerBoard.debug) - pl.getLogger().info("The player "+p.getName()+" has now the rank (permission/none): Prefix: "+prefix+"; Suffix: "+suffix+"; Permission: "+permission); - return true; - } + Teams.addPlayer(p, prefix, suffix, nameColor, chatPrefix, placeholderName, null, weight); + Teams t = Teams.get(p); + t.setRankDisplayName(t.getNameColor()+t.getRankDisplayName()); + + if(PowerBoard.debug) + if(luckperms) { + pl.getLogger().info("The player "+p.getName()+" has now the rank (PermSystem: none): Prefix: "+prefix+"; Suffix: "+suffix+"; Permission: "+permission); + }else + pl.getLogger().info("The player "+p.getName()+" has now the rank (PermSystem: LuckPerms): Prefix: "+prefix+"; Suffix: "+suffix+"; Permission: "+permission); + if(pl.getConfig().getBoolean("tablist.ranks")) + RankManager.setTablistRanks(p); + return true; } weight++; } } if(Teams.get(p) == null && !pl.getConfig().getString("ranks.permissionsystem").equalsIgnoreCase("api")) { - Teams.addPlayer(p, "", "", "f", "noRank", null, -5555); // -5555 = error code for no rank + Teams.addPlayer(p, "", "", "f", "noRank", null, null, -5555); // -5555 = error code for no rank pl.getLogger().warning("The player "+p.getName()+" has no Rank! Make sure that he has the correct permissions."); } } - return false; } public static void setTablistRanks(Player p) { @@ -96,18 +113,16 @@ public static void setTablistRanks(Player p) { if(t == null) t = p.getScoreboard().registerNewTeam(teams.getTeamName()); - String prefix = teams.getPrefix(); - String suffix = teams.getSuffix(); ChatColor nameColor = teams.getNameColor(); - setPrefixSuffix(p, t, prefix, suffix); + setPrefixSuffix(p, t, teams.getPrefix(), teams.getSuffix(), teams.getPlayerListName()); if(PowerBoard.aboveMC_1_13 && nameColor != null) t.setColor(nameColor); t.addEntry(all.getName()); }else - pl.getLogger().warning("Did not set "+all.getName()+"'s tablist rank for player "+p.getName()+""); + pl.getLogger().warning("Did not set "+all.getName()+"'s rank for player "+p.getName()); } } @@ -115,15 +130,13 @@ public static void setTablistRanks(Player p) { // Set the new player for all players that are online if(teams != null) { ChatColor nameColor = teams.getNameColor(); - String prefix = teams.getPrefix(); - String suffix = teams.getSuffix(); for(Player all : Bukkit.getOnlinePlayers()) { Team t = all.getScoreboard().getTeam(teams.getTeamName()); if(t == null) t = all.getScoreboard().registerNewTeam(teams.getTeamName()); - setPrefixSuffix(p, t, prefix, suffix); + setPrefixSuffix(p, t, teams.getPrefix(), teams.getSuffix(), teams.getPlayerListName()); if(nameColor != null && PowerBoard.aboveMC_1_13) t.setColor(nameColor); @@ -132,9 +145,9 @@ public static void setTablistRanks(Player p) { } }else - pl.getLogger().severe("Did not set "+p.getName()+"'s rank for the already online players"); + pl.getLogger().warning("Did not set "+p.getName()+"'s rank for the already online players"); if(PowerBoard.debug) - pl.getLogger().info("Tablist ranks set for player "+p.getName()); + pl.getLogger().info("Ranks set for player "+p.getName()); } public static boolean updateTablistRanks(Player p) { @@ -162,23 +175,18 @@ public void run() { try { Teams teams = Teams.get(p); if(teams != null) { - String prefix = teams.getPrefix(); - String suffix = teams.getSuffix(); + ChatColor nameColor = teams.getNameColor(); - if(teams != null) { - ChatColor nameColor = teams.getNameColor(); + for(Player all : Bukkit.getOnlinePlayers()) { + Team t = all.getScoreboard().getTeam(teams.getTeamName()); + if(t == null) + t = all.getScoreboard().registerNewTeam(teams.getTeamName()); - for(Player all : Bukkit.getOnlinePlayers()) { - Team t = all.getScoreboard().getTeam(teams.getTeamName()); - if(t == null) - t = all.getScoreboard().registerNewTeam(teams.getTeamName()); - - setPrefixSuffix(p, t, prefix, suffix); - - if(nameColor != null && PowerBoard.aboveMC_1_13) - t.setColor(nameColor); - t.addEntry(p.getName()); - } + setPrefixSuffix(p, t, teams.getPrefix(), teams.getSuffix(), teams.getPlayerListName()); + + if(nameColor != null && PowerBoard.aboveMC_1_13) + t.setColor(nameColor); + t.addEntry(p.getName()); } } @@ -209,7 +217,7 @@ public void run() { //-------// // Utils // //-------// - public static void setPrefixSuffix(Player p, Team t, String prefix, String suffix) { + public static void setPrefixSuffix(Player p, Team t, String prefix, String suffix, String playerListName) { try { if(prefix.length() != 0) t.setPrefix(prefix); @@ -220,9 +228,12 @@ public static void setPrefixSuffix(Player p, Team t, String prefix, String suffi // IllegalArgumentException == prefix or suffix too long // With setPlayerListName you can bypass this limit, however the prefix and suffix will no longer be displayed above the player head + playerListName = prefix + p.getDisplayName() + suffix; + } + if(playerListName != null) { t.setPrefix(""); t.setSuffix(""); - p.setPlayerListName(prefix+p.getDisplayName()+suffix); + p.setPlayerListName(prefix + playerListName + suffix); if(PowerBoard.debug) { pl.getLogger().info("Using prefix/suffix too long bypass for player "+p.getName()+"."); diff --git a/src/de/xite/scoreboard/utils/Placeholders.java b/src/de/xite/scoreboard/utils/Placeholders.java index ea4a9b0..30e32a7 100644 --- a/src/de/xite/scoreboard/utils/Placeholders.java +++ b/src/de/xite/scoreboard/utils/Placeholders.java @@ -180,10 +180,10 @@ public static String replace(Player p, String s) { // Rank displayname if(s.contains("%player_rank%")) { Teams teams = Teams.get(p); - if(teams == null) { + /*if(teams == null) { RankManager.register(p); teams = Teams.get(p); - } + }*/ if(teams != null) { if(teams.getRankDisplayName() == null) { s = s.replace("%player_rank%", teams.getPrefix()); diff --git a/src/de/xite/scoreboard/utils/Teams.java b/src/de/xite/scoreboard/utils/Teams.java index f37c210..aedd9d6 100644 --- a/src/de/xite/scoreboard/utils/Teams.java +++ b/src/de/xite/scoreboard/utils/Teams.java @@ -18,15 +18,17 @@ public class Teams { String teamName; String chatPrefix; String rankDisplayName; + String playerListName; int weight; - public Teams(Player p, String prefix, String suffix, ChatColor nameColor, String chatPrefix, String rankDisplayName, int weight) { + public Teams(Player p, String prefix, String suffix, ChatColor nameColor, String chatPrefix, String rankDisplayName, String playerListName, int weight) { this.p = p; this.prefix = prefix; this.suffix = suffix; this.nameColor = nameColor; this.chatPrefix = chatPrefix; this.rankDisplayName = rankDisplayName; + this.playerListName = playerListName; this.weight = weight; if(p == null) { @@ -45,20 +47,22 @@ public Teams(Player p, String prefix, String suffix, ChatColor nameColor, String +"team-" +TeamCount; } - public static Teams addPlayer(Player p, String prefix, String suffix, ChatColor nameColor, String chatPrefix, String placeholderName, int weight) { - Teams teams = new Teams(p, prefix, suffix, nameColor, chatPrefix, placeholderName, weight); + public static Teams addPlayer(Player p, String prefix, String suffix, ChatColor nameColor, String chatPrefix, String placeholderName, String playerListName, int weight) { + Teams teams = new Teams(p, prefix, suffix, nameColor, chatPrefix, placeholderName, playerListName, weight); TeamsList.put(p, teams); return teams; } - public static Teams addPlayer(Player p, String prefix, String suffix, String nameColor, String chatPrefix, String placeholderName, int weight) { + public static Teams addPlayer(Player p, String prefix, String suffix, String nameColor, String chatPrefix, String placeholderName, String playerListName, int weight) { nameColor = nameColor.replace("&", "").replace("ยง", ""); ChatColor nameColorChat = ChatColor.WHITE; try { nameColorChat = ChatColor.getByChar(nameColor); }catch (Exception e) { - PowerBoard.pl.getLogger().warning("Could not read "+p.getName()+"'s name color. Please check your config."); + PowerBoard.pl.getLogger().warning("Could not read "+p.getName()+"'s name color." + + "The player's name will be white in the tablist." + + "To avoid this, make sure, you have a valid colorcode at the end of your prefix."); } - return addPlayer(p, prefix, suffix, nameColorChat, chatPrefix, placeholderName, weight); + return addPlayer(p, prefix, suffix, nameColorChat, chatPrefix, placeholderName, playerListName, weight); } public static void removePlayer(Player p) { if(TeamsList.containsKey(p)) { @@ -82,6 +86,9 @@ public String getChatPrefix() { public String getRankDisplayName() { return rankDisplayName; } + public String getPlayerListName() { // Custom playername + return playerListName; + } public String getRawPrefix() { if(this.prefix == null) { PowerBoard.pl.getLogger().severe("An error occured while reading the prefix of the player "+p.getName()+"! Maybe a wrong setting in your config.yml?"); @@ -155,4 +162,7 @@ public void setSuffix(String suffix) { public void setNameColor(ChatColor color) { this.nameColor = color; } + public void setPlayerListName(String playerListName) { + this.playerListName = playerListName; + } }