diff options
Diffstat (limited to 'spark-forge/src/main/java')
3 files changed, 22 insertions, 21 deletions
diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java index 4aad23a..5ee55f7 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java @@ -62,7 +62,7 @@ public class ForgeCommandSender extends AbstractCommandSender<ICommandSource> { @Override public void sendMessage(Component message) { - IFormattableTextComponent component = ITextComponent.Serializer.func_240643_a_(GsonComponentSerializer.INSTANCE.serialize(message)); + IFormattableTextComponent component = ITextComponent.Serializer.getComponentFromJson(GsonComponentSerializer.INSTANCE.serialize(message)); super.delegate.sendMessage(component, Util.DUMMY_UUID); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java index 4fa0274..e4e7c49 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java @@ -23,6 +23,7 @@ package me.lucko.spark.forge; import me.lucko.spark.forge.plugin.ForgeClientSparkPlugin; import me.lucko.spark.forge.plugin.ForgeServerSparkPlugin; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.ExtensionPoint; import net.minecraftforge.fml.ModContainer; @@ -30,7 +31,6 @@ import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import net.minecraftforge.fml.event.server.FMLServerStartingEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; import net.minecraftforge.fml.loading.FMLPaths; import net.minecraftforge.fml.network.FMLNetworkConstants; @@ -45,8 +45,10 @@ public class ForgeSparkMod { private Path configDirectory; public ForgeSparkMod() { - FMLJavaModLoadingContext.get().getModEventBus().register(this); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientInit); MinecraftForge.EVENT_BUS.register(this); + ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); } @@ -54,18 +56,16 @@ public class ForgeSparkMod { return this.container.getModInfo().getVersion().toString(); } - @SubscribeEvent public void setup(FMLCommonSetupEvent e) { this.container = ModLoadingContext.get().getActiveContainer(); this.configDirectory = FMLPaths.CONFIGDIR.get().resolve(this.container.getModId()); } @SubscribeEvent - public void serverInit(FMLServerStartingEvent e) { + public void registerCommands(RegisterCommandsEvent e) { ForgeServerSparkPlugin.register(this, e); } - @SubscribeEvent public void clientInit(FMLClientSetupEvent e) { ForgeClientSparkPlugin.register(this, e); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java index c7a4475..3433e3b 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java @@ -44,38 +44,39 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.event.server.FMLServerStartingEvent; +import net.minecraftforge.fml.event.server.FMLServerStoppingEvent; +import net.minecraftforge.fml.server.ServerLifecycleHooks; import net.minecraftforge.server.permission.DefaultPermissionLevel; import net.minecraftforge.server.permission.PermissionAPI; import java.util.Arrays; import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; import java.util.stream.Stream; public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command<CommandSource>, SuggestionProvider<CommandSource> { - public static void register(ForgeSparkMod mod, FMLServerStartingEvent event) { - final MinecraftServer minecraftServer = event.getServer(); - - ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, minecraftServer); + public static void register(ForgeSparkMod mod, RegisterCommandsEvent event) { + ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, ServerLifecycleHooks::getCurrentServer); MinecraftForge.EVENT_BUS.register(plugin); + CommandDispatcher<CommandSource> dispatcher = event.getDispatcher(); + registerCommands(dispatcher, plugin, plugin, "spark"); PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command"); } - private final MinecraftServer server; + @SubscribeEvent + public void onDisable(FMLServerStoppingEvent event) { + this.platform.disable(); + } + + private final Supplier<MinecraftServer> server; - public ForgeServerSparkPlugin(ForgeSparkMod mod, MinecraftServer server) { + public ForgeServerSparkPlugin(ForgeSparkMod mod, Supplier<MinecraftServer> server) { super(mod); this.server = server; } - @SubscribeEvent - public void onRegisterCommands(RegisterCommandsEvent e) { - CommandDispatcher<CommandSource> dispatcher = e.getDispatcher(); - registerCommands(dispatcher, this, this, "spark"); - } - @Override public int run(CommandContext<CommandSource> context) throws CommandSyntaxException { String[] args = processArgs(context); @@ -124,8 +125,8 @@ public class ForgeServerSparkPlugin extends ForgeSparkPlugin implements Command< @Override public Stream<ForgeCommandSender> getSendersWithPermission(String permission) { return Stream.concat( - this.server.getPlayerList().getPlayers().stream().filter(player -> hasPermission(player, permission)), - Stream.of(this.server) + this.server.get().getPlayerList().getPlayers().stream().filter(player -> hasPermission(player, permission)), + Stream.of(this.server.get()) ).map(sender -> new ForgeCommandSender(sender, this)); } |