Skip to content

Commit

Permalink
switch scoreboard provider
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonUden committed Apr 1, 2024
1 parent a581d05 commit b424310
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 72 deletions.
2 changes: 1 addition & 1 deletion MCTournamentSystem-Lobby/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ api-version: 1.13

authors: [Zeeraa, NovaUniverse]

depend: [NovaCore, HolographicDisplays, ProtocolLib, TitleAPI, TournamentSystem, Citizens]
depend: [NovaCore, DecentHolograms, ProtocolLib, TitleAPI, TournamentSystem, Citizens]
softdepent: [NovaCoreGameEngine]
loadbefore: [NovaGamesTarget]
6 changes: 3 additions & 3 deletions MCTournamentSystem-Lobby/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.9</version>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.8.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable;

import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;

import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.event.SpawnReason;
Expand All @@ -23,6 +22,7 @@
import net.zeeraa.novacore.commons.api.novauniverse.data.MojangPlayerProfile;
import net.zeeraa.novacore.commons.log.Log;
import net.zeeraa.novacore.commons.tasks.Task;
import net.zeeraa.novacore.commons.utils.ListUtils;
import net.zeeraa.novacore.spigot.module.ModuleManager;
import net.zeeraa.novacore.spigot.module.NovaModule;
import net.zeeraa.novacore.spigot.module.annotations.NovaAutoLoad;
Expand Down Expand Up @@ -123,7 +123,7 @@ public void onDisable() throws Exception {
this.config.getNpcs().clear();
}
}

public void updateUsernames() {
toUpdate.clear();
cachedResults.forEach(tournamentResult -> {
Expand All @@ -138,7 +138,7 @@ public void init(HallOfFameConfig config) {
this.initialized = true;
this.debug = config.isDebug();

nameHologram = HologramsAPI.createHologram(getPlugin(), config.getNameHologramLocation().toBukkitLocation(Lobby.getInstance().getWorld()));
nameHologram = DHAPI.createHologram(UUID.randomUUID().toString(), config.getNameHologramLocation().toBukkitLocation(Lobby.getInstance().getWorld()), false);

updateData();

Expand All @@ -161,8 +161,8 @@ public void showNext() {
Log.debug("HallOfFame", "NPC count: " + config.getNpcs().size());
Log.debug("HallOfFame", "Player count: " + top.getPlayers().size());
}
nameHologram.clearLines();
nameHologram.appendTextLine(ChatColor.GREEN + tournamentResult.getDisplayName());

DHAPI.setHologramLines(nameHologram, ListUtils.createList(ChatColor.GREEN + tournamentResult.getDisplayName()));

for (int i = 0; i < config.getNpcs().size(); i++) {
HallOfFameNPC npc = config.getNpcs().get(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -31,10 +32,8 @@
import org.bukkit.scheduler.BukkitRunnable;
import org.json.JSONObject;

import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;

import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
Expand Down Expand Up @@ -255,6 +254,8 @@ public void run() {
if (kotlHologram != null) {
int line = 1;

List<String> lines = new ArrayList<String>();
lines.add(ChatColor.GREEN + "" + ChatColor.BOLD + "Top KOTL Players");
for (KingOfTheLadderScore score : kotlScore.stream().sorted(kingOfTheLadderScoreComparator).limit(kotlHologramLines).collect(Collectors.toList())) {
net.md_5.bungee.api.ChatColor color = net.md_5.bungee.api.ChatColor.AQUA;
if (TeamManager.hasTeamManager()) {
Expand All @@ -263,18 +264,19 @@ public void run() {
color = team.getTeamColor();
}
}
((TextLine) kotlHologram.getLine(line)).setText(color + score.getName() + ChatColor.WHITE + " : " + ChatColor.AQUA + score.getScore());
lines.add(color + score.getName() + ChatColor.WHITE + " : " + ChatColor.AQUA + score.getScore());
line++;
}

for (; line <= kotlHologramLines; line++) {
((TextLine) kotlHologram.getLine(line)).setText(ChatColor.GRAY + "Empty");
lines.add(ChatColor.GRAY + "Empty");
}
/*
* while (kotlHologram.size() - 1 < kotlHologramLines) {
* kotlHologram.getLine(kotlHologramLines)
* kotlHologram.appendTextLine(ChatColor.GRAY + "Empty"); }
*/
DHAPI.setHologramLines(kotlHologram, lines);
}
}
}, 20L);
Expand Down Expand Up @@ -418,12 +420,13 @@ public void setKOTLHologramLines(int kotlHologramLines) {

public void setupKOTLHologram(XYZLocation location, int lines) {
Location hologramLocation = location.toBukkitLocation(getWorld());
this.kotlHologram = HologramsAPI.createHologram(getPlugin(), hologramLocation);

kotlHologram.appendTextLine(ChatColor.GREEN + "" + ChatColor.BOLD + "Top KOTL Players");
this.kotlHologram = DHAPI.createHologram(UUID.randomUUID().toString(), hologramLocation, false);
List<String> content = new ArrayList<String>();
content.add(ChatColor.GREEN + "" + ChatColor.BOLD + "Top KOTL Players");
for (int i = 0; i < lines; i++) {
kotlHologram.appendTextLine(ChatColor.DARK_GRAY + "Empty");
content.add(ChatColor.DARK_GRAY + "Empty");
}
DHAPI.setHologramLines(kotlHologram, content);
}

private boolean isInKOTLArena(Entity entity) {
Expand Down Expand Up @@ -632,7 +635,7 @@ public void onWinnerChange(WinnerChangeEvent e) {
Log.info("Lobby", "Updating winner holograms");
if (e.getNewValue() == -1) {
displayedWinnerString = null;
winnerHolograms.forEach(h -> h.getVisibilityManager().setVisibleByDefault(false));
winnerHolograms.forEach(h -> h.setDefaultVisibleState(false));
} else {
WrappedString teamName = new WrappedString("null");
WrappedString members = new WrappedString("null");
Expand All @@ -649,11 +652,13 @@ public void onWinnerChange(WinnerChangeEvent e) {

displayedWinnerString = winnerString;

List<String> lines = new ArrayList<String>();
lines.add(winnerString);
lines.add(members.get());

winnerHolograms.forEach(h -> {
h.clearLines();
h.appendTextLine(winnerString);
h.appendTextLine(members.get());
h.getVisibilityManager().setVisibleByDefault(true);
DHAPI.setHologramLines(h, lines);
h.setDefaultVisibleState(true);
});
}
}
Expand All @@ -663,8 +668,11 @@ public void clearKOTLScore() {
}

public void addWinnerHologram(XYZLocation location) {
Hologram hologram = HologramsAPI.createHologram(getPlugin(), location.toBukkitLocation(getWorld()));
hologram.getVisibilityManager().setVisibleByDefault(false);
Hologram hologram = DHAPI.createHologram(UUID.randomUUID().toString(), location.toBukkitLocation(getWorld()), false);
hologram.setDefaultVisibleState(false);
// Hologram hologram = HologramsAPI.createHologram(getPlugin(),
// location.toBukkitLocation(getWorld()));
// hologram.getVisibilityManager().setVisibleByDefault(false);
winnerHolograms.add(hologram);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package net.novauniverse.mctournamentsystem.lobby.modules.scoreboard;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import com.gmail.filoghost.holographicdisplays.api.Hologram;
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
import com.gmail.filoghost.holographicdisplays.api.line.TextLine;

import eu.decentsoftware.holograms.api.DHAPI;
import eu.decentsoftware.holograms.api.holograms.Hologram;
import net.novauniverse.mctournamentsystem.lobby.TournamentSystemLobby;
import net.novauniverse.mctournamentsystem.spigot.TournamentSystem;
import net.novauniverse.mctournamentsystem.spigot.score.PlayerScoreData;
import net.novauniverse.mctournamentsystem.spigot.score.TeamScoreData;
import net.novauniverse.mctournamentsystem.spigot.score.TopScore;
Expand Down Expand Up @@ -69,61 +69,47 @@ public void onDisable() {
}

if (teamHologram != null) {
teamHologram.clearLines();
teamHologram.delete();
}

if (playerHologram != null) {
playerHologram.clearLines();
playerHologram.delete();
}
}

public void update() {
if (playerHologram != null) {
int lineIndex = 0;

if (playerHologram.size() <= lineIndex) {
playerHologram.appendTextLine(ChatColor.GREEN + "" + ChatColor.BOLD + "Top player scores");
}

List<String> content = new ArrayList<String>();

content.add(ChatColor.GREEN + "" + ChatColor.BOLD + "Top player scores");

List<PlayerScoreData> scores = TopScore.getPlayerTopScore(lines);

int lineIndex = 0;
for (PlayerScoreData scoreData : scores) {
lineIndex++;

if (playerHologram.size() <= lineIndex) {
playerHologram.appendTextLine("-----------");
}
((TextLine) playerHologram.getLine(lineIndex)).setText(ChatColor.YELLOW + "" + lineIndex + ChatColor.GOLD + " : " + scoreData.toString());
content.add(ChatColor.YELLOW + "" + lineIndex + ChatColor.GOLD + " : " + scoreData.toString());
}

while (playerHologram.size() > lineIndex + 1) {
playerHologram.removeLine(playerHologram.size() - 1);
}
DHAPI.setHologramLines(playerHologram, content);
}

if (TeamManager.hasTeamManager()) {
if (teamHologram != null) {
List<String> content = new ArrayList<String>();

content.add(ChatColor.GREEN + "" + ChatColor.BOLD + "Top team scores");

int lineIndex = 0;

if (teamHologram.size() <= lineIndex) {
teamHologram.appendTextLine(ChatColor.GREEN + "" + ChatColor.BOLD + "Top team scores");
}

List<TeamScoreData> scores = TopScore.getTeamTopScore(lines);

for (TeamScoreData scoreData : scores) {
lineIndex++;

if (teamHologram.size() <= lineIndex) {
teamHologram.appendTextLine("-----------");
}
((TextLine) teamHologram.getLine(lineIndex)).setText(ChatColor.YELLOW + "" + lineIndex + ChatColor.GOLD + " : " + scoreData.toString());
content.add(ChatColor.YELLOW + "" + lineIndex + ChatColor.GOLD + " : " + scoreData.toString());
}

while (teamHologram.size() > lineIndex + 1) {
teamHologram.removeLine(teamHologram.size() - 1);
}
DHAPI.setHologramLines(teamHologram, content);
}
}
}
Expand All @@ -133,15 +119,15 @@ public void setTeamHologramLocation(Location location) {
teamHologram.delete();
}

teamHologram = HologramsAPI.createHologram(TournamentSystem.getInstance(), location);
teamHologram = DHAPI.createHologram(UUID.randomUUID().toString(), location, false); // HologramsAPI.createHologram(TournamentSystem.getInstance(), location);
}

public void setPlayerHologramLocation(Location location) {
if (playerHologram != null) {
playerHologram.delete();
}

playerHologram = HologramsAPI.createHologram(TournamentSystem.getInstance(), location);
playerHologram = DHAPI.createHologram(UUID.randomUUID().toString(), location, false); // HologramsAPI.createHologram(TournamentSystem.getInstance(), location);
}

public int getLines() {
Expand Down
2 changes: 1 addition & 1 deletion MCTournamentSystem-MissilewarsLobby/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ api-version: 1.13

authors: [Zeeraa, NovaUniverse]

depend: [NovaCore, HolographicDisplays, ProtocolLib, TitleAPI, NovaMissileWars]
depend: [NovaCore, DecentHolograms, ProtocolLib, TitleAPI, NovaMissileWars]
softdepent: [NovaCoreGameEngine]
loadbefore: [NovaGamesTarget]
9 changes: 5 additions & 4 deletions MCTournamentSystem-MissilewarsLobby/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
</repository>
<repository>
<id>novauniverse-thirdparty</id>
<url>https://nexus2.novauniverse.net/repository/third-party-proxy-group/</url>
<url>
https://nexus2.novauniverse.net/repository/third-party-proxy-group/</url>
</repository>
<repository>
<id>jitpack.io</id>
Expand Down Expand Up @@ -90,9 +91,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.6</version>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.8.6</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
Expand Down
4 changes: 2 additions & 2 deletions MCTournamentSystem-Spigot/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ api-version: 1.13

authors: [Zeeraa, NovaUniverse]

depend: [NovaCore, HolographicDisplays, ProtocolLib, TitleAPI, LuckPerms, Citizens, NoteBlockAPI, spark]
depend: [NovaCore, DecentHolograms, ProtocolLib, TitleAPI, LuckPerms, Citizens, NoteBlockAPI, spark]
softdepend: [NovaCoreGameEngine, LabyApi, ItemsAdder, AdvancedGUI, CosmeticSystem, LabyApi]
loadbefore: [NovaGamesTarget, NovaSurvivalGames, ChickenOut, HolographicPlaceholders]
loadbefore: [NovaGamesTarget, NovaSurvivalGames, ChickenOut]

permissions:
tournamentsystem.staff:
Expand Down
6 changes: 3 additions & 3 deletions MCTournamentSystem-Spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
<artifactId>holographicdisplays-api</artifactId>
<version>2.4.6</version>
<groupId>com.github.decentsoftware-eu</groupId>
<artifactId>decentholograms</artifactId>
<version>2.8.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down

0 comments on commit b424310

Please sign in to comment.