|
| 1 | +package org.dynmap.forge_1_21_6; |
| 2 | + |
| 3 | +import java.io.File; |
| 4 | + |
| 5 | +import org.apache.commons.lang3.tuple.Pair; |
| 6 | +import org.dynmap.DynmapCommonAPI; |
| 7 | +import org.dynmap.DynmapCommonAPIListener; |
| 8 | +import org.dynmap.Log; |
| 9 | +import org.dynmap.forge_1_21_6.DynmapPlugin.OurLog; |
| 10 | + |
| 11 | +import net.minecraft.server.MinecraftServer; |
| 12 | +import net.minecraftforge.fml.common.Mod; |
| 13 | +import net.minecraftforge.common.MinecraftForge; |
| 14 | +import net.minecraftforge.event.server.ServerAboutToStartEvent; |
| 15 | +import net.minecraftforge.event.server.ServerStartedEvent; |
| 16 | +import net.minecraftforge.event.server.ServerStartingEvent; |
| 17 | +import net.minecraftforge.event.server.ServerStoppingEvent; |
| 18 | +import net.minecraftforge.eventbus.api.bus.BusGroup; |
| 19 | +import net.minecraftforge.eventbus.api.bus.EventBus; |
| 20 | +import net.minecraftforge.eventbus.api.listener.SubscribeEvent; |
| 21 | +import net.minecraftforge.fml.DistExecutor; |
| 22 | +import net.minecraftforge.fml.IExtensionPoint; |
| 23 | +import net.minecraftforge.fml.ModList; |
| 24 | +import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; |
| 25 | +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; |
| 26 | + |
| 27 | +@Mod("dynmap") |
| 28 | +public class DynmapMod |
| 29 | +{ |
| 30 | + // The instance of your mod that Forge uses. |
| 31 | + public static DynmapMod instance; |
| 32 | + public static BusGroup modBusGroup; |
| 33 | + |
| 34 | + // Says where the client and server 'proxy' code is loaded. |
| 35 | + public static Proxy proxy = DistExecutor.runForDist(() -> ClientProxy::new, () -> Proxy::new); |
| 36 | + |
| 37 | + public static DynmapPlugin plugin; |
| 38 | + public static File jarfile; |
| 39 | + public static String ver; |
| 40 | + public static boolean useforcedchunks; |
| 41 | + |
| 42 | + public class APICallback extends DynmapCommonAPIListener { |
| 43 | + @Override |
| 44 | + public void apiListenerAdded() { |
| 45 | + if(plugin == null) { |
| 46 | + plugin = proxy.startServer(server); |
| 47 | + } |
| 48 | + } |
| 49 | + @Override |
| 50 | + public void apiEnabled(DynmapCommonAPI api) { |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + public DynmapMod(FMLJavaModLoadingContext context) { |
| 55 | + instance = this; |
| 56 | + |
| 57 | + modBusGroup = context.getModBusGroup(); |
| 58 | + |
| 59 | + // Register the commonSetup method for modloading |
| 60 | + FMLCommonSetupEvent.getBus(modBusGroup).addListener(this::setup); |
| 61 | + |
| 62 | + MinecraftForge.EVENT_BUS.register(this); |
| 63 | + |
| 64 | + context.registerExtensionPoint(IExtensionPoint.DisplayTest.class, |
| 65 | + ()->new IExtensionPoint.DisplayTest(()->IExtensionPoint.DisplayTest.IGNORESERVERONLY, (remote, isServer)-> true)); |
| 66 | + |
| 67 | + Log.setLogger(new OurLog()); |
| 68 | + org.dynmap.modsupport.ModSupportImpl.init(); |
| 69 | + } |
| 70 | + |
| 71 | + public void setup(final FMLCommonSetupEvent event) |
| 72 | + { |
| 73 | + //TOOO |
| 74 | + jarfile = ModList.get().getModFileById("dynmap").getFile().getFilePath().toFile(); |
| 75 | + |
| 76 | + ver = ModList.get().getModContainerById("dynmap").get().getModInfo().getVersion().toString(); |
| 77 | + |
| 78 | + //// Load configuration file - use suggested (config/WesterosBlocks.cfg) |
| 79 | + //Configuration cfg = new Configuration(event.getSuggestedConfigurationFile()); |
| 80 | + //try { |
| 81 | + // cfg.load(); |
| 82 | + // |
| 83 | + // useforcedchunks = cfg.get("Settings", "UseForcedChunks", true).getBoolean(true); |
| 84 | + //} |
| 85 | + //finally |
| 86 | + //{ |
| 87 | + // cfg.save(); |
| 88 | + //} |
| 89 | + } |
| 90 | + |
| 91 | + private MinecraftServer server; |
| 92 | + |
| 93 | + @SubscribeEvent |
| 94 | + public void onServerStarting(ServerAboutToStartEvent event) { |
| 95 | + server = event.getServer(); |
| 96 | + if(plugin == null) |
| 97 | + plugin = proxy.startServer(server); |
| 98 | + plugin.onStarting(server.getCommands().getDispatcher()); |
| 99 | + } |
| 100 | + |
| 101 | + @SubscribeEvent |
| 102 | + public void onServerStarted(ServerStartedEvent event) { |
| 103 | + DynmapCommonAPIListener.register(new APICallback()); |
| 104 | + plugin.serverStarted(); |
| 105 | + } |
| 106 | + |
| 107 | + @SubscribeEvent |
| 108 | + public void serverStopping(ServerStoppingEvent event) |
| 109 | + { |
| 110 | + proxy.stopServer(plugin); |
| 111 | + plugin = null; |
| 112 | + } |
| 113 | +} |
0 commit comments