Skip to content

Commit a44cb1b

Browse files
committed
Bundled packetevents, Improve maven dependencies resolve (~5s faster)
1 parent ac76739 commit a44cb1b

File tree

24 files changed

+199
-142
lines changed

24 files changed

+199
-142
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ subprojects {
101101
buildConfigField("DEP_VERSION_H2DATABASE", rootProject.libs.versions.h2database)
102102
buildConfigField("DEP_VERSION_HIKARICP", rootProject.libs.versions.hikariCP)
103103
buildConfigField("DEP_VERSION_MARIADB_CLIENT", rootProject.libs.versions.mariadb.client)
104+
buildConfigField("DEP_VERSION_PACKETEVENTS", rootProject.libs.versions.packetevents)
104105
}
105106
}
106107

bukkit/build.gradle.kts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ allprojects {
3636
name = "NeoForged"
3737
url = uri("https://maven.neoforged.net/releases/")
3838
}
39+
maven("https://jitpack.io")
3940
}
4041

4142
dependencies {
42-
compileOnly(rootProject.libs.packetevents.spigot)
4343
compileOnly("org.lz4:lz4-java:1.8.0")
4444
}
4545

@@ -108,17 +108,9 @@ buildConfig {
108108
buildConfigField("DEP_VERSION_NBTAPI", rootProject.libs.versions.nbt.api)
109109
}
110110

111-
112-
allprojects {
113-
repositories {
114-
maven("https://jitpack.io")
115-
}
116-
}
117-
118111
modrinth {
119112
loaders = listOf("bukkit", "spigot", "paper", "purpur", "folia")
120113
dependencies {
121-
optional.project("packetevents")
122114
optional.project("PlaceholderAPI")
123115
optional.project("PlugManX")
124116
}

bukkit/dep-bukkit/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,17 @@ dependencies {
1313
implementation("net.kyori:adventure-platform-bukkit:4.4.1")
1414
implementation(libs.nbt.api)
1515
implementation(libs.bstats.bukkit)
16+
17+
implementation(libs.packetevents.spigot) {
18+
exclude(group = "com.github.retrooper", module = "packetevents-api")
19+
}
1620
}
1721

1822
relocateSources {
1923
relocate("net.kyori")
2024
relocate("net.kyori.adventure", "adventure")
25+
relocate("com.github.retrooper.packetevents", "packetevents")
26+
relocate("io.github.retrooper.packetevents", "packetevents")
2127

2228
relocate("de.tr7zw.changeme.nbtapi", "nbtapi")
2329
relocate("org.bstats", "bstats")

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/EsuBootstrapBukkit.kt

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import io.github.rothes.esu.core.util.artifact.relocator.PackageRelocator
1010
import it.unimi.dsi.fastutil.shorts.ShortArrayList
1111
import net.jpountz.lz4.LZ4Factory
1212
import org.bukkit.plugin.java.JavaPlugin
13+
import org.eclipse.aether.artifact.Artifact
14+
import java.io.File
1315
import java.nio.file.Path
1416
import java.util.logging.Level
1517

@@ -25,7 +27,7 @@ class EsuBootstrapBukkit: JavaPlugin(), EsuBootstrap {
2527
val esu = EsuPluginBukkit(this)
2628

2729
override fun onLoad() {
28-
super.onLoad()
30+
esu.onLoad()
2931
}
3032

3133
override fun onEnable() {
@@ -63,18 +65,27 @@ class EsuBootstrapBukkit: JavaPlugin(), EsuBootstrap {
6365
MavenResolver.loadDependencies(
6466
listOf(
6567
"net.neoforged:AutoRenamingTool:2.0.13",
66-
)
68+
),
69+
extraRepo = if (MavenResolver.loadRepoConfiguration().id == "aliyun") listOf() else listOf(MavenResolver.MavenRepos.NEO_FORGED)
6770
)
6871
if (ServerCompatibility.hasMojmap)
6972
MappingsLoader
7073
}
7174
val relocator = PackageRelocator(
7275
"net/kyori/adventure/" to "io/github/rothes/esu/lib/adventure/",
7376
"net/kyori/" to "io/github/rothes/esu/lib/net/kyori/",
77+
"io/github/retrooper/packetevents" to "io/github/rothes/esu/lib/packetevents",
78+
"com/github/retrooper/packetevents" to "io/github/rothes/esu/lib/packetevents",
7479

7580
"org/bstats" to "io/github/rothes/esu/lib/bstats",
7681
"de/tr7zw/changeme/nbtapi" to "io/github/rothes/esu/lib/nbtapi",
7782
)
83+
val loader = { file: File, artifact: Artifact ->
84+
if (artifact.extension == "jar" && setOf("net.kyori", "com.github.retrooper", "org.bstats", "de.tr7zw").contains(artifact.groupId))
85+
CachedRelocator.relocate(relocator, file, outputName = "${artifact.groupId}_${artifact.artifactId}")
86+
else
87+
file
88+
}
7889
MavenResolver.loadDependencies(
7990
listOf(
8091
"net.kyori:adventure-api:${BuildConfig.DEP_VERSION_ADVENTURE}",
@@ -84,15 +95,18 @@ class EsuBootstrapBukkit: JavaPlugin(), EsuBootstrap {
8495
"net.kyori:adventure-text-serializer-legacy:${BuildConfig.DEP_VERSION_ADVENTURE}",
8596
"net.kyori:adventure-text-serializer-plain:${BuildConfig.DEP_VERSION_ADVENTURE}",
8697
"net.kyori:adventure-platform-bukkit:4.4.1",
98+
),
99+
loader = loader,
100+
)
101+
MavenResolver.loadDependencies(
102+
listOf(
103+
"com.github.retrooper:packetevents-spigot:${BuildConfig.DEP_VERSION_PACKETEVENTS}",
87104
"org.bstats:bstats-bukkit:3.1.0",
88105
"de.tr7zw:item-nbt-api:${BuildConfig.DEP_VERSION_NBTAPI}",
89-
)
90-
) { file, artifact ->
91-
if (artifact.extension == "jar" && setOf("net.kyori", "org.bstats", "de.tr7zw").contains(artifact.groupId))
92-
CachedRelocator.relocate(relocator, file, outputName = "${artifact.groupId}_${artifact.artifactId}")
93-
else
94-
file
95-
}
106+
),
107+
extraRepo = listOf(MavenResolver.MavenRepos.CODEMC),
108+
loader = loader,
109+
)
96110
MavenResolver.testDependency("org.lz4:lz4-java:1.8.0") {
97111
LZ4Factory.fastestInstance()
98112
}

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/EsuPluginBukkit.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ import io.github.rothes.esu.core.storage.StorageManager
2929
import io.github.rothes.esu.core.util.InitOnce
3030
import io.github.rothes.esu.core.util.extension.ClassExt.jarFile
3131
import io.github.rothes.esu.lib.bstats.bukkit.Metrics
32+
import io.github.rothes.esu.lib.packetevents.PacketEvents
33+
import io.github.rothes.esu.lib.packetevents.factory.spigot.SpigotPacketEventsBuilder
3234
import org.bukkit.Bukkit
3335
import org.bukkit.command.ConsoleCommandSender
3436
import org.bukkit.entity.Player
@@ -117,6 +119,11 @@ class EsuPluginBukkit(
117119
}
118120
}
119121

122+
fun onLoad() {
123+
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(bootstrap))
124+
PacketEvents.getAPI().load()
125+
}
126+
120127
fun onEnable() {
121128
adventure // Init adventure
122129
EsuConfig // Load global config
@@ -125,6 +132,8 @@ class EsuPluginBukkit(
125132
ColorSchemes // Load color schemes
126133
UpdateCheckerMan // Init update checker
127134

135+
PacketEvents.getAPI().init()
136+
128137
ModuleManager.addModule(AutoReloadExtensionPluginsModule)
129138
ModuleManager.addModule(AutoRestartModule)
130139
ModuleManager.addModule(BetterEventMessagesModule)
@@ -268,6 +277,7 @@ class EsuPluginBukkit(
268277
UpdateCheckerMan.shutdown()
269278
StorageManager.shutdown()
270279
adventure.close()
280+
PacketEvents.getAPI().terminate()
271281
}
272282

273283
private fun byPlugMan(): Boolean {

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/NetworkThrottleModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.rothes.esu.bukkit.module
22

3-
import io.github.retrooper.packetevents.util.SpigotConversionUtil
43
import io.github.rothes.esu.bukkit.module.networkthrottle.ChunkDataThrottle
54
import io.github.rothes.esu.bukkit.module.networkthrottle.DynamicChunkSendRate
65
import io.github.rothes.esu.bukkit.module.networkthrottle.HighLatencyAdjust
@@ -17,6 +16,7 @@ import io.github.rothes.esu.core.configuration.serializer.MapSerializer.Defaulte
1716
import io.github.rothes.esu.core.module.configuration.BaseModuleConfiguration
1817
import io.github.rothes.esu.core.util.version.Version
1918
import io.github.rothes.esu.lib.configurate.objectmapping.meta.PostProcess
19+
import io.github.rothes.esu.lib.packetevents.util.SpigotConversionUtil
2020
import org.bukkit.Material
2121
import java.time.Duration
2222
import java.util.*

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/NewsModule.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import io.github.rothes.esu.bukkit.config.data.ItemData
55
import io.github.rothes.esu.bukkit.event.UserLoginEvent
66
import io.github.rothes.esu.bukkit.module.news.EditorManager
77
import io.github.rothes.esu.bukkit.module.news.NewsDataManager
8-
import io.github.rothes.esu.bukkit.plugin
98
import io.github.rothes.esu.bukkit.user
109
import io.github.rothes.esu.bukkit.user.ConsoleUser.buildMiniMessage
1110
import io.github.rothes.esu.bukkit.user.PlayerUser
@@ -40,16 +39,6 @@ object NewsModule: BukkitModule<NewsModule.ModuleConfig, NewsModule.ModuleLang>(
4039

4140
private val checkedCache = mutableMapOf<User, Int>()
4241

43-
override fun canUse(): Boolean {
44-
if (!super.canUse())
45-
return false
46-
if (!Bukkit.getPluginManager().isPluginEnabled("packetevents")) {
47-
plugin.err("[NewsModule] This module requires packetevents plugin!")
48-
return false
49-
}
50-
return true
51-
}
52-
5342
override fun enable() {
5443
EditorManager.enable()
5544
NewsDataManager.start()

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/SpoofServerSettingsModule.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package io.github.rothes.esu.bukkit.module
22

3-
import com.github.retrooper.packetevents.PacketEvents
4-
import com.github.retrooper.packetevents.event.PacketListenerAbstract
5-
import com.github.retrooper.packetevents.event.PacketListenerPriority
6-
import com.github.retrooper.packetevents.event.PacketSendEvent
7-
import com.github.retrooper.packetevents.protocol.packettype.PacketType
8-
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerDifficulty
9-
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateSimulationDistance
10-
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance
113
import io.github.rothes.esu.core.module.configuration.BaseModuleConfiguration
124
import io.github.rothes.esu.core.module.configuration.EmptyConfiguration
5+
import io.github.rothes.esu.lib.packetevents.PacketEvents
6+
import io.github.rothes.esu.lib.packetevents.event.PacketListenerAbstract
7+
import io.github.rothes.esu.lib.packetevents.event.PacketListenerPriority
8+
import io.github.rothes.esu.lib.packetevents.event.PacketSendEvent
9+
import io.github.rothes.esu.lib.packetevents.protocol.packettype.PacketType
10+
import io.github.rothes.esu.lib.packetevents.wrapper.play.server.WrapperPlayServerDifficulty
11+
import io.github.rothes.esu.lib.packetevents.wrapper.play.server.WrapperPlayServerUpdateSimulationDistance
12+
import io.github.rothes.esu.lib.packetevents.wrapper.play.server.WrapperPlayServerUpdateViewDistance
1313
import org.bukkit.Difficulty
1414
import java.util.*
1515
import kotlin.jvm.optionals.getOrNull
@@ -28,7 +28,7 @@ object SpoofServerSettingsModule: BukkitModule<SpoofServerSettingsModule.ModuleC
2828

2929
override fun onPacketSend(event: PacketSendEvent) {
3030
when (event.packetType) {
31-
PacketType.Play.Server.UPDATE_VIEW_DISTANCE -> {
31+
PacketType.Play.Server.UPDATE_VIEW_DISTANCE -> {
3232
val wrapper = WrapperPlayServerUpdateViewDistance(event)
3333
config.viewDistance.getOrNull()?.let {
3434
wrapper.viewDistance = it
@@ -43,7 +43,7 @@ object SpoofServerSettingsModule: BukkitModule<SpoofServerSettingsModule.ModuleC
4343
PacketType.Play.Server.SERVER_DIFFICULTY -> {
4444
val wrapper = WrapperPlayServerDifficulty(event)
4545
config.difficulty.getOrNull()?.let {
46-
wrapper.difficulty = com.github.retrooper.packetevents.protocol.world.Difficulty.valueOf(it.name)
46+
wrapper.difficulty = io.github.rothes.esu.lib.packetevents.protocol.world.Difficulty.valueOf(it.name)
4747
}
4848
}
4949
}

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/networkthrottle/HighLatencyAdjust.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
package io.github.rothes.esu.bukkit.module.networkthrottle
22

3-
import com.github.retrooper.packetevents.PacketEvents
4-
import com.github.retrooper.packetevents.event.PacketListenerAbstract
5-
import com.github.retrooper.packetevents.event.PacketListenerPriority
6-
import com.github.retrooper.packetevents.event.PacketReceiveEvent
7-
import com.github.retrooper.packetevents.protocol.packettype.PacketType
8-
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientSettings
93
import io.github.rothes.esu.bukkit.module.NetworkThrottleModule.config
104
import io.github.rothes.esu.bukkit.module.NetworkThrottleModule.data
115
import io.github.rothes.esu.bukkit.module.NetworkThrottleModule.locale
@@ -16,6 +10,12 @@ import io.github.rothes.esu.bukkit.util.extension.ListenerExt.register
1610
import io.github.rothes.esu.bukkit.util.extension.ListenerExt.unregister
1711
import io.github.rothes.esu.bukkit.util.scheduler.ScheduledTask
1812
import io.github.rothes.esu.bukkit.util.scheduler.Scheduler
13+
import io.github.rothes.esu.lib.packetevents.PacketEvents
14+
import io.github.rothes.esu.lib.packetevents.event.PacketListenerAbstract
15+
import io.github.rothes.esu.lib.packetevents.event.PacketListenerPriority
16+
import io.github.rothes.esu.lib.packetevents.event.PacketReceiveEvent
17+
import io.github.rothes.esu.lib.packetevents.protocol.packettype.PacketType
18+
import io.github.rothes.esu.lib.packetevents.wrapper.play.client.WrapperPlayClientSettings
1919
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap
2020
import org.bukkit.Bukkit
2121
import org.bukkit.entity.Player

bukkit/src/main/kotlin/io/github/rothes/esu/bukkit/module/news/EditorManager.kt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package io.github.rothes.esu.bukkit.module.news
22

3-
import com.github.retrooper.packetevents.PacketEvents
4-
import com.github.retrooper.packetevents.event.PacketListenerAbstract
5-
import com.github.retrooper.packetevents.event.PacketListenerPriority
6-
import com.github.retrooper.packetevents.event.PacketReceiveEvent
7-
import com.github.retrooper.packetevents.event.PacketSendEvent
8-
import com.github.retrooper.packetevents.protocol.packettype.PacketType
9-
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientEditBook
10-
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSetSlot
11-
import io.github.retrooper.packetevents.util.SpigotConversionUtil
123
import io.github.rothes.esu.bukkit.module.NewsModule.locale
134
import io.github.rothes.esu.bukkit.user
145
import io.github.rothes.esu.bukkit.user.PlayerUser
156
import io.github.rothes.esu.bukkit.util.extension.ListenerExt.register
167
import io.github.rothes.esu.bukkit.util.extension.ListenerExt.unregister
178
import io.github.rothes.esu.bukkit.util.version.adapter.ItemStackAdapter.Companion.meta
189
import io.github.rothes.esu.bukkit.util.version.adapter.ItemStackAdapter.Companion.metaGet
10+
import io.github.rothes.esu.lib.packetevents.PacketEvents
11+
import io.github.rothes.esu.lib.packetevents.event.PacketListenerAbstract
12+
import io.github.rothes.esu.lib.packetevents.event.PacketListenerPriority
13+
import io.github.rothes.esu.lib.packetevents.event.PacketReceiveEvent
14+
import io.github.rothes.esu.lib.packetevents.event.PacketSendEvent
15+
import io.github.rothes.esu.lib.packetevents.protocol.packettype.PacketType
16+
import io.github.rothes.esu.lib.packetevents.util.SpigotConversionUtil
17+
import io.github.rothes.esu.lib.packetevents.wrapper.play.client.WrapperPlayClientEditBook
18+
import io.github.rothes.esu.lib.packetevents.wrapper.play.server.WrapperPlayServerSetSlot
1919
import org.bukkit.Material
2020
import org.bukkit.entity.Player
2121
import org.bukkit.event.EventHandler
@@ -62,8 +62,7 @@ object EditorManager {
6262
meta.pages = content
6363
}
6464
val packet = WrapperPlayServerSetSlot(
65-
-2, 0, slot,
66-
SpigotConversionUtil.fromBukkitItemStack(item)
65+
-2, 0, slot, SpigotConversionUtil.fromBukkitItemStack(item)
6766
)
6867
PacketEvents.getAPI().playerManager.sendPacket(user.player, packet)
6968
}
@@ -104,8 +103,7 @@ object EditorManager {
104103
private fun restoreSlot(player: Player, slot: Int) {
105104
val item = player.inventory.getItem(slot)
106105
val packet = WrapperPlayServerSetSlot(
107-
-2, 0, slot,
108-
SpigotConversionUtil.fromBukkitItemStack(item)
106+
-2, 0, slot, SpigotConversionUtil.fromBukkitItemStack(item)
109107
)
110108
PacketEvents.getAPI().playerManager.sendPacket(player, packet)
111109
}

0 commit comments

Comments
 (0)