Skip to content

Commit 0a893c6

Browse files
committed
feat: add getServerIp to SurfBukkitNmsCommonBridge for retrieving server IP address
- Introduced `getServerIp` method in `SurfBukkitNmsCommonBridge` and its implementation. - Added `ServerConnectionListenerProxy` for accessing server connection listener channels via reflection.
1 parent a3c0742 commit 0a893c6

File tree

7 files changed

+34
-1
lines changed

7 files changed

+34
-1
lines changed

.idea/modules.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
77
javaVersion=21
88
mcVersion=1.21.7
99
group=dev.slne.surf
10-
version=1.21.7-2.29.4
10+
version=1.21.7-2.30.0
1111
relocationPrefix=dev.slne.surf.surfapi.libs
1212
snapshot=false

surf-api-bukkit/surf-api-bukkit-api/api/surf-api-bukkit-api.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,7 @@ public abstract interface class dev/slne/surf/surfapi/bukkit/api/nms/bridges/Sur
16631663
public abstract fun clearDialogs (Lorg/bukkit/entity/Player;Z)V
16641664
public static synthetic fun clearDialogs$default (Ldev/slne/surf/surfapi/bukkit/api/nms/bridges/SurfBukkitNmsCommonBridge;Lorg/bukkit/entity/Player;ZILjava/lang/Object;)V
16651665
public abstract fun generateNextInventoryId (Lorg/bukkit/entity/Player;)I
1666+
public abstract fun getServerIp ()Ljava/net/InetSocketAddress;
16661667
public abstract fun getStateId (Lorg/bukkit/Material;)I
16671668
public abstract fun getStateId (Lorg/bukkit/block/data/BlockData;)I
16681669
public abstract fun getVelocitySecret ()Ljava/lang/String;

surf-api-bukkit/surf-api-bukkit-api/src/main/kotlin/dev/slne/surf/surfapi/bukkit/api/nms/bridges/SurfBukkitNmsCommonBridge.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dev.slne.surf.surfapi.core.api.util.requiredService
55
import org.bukkit.Material
66
import org.bukkit.block.data.BlockData
77
import org.bukkit.entity.Player
8+
import java.net.InetSocketAddress
89

910
@NmsUseWithCaution
1011
interface SurfBukkitNmsCommonBridge {
@@ -28,6 +29,8 @@ interface SurfBukkitNmsCommonBridge {
2829

2930
fun clearDialogs(player: Player, showEmptyDialogBefore: Boolean = false)
3031

32+
fun getServerIp(): InetSocketAddress
33+
3134
companion object {
3235
val instance = requiredService<SurfBukkitNmsCommonBridge>()
3336
val nextEntityId get() = instance.nextEntityId()

surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/impl/nms/bridges/SurfBukkitNmsCommonBridgeImpl.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import dev.slne.surf.surfapi.bukkit.api.nms.bridges.SurfBukkitNmsCommonBridge
77
import dev.slne.surf.surfapi.bukkit.server.nms.toNms
88
import dev.slne.surf.surfapi.bukkit.server.nms.toNmsBlock
99
import dev.slne.surf.surfapi.bukkit.server.nms.toNmsItem
10+
import dev.slne.surf.surfapi.bukkit.server.reflection.Reflection
1011
import dev.slne.surf.surfapi.core.api.util.checkInstantiationByServiceLoader
1112
import io.papermc.paper.configuration.GlobalConfiguration
1213
import net.kyori.adventure.text.Component
@@ -19,6 +20,7 @@ import org.bukkit.Bukkit
1920
import org.bukkit.Material
2021
import org.bukkit.block.data.BlockData
2122
import org.bukkit.entity.Player
23+
import java.net.InetSocketAddress
2224

2325
@AutoService(SurfBukkitNmsCommonBridge::class)
2426
@NmsUseWithCaution
@@ -83,4 +85,14 @@ class SurfBukkitNmsCommonBridgeImpl : SurfBukkitNmsCommonBridge {
8385

8486
player.toNms().connection.send(ClientboundClearDialogPacket.INSTANCE)
8587
}
88+
89+
override fun getServerIp(): InetSocketAddress {
90+
val channels =
91+
Reflection.SERVER_CONNECTION_LISTENER_PROXY.getChannels(MinecraftServer.getServer().connection)
92+
val channel =
93+
channels.firstOrNull() ?: error("No channels found in server connection listener proxy")
94+
95+
return channel.channel().remoteAddress() as? InetSocketAddress
96+
?: error("Remote address is not an instance of InetSocketAddress")
97+
}
8698
}

surf-api-bukkit/surf-api-bukkit-server/src/main/kotlin/dev/slne/surf/surfapi/bukkit/server/reflection/Reflection.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object Reflection {
1010
val SERVER_STATS_COUNTER_PROXY: ServerStatsCounterProxy
1111
val ITEM_PROXY: ItemProxy
1212
val ENTITY_PROXY: EntityProxy
13+
val SERVER_CONNECTION_LISTENER_PROXY: ServerConnectionListenerProxy
1314

1415
init {
1516
val remapper = ReflectionRemapper.forReobfMappingsInPaperJar()
@@ -19,6 +20,7 @@ object Reflection {
1920
SERVER_STATS_COUNTER_PROXY = proxyFactory.reflectionProxy<ServerStatsCounterProxy>()
2021
ITEM_PROXY = surfReflection.createProxy<ItemProxy>()
2122
ENTITY_PROXY = proxyFactory.reflectionProxy<EntityProxy>()
23+
SERVER_CONNECTION_LISTENER_PROXY = proxyFactory.reflectionProxy<ServerConnectionListenerProxy>()
2224

2325
// gc the remapper
2426
System.gc()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package dev.slne.surf.surfapi.bukkit.server.reflection
2+
3+
import io.netty.channel.ChannelFuture
4+
import net.minecraft.server.network.ServerConnectionListener
5+
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter
6+
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies
7+
8+
@Proxies(ServerConnectionListener::class)
9+
interface ServerConnectionListenerProxy {
10+
@FieldGetter("channels")
11+
fun getChannels(instance: ServerConnectionListener): List<ChannelFuture>
12+
}

0 commit comments

Comments
 (0)