Skip to content

Commit

Permalink
Add enable/disable scoreboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelillo15 committed Dec 21, 2023
1 parent 723541d commit b24ec4d
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import com.google.inject.Inject;
import com.nookure.mast.api.config.bukkit.ScoreboardConfig;
import com.nookure.mast.api.event.EventManager;
import com.nookure.mast.api.event.staff.freeze.PlayerFreezeEvent;
import com.nookure.mast.api.event.staff.freeze.PlayerUnfreezeEvent;
Expand Down Expand Up @@ -36,12 +37,15 @@

import java.io.File;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import javax.annotation.Nullable;

import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import lombok.val;
import net.megavex.scoreboardlibrary.api.ScoreboardLibrary;
import net.megavex.scoreboardlibrary.api.sidebar.Sidebar;
import org.bukkit.*;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
Expand All @@ -66,6 +70,11 @@ public class StaffPlayer implements IStaffPlayer {
private EventManager eventManager;
@Inject
private FreezeManager freezeManager;
@Inject
private ScoreboardConfig scoreboardConfig;
@Inject
private ScoreboardLibrary sbLib;
private Sidebar sidebar;

private final Map<String, StaffItem> items = new HashMap<>();
@Getter
Expand Down Expand Up @@ -167,6 +176,7 @@ public void disableStaffMode() {
}
Bukkit.getPluginManager().callEvent(new StaffDisableEvent(this));
disableStaffFeatures();
disableScoreboard();
eventManager.fireEvent(new StaffModeDisabledEvent(this));
}

Expand All @@ -191,6 +201,7 @@ public void enableStaffMode(boolean saveInventory) {
staffModeAsyncInventoryChecker();
Bukkit.getPluginManager().callEvent(new StaffEnableEvent(this));
enableStaffFeatures();
enableScoreboard();
eventManager.fireEvent(new StaffModeEnabledEvent(this));
}

Expand Down Expand Up @@ -621,4 +632,34 @@ public void disableStaffFeatures() {
}
});
}

public void enableScoreboard() {
if (!scoreboardConfig.enabled()) return;
if (sbLib == null) return;
if (sidebar != null) return;

sidebar = sbLib.createSidebar();

sidebar.title(TextUtils.toComponent(scoreboardConfig.scoreboard.title()));

AtomicInteger i = new AtomicInteger();

scoreboardConfig.scoreboard.lines().forEach(line -> {
sidebar.line(i.get(), TextUtils.toComponent(TextUtils.processPlaceholders(player, line)));

i.getAndIncrement();
});

sidebar.addPlayer(player);
}

public void disableScoreboard() {
if (!scoreboardConfig.enabled()) return;
if (sbLib == null) return;
if (sidebar == null) return;

sidebar.removePlayer(player);
sidebar.close();
sidebar = null;
}
}

0 comments on commit b24ec4d

Please sign in to comment.