aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt72
-rw-r--r--src/main/kotlin/com/dulkirfabric/util/Utils.kt7
2 files changed, 79 insertions, 0 deletions
diff --git a/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt b/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt
new file mode 100644
index 0000000..a2bdb3a
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/ScoreBoardUtils.kt
@@ -0,0 +1,72 @@
+package com.dulkirfabric.util
+
+import com.dulkirfabric.DulkirModFabric
+import net.minecraft.scoreboard.Team
+import net.minecraft.text.StringVisitable
+import net.minecraft.text.Style
+import net.minecraft.text.Text
+import net.minecraft.util.Formatting
+import java.util.*
+
+object ScoreBoardUtils {
+
+ /**
+ * Gets Scoreboard lines, will return null if not in Skyblock.
+ */
+ fun getLines(): MutableList<String>? {
+ val scoreboard = DulkirModFabric.mc.player?.scoreboard ?: return null
+ // This returns null if we're not in skyblock curiously
+ val sidebarObjective = scoreboard.getObjective("SBScoreboard") ?: return null
+ val scores = scoreboard.getAllPlayerScores(sidebarObjective)
+ val lines: MutableList<String> = ArrayList()
+ for (score in scores.reversed()) {
+ val team = scoreboard.getPlayerTeam(score.playerName)
+ var str = Team.decorateName(team, Text.literal(score.playerName)).string
+ .replace("§[^a-f0-9]".toRegex(), "")
+ lines.add(str)
+ }
+ return lines
+ }
+
+ /**
+ * This is useful for a few number of features in which you want to register the color of the scoreboard,
+ * namely effigy display for now - but might be useful later? Who knows.
+ */
+ fun getLinesWithColor(): MutableList<String>? {
+ val scoreboard = DulkirModFabric.mc.player?.scoreboard ?: return null
+ // This returns null if we're not in skyblock curiously
+ val sidebarObjective = scoreboard.getObjective("SBScoreboard") ?: return null
+ val scores = scoreboard.getAllPlayerScores(sidebarObjective)
+ val lines: MutableList<String> = ArrayList()
+ for (score in scores.reversed()) {
+ val team = scoreboard.getPlayerTeam(score.playerName)
+ lines.add(Team.decorateName(team, Text.literal(score.playerName)).formattedString())
+ }
+ return lines
+ }
+
+ /**
+ * Function to add 1.8.9 Style color coding to strings, if you wish. Helpful for porting some 1.8.9 features
+ * to newer versions.
+ *
+ * @author nea
+ */
+ fun Text.formattedString(): String {
+ val sb = StringBuilder()
+ visit(StringVisitable.StyledVisitor<Unit> { style, string ->
+ val c = Formatting.byName(style.color?.name)
+ if (c != null) {
+ sb.append("§${c.code}")
+ }
+ if (style.isUnderlined) {
+ sb.append("§n")
+ }
+ if (style.isBold) {
+ sb.append("§l")
+ }
+ sb.append(string)
+ Optional.empty()
+ }, Style.EMPTY)
+ return sb.toString().replace("§[^a-f0-9]".toRegex(), "")
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/com/dulkirfabric/util/Utils.kt b/src/main/kotlin/com/dulkirfabric/util/Utils.kt
new file mode 100644
index 0000000..ce6665b
--- /dev/null
+++ b/src/main/kotlin/com/dulkirfabric/util/Utils.kt
@@ -0,0 +1,7 @@
+package com.dulkirfabric.util
+
+object Utils {
+ fun isInSkyblock(): Boolean {
+ return ScoreBoardUtils.getLines() != null
+ }
+} \ No newline at end of file