Register forge-commands on the correct event

This commit is contained in:
Lukas Rieger (Blue) 2022-08-03 19:00:04 +02:00
parent 35cbdf67d6
commit 3c866b317d
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
5 changed files with 25 additions and 5 deletions

View File

@ -43,6 +43,7 @@
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent; import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
@ -99,9 +100,12 @@ public ForgeMod() {
@SubscribeEvent @SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) { public void onServerStarting(FMLServerStartingEvent event) {
this.serverInstance = event.getServer(); this.serverInstance = event.getServer();
}
@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent event) {
//register commands //register commands
new Commands<>(pluginInstance, event.getServer().getCommandManager().getDispatcher(), forgeSource -> new Commands<>(pluginInstance, event.getDispatcher(), forgeSource ->
new ForgeCommandSource(this, pluginInstance, forgeSource) new ForgeCommandSource(this, pluginInstance, forgeSource)
); );
} }

View File

@ -43,6 +43,7 @@
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent; import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
@ -98,9 +99,12 @@ public ForgeMod() {
@SubscribeEvent @SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) { public void onServerStarting(FMLServerStartingEvent event) {
this.serverInstance = event.getServer(); this.serverInstance = event.getServer();
}
@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent event) {
//register commands //register commands
new Commands<>(pluginInstance, event.getServer().getCommands().getDispatcher(), forgeSource -> new Commands<>(pluginInstance, event.getDispatcher(), forgeSource ->
new ForgeCommandSource(this, pluginInstance, forgeSource) new ForgeCommandSource(this, pluginInstance, forgeSource)
); );
} }

View File

@ -43,6 +43,7 @@
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent; import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
@ -98,9 +99,12 @@ public ForgeMod() {
@SubscribeEvent @SubscribeEvent
public void onServerStarting(ServerStartingEvent event) { public void onServerStarting(ServerStartingEvent event) {
this.serverInstance = event.getServer(); this.serverInstance = event.getServer();
}
@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent event) {
//register commands //register commands
new Commands<>(pluginInstance, event.getServer().getCommands().getDispatcher(), forgeSource -> new Commands<>(pluginInstance, event.getDispatcher(), forgeSource ->
new ForgeCommandSource(this, pluginInstance, forgeSource) new ForgeCommandSource(this, pluginInstance, forgeSource)
); );
} }

View File

@ -43,6 +43,7 @@
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent; import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
@ -98,9 +99,12 @@ public ForgeMod() {
@SubscribeEvent @SubscribeEvent
public void onServerStarting(ServerStartingEvent event) { public void onServerStarting(ServerStartingEvent event) {
this.serverInstance = event.getServer(); this.serverInstance = event.getServer();
}
@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent event) {
//register commands //register commands
new Commands<>(pluginInstance, event.getServer().getCommands().getDispatcher(), forgeSource -> new Commands<>(pluginInstance, event.getDispatcher(), forgeSource ->
new ForgeCommandSource(this, pluginInstance, forgeSource) new ForgeCommandSource(this, pluginInstance, forgeSource)
); );
} }

View File

@ -43,6 +43,7 @@
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TickEvent.ServerTickEvent; import net.minecraftforge.event.TickEvent.ServerTickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent; import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
@ -98,9 +99,12 @@ public ForgeMod() {
@SubscribeEvent @SubscribeEvent
public void onServerStarting(ServerStartingEvent event) { public void onServerStarting(ServerStartingEvent event) {
this.serverInstance = event.getServer(); this.serverInstance = event.getServer();
}
@SubscribeEvent
public void onRegisterCommands(RegisterCommandsEvent event) {
//register commands //register commands
new Commands<>(pluginInstance, event.getServer().getCommands().getDispatcher(), forgeSource -> new Commands<>(pluginInstance, event.getDispatcher(), forgeSource ->
new ForgeCommandSource(this, pluginInstance, forgeSource) new ForgeCommandSource(this, pluginInstance, forgeSource)
); );
} }