Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'fabric-loom' version '1.13.6'
id 'maven-publish'
id 'org.jetbrains.kotlin.jvm' version '2.0.0-Beta4'
id 'org.jetbrains.kotlin.jvm' version '2.2.21'
id 'me.modmuss50.mod-publish-plugin' version '0.5.1'
}

Expand Down Expand Up @@ -32,6 +32,12 @@ repositories {
}
}
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven {
url 'https://repo.pauli.fyi/releases/'
content {
includeGroup 'net.silkmc'
}
}
maven { url 'https://maven.nucleoid.xyz' }
}

Expand All @@ -50,7 +56,7 @@ dependencies {
include modImplementation("net.silkmc:silk-commands:${property('deps.silk')}")

// Database
modImplementation "maven.modrinth:sqlite-jdbc:${property('deps.sqlite_jdbc')}"
modImplementation "maven.modrinth:${property('deps.sqlite_jdbc_module')}:${property('deps.sqlite_jdbc')}"

// Translations
include modImplementation("xyz.nucleoid:server-translations-api:${property('deps.server_translations')}")
Expand All @@ -71,12 +77,12 @@ def targetMCVersions() {
}

def expandProperties = [
"version": project.version,
"name": modName,
"minecraft_version": targetMCVersions(),
"loader_version": property('deps.fabric_loader'),
"fabric_kotlin_version": property('deps.fabric_kotlin'),
"sqlite_jdbc_version": property('deps.sqlite_jdbc'),
"version" : project.version,
"name" : modName,
"minecraft_version" : targetMCVersions(),
"loader_version" : property('deps.fabric_loader'),
"fabric_kotlin_version": property('deps.fabric_kotlin'),
"sqlite_jdbc_version" : property('deps.sqlite_jdbc'),
]

processResources {
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ deps.minecraft.min = [VERSIONED]
deps.minecraft.max = [VERSIONED]
# Mappings for minimum Minecraft version
deps.yarn_build = [VERSIONED]
deps.fabric_loader = 0.16.9
deps.fabric_loader = 0.17.3

# Mod Properties
mod.group = io.github.kr8gz
Expand All @@ -18,7 +18,8 @@ mod.name = Player Statistics
mod.version = 0.3.0

# Global Dependencies
deps.fabric_kotlin = 1.10.18+kotlin.1.9.22
deps.fabric_kotlin = 1.13.7+kotlin.2.2.21
deps.sqlite_jdbc_module = sqlite-jdbc
deps.sqlite_jdbc = 3.41.2.1+20230506
deps.hoplite = 2.7.5

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ plugins {

stonecutter {
shared {
versions '1.21.2', '1.21', '1.20.5', '1.20.3', '1.20.2', '1.20'
versions '1.21.11', '1.21.2', '1.21', '1.20.5', '1.20.3', '1.20.2', '1.20'
}

create rootProject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
import java.util.Map;

public interface ServerStatHandlerAccess {
String getStatsFileName();

Map<Stat<?>, Integer> takeChangedStats();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import net.minecraft.stat.ServerStatHandler;
import net.minecraft.stat.Stat;
import net.minecraft.stat.StatHandler;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -18,6 +20,11 @@

@Mixin(ServerStatHandler.class)
public abstract class ServerStatHandlerMixin extends StatHandler implements ServerStatHandlerAccess {
//? if >=1.21.11
@Shadow @Final private java.nio.file.Path path;
//? if <1.21.11
// @Shadow @Final private java.io.File file;

@Unique private final Map<Stat<?>, Integer> changedStats = new Object2IntOpenHashMap<>();

@Inject(method = "setStat", at = @At("TAIL"))
Expand All @@ -30,6 +37,14 @@ private void save(CallbackInfo ci) {
Statistics.launchStatsUpdate((ServerStatHandler) (Object) this);
}

@Override
public String getStatsFileName() {
//? if >=1.21.11
return path.getFileName().toString();
//? if <1.21.11
// return file.getName();
}

@Override
public Map<Stat<?>, Integer> takeChangedStats() {
var map = ImmutableMap.copyOf(changedStats);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,18 @@ object LeaderboardCommand : StatsCommand("leaderboard") {
command = LeaderboardCommand.formatCommandString(stat.formatCommandArgs(), player)
}

hoverEvent = hint?.let { HoverEvent(HoverEvent.Action.SHOW_TEXT, it) }
clickEvent = command?.let { ClickEvent(ClickEvent.Action.RUN_COMMAND, it) }
hoverEvent = hint?.let {
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, it)
*///?} else
HoverEvent.ShowText(it)
}
clickEvent = command?.let {
//? if <1.21.11 {
/*ClickEvent(ClickEvent.Action.RUN_COMMAND, it)
*///?} else
ClickEvent.RunCommand(it)
}
color = config.colors.name.altIf(isHighlighted)
}
text(" - ") { bold = false }
Expand All @@ -90,7 +100,15 @@ object LeaderboardCommand : StatsCommand("leaderboard") {
}

fun formatStatNameWithSuggestion(stat: StatSource) = stat.formatNameText().build {
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("playerstatistics.command.leaderboard.hint"))
clickEvent = ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, formatCommandString(stat.formatCommandArgs()))
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("playerstatistics.command.leaderboard.hint"))
*///?} else
HoverEvent.ShowText(Text.translatable("playerstatistics.command.leaderboard.hint"))
clickEvent =
//? if <1.21.11 {
/*ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, formatCommandString(stat.formatCommandArgs()))
*///?} else
ClickEvent.SuggestCommand(formatCommandString(stat.formatCommandArgs()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import net.minecraft.text.HoverEvent
import net.minecraft.text.Text
import net.minecraft.text.Texts
import net.silkmc.silk.commands.LiteralCommandBuilder
import net.silkmc.silk.core.text.broadcastText
import net.silkmc.silk.core.text.literalText
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
Expand Down Expand Up @@ -51,10 +50,14 @@ object ShareCommand : StatsCommand("share") {
Text.translatable("playerstatistics.command.share.message", sharerName, data.label).build { color = config.colors.text.main }
}
val hoverText = Texts.bracketed(Text.translatable("playerstatistics.command.share.hover")).build {
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, data.content)
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, data.content)
*///?} else
HoverEvent.ShowText(data.content)
color = config.colors.action
}
server.broadcastText(message space hoverText)
server.playerManager.broadcast(message space hoverText, false)

data.shared = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ object Database {
}

Files.list(statsPath).asSequence().forEach { path ->
val statHandler = ServerStatHandler(server, path.toFile())
// the user cache can only store up to 1000 players by default, but at least it's better than nothing
server.userCache?.getByUuid(statHandler.uuid)?.let { if (it.isPresent) Players.updateProfile(it.get()) }
val statHandler =
//? if <1.21.11 {
/*ServerStatHandler(server, path.toFile())
*///?} else
ServerStatHandler(server, path)
// Since 1.21.11 the old direct user cache access is no longer available here.
// Refresh names when a matching player is currently online; otherwise they will be updated on next join.
server.playerManager.getPlayer(statHandler.uuid)?.gameProfile?.let { Players.updateProfile(it) }
Statistics.updateStats(statHandler, changedOnly = false)

completedFiles.incrementAndGet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import java.util.UUID

object ServerStatHandler {
val ServerStatHandler.uuid: UUID
get() = file.toString()
get() = statsFileName
.let(FilenameUtils::getBaseName)
.let(UUID::fromString)

val ServerStatHandler.statsFileName: String
get() = (this as ServerStatHandlerAccess).getStatsFileName()

fun ServerStatHandler.takeChangedStats(): Map<Stat<*>, Int> {
return (this as ServerStatHandlerAccess).takeChangedStats()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.github.kr8gz.playerstatistics.extensions

import net.minecraft.item.ItemStack
import net.minecraft.text.ClickEvent
import net.minecraft.text.HoverEvent
import net.minecraft.text.Text

object TextEvents {
fun showText(text: Text): HoverEvent {
//? if <1.21.11 {
/*return HoverEvent(HoverEvent.Action.SHOW_TEXT, text)
*///?} else
return HoverEvent.ShowText(text)
}

fun runCommand(command: String): ClickEvent {
//? if <1.21.11 {
/*return ClickEvent(ClickEvent.Action.RUN_COMMAND, command)
*///?} else
return ClickEvent.RunCommand(command)
}

fun suggestCommand(command: String): ClickEvent {
//? if <1.21.11 {
/*return ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command)
*///?} else
return ClickEvent.SuggestCommand(command)
}

fun showItem(stack: ItemStack): HoverEvent {
//? if <1.21.11 {
/*return HoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ItemStackContent(stack))
*///?} else
return HoverEvent.ShowItem(stack)
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ import java.util.UUID

object Components {
fun shareButton(code: UUID) = Texts.bracketed(Text.translatable("playerstatistics.command.share")).build {
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("playerstatistics.command.share.hint"))
clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, ShareCommand.formatCommandString(code))
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("playerstatistics.command.share.hint"))
*///?} else
HoverEvent.ShowText(Text.translatable("playerstatistics.command.share.hint"))
clickEvent =
//? if <1.21.11 {
/*ClickEvent(ClickEvent.Action.RUN_COMMAND, ShareCommand.formatCommandString(code))
*///?} else
ClickEvent.RunCommand(ShareCommand.formatCommandString(code))
color = config.colors.action
}

Expand All @@ -22,8 +30,16 @@ object Components {
fun pageButton(text: String, active: Boolean, newPage: Int, translationKey: String) = text(text) {
color = config.colors.footer.altIf(active)
if (active) {
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable(translationKey))
clickEvent = ClickEvent(ClickEvent.Action.RUN_COMMAND, PageCommand.formatCommandString(newPage))
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable(translationKey))
*///?} else
HoverEvent.ShowText(Text.translatable(translationKey))
clickEvent =
//? if <1.21.11 {
/*ClickEvent(ClickEvent.Action.RUN_COMMAND, PageCommand.formatCommandString(newPage))
*///?} else
ClickEvent.RunCommand(PageCommand.formatCommandString(newPage))
}
}

Expand Down
18 changes: 15 additions & 3 deletions src/main/kotlin/io/github/kr8gz/playerstatistics/format/format.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ fun formatDistanceText(value: Long): Text {

return literalText(formatUnitString(kilometers to "km", meters to "m", value to "cm")) {
val hoverText = Text.translatable("playerstatistics.unit.blocks", formatDecimalString(meters))
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)
*///?} else
HoverEvent.ShowText(hoverText)
}
}

Expand All @@ -37,14 +41,22 @@ fun formatTimeText(value: Long): Text {

return literalText(formatUnitString(years to "y", days to "d", hours to "h", minutes to "m", seconds to "s")) {
val hoverText = Text.translatable("playerstatistics.unit.ticks", formatDecimalString(value))
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)
*///?} else
HoverEvent.ShowText(hoverText)
}
}

fun formatHeartsText(value: Long): Text {
return literalText(formatDecimalString(value / 20.0)) {
text(" ❤") { color = config.colors.heart; bold = false }
val hoverText = Text.translatable("playerstatistics.unit.damage", formatDecimalString(value / 10.0))
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_TEXT, hoverText)
*///?} else
HoverEvent.ShowText(hoverText)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ class MinecraftStatSource(val stat: Stat<*>) : StatSource() {

private fun formatItemText(item: Item) = formatTextWithStatType(item.name.build {
if (item != Items.AIR) {
hoverEvent = HoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ItemStackContent(item.defaultStack))
hoverEvent =
//? if <1.21.11 {
/*HoverEvent(HoverEvent.Action.SHOW_ITEM, HoverEvent.ItemStackContent(item.defaultStack))
*///?} else
HoverEvent.ShowItem(item.defaultStack)
}
})

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/playerstatistics.accesswidener
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
accessWidener v2 named

accessible field net/minecraft/stat/ServerStatHandler file Ljava/io/File;
accessible field net/minecraft/stat/StatHandler statMap Lit/unimi/dsi/fastutil/objects/Object2IntMap;
accessible field net/minecraft/stat/Stat formatter Lnet/minecraft/stat/StatFormatter;
2 changes: 1 addition & 1 deletion stonecutter.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins.apply "dev.kikugie.stonecutter"
stonecutter.active "1.21.2" /* [SC] DO NOT EDIT */
stonecutter.active "1.21.11" /* [SC] DO NOT EDIT */

stonecutter.registerChiseled tasks.register('buildAll', stonecutter.chiseled) {
group = 'project'
Expand Down
12 changes: 12 additions & 0 deletions versions/1.21.11/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
deps.minecraft.min = 1.21.11
deps.minecraft.max = 1.21.11
deps.yarn_build = 5

# Versioned Dependencies
deps.silk = 1.11.5
deps.server_translations = 2.5.2+1.21.9-pre3
deps.fabric_api = 0.141.4+1.21.11
deps.sqlite_jdbc_module = minecraft-sqlite-jdbc
deps.sqlite_jdbc = 3.53.1.0+2026-05-07