added permission-based scoreboard

This commit is contained in:
NEZNAMY committed 2019-08-18 23:42:24 +02:00
1 parent 0b1b0a6b9a
commit 2a48233f2f
4 files changed
+92 -45

No files matched your search

+37 -31
View File
@@ -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.<scoreboard name>", 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"
+3 -1
View File
@@ -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<String, Object>)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<String> 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));
}
}
}
+16 -1
View File
@@ -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<Integer, Score> scores = new HashMap<Integer, Score>();
private ConcurrentHashMap<ITabPlayer, String> players = new ConcurrentHashMap<ITabPlayer, String>();
private String objectiveName;
public Scoreboard(String title, List<String> lines) {
public Scoreboard(String name, String title, List<String> 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<lines.size(); i++) {
scores.put(i, new Score("TABSBTM"+i, getLineName(i), lines.get(i), 0));
}
}
public String getName() {
return name;
}
public boolean isPermissionRequired() {
return permissionRequired;
}
public String getChildScoreboard() {
return childBoard;
}
public String getLineName(int i) {
String id = i+"";
if (id.length() == 1) id = "0" + id;
@@ -17,23 +17,46 @@ public class ScoreboardManager {
public static int refresh;
public static Map<String, String> perWorld;
public static Map<String, Scoreboard> scoreboards = new HashMap<String, Scoreboard>();
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;