Skip to content

Commit

Permalink
only construct team manager if scoreboard is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmakila committed Aug 13, 2024
1 parent 00aeecb commit b464e95
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,18 @@
public abstract class TeamManager<P> {
protected final MiniMessage miniMessage = MiniMessage.miniMessage();
protected final List<Sorter> sorters = new ArrayList<>();
private final PlayerList playerList;
protected ScoreboardTeamConfigurationSection configuration;
protected final ScoreboardTeamConfigurationSection configuration;

public TeamManager(PlayerList playerList) {
this.playerList = playerList;
}

public void reload() {
this.configuration = this.playerList.configuration().scoreBoard().team();
this.configuration = playerList.configuration().scoreBoard().team();

this.sorters.clear();
SorterFactory sorterFactory = new SorterFactory(this.playerList);
SorterFactory sorterFactory = new SorterFactory(playerList);
this.configuration.sorters().forEach(unparsed -> {
Sorter sorter;
try {
sorter = sorterFactory.sorter(unparsed);
} catch (Exception ex) {
this.playerList.platform().logger().warn("Could not parse sorter {}", unparsed, ex);
playerList.platform().logger().warn("Could not parse sorter {}", unparsed, ex);
return;
}
this.sorters.add(sorter);
Expand All @@ -45,4 +39,9 @@ public void update(List<P> players) {
public abstract void sort();

public abstract void unregisterAllTeams();

public void shutdown() {
unregisterAllTeams();
this.sorters.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public LuckPermsSorter(SorterOrder order, Criteria criteria) {

try {
this.api = LuckPermsProvider.get();
} catch (IllegalStateException ignored) {
} catch (IllegalStateException | NoClassDefFoundError ignored) {
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,50 @@
public final class ScoreboardManager {
private final PlayerListPaper plugin;
private final Scoreboard scoreboard;
private final PaperTeamManager teamManager;
private PaperTeamManager teamManager;
private ScheduledFuture<?> updateScheduledFuture;
private ScoreboardConfigurationSection configuration;

public ScoreboardManager(PlayerListPaper plugin) {
this.plugin = plugin;
this.scoreboard = plugin.getServer().getScoreboardManager().getNewScoreboard();
this.teamManager = new PaperTeamManager(this.plugin, this.scoreboard);
}

public void reload() {
this.configuration = this.plugin.playerList().configuration().scoreBoard();

// Cancel update task
if (this.updateScheduledFuture != null) {
this.updateScheduledFuture.cancel(true);
}

this.teamManager.reload();
this.teamManager.unregisterAllTeams();
// Shutdown team manager
if (this.teamManager != null) {
this.teamManager.shutdown();
this.teamManager = null;
}

// Stop here if scoreboard is not enabled
if (!this.configuration.enabled()) {
return;
}

// Set everyone's scoreboard
List<Player> onlinePlayers = List.copyOf(this.plugin.getServer().getOnlinePlayers());
onlinePlayers.forEach(player -> player.setScoreboard(this.scoreboard));

// Construct team manager and sort right away
this.teamManager = new PaperTeamManager(this.plugin, this.scoreboard);
this.teamManager.sort();

// Start the update task
int updateInterval = this.plugin.playerList().configuration().placeholderRefreshInterval();
this.updateScheduledFuture = this.plugin.playerList().scheduledExecutor().scheduleAtFixedRate(() ->
this.plugin.onlinePlayers().thenAcceptAsync(
this::update,
this.plugin.playerList().scheduledExecutor()
), 0, updateInterval, TimeUnit.SECONDS
);

List<Player> onlinePlayers = List.copyOf(this.plugin.getServer().getOnlinePlayers());
onlinePlayers.forEach(player -> player.setScoreboard(this.scoreboard));

this.teamManager.sort();
}

public void register(Player player) {
Expand Down

0 comments on commit b464e95

Please sign in to comment.