Skip to content

Commit 7947a61

Browse files
committed
Unregistered command on client after re-login fixed.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 6b0320d commit 7947a61

3 files changed

Lines changed: 7 additions & 31 deletions

File tree

src/main/kotlin/com/mairwunnx/projectessentials/core/EntryPoint.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ internal class EntryPoint {
5353

5454
init {
5555
EventBridge.initialize()
56-
providers.forEach { ProviderAPI.addProvider(it) }
56+
providers.forEach(ProviderAPI::addProvider)
5757
subscribeEvents()
5858
EVENT_BUS.register(this)
5959
}

src/main/kotlin/com/mairwunnx/projectessentials/core/api/v1/commands/CommandAPI.kt

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import com.mojang.brigadier.arguments.BoolArgumentType
77
import com.mojang.brigadier.arguments.IntegerArgumentType
88
import com.mojang.brigadier.arguments.StringArgumentType
99
import com.mojang.brigadier.context.CommandContext
10-
import com.mojang.brigadier.tree.RootCommandNode
1110
import net.minecraft.command.CommandSource
1211
import net.minecraft.command.arguments.EntityArgument
1312
import net.minecraft.entity.Entity
@@ -18,30 +17,9 @@ import net.minecraft.entity.player.ServerPlayerEntity
1817
* @since 2.0.0-SNAPSHOT.1.
1918
*/
2019
object CommandAPI {
21-
private lateinit var registeredCommands: RootCommandNode<CommandSource>
2220
private lateinit var dispatcher: CommandDispatcher<CommandSource>
2321
private var dispatcherAssigned = false
2422

25-
/**
26-
* Internal function. Assign dispatcher root
27-
* for removing command. Must be called before
28-
* any processor initializing.
29-
* @param dispatcher command dispatcher.
30-
* @since 2.0.0-SNAPSHOT.1.
31-
*/
32-
/*
33-
This is a crutch to replace vanilla commands,
34-
and to gain access to the dispatcher root.
35-
*/
36-
@Suppress("UNCHECKED_CAST")
37-
internal fun assignDispatcherRoot(
38-
dispatcher: CommandDispatcher<CommandSource>
39-
) {
40-
val root = dispatcher.javaClass.getDeclaredField("root")
41-
root.isAccessible = true
42-
registeredCommands = root.get(dispatcher) as RootCommandNode<CommandSource>
43-
}
44-
4523
/**
4624
* Assign dispatcher for command registering.
4725
* @param dispatcher command dispatcher.
@@ -50,10 +28,8 @@ object CommandAPI {
5028
fun assignDispatcher(
5129
dispatcher: CommandDispatcher<CommandSource>
5230
) {
53-
if (!dispatcherAssigned) {
54-
dispatcherAssigned = true
55-
this.dispatcher = dispatcher
56-
}
31+
if (!dispatcherAssigned) dispatcherAssigned = true
32+
this.dispatcher = dispatcher
5733
}
5834

5935
/**
@@ -81,8 +57,8 @@ object CommandAPI {
8157
* @return true if command removed, false otherwise.
8258
* @since 2.0.0-SNAPSHOT.1.
8359
*/
84-
fun removeCommand(command: String): Boolean =
85-
registeredCommands.children.removeIf { it.name == command }
60+
fun removeCommand(command: String) =
61+
dispatcher.root.children.removeIf { it.name == command }
8662

8763
/**
8864
* @param context command context.

src/main/kotlin/com/mairwunnx/projectessentials/core/impl/ModuleObject.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import net.minecraftforge.common.MinecraftForge
2525
import net.minecraftforge.event.entity.living.LivingDeathEvent
2626
import net.minecraftforge.event.entity.player.PlayerEvent
2727
import net.minecraftforge.event.world.BlockEvent
28+
import net.minecraftforge.eventbus.api.EventPriority
2829
import net.minecraftforge.eventbus.api.SubscribeEvent
2930
import net.minecraftforge.fml.event.server.FMLServerStartingEvent
3031
import net.minecraftforge.fml.event.server.FMLServerStoppingEvent
@@ -74,13 +75,12 @@ internal class ModuleObject : IModule {
7475
event: FMLServerStoppingEvent
7576
) = ConfigurationAPI.saveAll()
7677

77-
@SubscribeEvent
78+
@SubscribeEvent(priority = EventPriority.HIGHEST)
7879
fun onServerStarting(event: FMLServerStartingEvent) {
7980
dudeFuckedOff = File(
8081
projectConfigDirectory + File.separator + "fuck-off-dude.txt"
8182
).exists().also { if (!it) printGreetingMessage() }
8283

83-
CommandAPI.assignDispatcherRoot(event.commandDispatcher)
8484
CommandAPI.assignDispatcher(event.commandDispatcher)
8585

8686
if (generalConfiguration.getBool(SETTING_NATIVE_COMMAND_REPLACE)) {

0 commit comments

Comments
 (0)