diff options
author | Darkere <Dark-277@web.de> | 2020-08-30 10:27:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-30 09:27:21 +0100 |
commit | 0e073d913f659c6e957de6c651fc5304a82f93b3 (patch) | |
tree | 0e2dc3a6040ad416b6489c71d77a0d7a810c80bc /spark-forge/src/main/java | |
parent | 4f59483b8e337666363100e820f05e8e94be1523 (diff) | |
download | spark-0e073d913f659c6e957de6c651fc5304a82f93b3.tar.gz spark-0e073d913f659c6e957de6c651fc5304a82f93b3.tar.bz2 spark-0e073d913f659c6e957de6c651fc5304a82f93b3.zip |
sparkforge for 1.16.1 (#65)
Diffstat (limited to 'spark-forge/src/main/java')
5 files changed, 28 insertions, 28 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 4ef5087..4aad23a 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 @@ -27,6 +27,8 @@ import net.kyori.text.serializer.gson.GsonComponentSerializer; import net.minecraft.command.ICommandSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.network.rcon.IServer; +import net.minecraft.util.Util; +import net.minecraft.util.text.IFormattableTextComponent; import net.minecraft.util.text.ITextComponent; import java.util.UUID; @@ -60,8 +62,8 @@ public class ForgeCommandSender extends AbstractCommandSender<ICommandSource> { @Override public void sendMessage(Component message) { - ITextComponent component = ITextComponent.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(message)); - super.delegate.sendMessage(component); + IFormattableTextComponent component = ITextComponent.Serializer.func_240643_a_(GsonComponentSerializer.INSTANCE.serialize(message)); + super.delegate.sendMessage(component, Util.DUMMY_UUID); } @Override 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 a1c7d55..b6d166b 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 @@ -30,7 +30,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; @@ -43,10 +42,12 @@ public class ForgeSparkMod { private ModContainer container; private Path configDirectory; + public static ForgeSparkMod mod = null; public ForgeSparkMod() { + mod = this; FMLJavaModLoadingContext.get().getModEventBus().register(this); - MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(ForgeServerSparkPlugin.class); ModLoadingContext.get().registerExtensionPoint(ExtensionPoint.DISPLAYTEST, () -> Pair.of(() -> FMLNetworkConstants.IGNORESERVERONLY, (a, b) -> true)); } @@ -62,12 +63,7 @@ public class ForgeSparkMod { @SubscribeEvent public void clientInit(FMLClientSetupEvent e) { - ForgeClientSparkPlugin.register(this, e); - } - - @SubscribeEvent - public void serverInit(FMLServerStartingEvent e) { - ForgeServerSparkPlugin.register(this, e); + ForgeClientSparkPlugin.register(e); } public Path getConfigDirectory() { diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java index 66fd3ab..83c448a 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeClientSparkPlugin.java @@ -53,10 +53,10 @@ import java.util.stream.Stream; public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements SuggestionProvider<ISuggestionProvider> { - public static void register(ForgeSparkMod mod, FMLClientSetupEvent event) { + public static void register(FMLClientSetupEvent event) { Minecraft minecraft = event.getMinecraftSupplier().get(); - ForgeClientSparkPlugin plugin = new ForgeClientSparkPlugin(mod, minecraft); + ForgeClientSparkPlugin plugin = new ForgeClientSparkPlugin(minecraft); MinecraftForge.EVENT_BUS.register(plugin); plugin.scheduler.scheduleWithFixedDelay(plugin::checkCommandRegistered, 10, 10, TimeUnit.SECONDS); @@ -65,8 +65,8 @@ public class ForgeClientSparkPlugin extends ForgeSparkPlugin implements Suggesti private final Minecraft minecraft; private CommandDispatcher<ISuggestionProvider> dispatcher; - public ForgeClientSparkPlugin(ForgeSparkMod mod, Minecraft minecraft) { - super(mod); + public ForgeClientSparkPlugin(Minecraft minecraft) { + super(); this.minecraft = minecraft; } 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 3978ba4..b7285b4 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 @@ -32,7 +32,6 @@ import me.lucko.spark.common.sampler.tick.TickHook; import me.lucko.spark.common.sampler.tick.TickReporter; import me.lucko.spark.forge.ForgeCommandSender; import me.lucko.spark.forge.ForgePlatformInfo; -import me.lucko.spark.forge.ForgeSparkMod; import me.lucko.spark.forge.ForgeTickHook; import me.lucko.spark.forge.ForgeTickReporter; import net.minecraft.command.CommandSource; @@ -40,30 +39,33 @@ import net.minecraft.command.ICommandSource; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.server.MinecraftServer; +import net.minecraftforge.event.RegisterCommandsEvent; import net.minecraftforge.event.TickEvent; -import net.minecraftforge.fml.event.server.FMLServerStartingEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +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) { - MinecraftServer server = event.getServer(); - ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(mod, server); - - CommandDispatcher<CommandSource> dispatcher = event.getCommandDispatcher(); + @SubscribeEvent + public static void register(RegisterCommandsEvent event) { + ForgeServerSparkPlugin plugin = new ForgeServerSparkPlugin(ServerLifecycleHooks::getCurrentServer); + CommandDispatcher<CommandSource> dispatcher = event.getDispatcher(); registerCommands(dispatcher, plugin, plugin, "spark"); PermissionAPI.registerNode("spark", DefaultPermissionLevel.OP, "Access to the spark command"); } - private final MinecraftServer server; - public ForgeServerSparkPlugin(ForgeSparkMod mod, MinecraftServer server) { - super(mod); + private final Supplier<MinecraftServer> server; + + public ForgeServerSparkPlugin(Supplier<MinecraftServer> server) { + super(); this.server = server; } @@ -113,8 +115,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)); } diff --git a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java index 920ca24..d7ef386 100644 --- a/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java +++ b/spark-forge/src/main/java/me/lucko/spark/forge/plugin/ForgeSparkPlugin.java @@ -63,8 +63,8 @@ public abstract class ForgeSparkPlugin implements SparkPlugin { protected final ScheduledExecutorService scheduler; protected final SparkPlatform platform; - protected ForgeSparkPlugin(ForgeSparkMod mod) { - this.mod = mod; + protected ForgeSparkPlugin() { + this.mod = ForgeSparkMod.mod; this.scheduler = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("spark-forge-async-worker").build() ); |