diff --git a/premiumconfig.yml b/premiumconfig.yml index aee4abaa7..c04c258a1 100644 --- a/premiumconfig.yml +++ b/premiumconfig.yml @@ -30,50 +30,56 @@ unlimited-nametag-mode-static-lines: ############################################## ################# SCOREBOARD ################# ############################################## +#Limitations: +#1.8 - 1.12 clients: scoreboard title 32 characters, lines 30 characters +#1.13+ clients: no limits +#maximum 15 lines, client can't display more -#for bungee mode it counts as "server" instead of "world", such as disabled in servers +#for bungee mode it counts as "server" instead of "world", such as disable in servers scoreboard: enabled: false toggle-command: /sb disable-in-worlds: - disabledworld #set to NONE to have no default scoreboard - default-scoreboard: "MyDefaultScoreboard" + default-scoreboard: "scoreboard3" refresh-interval-ticks: 1 per-world: - survival: "survival" + testworld: "twscoreboard" scoreboards: - MyDefaultScoreboard: - title: "&7&l> %animation:ServerName% &7&l<" + scoreboard3: + #permission is "tab.scoreboard.", in this case tab.scoreboard.scoreboard3 + permission-required: true + #if player is missing the permission, display a different scoreboard + #if no other should be displayed / permission required is false, delete the line entirely + if-permission-missing: scoreboard2 + title: "Super board" lines: - - "%animation:MyAnimation1%" - - "&7%animation:Welcome%" - - "&b%nick%" - - "" - - "&7Online Players" - - "&b%online% &7/ &b%maxplayers%" - - "" - - "Money" - - "&f%money%&a$" - - "" - - "&7Website" - - "%animation:web%" - - "&a/sb &fto turn off" - - "%animation:MyAnimation1%" - survival: - title: "&7&l> %animation:ServerName% &7&l<" + - "Scoreboard for people with permission" + - "tab.scoreboard.scoreboard3" + scoreboard2: + #here the permission is "tab.scoreboard.scoreboard2" + permission-required: true + if-permission-missing: scoreboard1 + title: "Average board" lines: - - "%animation:MyAnimation1%" - - "&7Welcome to" - - "&b%world% &7world" - - "" - - "&7Online Players in world" - - "&b%worldonline%" - - "" - - "Position" - - "&b%xPos%&8X &b%yPos%&8Y &b%zPos%&8Z" - - "%animation:MyAnimation1%" + - "Scoreboard for people with permission" + - "tab.scoreboard.scoreboard2" + - "AND MISSING tab.scoreboard.scoreboard3" + scoreboard1: + permission-required: false + title: "Default" + lines: + - "Scoreboard for people with none of" + - "tab.scoreboard.scoreboard3 or" + - "tab.scoreboard.scoreboard2 " + - "permission" + twscoreboard: + permission-required: false + title: "TestWorld" + lines: + - "This is scoreboard for everyone in testworld world" #toggle messages scoreboard-on: "&2Scorebord enabled" scoreboard-off: "&7Scoreboard disabled" \ No newline at end of file diff --git a/src/me/neznamy/tab/premium/Premium.java b/src/me/neznamy/tab/premium/Premium.java index be89ac11e..f6ff9267e 100644 --- a/src/me/neznamy/tab/premium/Premium.java +++ b/src/me/neznamy/tab/premium/Premium.java @@ -50,9 +50,11 @@ public class Premium { ScoreboardManager.scoreboard_off = premiumconfig.getString("scoreboard-off", "&7Scoreboard disabled").replace("&", "§"); if (premiumconfig.get("scoreboards")!= null) for (String scoreboard : ((Map)premiumconfig.get("scoreboards")).keySet()) { + boolean permissionRequired = premiumconfig.getBoolean("scoreboards." + scoreboard + ".permission-required"); + String childBoard = premiumconfig.getString("scoreboards." + scoreboard + ".if-permission-missing"); String title = premiumconfig.getString("scoreboards." + scoreboard + ".title"); List lines = premiumconfig.getStringList("scoreboards." + scoreboard + ".lines"); - ScoreboardManager.scoreboards.put(scoreboard, new Scoreboard(title, lines)); + ScoreboardManager.scoreboards.put(scoreboard, new Scoreboard(scoreboard, title, lines, permissionRequired, childBoard)); } } } diff --git a/src/me/neznamy/tab/premium/Scoreboard.java b/src/me/neznamy/tab/premium/Scoreboard.java index 21ec02c1b..f710113c0 100644 --- a/src/me/neznamy/tab/premium/Scoreboard.java +++ b/src/me/neznamy/tab/premium/Scoreboard.java @@ -13,19 +13,34 @@ import me.neznamy.tab.shared.packets.PacketPlayOutScoreboardObjective.EnumScoreb public class Scoreboard { + private String name; private String title; + private boolean permissionRequired; + private String childBoard; private HashMap scores = new HashMap(); private ConcurrentHashMap players = new ConcurrentHashMap(); private String objectiveName; - public Scoreboard(String title, List lines) { + public Scoreboard(String name, String title, List lines, boolean permissionRequired, String childBoard) { + this.name = name; this.title = title; + this.permissionRequired = permissionRequired; + this.childBoard = childBoard; objectiveName = Math.random()*1000000+""; if (objectiveName.length() > 16) objectiveName = objectiveName.substring(0, 16); for (int i=0; i perWorld; public static Map scoreboards = new HashMap(); - + public static String scoreboard_on; public static String scoreboard_off; - + public static void load() { if (!enabled) return; for (ITabPlayer p : Shared.getPlayers()) { - playerJoin(p); + register(p); } Shared.scheduleRepeatingTask(refresh*50, "refreshing scoreboard", Feature.SCOREBOARD, new Runnable() { public void run() { + for (ITabPlayer p : Shared.getPlayers()) { + Scoreboard board = p.getActiveScoreboard(); + String current = board == null ? null : board.getName(); + String highest = getHighestScoreboard(p); + if (current == null && highest == null) continue; + if ((current == null && highest != null) || (current != null && highest == null) || (!current.equals(highest))) { + unregister(p); + register(p); + } + } for (Scoreboard board : scoreboards.values()) { board.refresh(); } } }); } + public static String getHighestScoreboard(ITabPlayer p) { + String scoreboard = perWorld.get(p.getWorldName()); + if (scoreboard == null && !defaultScoreboard.equalsIgnoreCase("NONE")) scoreboard = defaultScoreboard; + if (scoreboard != null) { + Scoreboard board = scoreboards.get(scoreboard); + while (board.isPermissionRequired() && !p.hasPermission("tab.scoreboard." + board.getName())) { + board = scoreboards.get(board.getChildScoreboard()); + if (board == null) return null; + scoreboard = board.getName(); + } + } + return scoreboard; + } public static void unload() { if (!enabled) return; for (Scoreboard board : scoreboards.values()) { @@ -44,21 +67,23 @@ public class ScoreboardManager { } scoreboards.clear(); } - public static void playerJoin(ITabPlayer p) { + public static void register(ITabPlayer p) { if (!enabled) return; if (disabledWorlds.contains(p.getWorldName())) return; if (p.hiddenScoreboard) return; - String scoreboard = perWorld.get(p.getWorldName()); - if (scoreboard == null && !defaultScoreboard.equalsIgnoreCase("NONE")) scoreboard = defaultScoreboard; + String scoreboard = getHighestScoreboard(p); if (scoreboard != null) { Scoreboard board = scoreboards.get(scoreboard); - board.register(p); - p.setActiveScoreboard(board); + if (board != null) { + board.register(p); + p.setActiveScoreboard(board); + } } } - public static void playerQuit(ITabPlayer p) { + public static void unregister(ITabPlayer p) { if (!enabled) return; if (p.getActiveScoreboard() != null) p.getActiveScoreboard().unregister(p); + p.setActiveScoreboard(null); } public static boolean onCommand(final ITabPlayer sender, String message) { if (!enabled) return false; @@ -66,11 +91,10 @@ public class ScoreboardManager { if (message.equalsIgnoreCase(toggleCommand)) { sender.hiddenScoreboard = !sender.hiddenScoreboard; if (sender.hiddenScoreboard) { - if (sender.getActiveScoreboard() != null) sender.getActiveScoreboard().unregister(sender); - sender.setActiveScoreboard(null); + unregister(sender); sender.sendMessage(scoreboard_off); } else { - playerJoin(sender); + register(sender); sender.sendMessage(scoreboard_on); } return true;