Skip to content

Commit

Permalink
v3.5.11
Browse files Browse the repository at this point in the history
  • Loading branch information
Xitee committed Jun 25, 2022
1 parent 941adb6 commit cbcb98a
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 41 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PowerBoard
version: 3.5.10
version: 3.5.11
author: Xitee
softdepend: [PermissionsEx, Vault, PlaceholderAPI, LuckPerms]
main: de.xite.scoreboard.main.PowerBoard
Expand Down
20 changes: 14 additions & 6 deletions src/de/xite/scoreboard/api/PowerBoardAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import de.xite.scoreboard.main.PowerBoard;
import de.xite.scoreboard.modules.board.ScoreTitleUtils;
import de.xite.scoreboard.modules.board.ScoreboardManager;
import de.xite.scoreboard.modules.board.ScoreboardPlayer;
import de.xite.scoreboard.modules.ranks.RankManager;
import de.xite.scoreboard.utils.Placeholders;
Expand All @@ -20,24 +21,31 @@ public static void registerCustomPlaceholders(CustomPlaceholders ph) {
// ---------------------//
// ---- Scoreboard ---- //
// ---------------------//
public static void setScoreboard(Player p) {
ScoreboardPlayer.setScoreboard(p, true);
public static void setScoreboard(Player p, boolean custom, String scoreboardName) {
if(custom == true || scoreboardName == null) {
ScoreboardPlayer.setScoreboard(p, custom, null);
}else {
ScoreboardPlayer.setScoreboard(p, custom, ScoreboardManager.get(scoreboardName));
}
}
public static void removeScoreboard(Player p) {
ScoreboardPlayer.removeScoreboard(p, false);
ScoreboardPlayer.removeScoreboard(p, true);
}
public static boolean hasConfigScoreboard(Player p) {
return ScoreboardPlayer.players.containsKey(p);
}

public static void setScoreboardTitle(Player p, String title, boolean usePlaceholders) {
if(!ScoreTitleUtils.setTitle(p, p.getScoreboard(), title, usePlaceholders, null))
PowerBoard.pl.getLogger().severe("Failed to set the Scoreboard-Title! The scoreboard is not registered yet - please set the scoreboard first with 'setScoreboard(p);' !");
PowerBoard.pl.getLogger().severe("Failed to set the Scoreboard-Title! "+p.getName()+"'s scoreboard is not registered yet - please set the scoreboard first!");
}
public static void setScoreboardScore(Player p, String score, int index, boolean usePlaceholders) {
if(!ScoreTitleUtils.setScore(p, p.getScoreboard(), score, index, usePlaceholders, null))
PowerBoard.pl.getLogger().severe("Failed to set the Scoreboard-Score! The scoreboard is not registered yet - please set the scoreboard first with 'setScoreboard(p);' !");
PowerBoard.pl.getLogger().severe("Failed to set the Scoreboard-Score! "+p.getName()+"'s scoreboard is not registered yet - please set the scoreboard first!");
}
public static void setScoreboardScores(Player p, ArrayList<String> scores, boolean usePlaceholders) {
if(!ScoreTitleUtils.setScores(p, p.getScoreboard(), scores, usePlaceholders, null))
PowerBoard.pl.getLogger().severe("Failed to set the Scoreboard-Scores! The scoreboard is not registered yet - please set the scoreboard first with 'setScoreboard(p);' !");
PowerBoard.pl.getLogger().severe("Failed to set the Scoreboard-Scores! "+p.getName()+"'s scoreboard is not registered yet - please set the scoreboard first with!");
}

// ----------------//
Expand Down
8 changes: 4 additions & 4 deletions src/de/xite/scoreboard/api/ScoreboardAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static void registerCustomPlaceholders(CustomPlaceholders ph) {
/**
* API has changed.
*
* @deprecated use {@link PowerBoardAPI.setScoreboard(p)} instead.
* @deprecated use {@link PowerBoardAPI.setScoreboard(p, custom)} instead.
*/
@Deprecated
public static void enableScoreboard(Player p, String s) {
PowerBoardAPI.setScoreboard(p);
PowerBoardAPI.setScoreboard(p, true, null);
}
/**
* API has changed.
Expand All @@ -41,7 +41,7 @@ public static void disableScoreboard(Player p, String s) {
*/
@Deprecated
public static void enableScoreboard(Player p) {
PowerBoardAPI.setScoreboard(p);
PowerBoardAPI.setScoreboard(p, true, null);
}
/**
* API has changed.
Expand All @@ -63,7 +63,7 @@ public static void disableScoreboard(Player p) {
*/
@Deprecated
public static void setScoreboard(Player p) {
PowerBoardAPI.setScoreboard(p);
PowerBoardAPI.setScoreboard(p, true, null);
}
/**
* API has changed.
Expand Down
2 changes: 1 addition & 1 deletion src/de/xite/scoreboard/commands/ScoreboardCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean onCommand(CommandSender s, Command arg1, String arg2, String[] ar
return true;
}else {
if(pl.getConfig().getBoolean("scoreboard")) {
ScoreboardPlayer.setScoreboard(p, false);
ScoreboardPlayer.setScoreboard(p, false, null);
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Enabled scoreboard.");
return true;
}else
Expand Down
18 changes: 17 additions & 1 deletion src/de/xite/scoreboard/listeners/JoinQuitListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.xite.scoreboard.listeners;

import java.util.ArrayList;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
Expand All @@ -8,6 +10,7 @@
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;
Expand Down Expand Up @@ -49,15 +52,28 @@ public void run() {
RankManager.register(p);

if(pl.getConfig().getBoolean("scoreboard"))
ScoreboardPlayer.setScoreboard(p, false);
ScoreboardPlayer.setScoreboard(p, false, null);

if(pl.getConfig().getBoolean("tablist.ranks"))
RankManager.setTablistRanks(p);

if(pl.getConfig().getBoolean("tablist.text"))
TablistPlayer.addPlayer(p, null);

PowerBoardAPI.setScoreboard(p, false, null);
PowerBoardAPI.setScoreboardTitle(p, "hey", false);
ArrayList<String> list = new ArrayList<>();
list.add("1");
list.add("2");
PowerBoardAPI.setScoreboardScores(p, list, false);
}
}, 3);
Bukkit.getScheduler().runTaskLater(pl, new Runnable() {
@Override
public void run() {
PowerBoardAPI.removeScoreboard(p);
}
}, 200);
}
@EventHandler
public void onQuit(PlayerQuitEvent e) {
Expand Down
31 changes: 19 additions & 12 deletions src/de/xite/scoreboard/main/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static void createDefaultScoreboard() {
+ "You can add as many animation steps as you like.\n\n"
+ "For every score (line) you can set a different speed.\n"
+ "You can set up to 14 scores. For that, just add a new number like \"'7':\"\n\n"
+ "If you have static scores (no animations or updates needed): Set the 'speed' value to '9999' or higher. Then the scheduler won't start to save performance.\n"
+ "If you have static scores (no animations or updates needed): Set the 'speed' value to '-1' or '9999' or higher. Then the scheduler won't start to save performance.\n"
+ "Note: Specify the speed in ticks, not seconds. 20 ticks = one second\n\n"
+ "To use multiple scoreboards, read this wiki: https://github.com/Xitee1/PowerBoard/wiki/Create-and-use-multiple-scoreboards\n";

Expand Down Expand Up @@ -265,7 +265,7 @@ private static void createScoreboardBlacklist() {
file.createNewFile();
YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file);
cfg.options().header("If the conditions match, no scoreboard will be displayed.\n"
+ "Here is explained what conditions there are and how to use them: https://github.com/Xitee1/PowerBoard/wiki/Create-and-use-multiple-scoreboards\n");
+ "Here is explained what conditions there are and how to use them: https://github.com/Xitee1/PowerBoard/wiki/Conditions\n");

ArrayList<String> list = new ArrayList<>();
list.add("world:disabled_sb_world");
Expand Down Expand Up @@ -399,29 +399,36 @@ public void run() {
reloadDelay = false;
}
}, 40);
// General config
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"config"+ChatColor.GRAY+"...");
Config.loadConfig();

// Scoreboards
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"scoreboards"+ChatColor.GRAY+"...");
ArrayList<Player> players = new ArrayList<Player>();
players.addAll(ScoreboardPlayer.players.keySet());
for(Player p : players)
ScoreboardPlayer.removeScoreboard(p, true);
ScoreboardManager.unregisterAllScoreboards();
if(PowerBoard.pl.getConfig().getBoolean("scoreboard")) {
s.sendMessage(PowerBoard.pr+ChatColor.GRAY+"Reloading "+ChatColor.YELLOW+"scoreboards"+ChatColor.GRAY+"...");
ArrayList<Player> players = new ArrayList<Player>();
players.addAll(ScoreboardPlayer.players.keySet());
for(Player p : players)
ScoreboardPlayer.removeScoreboard(p, true);
ScoreboardManager.unregisterAllScoreboards();
ScoreboardManager.registerAllScoreboards();
Bukkit.getScheduler().runTaskLater(pl, new Runnable() {
Bukkit.getScheduler().runTaskLaterAsynchronously(pl, new Runnable() {
@Override
public void run() {
for(Player all : Bukkit.getOnlinePlayers())
ScoreboardPlayer.setScoreboard(all, false);
ScoreboardPlayer.setScoreboard(all, false, null);
}
}, 5);
}
if(pl.getConfig().getBoolean("tablist.ranks")) {

// Ranks
boolean tabRanks = pl.getConfig().getBoolean("tablist.ranks");
if(tabRanks || PowerBoard.pl.getConfig().getBoolean("chat.ranks")) {
for(Player all : Bukkit.getOnlinePlayers()) {
Teams.removePlayer(all);
RankManager.register(all);
RankManager.setTablistRanks(all);
if(tabRanks)
RankManager.setTablistRanks(all);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/de/xite/scoreboard/main/PowerBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void run() {
RankManager.setTablistRanks(all);

if(pl.getConfig().getBoolean("scoreboard"))
ScoreboardPlayer.setScoreboard(all, false);
ScoreboardPlayer.setScoreboard(all, false, null);

if(pl.getConfig().getBoolean("tablist.text"))
TablistPlayer.addPlayer(all, null);
Expand Down
6 changes: 2 additions & 4 deletions src/de/xite/scoreboard/modules/board/ScoreboardManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private void importScores(YamlConfiguration cfg) {

// Check if the numbers are in the correct ordner and begin with 0
if(id != i) {
pl.getLogger().warning("Your scores of scoreboard "+name+" do not begin with 0 or have an incorrect order. Please check that the numbers begin with 0 (not 1) and are sequentially. This could cause problems with your scoreboard!");
pl.getLogger().warning("Your scores of scoreboard '"+name+"' do not begin with 0 or have an incorrect order. Please check that the numbers begin with 0 (not 1) and are sequentially. This could cause problems with your scoreboard!");
id = i;
}
i++;
Expand Down Expand Up @@ -256,12 +256,10 @@ public boolean accept(File f, String name) {
String s = files[i].getName();
boards.add(s.substring(0, s.lastIndexOf(".yml")));
}
new ScoreboardPlayer(); // prepare the scoreboard
for(String board : boards) {
pl.getLogger().info("Registering scoreboard "+board+".");
ScoreboardManager.get(board);
pl.getLogger().info("Registered scoreboard "+board+".");
}

}
public static void unregisterAllScoreboards() {
for(Iterator<ScoreboardManager> iterator = scoreboards.values().iterator(); iterator.hasNext();) {
Expand Down
23 changes: 12 additions & 11 deletions src/de/xite/scoreboard/modules/board/ScoreboardPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ public class ScoreboardPlayer {
public static HashMap<Player, String> players = new HashMap<>(); // Player; Scoreboard config file name

@SuppressWarnings("deprecation")
public static void setScoreboard(Player p, boolean API) {
public static void setScoreboard(Player p, boolean API, ScoreboardManager sm) {
Scoreboard board = p.getScoreboard();

// ---- Scoreboard ---- //
ScoreboardManager sm = null;
if(ConditionListener.checkConditions(p, Config.scoreboardBlacklistConditions)) {
removeScoreboard(p, false);
if(!API)
Expand All @@ -34,7 +33,8 @@ public static void setScoreboard(Player p, boolean API) {
return;
}
if(!API) {
sm = getMatchingScoreboard(p);
if(sm == null)
sm = getMatchingScoreboard(p);
if(sm == null)
return;
if(players.containsKey(p))
Expand All @@ -60,11 +60,6 @@ public static void setScoreboard(Player p, boolean API) {
obj.setDisplaySlot(DisplaySlot.SIDEBAR);

if(!API) {
if(sm == null)
sm = getMatchingScoreboard(p);
if(sm == null)
return;

if(players.containsKey(p)) {
if(players.get(p).equals("blacklisted")) {
players.remove(p);
Expand All @@ -80,13 +75,19 @@ public static void setScoreboard(Player p, boolean API) {
p.setScoreboard(board);

// Debug
if(PowerBoard.debug)
PowerBoard.pl.getLogger().info("Scoreboard set for player "+p.getName());
if(PowerBoard.debug) {
if(sm == null) {
PowerBoard.pl.getLogger().info("Custom scoreboard set for player "+p.getName());
}else {
PowerBoard.pl.getLogger().info("Scoreboard "+sm.getName()+" set for player "+p.getName());
}
}

}
public static void updateScoreboard(Player p) {
if(!players.containsKey(p))
return;
setScoreboard(p, false);
setScoreboard(p, false, null);
}
public static ScoreboardManager getMatchingScoreboard(Player p) {
/* Config syntax:
Expand Down

0 comments on commit cbcb98a

Please sign in to comment.