Only use nms classes when needed

This commit is contained in:
Jakob K
2021-08-24 01:17:04 +02:00
parent 667f6399a4
commit d408114333

View File

@@ -29,8 +29,9 @@ object BrigardierSupport {
* and to manage and dispatch the brigardier commands for * and to manage and dispatch the brigardier commands for
* all players on the server. * all players on the server.
*/ */
@Suppress("HasPlatformType") // do not refer non-lazily to the type in this class
@NMS_General @NMS_General
val commandManager: net.minecraft.commands.CommandDispatcher by lazy { val commandManager by lazy {
(server as CraftServer).server.commandDispatcher (server as CraftServer).server.commandDispatcher
} }
@@ -45,10 +46,13 @@ object BrigardierSupport {
@NMS_General @NMS_General
internal fun registerAll() { internal fun registerAll() {
commands.forEach { commandDispatcher.register(it) }
executedDefaultRegistration = true executedDefaultRegistration = true
if (onlinePlayers.isNotEmpty())
updateCommandTree() if (commands.isNotEmpty()) {
commands.forEach { commandDispatcher.register(it) }
if (onlinePlayers.isNotEmpty())
updateCommandTree()
}
} }
@NMS_1_17 @NMS_1_17