aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2021-08-17 19:54:22 -0400
committerMy-Name-Is-Jeff <37018278+My-Name-Is-Jeff@users.noreply.github.com>2021-08-17 19:54:22 -0400
commitcdb18175ae6208254cca1b9e49c7b40a9a0dbc29 (patch)
tree98d19138d1b67265bae3e82604c97953f67654bc /src/main
parent081dc210df4eb19eb8f18355a9feef22024d4e26 (diff)
downloadSkytilsMod-cdb18175ae6208254cca1b9e49c7b40a9a0dbc29.tar.gz
SkytilsMod-cdb18175ae6208254cca1b9e49c7b40a9a0dbc29.tar.bz2
SkytilsMod-cdb18175ae6208254cca1b9e49c7b40a9a0dbc29.zip
Add old server list pinger method to ping display
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/skytils/skytilsmod/mixins/transformers/accessors/AccessorServerListEntryNormal.java33
-rw-r--r--src/main/kotlin/skytils/skytilsmod/core/Config.kt7
-rw-r--r--src/main/kotlin/skytils/skytilsmod/features/impl/misc/Ping.kt39
-rw-r--r--src/main/resources/mixins.skytils.json1
4 files changed, 67 insertions, 13 deletions
diff --git a/src/main/java/skytils/skytilsmod/mixins/transformers/accessors/AccessorServerListEntryNormal.java b/src/main/java/skytils/skytilsmod/mixins/transformers/accessors/AccessorServerListEntryNormal.java
new file mode 100644
index 00000000..f4d6eb80
--- /dev/null
+++ b/src/main/java/skytils/skytilsmod/mixins/transformers/accessors/AccessorServerListEntryNormal.java
@@ -0,0 +1,33 @@
+/*
+ * Skytils - Hypixel Skyblock Quality of Life Mod
+ * Copyright (C) 2021 Skytils
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
+ * by the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package skytils.skytilsmod.mixins.transformers.accessors;
+
+import net.minecraft.client.gui.ServerListEntryNormal;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Mixin(ServerListEntryNormal.class)
+public interface AccessorServerListEntryNormal {
+ @Accessor("field_148302_b")
+ static ThreadPoolExecutor getPingerPool() {
+ return null;
+ }
+}
diff --git a/src/main/kotlin/skytils/skytilsmod/core/Config.kt b/src/main/kotlin/skytils/skytilsmod/core/Config.kt
index ff286eaf..35fdb455 100644
--- a/src/main/kotlin/skytils/skytilsmod/core/Config.kt
+++ b/src/main/kotlin/skytils/skytilsmod/core/Config.kt
@@ -1204,11 +1204,12 @@ object Config : Vigilant(File("./config/skytils/config.toml"), "Skytils", sortin
var summoningEyeDisplay = false
@Property(
- type = PropertyType.SWITCH, name = "Ping Display",
+ type = PropertyType.SELECTOR, name = "Ping Display",
description = "Shows your ping to the current server, similar to the /skytils ping command.\nYou must be in a GUI or not moving in order to queue a ping.\nThere is a tiny chance that this will cause you to be punished.",
- category = "Miscellaneous", subcategory = "Other"
+ category = "Miscellaneous", subcategory = "Other",
+ options = ["Off", "Server List", "Packet"]
)
- var pingDisplay = false
+ var pingDisplay = 0
@Property(
type = PropertyType.PERCENT_SLIDER, name = "Transparent Armor Layer",
diff --git a/src/main/kotlin/skytils/skytilsmod/features/impl/misc/Ping.kt b/src/main/kotlin/skytils/skytilsmod/features/impl/misc/Ping.kt
index 0b96423c..f92f7235 100644
--- a/src/main/kotlin/skytils/skytilsmod/features/impl/misc/Ping.kt
+++ b/src/main/kotlin/skytils/skytilsmod/features/impl/misc/Ping.kt
@@ -19,6 +19,7 @@
package skytils.skytilsmod.features.impl.misc
import gg.essential.universal.UChat
+import net.minecraft.client.network.OldServerPinger
import net.minecraft.network.play.client.C16PacketClientStatus
import net.minecraft.network.play.server.S01PacketJoinGame
import net.minecraft.network.play.server.S37PacketStatistics
@@ -28,6 +29,8 @@ import skytils.skytilsmod.Skytils.Companion.mc
import skytils.skytilsmod.core.structure.FloatPair
import skytils.skytilsmod.core.structure.GuiElement
import skytils.skytilsmod.events.PacketEvent
+import skytils.skytilsmod.mixins.transformers.accessors.AccessorServerListEntryNormal
+import skytils.skytilsmod.utils.NumberUtil
import skytils.skytilsmod.utils.NumberUtil.roundToPrecision
import skytils.skytilsmod.utils.Utils
import skytils.skytilsmod.utils.graphics.SmartFontRenderer
@@ -40,10 +43,12 @@ object Ping {
var lastPingAt = -1L
- var pingCache = 0.0
+ var pingCache = -1.0
var invokedCommand = false
+ val oldServerPinger = OldServerPinger()
+ var lastOldServerPing = 0L
fun sendPing() {
if (lastPingAt > 0) {
@@ -67,7 +72,7 @@ object Ping {
invokedCommand = false
}
is S37PacketStatistics -> {
- val diff = (abs(System.nanoTime() - lastPingAt) / 1_000_000.0).roundToPrecision(2)
+ val diff = (abs(System.nanoTime() - lastPingAt) / 1_000_000.0)
lastPingAt *= -1
pingCache = diff
if (invokedCommand) {
@@ -79,7 +84,7 @@ object Ping {
diff < 249 -> "6"
else -> "c"
}
- }$diff §7ms"
+ }${diff.roundToPrecision(2)} §7ms"
)
}
}
@@ -90,14 +95,28 @@ object Ping {
class PingDisplayElement : GuiElement(name = "Ping Display", fp = FloatPair(10, 10)) {
override fun render() {
if (Utils.isOnHypixel && toggled && mc.thePlayer != null) {
- if (lastPingAt < 0 && (mc.currentScreen != null || !mc.thePlayer.hasMoved) && System.nanoTime()
- - lastPingAt.absoluteValue > 1_000_000L * 5_000
- ) {
- sendPing()
+ when (Skytils.config.pingDisplay) {
+ 1 -> {
+ if (System.currentTimeMillis() - lastOldServerPing > 5000) {
+ lastOldServerPing = System.currentTimeMillis()
+ AccessorServerListEntryNormal.getPingerPool().submit {
+ oldServerPinger.ping(mc.currentServerData)
+ }
+ }
+ if (mc.currentServerData.pingToServer != -1L) pingCache =
+ mc.currentServerData.pingToServer.toDouble()
+ }
+ 2 -> {
+ if (lastPingAt < 0 && (mc.currentScreen != null || !mc.thePlayer.hasMoved) && System.nanoTime()
+ - lastPingAt.absoluteValue > 1_000_000L * 5_000
+ ) {
+ sendPing()
+ }
+ }
}
- if (lastPingAt != -1L) {
+ if (pingCache != -1.0) {
fr.drawString(
- "${pingCache}ms",
+ "${NumberUtil.nf.format(pingCache.roundToPrecision(2))}ms",
0f,
0f,
when {
@@ -124,7 +143,7 @@ object Ping {
}
override val toggled: Boolean
- get() = true
+ get() = Skytils.config.pingDisplay != 0
override val height: Int
get() = fr.FONT_HEIGHT
override val width: Int
diff --git a/src/main/resources/mixins.skytils.json b/src/main/resources/mixins.skytils.json
index a7e69ed6..41dbab13 100644
--- a/src/main/resources/mixins.skytils.json
+++ b/src/main/resources/mixins.skytils.json
@@ -13,6 +13,7 @@
"accessors.AccessorGuiNewChat",
"accessors.AccessorMinecraft",
"accessors.AccessorRenderItem",
+ "accessors.AccessorServerListEntryNormal",
"accessors.AccessorSettingsGui",
"accessors.AccessorWorldInfo",
"audio.MixinSoundManager",