aboutsummaryrefslogtreecommitdiff
path: root/spark-forge/src/main/java/me
diff options
context:
space:
mode:
authorPhilip T <me@phit.link>2020-10-25 13:33:47 +0100
committerGitHub <noreply@github.com>2020-10-25 12:33:47 +0000
commit91c75536a3085378467a83e0cfb03d49c72e78cf (patch)
tree2f632fcfd4c8e2a5537e89da2087e6020186ca81 /spark-forge/src/main/java/me
parentedce348ac2dbc4e1f8d033633e06ca4f039f4fa0 (diff)
downloadspark-91c75536a3085378467a83e0cfb03d49c72e78cf.tar.gz
spark-91c75536a3085378467a83e0cfb03d49c72e78cf.tar.bz2
spark-91c75536a3085378467a83e0cfb03d49c72e78cf.zip
Update for Forge 1.16.3 (#76)
Diffstat (limited to 'spark-forge/src/main/java/me')
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/ForgeCommandSender.java2
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/ForgeSparkMod.java10
-rw-r--r--spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeServerSparkPlugin.java31
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));
}