diff --git a/README.md b/README.md index d4f741c0..416ae7e5 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,10 @@ Minecraft server mod/plugin to show TPS, MSPT, and other information in the tab menu, boss bar, and action bar. Current supported platforms: -- [Paper](https://papermc.io)/Spigot API (Minecraft versions 1.8.8-1.21.1+) +- [Paper](https://papermc.io)/Spigot API (Minecraft versions 1.8.8-1.21.4+) - [Sponge](https://spongepowered.org) 12+ -- [Fabric](https://fabricmc.net/) (Minecraft 1.21.1, requires [Fabric API](https://modrinth.com/mod/fabric-api)) -- [NeoForge](https://neoforged.net/) (Minecraft 1.21.1) +- [Fabric](https://fabricmc.net/) (Minecraft 1.21.4, requires [Fabric API](https://modrinth.com/mod/fabric-api)) +- [NeoForge](https://neoforged.net/) (Minecraft 1.21.4) ## Features diff --git a/common/src/main/java/xyz/jpenilla/tabtps/common/command/commands/TickInfoCommand.java b/common/src/main/java/xyz/jpenilla/tabtps/common/command/commands/TickInfoCommand.java index 46c4166c..3b145f60 100644 --- a/common/src/main/java/xyz/jpenilla/tabtps/common/command/commands/TickInfoCommand.java +++ b/common/src/main/java/xyz/jpenilla/tabtps/common/command/commands/TickInfoCommand.java @@ -132,7 +132,7 @@ private void executeTickInfo(final @NonNull CommandContext ctx) { .append(space()); final Iterator tpsIterator = Arrays.stream(tps).iterator(); final Deque tpsDurations = tps.length == 4 - ? new ArrayDeque<>(Arrays.asList("5s", "1m", "5m", "15m")) + ? new ArrayDeque<>(Arrays.asList("15s", "1m", "5m", "15m")) : new ArrayDeque<>(Arrays.asList("1m", "5m", "15m")); while (tpsIterator.hasNext()) { builder.append(TPSUtil.coloredTps(tpsIterator.next(), Theme.DEFAULT.colorScheme())) diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 69a1704b..f0424bad 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -33,6 +33,9 @@ dependencies { include(libs.bundles.configurate) implementation(libs.adventureSerializerConfigurate4) include(libs.adventureSerializerConfigurate4) + + modImplementation(libs.fabricPermissionsApi) + include(libs.fabricPermissionsApi) } indra { diff --git a/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/FabricUser.java b/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/FabricUser.java index d784ff4b..6b50e945 100644 --- a/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/FabricUser.java +++ b/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/FabricUser.java @@ -25,6 +25,7 @@ import me.lucko.fabric.api.permissions.v0.Permissions; import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.modcommon.MinecraftServerAudiences; import net.kyori.adventure.text.Component; import net.minecraft.server.level.ServerPlayer; import org.checkerframework.checker.nullness.qual.NonNull; @@ -46,7 +47,7 @@ public static FabricUser from(final TabTPSFabric tabTPSFabric, final ServerPlaye @Override public Component displayName() { - return this.base().getDisplayName().asComponent(); + return MinecraftServerAudiences.of(this.base().getServer()).asAdventure(this.base().getDisplayName()); } @Override diff --git a/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/mixin/MinecraftServerMixin.java b/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/mixin/MinecraftServerMixin.java index c6f20ae0..95880cc8 100644 --- a/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/mixin/MinecraftServerMixin.java +++ b/fabric/src/main/java/xyz/jpenilla/tabtps/fabric/mixin/MinecraftServerMixin.java @@ -23,6 +23,7 @@ */ package xyz.jpenilla.tabtps.fabric.mixin; +import com.llamalad7.mixinextras.sugar.Local; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.function.BooleanSupplier; @@ -37,7 +38,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import xyz.jpenilla.tabtps.common.service.TickTimeService; import xyz.jpenilla.tabtps.common.util.RollingAverage; import xyz.jpenilla.tabtps.common.util.TPSUtil; @@ -51,34 +51,60 @@ @Mixin(MinecraftServer.class) @Implements({@Interface(iface = TickTimeService.class, prefix = "tabtps$")}) abstract class MinecraftServerMixin implements MinecraftServerAccess { + @Unique private final TickTimes tickTimes5s = new TickTimes(100); + @Unique private final TickTimes tickTimes10s = new TickTimes(200); + @Unique private final TickTimes tickTimes60s = new TickTimes(1200); - private final RollingAverage tps5s = new RollingAverage(5); + @Unique + private final RollingAverage tps15s = new RollingAverage(15); + @Unique private final RollingAverage tps1m = new RollingAverage(60); + @Unique private final RollingAverage tps5m = new RollingAverage(60 * 5); + @Unique private final RollingAverage tps15m = new RollingAverage(60 * 15); + @Unique private long previousTime; + @Unique + private boolean tickingPaused; @Shadow private int tickCount; @Shadow @Final private long[] tickTimesNanos; - @Inject(method = "tickServer", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final long tickStartTimeNanos, final long tickDurationNanos) { + @Inject( + method = "tickServer", + at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 0) + ) + private void injectPause(final BooleanSupplier keepTicking, final CallbackInfo ci) { + this.tickingPaused = true; + } + + @Inject(method = "tickServer", at = @At(value = "RETURN", ordinal = 1)) + public void injectTick( + final BooleanSupplier keepTicking, + final CallbackInfo ci, + @Local(ordinal = 0) final long tickStartTimeNanos, + @Local(ordinal = 1) final long tickDurationNanos + ) { this.tickTimes5s.add(this.tickCount, tickDurationNanos); this.tickTimes10s.add(this.tickCount, tickDurationNanos); this.tickTimes60s.add(this.tickCount, tickDurationNanos); if (this.tickCount % RollingAverage.SAMPLE_INTERVAL == 0) { - if (this.previousTime == 0) { - this.previousTime = tickStartTimeNanos - RollingAverage.TICK_TIME; + if (this.previousTime == 0 || this.tickingPaused) { + this.previousTime = tickStartTimeNanos - tickDurationNanos; + if (this.tickingPaused) { + this.tickingPaused = false; + } } final long diff = tickStartTimeNanos - this.previousTime; this.previousTime = tickStartTimeNanos; final BigDecimal currentTps = RollingAverage.TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP); - this.tps5s.add(currentTps, diff); + this.tps15s.add(currentTps, diff); this.tps1m.add(currentTps, diff); this.tps5m.add(currentTps, diff); this.tps15m.add(currentTps, diff); @@ -91,7 +117,7 @@ public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final public double @NonNull [] tabtps$recentTps() { final double[] tps = new double[4]; - tps[0] = this.tps5s.average(); + tps[0] = this.tps15s.average(); tps[1] = this.tps1m.average(); tps[2] = this.tps5m.average(); tps[3] = this.tps15m.average(); diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json index 418a92e9..f21c7ed8 100644 --- a/fabric/src/main/resources/fabric.mod.json +++ b/fabric/src/main/resources/fabric.mod.json @@ -29,6 +29,6 @@ "fabricloader": ">=0.15.11", "fabric": "*", "fabric-permissions-api-v0": "*", - "minecraft": ">=1.21 <=1.21.1" + "minecraft": "1.21.4" } } diff --git a/gradle/build-logic/src/main/kotlin/ext.kt b/gradle/build-logic/src/main/kotlin/ext.kt index f53c0ac8..51396f24 100644 --- a/gradle/build-logic/src/main/kotlin/ext.kt +++ b/gradle/build-logic/src/main/kotlin/ext.kt @@ -34,5 +34,5 @@ val bukkitVersions = listOf( "1.18.2", "1.19.4", "1.20.6", - "1.21.1", + "1.21.4", ) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c6e34e9c..54b4b050 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,8 +9,8 @@ adventure = "4.17.0" adventurePagination = "4.0.0-SNAPSHOT" adventurePlatform = "4.3.4" cloud = "2.0.0" -cloudMinecraft = "2.0.0-beta.9" -cloudModded = "2.0.0-beta.9" +cloudMinecraft = "2.0.0-beta.10" +cloudModded = "2.0.0-beta.10" cloudSponge = "2.0.0-SNAPSHOT" configurate = "4.1.2" typesafeConfig = "1.4.3" @@ -22,14 +22,13 @@ guava = "21.0" bstats = "3.1.0" paperApi = "1.16.5-R0.1-SNAPSHOT" paperLib = "1.0.8" -fabricApi = "0.110.0+1.21.1" +fabricApi = "0.112.2+1.21.4" fabricLoader = "0.16.9" -minecraft = "1.21.1" -adventurePlatformFabric = "5.14.2" -adventurePlatformNeoforge = "6.0.0" +minecraft = "1.21.4" +adventurePlatformMod = "6.1.0" mixin = "0.8.7" -neoforge = "21.1.82" -neoForm = "1.21.1-20240808.144430" +neoforge = "21.4.33-beta" +neoForm = "1.21.4-20241203.161809" # buildSrc indra = "3.1.3" @@ -44,8 +43,8 @@ adventureTextSerializerLegacy = { group = "net.kyori", name = "adventure-text-se adventureSerializerConfigurate4 = { group = "net.kyori", name = "adventure-serializer-configurate4", version.ref = "adventure" } adventureTextFeaturePagination = { group = "net.kyori", name = "adventure-text-feature-pagination", version.ref = "adventurePagination" } adventurePlatformBukkit = { group = "net.kyori", name = "adventure-platform-bukkit", version.ref = "adventurePlatform" } -adventurePlatformFabric = { group = "net.kyori", name = "adventure-platform-fabric", version.ref = "adventurePlatformFabric" } -adventurePlatformNeoforge = { group = "net.kyori", name = "adventure-platform-neoforge", version.ref = "adventurePlatformNeoforge" } +adventurePlatformFabric = { group = "net.kyori", name = "adventure-platform-fabric", version.ref = "adventurePlatformMod" } +adventurePlatformNeoforge = { group = "net.kyori", name = "adventure-platform-neoforge", version.ref = "adventurePlatformMod" } minimessage = { group = "net.kyori", name = "adventure-text-minimessage", version.ref = "adventure" } cloudBom = { group = "org.incendo", name = "cloud-bom", version.ref = "cloud" } @@ -81,6 +80,7 @@ paperLib = { group = "io.papermc", name = "paperlib", version.ref = "paperLib" } fabricApi = { group = "net.fabricmc.fabric-api", name = "fabric-api", version.ref = "fabricApi" } fabricLoader = { group = "net.fabricmc", name = "fabric-loader", version.ref = "fabricLoader" } +fabricPermissionsApi = "me.lucko:fabric-permissions-api:0.3.3" minecraft = { group = "com.mojang", name = "minecraft", version.ref = "minecraft" } zNeoforge = { module = "net.neoforged:neoforge", version.ref = "neoforge" } diff --git a/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/mixin/MinecraftServerMixin.java b/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/mixin/MinecraftServerMixin.java index 923239c1..08926e7e 100644 --- a/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/mixin/MinecraftServerMixin.java +++ b/neoforge/src/main/java/xyz/jpenilla/tabtps/neoforge/mixin/MinecraftServerMixin.java @@ -23,6 +23,7 @@ */ package xyz.jpenilla.tabtps.neoforge.mixin; +import com.llamalad7.mixinextras.sugar.Local; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.function.BooleanSupplier; @@ -37,7 +38,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import xyz.jpenilla.tabtps.common.service.TickTimeService; import xyz.jpenilla.tabtps.common.util.RollingAverage; import xyz.jpenilla.tabtps.common.util.TPSUtil; @@ -51,34 +51,60 @@ @Mixin(MinecraftServer.class) @Implements({@Interface(iface = TickTimeService.class, prefix = "tabtps$")}) abstract class MinecraftServerMixin implements MinecraftServerAccess { + @Unique private final TickTimes tickTimes5s = new TickTimes(100); + @Unique private final TickTimes tickTimes10s = new TickTimes(200); + @Unique private final TickTimes tickTimes60s = new TickTimes(1200); - private final RollingAverage tps5s = new RollingAverage(5); + @Unique + private final RollingAverage tps15s = new RollingAverage(15); + @Unique private final RollingAverage tps1m = new RollingAverage(60); + @Unique private final RollingAverage tps5m = new RollingAverage(60 * 5); + @Unique private final RollingAverage tps15m = new RollingAverage(60 * 15); + @Unique private long previousTime; + @Unique + private boolean tickingPaused; @Shadow private int tickCount; @Shadow @Final private long[] tickTimesNanos; - @Inject(method = "tickServer", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final long tickStartTimeNanos, final long tickDurationNanos) { + @Inject( + method = "tickServer", + at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 0) + ) + private void injectPause(final BooleanSupplier keepTicking, final CallbackInfo ci) { + this.tickingPaused = true; + } + + @Inject(method = "tickServer", at = @At(value = "RETURN", ordinal = 1)) + public void injectTick( + final BooleanSupplier keepTicking, + final CallbackInfo ci, + @Local(ordinal = 0) final long tickStartTimeNanos, + @Local(ordinal = 1) final long tickDurationNanos + ) { this.tickTimes5s.add(this.tickCount, tickDurationNanos); this.tickTimes10s.add(this.tickCount, tickDurationNanos); this.tickTimes60s.add(this.tickCount, tickDurationNanos); if (this.tickCount % RollingAverage.SAMPLE_INTERVAL == 0) { - if (this.previousTime == 0) { - this.previousTime = tickStartTimeNanos - RollingAverage.TICK_TIME; + if (this.previousTime == 0 || this.tickingPaused) { + this.previousTime = tickStartTimeNanos - tickDurationNanos; + if (this.tickingPaused) { + this.tickingPaused = false; + } } final long diff = tickStartTimeNanos - this.previousTime; this.previousTime = tickStartTimeNanos; final BigDecimal currentTps = RollingAverage.TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP); - this.tps5s.add(currentTps, diff); + this.tps15s.add(currentTps, diff); this.tps1m.add(currentTps, diff); this.tps5m.add(currentTps, diff); this.tps15m.add(currentTps, diff); @@ -91,7 +117,7 @@ public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final public double @NonNull [] tabtps$recentTps() { final double[] tps = new double[4]; - tps[0] = this.tps5s.average(); + tps[0] = this.tps15s.average(); tps[1] = this.tps1m.average(); tps[2] = this.tps5m.average(); tps[3] = this.tps15m.average(); diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml index a75bd25a..f4e23b5d 100644 --- a/neoforge/src/main/resources/META-INF/neoforge.mods.toml +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -23,7 +23,7 @@ side = "BOTH" [[dependencies.tabtps]] modId = "minecraft" type = "required" -versionRange = "[1.21,1.21.2)" +versionRange = "[1.21.4]" ordering = "NONE" side = "BOTH" diff --git a/settings.gradle.kts b/settings.gradle.kts index b22edab7..52fa6baa 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -33,9 +33,9 @@ pluginManagement { } plugins { - id("quiet-fabric-loom") version "1.8-SNAPSHOT" + id("quiet-fabric-loom") version "1.9-SNAPSHOT" id("org.gradle.toolchains.foojay-resolver-convention") version "0.9.0" - id("net.neoforged.moddev.repositories") version "2.0.49-beta" + id("net.neoforged.moddev.repositories") version "2.0.61-beta" } rootProject.name = "TabTPS" diff --git a/sponge/build.gradle.kts b/sponge/build.gradle.kts index 5d7179a5..9831f78a 100644 --- a/sponge/build.gradle.kts +++ b/sponge/build.gradle.kts @@ -27,7 +27,7 @@ java { sponge { injectRepositories(false) - apiVersion("12.0.0-SNAPSHOT") + apiVersion("13.0.0-SNAPSHOT") plugin(rootProject.name.lowercase()) { loader { name(PluginLoaders.JAVA_PLAIN) @@ -95,18 +95,16 @@ tabTPSPlatform { publishMods.modrinth { modLoaders.add("sponge") minecraftVersions.addAll( - "1.21.1" + "1.21.4" ) } -/* configurations.spongeRuntime { resolutionStrategy { eachDependency { if (target.name == "spongevanilla") { - useVersion("1.20.+") + useVersion("1.21.+") } } } } - */ diff --git a/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java b/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java index d8d7bb32..48bc4c46 100644 --- a/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java +++ b/sponge/src/main/java/xyz/jpenilla/tabtps/sponge/mixin/MinecraftServerMixin.java @@ -27,6 +27,7 @@ import java.math.RoundingMode; import java.util.function.BooleanSupplier; import net.minecraft.server.MinecraftServer; +import net.minecraft.util.profiling.ProfilerFiller; import org.checkerframework.checker.nullness.qual.NonNull; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Implements; @@ -51,34 +52,61 @@ @Mixin(MinecraftServer.class) @Implements({@Interface(iface = TickTimeService.class, prefix = "tabtps$")}) abstract class MinecraftServerMixin implements MinecraftServerAccess { + @Unique private final TickTimes tickTimes5s = new TickTimes(100); + @Unique private final TickTimes tickTimes10s = new TickTimes(200); + @Unique private final TickTimes tickTimes60s = new TickTimes(1200); - private final RollingAverage tps5s = new RollingAverage(5); + @Unique + private final RollingAverage tps15s = new RollingAverage(15); + @Unique private final RollingAverage tps1m = new RollingAverage(60); + @Unique private final RollingAverage tps5m = new RollingAverage(60 * 5); + @Unique private final RollingAverage tps15m = new RollingAverage(60 * 15); + @Unique private long previousTime; + @Unique + private boolean tickingPaused; @Shadow private int tickCount; @Shadow @Final private long[] tickTimesNanos; - @Inject(method = "tickServer", at = @At("RETURN"), locals = LocalCapture.CAPTURE_FAILHARD) - public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final long tickStartTimeNanos, final long tickDurationNanos) { + @Inject( + method = "tickServer", + at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;info(Ljava/lang/String;Ljava/lang/Object;)V", ordinal = 0) + ) + private void injectPause(final BooleanSupplier keepTicking, final CallbackInfo ci) { + this.tickingPaused = true; + } + + @Inject(method = "tickServer", at = @At(value = "RETURN", ordinal = 1), locals = LocalCapture.CAPTURE_FAILHARD) + public void injectTick( + final BooleanSupplier keepTicking, + final CallbackInfo ci, + final long tickStartTimeNanos, + final ProfilerFiller profilerFiller, + final long tickDurationNanos + ) { this.tickTimes5s.add(this.tickCount, tickDurationNanos); this.tickTimes10s.add(this.tickCount, tickDurationNanos); this.tickTimes60s.add(this.tickCount, tickDurationNanos); if (this.tickCount % RollingAverage.SAMPLE_INTERVAL == 0) { - if (this.previousTime == 0) { - this.previousTime = tickStartTimeNanos - RollingAverage.TICK_TIME; + if (this.previousTime == 0 || this.tickingPaused) { + this.previousTime = tickStartTimeNanos - tickDurationNanos; + if (this.tickingPaused) { + this.tickingPaused = false; + } } final long diff = tickStartTimeNanos - this.previousTime; this.previousTime = tickStartTimeNanos; final BigDecimal currentTps = RollingAverage.TPS_BASE.divide(new BigDecimal(diff), 30, RoundingMode.HALF_UP); - this.tps5s.add(currentTps, diff); + this.tps15s.add(currentTps, diff); this.tps1m.add(currentTps, diff); this.tps5m.add(currentTps, diff); this.tps15m.add(currentTps, diff); @@ -91,7 +119,7 @@ public void injectTick(final BooleanSupplier var1, final CallbackInfo ci, final public double @NonNull [] tabtps$recentTps() { final double[] tps = new double[4]; - tps[0] = this.tps5s.average(); + tps[0] = this.tps15s.average(); tps[1] = this.tps1m.average(); tps[2] = this.tps5m.average(); tps[3] = this.tps15m.average();