Skip to content

Commit

Permalink
#425 Fixed network manager access hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Mar 7, 2022
1 parent 9282671 commit 09d1ccc
Showing 1 changed file with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.shynixn.blockball.bukkit.logic.business.service

import com.github.shynixn.blockball.api.bukkit.event.PacketEvent
import com.github.shynixn.blockball.api.business.enumeration.Version
import com.github.shynixn.blockball.api.business.proxy.PluginProxy
import com.github.shynixn.blockball.api.business.service.ProtocolService
import com.github.shynixn.blockball.core.logic.business.extension.accessible
Expand Down Expand Up @@ -41,18 +42,20 @@ class ProtocolServiceImpl @Inject constructor(private val plugin: PluginProxy, p
}
private val channelField by lazy {
try {
plugin.findClazz("net.minecraft.network.NetworkManager")
.getDeclaredField("m")
.accessible(true)
} catch (e: Exception) {
try {
if (plugin.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_18_R2)) {
plugin.findClazz("net.minecraft.network.NetworkManager")
.getDeclaredField("m")
.accessible(true)
} else if (plugin.getServerVersion().isVersionSameOrGreaterThan(Version.VERSION_1_17_R1)) {
plugin.findClazz("net.minecraft.network.NetworkManager")
.getDeclaredField("k")
.accessible(true)
}catch (e1 : Exception){
plugin.findClazz("net.minecraft.server.VERSION.NetworkManager")
.getDeclaredField("channel")
} else {
throw RuntimeException("Impl not found!")
}
} catch (e1: Exception) {
plugin.findClazz("net.minecraft.server.VERSION.NetworkManager")
.getDeclaredField("channel")
}
}

Expand Down

0 comments on commit 09d1ccc

Please sign in to comment.