From ede927da9ade2399399eab7142dc1cfff9446d2b Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Sun, 29 Nov 2020 16:44:08 -0500 Subject: [PATCH 1/9] yasy --- pom.xml | 14 ++++++++ .../lib/scoreboard/type/SimpleScoreboard.java | 33 ++++++++++++++----- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 295a251..859a2e0 100644 --- a/pom.xml +++ b/pom.xml @@ -60,4 +60,18 @@ + + + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT + provided + + diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java index b864c1b..46b2e31 100755 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java @@ -4,6 +4,7 @@ import com.google.common.collect.Table; import me.tigerhix.lib.scoreboard.ScoreboardLib; import me.tigerhix.lib.scoreboard.common.Strings; +import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -36,6 +37,7 @@ public class SimpleScoreboard implements Scoreboard { private Map entryCache = new ConcurrentHashMap<>(); private Table playerCache = HashBasedTable.create(); private Table teamCache = HashBasedTable.create(); + private Map previousEntries = new HashMap<>(); private BukkitRunnable updateTask; public SimpleScoreboard(Player holder) { @@ -143,9 +145,10 @@ private void update() { if (!appeared.containsKey(appearance)) appeared.put(appearance, -1); appeared.put(appearance, appeared.get(appearance) + 1); // Get fake player - FakePlayer faker = getFakePlayer(key, appeared.get(appearance)); + FakePlayer faker = getFakePlayer(key, appeared.get(appearance), score); // Set score - objective.getScore(faker).setScore(score); + //if(objective.getScore(faker).getScore() != score) + //objective.getScore(faker).setScore(score); // Update references entryCache.put(faker, score); current.put(faker, score); @@ -155,13 +158,14 @@ private void update() { for (FakePlayer fakePlayer : entryCache.keySet()) { if (!current.containsKey(fakePlayer)) { entryCache.remove(fakePlayer); - scoreboard.resetScores(fakePlayer.getName()); + Bukkit.broadcastMessage(objective.getScore(fakePlayer).getScore() + " updated: " + MinecraftServer.currentTick); + //scoreboard.resetScores(fakePlayer.getName()); } } } @SuppressWarnings("deprecation") - private FakePlayer getFakePlayer(String text, int offset) { + private FakePlayer getFakePlayer(String text, int offset, int score) { Team team = null; String name; // If the text has a length less than 16, teams need not to be be created @@ -177,17 +181,28 @@ private FakePlayer getFakePlayer(String text, int offset) { if (name.length() > 16) name = name.substring(0, 16); if (text.length() > 32) suffix = text.substring(32 - offset); // If teams already exist, use them - for (Team other : teamCache.rowKeySet()) { - if (other.getPrefix().equals(prefix) && other.getSuffix().equals(suffix)) { - team = other; - } - } + + team = scoreboard.getTeam(TEAM_PREFIX + score); // Otherwise create them if (team == null) { team = scoreboard.registerNewTeam(TEAM_PREFIX + TEAM_COUNTER++); team.setPrefix(prefix); team.setSuffix(suffix); teamCache.put(team, prefix, suffix); + } else { + if(objective.getScore(TEAM_PREFIX + score).getScore() != score) { + objective.getScore(TEAM_PREFIX + score).setScore(score); + } + team.setPrefix(prefix); + team.setSuffix(suffix); + team.setDisplayName(name); + if(!team.getName().equals(name)) { + scoreboard.resetScores(team.getName()); + team.removeEntry(team.getName()); + if(!team.hasEntry(team.getName())) + team.addEntry(team.getName()); + } + teamCache.put(team, prefix, suffix); } } FakePlayer faker; From 2802d32d3b65b4c4235bf741e48d010256a0fedf Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Fri, 19 Mar 2021 11:52:38 -0400 Subject: [PATCH 2/9] Update pom.xml --- pom.xml | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 859a2e0..0476512 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,16 @@ tiger-repo http://repo.tigerhix.me/content/groups/public/ + + funkemunky-releases + https://nexus.funkemunky.cc/content/repositories/releases/ + - nexus - http://repo.tigerhix.me/content/repositories/snapshots + funkemunky-snapshots + https://nexus.funkemunky.cc/content/repositories/snapshots @@ -57,21 +61,29 @@ true + + maven-deploy-plugin + 2.8.2 + + + snapshot-deploy + deploy + + deploy + + + + - org.spigotmc - spigot - 1.8.8-R0.1-SNAPSHOT - provided - - - org.spigotmc - spigot-api - 1.8.8-R0.1-SNAPSHOT + org.github.spigot + 1.8.8 + 1.8.8 provided + From 976c81ad1990a05552e985c883eceb5abc142e0c Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Fri, 19 Mar 2021 11:57:40 -0400 Subject: [PATCH 3/9] Revert "Update pom.xml" This reverts commit 2802d32d3b65b4c4235bf741e48d010256a0fedf. --- pom.xml | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 0476512..859a2e0 100644 --- a/pom.xml +++ b/pom.xml @@ -21,16 +21,12 @@ tiger-repo http://repo.tigerhix.me/content/groups/public/ - - funkemunky-releases - https://nexus.funkemunky.cc/content/repositories/releases/ - - funkemunky-snapshots - https://nexus.funkemunky.cc/content/repositories/snapshots + nexus + http://repo.tigerhix.me/content/repositories/snapshots @@ -61,29 +57,21 @@ true - - maven-deploy-plugin - 2.8.2 - - - snapshot-deploy - deploy - - deploy - - - - - org.github.spigot - 1.8.8 - 1.8.8 + org.spigotmc + spigot + 1.8.8-R0.1-SNAPSHOT + provided + + + org.spigotmc + spigot-api + 1.8.8-R0.1-SNAPSHOT provided - From af9e232ec65bfab26d732b5671972464cf481c09 Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Fri, 19 Mar 2021 11:57:43 -0400 Subject: [PATCH 4/9] Revert "Revert "Update pom.xml"" This reverts commit 976c81ad1990a05552e985c883eceb5abc142e0c. --- pom.xml | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 859a2e0..0476512 100644 --- a/pom.xml +++ b/pom.xml @@ -21,12 +21,16 @@ tiger-repo http://repo.tigerhix.me/content/groups/public/ + + funkemunky-releases + https://nexus.funkemunky.cc/content/repositories/releases/ + - nexus - http://repo.tigerhix.me/content/repositories/snapshots + funkemunky-snapshots + https://nexus.funkemunky.cc/content/repositories/snapshots @@ -57,21 +61,29 @@ true + + maven-deploy-plugin + 2.8.2 + + + snapshot-deploy + deploy + + deploy + + + + - org.spigotmc - spigot - 1.8.8-R0.1-SNAPSHOT - provided - - - org.spigotmc - spigot-api - 1.8.8-R0.1-SNAPSHOT + org.github.spigot + 1.8.8 + 1.8.8 provided + From 6131b441b12a54d851e9fbc3d20389f8225afdaf Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Fri, 19 Mar 2021 12:07:34 -0400 Subject: [PATCH 5/9] Updating repository in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0a254e7..be74f70 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ How do I add it to my project? Simply add the following to your `pom.xml`. - tiger-repo - http://repo.tigerhix.me/content/repositories/snapshots/ + funkemunky-snapshots + https://nexus.funkemunky.cc/content/repositories/snapshots From b59291e1e771bf8d7664aba4d5dd05dd3be2a7c9 Mon Sep 17 00:00:00 2001 From: Dawson Hessler Date: Wed, 2 Jun 2021 12:02:06 -0400 Subject: [PATCH 6/9] Update SimpleScoreboard.java --- .../lib/scoreboard/type/SimpleScoreboard.java | 33 +++++-------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java index 46b2e31..b864c1b 100755 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java @@ -4,7 +4,6 @@ import com.google.common.collect.Table; import me.tigerhix.lib.scoreboard.ScoreboardLib; import me.tigerhix.lib.scoreboard.common.Strings; -import net.minecraft.server.v1_8_R3.MinecraftServer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; @@ -37,7 +36,6 @@ public class SimpleScoreboard implements Scoreboard { private Map entryCache = new ConcurrentHashMap<>(); private Table playerCache = HashBasedTable.create(); private Table teamCache = HashBasedTable.create(); - private Map previousEntries = new HashMap<>(); private BukkitRunnable updateTask; public SimpleScoreboard(Player holder) { @@ -145,10 +143,9 @@ private void update() { if (!appeared.containsKey(appearance)) appeared.put(appearance, -1); appeared.put(appearance, appeared.get(appearance) + 1); // Get fake player - FakePlayer faker = getFakePlayer(key, appeared.get(appearance), score); + FakePlayer faker = getFakePlayer(key, appeared.get(appearance)); // Set score - //if(objective.getScore(faker).getScore() != score) - //objective.getScore(faker).setScore(score); + objective.getScore(faker).setScore(score); // Update references entryCache.put(faker, score); current.put(faker, score); @@ -158,14 +155,13 @@ private void update() { for (FakePlayer fakePlayer : entryCache.keySet()) { if (!current.containsKey(fakePlayer)) { entryCache.remove(fakePlayer); - Bukkit.broadcastMessage(objective.getScore(fakePlayer).getScore() + " updated: " + MinecraftServer.currentTick); - //scoreboard.resetScores(fakePlayer.getName()); + scoreboard.resetScores(fakePlayer.getName()); } } } @SuppressWarnings("deprecation") - private FakePlayer getFakePlayer(String text, int offset, int score) { + private FakePlayer getFakePlayer(String text, int offset) { Team team = null; String name; // If the text has a length less than 16, teams need not to be be created @@ -181,28 +177,17 @@ private FakePlayer getFakePlayer(String text, int offset, int score) { if (name.length() > 16) name = name.substring(0, 16); if (text.length() > 32) suffix = text.substring(32 - offset); // If teams already exist, use them - - team = scoreboard.getTeam(TEAM_PREFIX + score); + for (Team other : teamCache.rowKeySet()) { + if (other.getPrefix().equals(prefix) && other.getSuffix().equals(suffix)) { + team = other; + } + } // Otherwise create them if (team == null) { team = scoreboard.registerNewTeam(TEAM_PREFIX + TEAM_COUNTER++); team.setPrefix(prefix); team.setSuffix(suffix); teamCache.put(team, prefix, suffix); - } else { - if(objective.getScore(TEAM_PREFIX + score).getScore() != score) { - objective.getScore(TEAM_PREFIX + score).setScore(score); - } - team.setPrefix(prefix); - team.setSuffix(suffix); - team.setDisplayName(name); - if(!team.getName().equals(name)) { - scoreboard.resetScores(team.getName()); - team.removeEntry(team.getName()); - if(!team.hasEntry(team.getName())) - team.addEntry(team.getName()); - } - teamCache.put(team, prefix, suffix); } } FakePlayer faker; From a34a867d3738e6cc44014820692bc727c180afd4 Mon Sep 17 00:00:00 2001 From: Dawson Date: Mon, 30 Dec 2024 15:31:50 -0500 Subject: [PATCH 7/9] Updated --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 0476512..3b31b9c 100644 --- a/pom.xml +++ b/pom.xml @@ -49,10 +49,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.0 + 3.13.0 - 1.7 - 1.7 + 17 + 17 -Xlint:all -Xlint:-path @@ -63,7 +63,7 @@ maven-deploy-plugin - 2.8.2 + 3.1.3 snapshot-deploy From 13e34ae14a895e21d9098ab4a1efaa6810fedd94 Mon Sep 17 00:00:00 2001 From: Dawson Date: Mon, 9 Jun 2025 09:53:31 -0400 Subject: [PATCH 8/9] Making function on 1.19 --- pom.xml | 22 ++-- .../lib/scoreboard/type/SimpleScoreboard.java | 121 +++++++++++++++++- 2 files changed, 128 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 3b31b9c..3113c62 100644 --- a/pom.xml +++ b/pom.xml @@ -17,14 +17,14 @@ - - tiger-repo - http://repo.tigerhix.me/content/groups/public/ - funkemunky-releases https://nexus.funkemunky.cc/content/repositories/releases/ + + papermc + https://repo.papermc.io/repository/maven-public/ + @@ -63,7 +63,7 @@ maven-deploy-plugin - 3.1.3 + 3.1.4 snapshot-deploy @@ -79,9 +79,15 @@ - org.github.spigot - 1.8.8 - 1.8.8 + io.papermc.paper + paper-api + 1.19.4-R0.1-SNAPSHOT + provided + + + org.github.paperspigot + 1.19.4 + 1.19.4 provided diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java index b864c1b..5db3dea 100755 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java @@ -1,18 +1,19 @@ package me.tigerhix.lib.scoreboard.type; +import com.destroystokyo.paper.profile.PlayerProfile; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Table; import me.tigerhix.lib.scoreboard.ScoreboardLib; import me.tigerhix.lib.scoreboard.common.Strings; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.OfflinePlayer; +import org.bukkit.*; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.List; @@ -265,12 +266,13 @@ public UUID getUniqueId() { } @Override - public boolean isBanned() { - return false; + public @NotNull PlayerProfile getPlayerProfile() { + return null; } @Override - public void setBanned(boolean banned) { + public boolean isBanned() { + return false; } @Override @@ -307,6 +309,111 @@ public Location getBedSpawnLocation() { return null; } + @Override + public long getLastLogin() { + return 0; + } + + @Override + public long getLastSeen() { + return 0; + } + + @Override + public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { + + } + + @Override + public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { + + } + + @Override + public void incrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { + + } + + @Override + public void decrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { + + } + + @Override + public void setStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { + + } + + @Override + public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { + return 0; + } + + @Override + public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { + + } + + @Override + public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { + + } + + @Override + public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { + return 0; + } + + @Override + public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { + + } + + @Override + public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { + + } + + @Override + public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { + + } + + @Override + public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { + + } + + @Override + public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { + + } + + @Override + public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { + return 0; + } + + @Override + public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) throws IllegalArgumentException { + + } + + @Override + public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { + + } + + @Override + public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { + + } + + @Override + public @Nullable Location getLastDeathLocation() { + return null; + } + @Override public Map serialize() { return null; From dc99c375f65cfd9f2f05f0900b37b3b4b984aff2 Mon Sep 17 00:00:00 2001 From: Dawson Date: Tue, 10 Jun 2025 09:38:21 -0400 Subject: [PATCH 9/9] Updated for 1.19 --- pom.xml | 2 +- .../tigerhix/lib/scoreboard/type/Entry.java | 11 +- .../lib/scoreboard/type/SimpleScoreboard.java | 348 +++--------------- 3 files changed, 57 insertions(+), 304 deletions(-) diff --git a/pom.xml b/pom.xml index 3113c62..f0c8899 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.tigerhix.lib scoreboard - 1.0.1-SNAPSHOT + 1.1.0-SNAPSHOT jar diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/Entry.java b/src/main/java/me/tigerhix/lib/scoreboard/type/Entry.java index 6c04a2b..4268730 100644 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/Entry.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/Entry.java @@ -1,22 +1,23 @@ package me.tigerhix.lib.scoreboard.type; -import me.tigerhix.lib.scoreboard.common.Strings; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; public class Entry { - private String name; + private TextComponent name; private int position; public Entry(String name, int position) { - this.name = Strings.format(name); + this.name = LegacyComponentSerializer.legacySection().deserialize(name); this.position = position; } - public String getName() { + public TextComponent getName() { return name; } - public void setName(String name) { + public void setName(TextComponent name) { this.name = name; } diff --git a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java index 5db3dea..2373ab2 100755 --- a/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java +++ b/src/main/java/me/tigerhix/lib/scoreboard/type/SimpleScoreboard.java @@ -1,31 +1,22 @@ package me.tigerhix.lib.scoreboard.type; -import com.destroystokyo.paper.profile.PlayerProfile; -import com.google.common.collect.HashBasedTable; -import com.google.common.collect.Table; import me.tigerhix.lib.scoreboard.ScoreboardLib; import me.tigerhix.lib.scoreboard.common.Strings; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; import org.bukkit.*; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Team; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; public class SimpleScoreboard implements Scoreboard { - private static final String TEAM_PREFIX = "Scoreboard_"; - private static int TEAM_COUNTER = 0; - private final org.bukkit.scoreboard.Scoreboard scoreboard; private final Objective objective; @@ -34,9 +25,8 @@ public class SimpleScoreboard implements Scoreboard { private boolean activated; private ScoreboardHandler handler; - private Map entryCache = new ConcurrentHashMap<>(); - private Table playerCache = HashBasedTable.create(); - private Table teamCache = HashBasedTable.create(); + // We use a map to track teams by line number for easy updating. + private final Map teams = new HashMap<>(); private BukkitRunnable updateTask; public SimpleScoreboard(Player holder) { @@ -75,7 +65,7 @@ public void deactivate() { } } // Unregister teams that are created for this scoreboard - for (Team team : teamCache.rowKeySet()) { + for (Team team : teams.values()) { team.unregister(); } // Stop updating @@ -127,88 +117,15 @@ private void update() { if (!objective.getDisplayName().equals(finalTitle)) objective.setDisplayName(Strings.format(finalTitle)); // Entries List passed = handler.getEntries(holder); - Map appeared = new HashMap<>(); - Map current = new HashMap<>(); if (passed == null) return; for (Entry entry : passed) { // Handle the entry - String key = entry.getName(); - Integer score = entry.getPosition(); - if (key.length() > 48) key = key.substring(0, 47); - String appearance; - if (key.length() > 16) { - appearance = key.substring(16); - } else { - appearance = key; - } - if (!appeared.containsKey(appearance)) appeared.put(appearance, -1); - appeared.put(appearance, appeared.get(appearance) + 1); - // Get fake player - FakePlayer faker = getFakePlayer(key, appeared.get(appearance)); - // Set score - objective.getScore(faker).setScore(score); - // Update references - entryCache.put(faker, score); - current.put(faker, score); - } - appeared.clear(); - // Remove duplicated or non-existent entries - for (FakePlayer fakePlayer : entryCache.keySet()) { - if (!current.containsKey(fakePlayer)) { - entryCache.remove(fakePlayer); - scoreboard.resetScores(fakePlayer.getName()); - } - } - } + TextComponent key = entry.getName(); + int score = entry.getPosition(); - @SuppressWarnings("deprecation") - private FakePlayer getFakePlayer(String text, int offset) { - Team team = null; - String name; - // If the text has a length less than 16, teams need not to be be created - if (text.length() <= 16) { - name = text + Strings.repeat(" ", offset); - } else { - String prefix; - String suffix = ""; - offset++; - // Otherwise, iterate through the string and cut off prefix and suffix - prefix = text.substring(0, 16 - offset); - name = text.substring(16 - offset); - if (name.length() > 16) name = name.substring(0, 16); - if (text.length() > 32) suffix = text.substring(32 - offset); - // If teams already exist, use them - for (Team other : teamCache.rowKeySet()) { - if (other.getPrefix().equals(prefix) && other.getSuffix().equals(suffix)) { - team = other; - } - } - // Otherwise create them - if (team == null) { - team = scoreboard.registerNewTeam(TEAM_PREFIX + TEAM_COUNTER++); - team.setPrefix(prefix); - team.setSuffix(suffix); - teamCache.put(team, prefix, suffix); - } - } - FakePlayer faker; - if (!playerCache.contains(name, offset)) { - faker = new FakePlayer(name, team, offset); - playerCache.put(name, offset, faker); - if (faker.getTeam() != null) { - faker.getTeam().addPlayer(faker); - } - } else { - faker = playerCache.get(name, offset); - if (team != null && faker.getTeam() != null) { - faker.getTeam().removePlayer(faker); - } - faker.setTeam(team); - if (faker.getTeam() != null) { - faker.getTeam().addPlayer(faker); - } + setLine(score, key); + // Update references } - return faker; } public Objective getObjective() { @@ -219,223 +136,58 @@ public org.bukkit.scoreboard.Scoreboard getScoreboard() { return scoreboard; } - private static class FakePlayer implements OfflinePlayer { - - private final String name; - - private Team team; - private int offset; - - FakePlayer(String name, Team team, int offset) { - this.name = name; - this.team = team; - this.offset = offset; - } - - public Team getTeam() { - return team; - } - - public void setTeam(Team team) { - this.team = team; - } - - public int getOffset() { - return offset; - } - - public String getFullName() { - if (team == null) return name; - if (team.getSuffix() == null) return team.getPrefix() + name; - return team.getPrefix() + name + team.getSuffix(); - } - - @Override - public boolean isOnline() { - return true; - } - - @Override - public String getName() { - return name; - } - - @Override - public UUID getUniqueId() { - return UUID.randomUUID(); - } - - @Override - public @NotNull PlayerProfile getPlayerProfile() { - return null; - } - - @Override - public boolean isBanned() { - return false; - } - - @Override - public boolean isWhitelisted() { - return false; - } - - @Override - public void setWhitelisted(boolean whitelisted) { - } - - @Override - public Player getPlayer() { - return null; - } - - @Override - public long getFirstPlayed() { - return 0; - } - - @Override - public long getLastPlayed() { - return 0; - } - - @Override - public boolean hasPlayedBefore() { - return false; - } - - @Override - public Location getBedSpawnLocation() { - return null; - } - - @Override - public long getLastLogin() { - return 0; - } - - @Override - public long getLastSeen() { - return 0; - } - @Override - public void incrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - - } - - @Override - public void setStatistic(@NotNull Statistic statistic, int i) throws IllegalArgumentException { - - } - - @Override - public int getStatistic(@NotNull Statistic statistic) throws IllegalArgumentException { - return 0; - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - - } - - @Override - public int getStatistic(@NotNull Statistic statistic, @NotNull Material material) throws IllegalArgumentException { - return 0; - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { - - } - - @Override - public void setStatistic(@NotNull Statistic statistic, @NotNull Material material, int i) throws IllegalArgumentException { - - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { - - } - - @Override - public int getStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType) throws IllegalArgumentException { - return 0; - } - - @Override - public void incrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) throws IllegalArgumentException { - - } - - @Override - public void decrementStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { + /** + * Sets the title of the scoreboard. + * @param title The new title (supports ChatColor). + */ + public void setTitle(String title) { + this.objective.setDisplayName(title); + } - } + /** + * Sets a specific line on the scoreboard to a rich TextComponent. + * @param line The line number (from top to bottom, 15 is highest). + * @param component The BaseComponent (e.g., TextComponent) to display. + */ + public void setLine(int line, Component component) { + Team team = getTeamForLine(line); - @Override - public void setStatistic(@NotNull Statistic statistic, @NotNull EntityType entityType, int i) { + // In 1.13+ we can set the prefix/suffix directly with components. + team.prefix(component); - } + // Set the score to show this line. + objective.getScore(getEntryForLine(line)).setScore(line); + } - @Override - public @Nullable Location getLastDeathLocation() { - return null; - } - @Override - public Map serialize() { - return null; + /** + * Retrieves or creates a team for a given line number. + * Teams are used to hold the prefix, which is our component content. + */ + private Team getTeamForLine(int line) { + if (teams.containsKey(line)) { + return teams.get(line); } - @Override - public boolean isOp() { - return false; - } + // Team name must be unique. Line number is a good candidate. + Team team = scoreboard.registerNewTeam("line" + line); - @Override - public void setOp(boolean op) { - } + // Each team needs a unique entry to display. We use ChatColor codes. + // This entry is what gets the score, but it will be invisible. + String entry = getEntryForLine(line); + team.addEntry(entry); - @Override - public String toString() { - return "FakePlayer{" + - "name='" + name + '\'' + - ", team=" + team - + '}'; - } + teams.put(line, team); + return team; + } + /** + * Gets the unique, invisible entry name for a given line. + * We use ChatColor codes to make them unique and not display in chat. + */ + private String getEntryForLine(int line) { + return ChatColor.values()[line].toString() + ChatColor.RESET; } } \ No newline at end of file