Skip to content

Commit ff0ed0e

Browse files
committed
fix: handle commands with no package defined
1 parent 0b5e10b commit ff0ed0e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/kotlin/gg/skytils/skytilsmod/features/impl/handlers/NamespacedCommands.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import gg.skytils.skytilsmod.utils.ObservableSet
2929
import net.minecraft.command.ICommand
3030
import net.minecraftforge.client.ClientCommandHandler
3131
import net.minecraftforge.fml.common.Loader
32+
import net.minecraftforge.fml.common.ModContainer
3233
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
3334

3435
/**
@@ -75,7 +76,7 @@ object NamespacedCommands {
7576
* This method takes a command and registers the command's namespaced version.
7677
*/
7778
fun registerCommandHelper(command: ICommand) {
78-
val owners = Loader.instance().modList.filter { command.javaClass.`package`.name in it.ownedPackages }
79+
val owners = getCommandModOwner(command.javaClass)
7980
if (owners.size != 1) {
8081
println("WARNING! Command ${command.commandName} has ${owners.size}; owners: $owners")
8182
}
@@ -90,6 +91,11 @@ object NamespacedCommands {
9091
aliasMap[command] = helper
9192
}
9293

94+
fun getCommandModOwner(command: Class<*>) : List<ModContainer> {
95+
val packageName = command.`package`.name ?: return emptyList()
96+
return Loader.instance().modList.filter { packageName in it.ownedPackages }
97+
}
98+
9399
/**
94100
* Handles the actual sending of the command.
95101
*

0 commit comments

Comments
 (0)