diff --git a/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java b/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java deleted file mode 100644 index 72a66f2..0000000 --- a/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public interface IProxy { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java index 43f16c7..5a6e5a6 100644 --- a/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ b/1.10.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -1,10 +1,13 @@ package net.teamfruit.serverobserver; +import java.io.File; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.logging.log4j.Logger; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; @@ -13,11 +16,14 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkCheckHandler; import net.minecraftforge.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class ServerObserver { @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - private static @Nullable IProxy proxy; + private static @Nullable CommonProxy proxy; @NetworkCheckHandler public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map versions, final @ @EventHandler public void preInit(final @Nonnull FMLPreInitializationEvent event) { if (proxy!=null) - proxy.preInit(event); + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); } @EventHandler public void init(final @Nonnull FMLInitializationEvent event) { if (proxy!=null) - proxy.init(event); + proxy.init(new CompatFMLInitializationEventImpl(event)); } @EventHandler public void postInit(final @Nonnull FMLPostInitializationEvent event) { if (proxy!=null) - proxy.postInit(event); + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } } } diff --git a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java deleted file mode 100644 index 3c7bb02..0000000 --- a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nonnull; - -import org.apache.commons.io.FileUtils; - -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class ClientProxy extends CommonProxy { - @Override - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - super.preInit(event); - final File cfgDir = event.getModConfigurationDirectory(); - final File modCfgDir = new File(cfgDir, Reference.MODID); - final File oldCfg = event.getSuggestedConfigurationFile(); - final File cfg = new File(modCfgDir, Reference.MODID+".cfg"); - if (oldCfg.exists()) - try { - FileUtils.moveFile(oldCfg, cfg); - } catch (final IOException e) { - } - final File dynCfg = new File(Minecraft.getMinecraft().mcDataDir, Reference.MODID+".cfg"); - Config.init(cfg, dynCfg, "1.1.0", Compat.compat); - CoreHandler.instance.preInit(modCfgDir); - } - - @Override - public void init(final @Nonnull FMLInitializationEvent event) { - super.init(event); - // Event Register - CoreHandler.instance.init(); - } - - @Override - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - super.postInit(event); - Config.getConfig().save(); - } -} \ No newline at end of file diff --git a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java deleted file mode 100644 index 42d04c0..0000000 --- a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.teamfruit.serverobserver; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy implements IProxy { - @Override - public void preInit(final FMLPreInitializationEvent event) { - } - - @Override - public void init(final FMLInitializationEvent event) { - } - - @Override - public void postInit(final FMLPostInitializationEvent event) { - } -} diff --git a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java new file mode 100644 index 0000000..ae99387 --- /dev/null +++ b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java @@ -0,0 +1,66 @@ +package net.teamfruit.serverobserver; + +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.IModGuiFactory; +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.IConfigElement; + +public class CompatConfigs { + public static class CompatGuiConfig extends GuiConfig { + public CompatGuiConfig(final GuiScreen parentScreen, final List configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + public final IConfigElement element; + + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @SuppressWarnings("deprecation") + @Override + public RuntimeOptionGuiHandler getHandlerFor(final RuntimeOptionCategoryElement element) { + return null; + } + + @Override + public @Nullable Class mainConfigGuiClass() { + return mainConfigGuiClassCompat(); + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..5eec16c --- /dev/null +++ b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.getModID(); + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java deleted file mode 100644 index fed6de7..0000000 --- a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java +++ /dev/null @@ -1,92 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringUtils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.I18n; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.IModGuiFactory; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; - -/** - * コンフィグGUI - * - * @author Kamesuta - */ -public class ConfigGuiFactory implements IModGuiFactory { - - public static class ConfigGui extends GuiConfig { - - public ConfigGui(final @Nullable GuiScreen parent) { - super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("serverobserver.config")); - } - - private static @Nonnull List getConfigElements() { - final List list = new ArrayList(); - getConfigElements(list, Config.getConfig().getBase()); - getConfigElements(list, Config.getConfig().getBaseDynamic()); - return list; - } - - private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { - ConfigCategory general = null; - - for (final String cat : cb.getCategoryNames()) { - final ConfigCategory cc = cb.getCategory(cat); - - if (StringUtils.equals(cc.getName(), Configuration.CATEGORY_GENERAL)) { - general = cc; - continue; - } - - if (cc.isChild()) - continue; - - list.add(new ConfigElement(cc)); - } - - // General項目をトップに表示します - if (general!=null) { - for (final ConfigCategory cc : general.getChildren()) - list.add(new ConfigElement(cc)); - for (final Property prop : general.values()) - list.add(new ConfigElement(prop)); - } - - return list; - } - } - - @Override - public void initialize(final @Nullable Minecraft minecraftInstance) { - - } - - @Override - public @Nullable Class mainConfigGuiClass() { - return ConfigGui.class; - } - - @Override - public @Nullable Set runtimeGuiCategories() { - return null; - } - - @SuppressWarnings("deprecation") - @Override - public @Nullable RuntimeOptionGuiHandler getHandlerFor(final @Nullable RuntimeOptionCategoryElement element) { - return null; - } -} \ No newline at end of file diff --git a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java deleted file mode 100644 index 0d9b3f6..0000000 --- a/1.10.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; - -import javax.annotation.Nonnull; - -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; -import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; - -public class CoreHandler { - public static final @Nonnull CoreHandler instance = new CoreHandler(); - - public final @Nonnull Config configHandler = Config.getConfig(); - public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); - - public void preInit(final File root) { - this.guiHandler.init(root); - } - - public void init() { - // FMLCommonHandler.instance().bus().register(this); - MinecraftForge.EVENT_BUS.register(this); - } - - @SubscribeEvent - public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { - for (final ConfigBase base : ConfigBase.configChangeHandlers) - base.onConfigChanged(eventArgs.getModID()); - } - - @SubscribeEvent - public void open(final InitGuiEvent.Post e) { - this.guiHandler.open(e); - } - - @SubscribeEvent - public void draw(final DrawScreenEvent.Post e) { - this.guiHandler.draw(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Pre e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Post e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void tickclient(final @Nonnull ClientTickEvent e) { - this.guiHandler.tickclient(); - } -} \ No newline at end of file diff --git a/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java b/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java deleted file mode 100644 index 72a66f2..0000000 --- a/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public interface IProxy { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java index 43f16c7..5a6e5a6 100644 --- a/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ b/1.11.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -1,10 +1,13 @@ package net.teamfruit.serverobserver; +import java.io.File; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.logging.log4j.Logger; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; @@ -13,11 +16,14 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkCheckHandler; import net.minecraftforge.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class ServerObserver { @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - private static @Nullable IProxy proxy; + private static @Nullable CommonProxy proxy; @NetworkCheckHandler public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map versions, final @ @EventHandler public void preInit(final @Nonnull FMLPreInitializationEvent event) { if (proxy!=null) - proxy.preInit(event); + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); } @EventHandler public void init(final @Nonnull FMLInitializationEvent event) { if (proxy!=null) - proxy.init(event); + proxy.init(new CompatFMLInitializationEventImpl(event)); } @EventHandler public void postInit(final @Nonnull FMLPostInitializationEvent event) { if (proxy!=null) - proxy.postInit(event); + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } } } diff --git a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java deleted file mode 100644 index 9da3ac9..0000000 --- a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nonnull; - -import org.apache.commons.io.FileUtils; - -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class ClientProxy extends CommonProxy { - @Override - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - super.preInit(event); - final File cfgDir = event.getModConfigurationDirectory(); - final File modCfgDir = new File(cfgDir, Reference.MODID); - final File oldCfg = event.getSuggestedConfigurationFile(); - final File cfg = new File(modCfgDir, Reference.MODID+".cfg"); - if (oldCfg.exists()) - try { - FileUtils.moveFile(oldCfg, cfg); - } catch (final IOException e) { - } - final File dynCfg = new File(Minecraft.getMinecraft().mcDataDir, Reference.MODID+".cfg"); - Config.init(cfg, dynCfg, "1.0.0", Compat.compat); - CoreHandler.instance.preInit(modCfgDir); - } - - @Override - public void init(final @Nonnull FMLInitializationEvent event) { - super.init(event); - // Event Register - CoreHandler.instance.init(); - } - - @Override - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - super.postInit(event); - Config.getConfig().save(); - } -} \ No newline at end of file diff --git a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java deleted file mode 100644 index 42d04c0..0000000 --- a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.teamfruit.serverobserver; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy implements IProxy { - @Override - public void preInit(final FMLPreInitializationEvent event) { - } - - @Override - public void init(final FMLInitializationEvent event) { - } - - @Override - public void postInit(final FMLPostInitializationEvent event) { - } -} diff --git a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java new file mode 100644 index 0000000..fbdf279 --- /dev/null +++ b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java @@ -0,0 +1,76 @@ +package net.teamfruit.serverobserver; + +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.IModGuiFactory; +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.IConfigElement; + +public class CompatConfigs { + public static class CompatGuiConfig extends GuiConfig { + public CompatGuiConfig(final GuiScreen parentScreen, final List configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + public final IConfigElement element; + + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @SuppressWarnings("deprecation") + @Override + public RuntimeOptionGuiHandler getHandlerFor(final RuntimeOptionCategoryElement element) { + return null; + } + + @Override + public boolean hasConfigGui() { + return mainConfigGuiClassCompat()!=null; + } + + @Override + public @Nullable Class mainConfigGuiClass() { + return mainConfigGuiClassCompat(); + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + @Override + public GuiScreen createConfigGui(final GuiScreen parentScreen) { + return createConfigGuiCompat(parentScreen); + } + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..5eec16c --- /dev/null +++ b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.getModID(); + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java deleted file mode 100644 index 7800bc8..0000000 --- a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java +++ /dev/null @@ -1,102 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringUtils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.I18n; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.IModGuiFactory; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; - -/** - * コンフィグGUI - * - * @author Kamesuta - */ -public class ConfigGuiFactory implements IModGuiFactory { - - public static class ConfigGui extends GuiConfig { - - public ConfigGui(final @Nullable GuiScreen parent) { - super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("serverobserver.config")); - } - - private static @Nonnull List getConfigElements() { - final List list = new ArrayList(); - getConfigElements(list, Config.getConfig().getBase()); - getConfigElements(list, Config.getConfig().getBaseDynamic()); - return list; - } - - private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { - ConfigCategory general = null; - - for (final String cat : cb.getCategoryNames()) { - final ConfigCategory cc = cb.getCategory(cat); - - if (StringUtils.equals(cc.getName(), Configuration.CATEGORY_GENERAL)) { - general = cc; - continue; - } - - if (cc.isChild()) - continue; - - list.add(new ConfigElement(cc)); - } - - // General項目をトップに表示します - if (general!=null) { - for (final ConfigCategory cc : general.getChildren()) - list.add(new ConfigElement(cc)); - for (final Property prop : general.values()) - list.add(new ConfigElement(prop)); - } - - return list; - } - } - - @Override - public void initialize(final @Nullable Minecraft minecraftInstance) { - - } - - @Override - public @Nullable Class mainConfigGuiClass() { - return ConfigGui.class; - } - - @Override - public @Nullable Set runtimeGuiCategories() { - return null; - } - - @SuppressWarnings("deprecation") - @Override - public @Nullable RuntimeOptionGuiHandler getHandlerFor(final @Nullable RuntimeOptionCategoryElement element) { - return null; - } - - @Override - public boolean hasConfigGui() { - return true; - } - - @Override - public GuiScreen createConfigGui(final GuiScreen parentScreen) { - return new ConfigGui(parentScreen); - } -} \ No newline at end of file diff --git a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java deleted file mode 100644 index 0d9b3f6..0000000 --- a/1.11.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; - -import javax.annotation.Nonnull; - -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; -import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; - -public class CoreHandler { - public static final @Nonnull CoreHandler instance = new CoreHandler(); - - public final @Nonnull Config configHandler = Config.getConfig(); - public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); - - public void preInit(final File root) { - this.guiHandler.init(root); - } - - public void init() { - // FMLCommonHandler.instance().bus().register(this); - MinecraftForge.EVENT_BUS.register(this); - } - - @SubscribeEvent - public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { - for (final ConfigBase base : ConfigBase.configChangeHandlers) - base.onConfigChanged(eventArgs.getModID()); - } - - @SubscribeEvent - public void open(final InitGuiEvent.Post e) { - this.guiHandler.open(e); - } - - @SubscribeEvent - public void draw(final DrawScreenEvent.Post e) { - this.guiHandler.draw(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Pre e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Post e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void tickclient(final @Nonnull ClientTickEvent e) { - this.guiHandler.tickclient(); - } -} \ No newline at end of file diff --git a/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java b/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java deleted file mode 100644 index 72a66f2..0000000 --- a/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public interface IProxy { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java index 43f16c7..5a6e5a6 100644 --- a/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ b/1.12.2/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -1,10 +1,13 @@ package net.teamfruit.serverobserver; +import java.io.File; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.logging.log4j.Logger; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; @@ -13,11 +16,14 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkCheckHandler; import net.minecraftforge.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class ServerObserver { @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - private static @Nullable IProxy proxy; + private static @Nullable CommonProxy proxy; @NetworkCheckHandler public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map versions, final @ @EventHandler public void preInit(final @Nonnull FMLPreInitializationEvent event) { if (proxy!=null) - proxy.preInit(event); + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); } @EventHandler public void init(final @Nonnull FMLInitializationEvent event) { if (proxy!=null) - proxy.init(event); + proxy.init(new CompatFMLInitializationEventImpl(event)); } @EventHandler public void postInit(final @Nonnull FMLPostInitializationEvent event) { if (proxy!=null) - proxy.postInit(event); + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } } } diff --git a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java deleted file mode 100644 index 42d04c0..0000000 --- a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.teamfruit.serverobserver; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy implements IProxy { - @Override - public void preInit(final FMLPreInitializationEvent event) { - } - - @Override - public void init(final FMLInitializationEvent event) { - } - - @Override - public void postInit(final FMLPostInitializationEvent event) { - } -} diff --git a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java b/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java new file mode 100644 index 0000000..d6de976 --- /dev/null +++ b/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java @@ -0,0 +1,65 @@ +package net.teamfruit.serverobserver; + +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.IModGuiFactory; +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.IConfigElement; + +public class CompatConfigs { + public static class CompatGuiConfig extends GuiConfig { + public CompatGuiConfig(final GuiScreen parentScreen, final List configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + public final IConfigElement element; + + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public boolean hasConfigGui() { + return mainConfigGuiClassCompat()!=null; + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + @Override + public GuiScreen createConfigGui(final GuiScreen parentScreen) { + return createConfigGuiCompat(parentScreen); + } + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..5eec16c --- /dev/null +++ b/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.getModID(); + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java deleted file mode 100644 index 0d9b3f6..0000000 --- a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; - -import javax.annotation.Nonnull; - -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; -import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; - -public class CoreHandler { - public static final @Nonnull CoreHandler instance = new CoreHandler(); - - public final @Nonnull Config configHandler = Config.getConfig(); - public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); - - public void preInit(final File root) { - this.guiHandler.init(root); - } - - public void init() { - // FMLCommonHandler.instance().bus().register(this); - MinecraftForge.EVENT_BUS.register(this); - } - - @SubscribeEvent - public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { - for (final ConfigBase base : ConfigBase.configChangeHandlers) - base.onConfigChanged(eventArgs.getModID()); - } - - @SubscribeEvent - public void open(final InitGuiEvent.Post e) { - this.guiHandler.open(e); - } - - @SubscribeEvent - public void draw(final DrawScreenEvent.Post e) { - this.guiHandler.draw(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Pre e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Post e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void tickclient(final @Nonnull ClientTickEvent e) { - this.guiHandler.tickclient(); - } -} \ No newline at end of file diff --git a/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxyL.java b/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxyL.java deleted file mode 100644 index 0116e65..0000000 --- a/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxyL.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; - -public interface IProxyL { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java index 3d0f97d..5b9b41c 100644 --- a/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ b/1.7.10/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -1,10 +1,13 @@ package net.teamfruit.serverobserver; +import java.io.File; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.logging.log4j.Logger; + import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.SidedProxy; @@ -13,11 +16,14 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkCheckHandler; import cpw.mods.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class ServerObserver { @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - private static @Nullable IProxyL proxy; + private static @Nullable CommonProxy proxy; @NetworkCheckHandler public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map versions, final @ @EventHandler public void preInit(final @Nonnull FMLPreInitializationEvent event) { if (proxy!=null) - proxy.preInit(event); + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); } @EventHandler public void init(final @Nonnull FMLInitializationEvent event) { if (proxy!=null) - proxy.init(event); + proxy.init(new CompatFMLInitializationEventImpl(event)); } @EventHandler public void postInit(final @Nonnull FMLPostInitializationEvent event) { if (proxy!=null) - proxy.postInit(event); + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } } } diff --git a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java deleted file mode 100644 index 83dd19c..0000000 --- a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nonnull; - -import org.apache.commons.io.FileUtils; - -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import net.minecraft.client.Minecraft; - -public class ClientProxy extends CommonProxy { - @Override - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - super.preInit(event); - final File cfgDir = event.getModConfigurationDirectory(); - final File modCfgDir = new File(cfgDir, Reference.MODID); - final File oldCfg = event.getSuggestedConfigurationFile(); - final File cfg = new File(modCfgDir, Reference.MODID+".cfg"); - if (oldCfg.exists()) - try { - FileUtils.moveFile(oldCfg, cfg); - } catch (final IOException e) { - } - final File dynCfg = new File(Minecraft.getMinecraft().mcDataDir, Reference.MODID+".cfg"); - Config.init(cfg, dynCfg, "1.0.0", Compat.compat); - CoreHandler.instance.preInit(modCfgDir); - } - - @Override - public void init(final @Nonnull FMLInitializationEvent event) { - super.init(event); - // Event Register - CoreHandler.instance.init(); - } - - @Override - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - super.postInit(event); - Config.getConfig().save(); - } -} \ No newline at end of file diff --git a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java deleted file mode 100644 index 1a894bb..0000000 --- a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.teamfruit.serverobserver; - -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy implements IProxyL { - @Override - public void preInit(final FMLPreInitializationEvent event) { - } - - @Override - public void init(final FMLInitializationEvent event) { - } - - @Override - public void postInit(final FMLPostInitializationEvent event) { - } -} diff --git a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java new file mode 100644 index 0000000..40c67a6 --- /dev/null +++ b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java @@ -0,0 +1,68 @@ +package net.teamfruit.serverobserver; + +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; + +import cpw.mods.fml.client.IModGuiFactory; +import cpw.mods.fml.client.config.GuiConfig; +import cpw.mods.fml.client.config.IConfigElement; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; + +public class CompatConfigs { + public static class CompatGuiConfig extends GuiConfig { + public CompatGuiConfig(final GuiScreen parentScreen, final List configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + @SuppressWarnings("rawtypes") + public final IConfigElement element; + + @SuppressWarnings("rawtypes") + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + @SuppressWarnings("rawtypes") + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement<>(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement<>(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(final RuntimeOptionCategoryElement element) { + return null; + } + + @Override + public @Nullable Class mainConfigGuiClass() { + return mainConfigGuiClassCompat(); + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..3652fc4 --- /dev/null +++ b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import cpw.mods.fml.client.event.ConfigChangedEvent; +import cpw.mods.fml.common.eventhandler.Event; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.modID; + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java deleted file mode 100644 index aa4fef3..0000000 --- a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringUtils; - -import cpw.mods.fml.client.IModGuiFactory; -import cpw.mods.fml.client.config.GuiConfig; -import cpw.mods.fml.client.config.IConfigElement; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.I18n; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; - -/** - * コンフィグGUI - * - * @author Kamesuta - */ -public class ConfigGuiFactory implements IModGuiFactory { - - public static class ConfigGui extends GuiConfig { - - public ConfigGui(final @Nullable GuiScreen parent) { - super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("serverobserver.config")); - } - - @SuppressWarnings("rawtypes") - private static @Nonnull List getConfigElements() { - final List list = new ArrayList(); - getConfigElements(list, Config.getConfig().getBase()); - getConfigElements(list, Config.getConfig().getBaseDynamic()); - return list; - } - - @SuppressWarnings("rawtypes") - private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { - ConfigCategory general = null; - - for (final String cat : cb.getCategoryNames()) { - final ConfigCategory cc = cb.getCategory(cat); - - if (StringUtils.equals(cc.getName(), Configuration.CATEGORY_GENERAL)) { - general = cc; - continue; - } - - if (cc.isChild()) - continue; - - list.add(new ConfigElement(cc)); - } - - // General項目をトップに表示します - if (general!=null) { - for (final ConfigCategory cc : general.getChildren()) - list.add(new ConfigElement(cc)); - for (final Property prop : general.values()) - list.add(new ConfigElement(prop)); - } - - return list; - } - - } - - @Override - public void initialize(final @Nullable Minecraft minecraftInstance) { - - } - - @Override - public @Nullable Class mainConfigGuiClass() { - return ConfigGui.class; - } - - @Override - public @Nullable Set runtimeGuiCategories() { - return null; - } - - @Override - public @Nullable RuntimeOptionGuiHandler getHandlerFor(final @Nullable RuntimeOptionCategoryElement element) { - return null; - } -} \ No newline at end of file diff --git a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java deleted file mode 100644 index ae5a7b5..0000000 --- a/1.7.10/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; - -import javax.annotation.Nonnull; - -import cpw.mods.fml.client.event.ConfigChangedEvent; -import cpw.mods.fml.common.FMLCommonHandler; -import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent; -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; -import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.common.MinecraftForge; - -public class CoreHandler { - public static final @Nonnull CoreHandler instance = new CoreHandler(); - - public final @Nonnull Config configHandler = Config.getConfig(); - public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); - - public void preInit(final File root) { - this.guiHandler.init(root); - } - - public void init() { - // FMLCommonHandler.instance().bus().register(this); - MinecraftForge.EVENT_BUS.register(this); - FMLCommonHandler.instance().bus().register(this); - } - - @SubscribeEvent - public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { - for (final ConfigBase base : ConfigBase.configChangeHandlers) - base.onConfigChanged(eventArgs.modID); - } - - @SubscribeEvent - public void open(final InitGuiEvent.Post e) { - this.guiHandler.open(e); - } - - @SubscribeEvent - public void draw(final DrawScreenEvent.Post e) { - this.guiHandler.draw(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Pre e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Post e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void tickclient(final @Nonnull ClientTickEvent e) { - this.guiHandler.tickclient(); - } -} \ No newline at end of file diff --git a/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java b/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java deleted file mode 100644 index 72a66f2..0000000 --- a/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public interface IProxy { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java index 43f16c7..5a6e5a6 100644 --- a/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ b/1.8.9/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -1,10 +1,13 @@ package net.teamfruit.serverobserver; +import java.io.File; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.logging.log4j.Logger; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; @@ -13,11 +16,14 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkCheckHandler; import net.minecraftforge.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class ServerObserver { @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - private static @Nullable IProxy proxy; + private static @Nullable CommonProxy proxy; @NetworkCheckHandler public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map versions, final @ @EventHandler public void preInit(final @Nonnull FMLPreInitializationEvent event) { if (proxy!=null) - proxy.preInit(event); + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); } @EventHandler public void init(final @Nonnull FMLInitializationEvent event) { if (proxy!=null) - proxy.init(event); + proxy.init(new CompatFMLInitializationEventImpl(event)); } @EventHandler public void postInit(final @Nonnull FMLPostInitializationEvent event) { if (proxy!=null) - proxy.postInit(event); + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } } } diff --git a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java deleted file mode 100644 index 3c7bb02..0000000 --- a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nonnull; - -import org.apache.commons.io.FileUtils; - -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class ClientProxy extends CommonProxy { - @Override - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - super.preInit(event); - final File cfgDir = event.getModConfigurationDirectory(); - final File modCfgDir = new File(cfgDir, Reference.MODID); - final File oldCfg = event.getSuggestedConfigurationFile(); - final File cfg = new File(modCfgDir, Reference.MODID+".cfg"); - if (oldCfg.exists()) - try { - FileUtils.moveFile(oldCfg, cfg); - } catch (final IOException e) { - } - final File dynCfg = new File(Minecraft.getMinecraft().mcDataDir, Reference.MODID+".cfg"); - Config.init(cfg, dynCfg, "1.1.0", Compat.compat); - CoreHandler.instance.preInit(modCfgDir); - } - - @Override - public void init(final @Nonnull FMLInitializationEvent event) { - super.init(event); - // Event Register - CoreHandler.instance.init(); - } - - @Override - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - super.postInit(event); - Config.getConfig().save(); - } -} \ No newline at end of file diff --git a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java deleted file mode 100644 index 42d04c0..0000000 --- a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.teamfruit.serverobserver; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy implements IProxy { - @Override - public void preInit(final FMLPreInitializationEvent event) { - } - - @Override - public void init(final FMLInitializationEvent event) { - } - - @Override - public void postInit(final FMLPostInitializationEvent event) { - } -} diff --git a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java new file mode 100644 index 0000000..c1d3f37 --- /dev/null +++ b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java @@ -0,0 +1,65 @@ +package net.teamfruit.serverobserver; + +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.IModGuiFactory; +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.IConfigElement; + +public class CompatConfigs { + public static class CompatGuiConfig extends GuiConfig { + public CompatGuiConfig(final GuiScreen parentScreen, final List configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + public final IConfigElement element; + + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(final RuntimeOptionCategoryElement element) { + return null; + } + + @Override + public @Nullable Class mainConfigGuiClass() { + return mainConfigGuiClassCompat(); + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..beacf28 --- /dev/null +++ b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.modID; + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java deleted file mode 100644 index 386ce05..0000000 --- a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java +++ /dev/null @@ -1,91 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringUtils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.I18n; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.IModGuiFactory; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; - -/** - * コンフィグGUI - * - * @author Kamesuta - */ -public class ConfigGuiFactory implements IModGuiFactory { - - public static class ConfigGui extends GuiConfig { - - public ConfigGui(final @Nullable GuiScreen parent) { - super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("serverobserver.config")); - } - - private static @Nonnull List getConfigElements() { - final List list = new ArrayList(); - getConfigElements(list, Config.getConfig().getBase()); - getConfigElements(list, Config.getConfig().getBaseDynamic()); - return list; - } - - private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { - ConfigCategory general = null; - - for (final String cat : cb.getCategoryNames()) { - final ConfigCategory cc = cb.getCategory(cat); - - if (StringUtils.equals(cc.getName(), Configuration.CATEGORY_GENERAL)) { - general = cc; - continue; - } - - if (cc.isChild()) - continue; - - list.add(new ConfigElement(cc)); - } - - // General項目をトップに表示します - if (general!=null) { - for (final ConfigCategory cc : general.getChildren()) - list.add(new ConfigElement(cc)); - for (final Property prop : general.values()) - list.add(new ConfigElement(prop)); - } - - return list; - } - } - - @Override - public void initialize(final @Nullable Minecraft minecraftInstance) { - - } - - @Override - public @Nullable Class mainConfigGuiClass() { - return ConfigGui.class; - } - - @Override - public @Nullable Set runtimeGuiCategories() { - return null; - } - - @Override - public @Nullable RuntimeOptionGuiHandler getHandlerFor(final @Nullable RuntimeOptionCategoryElement element) { - return null; - } -} \ No newline at end of file diff --git a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java deleted file mode 100644 index 21449c9..0000000 --- a/1.8.9/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; - -import javax.annotation.Nonnull; - -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; -import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; - -public class CoreHandler { - public static final @Nonnull CoreHandler instance = new CoreHandler(); - - public final @Nonnull Config configHandler = Config.getConfig(); - public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); - - public void preInit(final File root) { - this.guiHandler.init(root); - } - - public void init() { - // FMLCommonHandler.instance().bus().register(this); - MinecraftForge.EVENT_BUS.register(this); - } - - @SubscribeEvent - public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { - for (final ConfigBase base : ConfigBase.configChangeHandlers) - base.onConfigChanged(eventArgs.modID); - } - - @SubscribeEvent - public void open(final InitGuiEvent.Post e) { - this.guiHandler.open(e); - } - - @SubscribeEvent - public void draw(final DrawScreenEvent.Post e) { - this.guiHandler.draw(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Pre e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Post e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void tickclient(final @Nonnull ClientTickEvent e) { - this.guiHandler.tickclient(); - } -} \ No newline at end of file diff --git a/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java b/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java deleted file mode 100644 index 72a66f2..0000000 --- a/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/IProxy.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public interface IProxy { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java index 43f16c7..5a6e5a6 100644 --- a/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ b/1.9.4/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -1,10 +1,13 @@ package net.teamfruit.serverobserver; +import java.io.File; import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import org.apache.logging.log4j.Logger; + import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; @@ -13,11 +16,14 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.network.NetworkCheckHandler; import net.minecraftforge.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; @Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) public class ServerObserver { @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - private static @Nullable IProxy proxy; + private static @Nullable CommonProxy proxy; @NetworkCheckHandler public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { @@ -27,18 +33,51 @@ public boolean checkModList(final @Nonnull Map versions, final @ @EventHandler public void preInit(final @Nonnull FMLPreInitializationEvent event) { if (proxy!=null) - proxy.preInit(event); + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); } @EventHandler public void init(final @Nonnull FMLInitializationEvent event) { if (proxy!=null) - proxy.init(event); + proxy.init(new CompatFMLInitializationEventImpl(event)); } @EventHandler public void postInit(final @Nonnull FMLPostInitializationEvent event) { if (proxy!=null) - proxy.postInit(event); + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } } } diff --git a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java deleted file mode 100644 index 3c7bb02..0000000 --- a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java +++ /dev/null @@ -1,45 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; -import java.io.IOException; - -import javax.annotation.Nonnull; - -import org.apache.commons.io.FileUtils; - -import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class ClientProxy extends CommonProxy { - @Override - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - super.preInit(event); - final File cfgDir = event.getModConfigurationDirectory(); - final File modCfgDir = new File(cfgDir, Reference.MODID); - final File oldCfg = event.getSuggestedConfigurationFile(); - final File cfg = new File(modCfgDir, Reference.MODID+".cfg"); - if (oldCfg.exists()) - try { - FileUtils.moveFile(oldCfg, cfg); - } catch (final IOException e) { - } - final File dynCfg = new File(Minecraft.getMinecraft().mcDataDir, Reference.MODID+".cfg"); - Config.init(cfg, dynCfg, "1.1.0", Compat.compat); - CoreHandler.instance.preInit(modCfgDir); - } - - @Override - public void init(final @Nonnull FMLInitializationEvent event) { - super.init(event); - // Event Register - CoreHandler.instance.init(); - } - - @Override - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - super.postInit(event); - Config.getConfig().save(); - } -} \ No newline at end of file diff --git a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java deleted file mode 100644 index 42d04c0..0000000 --- a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CommonProxy.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.teamfruit.serverobserver; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public class CommonProxy implements IProxy { - @Override - public void preInit(final FMLPreInitializationEvent event) { - } - - @Override - public void init(final FMLInitializationEvent event) { - } - - @Override - public void postInit(final FMLPostInitializationEvent event) { - } -} diff --git a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java new file mode 100644 index 0000000..c1d3f37 --- /dev/null +++ b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatConfigs.java @@ -0,0 +1,65 @@ +package net.teamfruit.serverobserver; + +import java.util.List; +import java.util.Set; + +import javax.annotation.Nullable; + +import com.google.common.collect.Lists; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigCategory; +import net.minecraftforge.common.config.ConfigElement; +import net.minecraftforge.common.config.Property; +import net.minecraftforge.fml.client.IModGuiFactory; +import net.minecraftforge.fml.client.config.GuiConfig; +import net.minecraftforge.fml.client.config.IConfigElement; + +public class CompatConfigs { + public static class CompatGuiConfig extends GuiConfig { + public CompatGuiConfig(final GuiScreen parentScreen, final List configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + public final IConfigElement element; + + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(final RuntimeOptionCategoryElement element) { + return null; + } + + @Override + public @Nullable Class mainConfigGuiClass() { + return mainConfigGuiClassCompat(); + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..5eec16c --- /dev/null +++ b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.getModID(); + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java deleted file mode 100644 index 386ce05..0000000 --- a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java +++ /dev/null @@ -1,91 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import org.apache.commons.lang3.StringUtils; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.resources.I18n; -import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; -import net.minecraftforge.common.config.Configuration; -import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.IModGuiFactory; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; - -/** - * コンフィグGUI - * - * @author Kamesuta - */ -public class ConfigGuiFactory implements IModGuiFactory { - - public static class ConfigGui extends GuiConfig { - - public ConfigGui(final @Nullable GuiScreen parent) { - super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("serverobserver.config")); - } - - private static @Nonnull List getConfigElements() { - final List list = new ArrayList(); - getConfigElements(list, Config.getConfig().getBase()); - getConfigElements(list, Config.getConfig().getBaseDynamic()); - return list; - } - - private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { - ConfigCategory general = null; - - for (final String cat : cb.getCategoryNames()) { - final ConfigCategory cc = cb.getCategory(cat); - - if (StringUtils.equals(cc.getName(), Configuration.CATEGORY_GENERAL)) { - general = cc; - continue; - } - - if (cc.isChild()) - continue; - - list.add(new ConfigElement(cc)); - } - - // General項目をトップに表示します - if (general!=null) { - for (final ConfigCategory cc : general.getChildren()) - list.add(new ConfigElement(cc)); - for (final Property prop : general.values()) - list.add(new ConfigElement(prop)); - } - - return list; - } - } - - @Override - public void initialize(final @Nullable Minecraft minecraftInstance) { - - } - - @Override - public @Nullable Class mainConfigGuiClass() { - return ConfigGui.class; - } - - @Override - public @Nullable Set runtimeGuiCategories() { - return null; - } - - @Override - public @Nullable RuntimeOptionGuiHandler getHandlerFor(final @Nullable RuntimeOptionCategoryElement element) { - return null; - } -} \ No newline at end of file diff --git a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java deleted file mode 100644 index 0d9b3f6..0000000 --- a/1.9.4/sources/compat/src/main/java/net/teamfruit/serverobserver/CoreHandler.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; - -import javax.annotation.Nonnull; - -import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; -import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; -import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; -import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fml.client.event.ConfigChangedEvent; -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; - -public class CoreHandler { - public static final @Nonnull CoreHandler instance = new CoreHandler(); - - public final @Nonnull Config configHandler = Config.getConfig(); - public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); - - public void preInit(final File root) { - this.guiHandler.init(root); - } - - public void init() { - // FMLCommonHandler.instance().bus().register(this); - MinecraftForge.EVENT_BUS.register(this); - } - - @SubscribeEvent - public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { - for (final ConfigBase base : ConfigBase.configChangeHandlers) - base.onConfigChanged(eventArgs.getModID()); - } - - @SubscribeEvent - public void open(final InitGuiEvent.Post e) { - this.guiHandler.open(e); - } - - @SubscribeEvent - public void draw(final DrawScreenEvent.Post e) { - this.guiHandler.draw(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Pre e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void action(final ActionPerformedEvent.Post e) { - this.guiHandler.action(e); - } - - @SubscribeEvent - public void tickclient(final @Nonnull ClientTickEvent e) { - this.guiHandler.tickclient(); - } -} \ No newline at end of file diff --git a/build.subprojects.gradle b/build.subprojects.gradle index 26f5f97..12c7133 100644 --- a/build.subprojects.gradle +++ b/build.subprojects.gradle @@ -189,7 +189,7 @@ dependencies { shade fileTree(dir: '../libs/shade', include: '*.jar') if (project.name==mod_commonname) { - compile 'net.teamfruit:fmllegacydependency:1.0.4' + compile 'net.teamfruit:fmllegacydependency:1.0.5' if (project.isProperty('extra_fmlcore')) shade 'net.teamfruit:coremodlegacydependency:1.0.0' } diff --git a/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java new file mode 100644 index 0000000..3713a05 --- /dev/null +++ b/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserver.java @@ -0,0 +1,87 @@ +package net.teamfruit.serverobserver; + +import java.io.File; +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import org.apache.logging.log4j.Logger; + +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.SidedProxy; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.network.NetworkCheckHandler; +import net.minecraftforge.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; + +@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) +public class ServerObserver { + @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) + private static @Nullable CommonProxy proxy; + + static { + UniversalVersioner.loadVersionFromFMLMod(); + } + + @NetworkCheckHandler + public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { + return true; + } + + @EventHandler + public void preInit(final @Nonnull FMLPreInitializationEvent event) { + if (proxy!=null) + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); + } + + @EventHandler + public void init(final @Nonnull FMLInitializationEvent event) { + if (proxy!=null) + proxy.init(new CompatFMLInitializationEventImpl(event)); + } + + @EventHandler + public void postInit(final @Nonnull FMLPostInitializationEvent event) { + if (proxy!=null) + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } + } +} diff --git a/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserverL.java b/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserverL.java new file mode 100644 index 0000000..d410016 --- /dev/null +++ b/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/ServerObserverL.java @@ -0,0 +1,87 @@ +package net.teamfruit.serverobserver; + +import java.io.File; +import java.util.Map; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import org.apache.logging.log4j.Logger; + +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.network.NetworkCheckHandler; +import cpw.mods.fml.relauncher.Side; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPostInitializationEvent; +import net.teamfruit.serverobserver.CompatProxy.CompatFMLPreInitializationEvent; + +@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) +public class ServerObserverL { + @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) + private static @Nullable CommonProxy proxy; + + static { + UniversalVersioner.loadVersionFromFMLMod(); + } + + @NetworkCheckHandler + public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { + return true; + } + + @EventHandler + public void preInit(final @Nonnull FMLPreInitializationEvent event) { + if (proxy!=null) + proxy.preInit(new CompatFMLPreInitializationEventImpl(event)); + } + + @EventHandler + public void init(final @Nonnull FMLInitializationEvent event) { + if (proxy!=null) + proxy.init(new CompatFMLInitializationEventImpl(event)); + } + + @EventHandler + public void postInit(final @Nonnull FMLPostInitializationEvent event) { + if (proxy!=null) + proxy.postInit(new CompatFMLPostInitializationEventImpl(event)); + } + + private static class CompatFMLPreInitializationEventImpl implements CompatFMLPreInitializationEvent { + private final @Nonnull FMLPreInitializationEvent event; + + public CompatFMLPreInitializationEventImpl(final FMLPreInitializationEvent event) { + this.event = event; + } + + @Override + public Logger getModLog() { + return this.event.getModLog(); + } + + @Override + public File getSuggestedConfigurationFile() { + return this.event.getSuggestedConfigurationFile(); + } + + @Override + public File getModConfigurationDirectory() { + return this.event.getModConfigurationDirectory(); + } + } + + private static class CompatFMLInitializationEventImpl implements CompatFMLInitializationEvent { + public CompatFMLInitializationEventImpl(final FMLInitializationEvent event) { + } + } + + private static class CompatFMLPostInitializationEventImpl implements CompatFMLPostInitializationEvent { + public CompatFMLPostInitializationEventImpl(final FMLPostInitializationEvent event) { + } + } +} diff --git a/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/UniversalVersioner.java b/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/UniversalVersioner.java new file mode 100644 index 0000000..bff1f11 --- /dev/null +++ b/common/sources/bootstrap/src/main/java/net/teamfruit/serverobserver/UniversalVersioner.java @@ -0,0 +1,156 @@ +package net.teamfruit.serverobserver; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.List; +import java.util.Map.Entry; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; + +import com.google.common.collect.ImmutableMap; + +import net.minecraft.launchwrapper.ITweaker; +import net.minecraft.launchwrapper.Launch; + +public class UniversalVersioner { + public static final ImmutableMap versions = ImmutableMap. builder() + .put("1.7", "1.7.10") + .put("1.8", "1.8.9") + .put("1.9", "1.9.4") + .put("1.10", "1.10.2") + .put("1.11", "1.11.2") + .put("1.12", "1.12.2") + .build(); + + public static String getVersion(final String mccversion) { + for (final Entry entry : UniversalVersioner.versions.entrySet()) { + final String key = entry.getKey(); + if (StringUtils.startsWith(mccversion, key)) + return entry.getValue(); + } + return null; + } + + private static Class getFMLClass(final String afterFmlPath) { + Class $class; + try { + $class = Class.forName("net.minecraftforge.fml."+afterFmlPath); + } catch (final ClassNotFoundException e1) { + try { + $class = Class.forName("cpw.mods.fml."+afterFmlPath); + } catch (final ClassNotFoundException e2) { + throw new RuntimeException("Could not load fml class"); + } + } + return $class; + } + + private static T invokeFMLMethod(final Class $class, final String name, final Class[] types, final Object instance, final Object[] params, final boolean declared) { + if ($class==null) + throw new RuntimeException("Could not find fml class"); + Method $method; + try { + $method = declared ? $class.getDeclaredMethod(name, types) : $class.getMethod(name, types); + $method.setAccessible(true); + } catch (final Exception e) { + throw new RuntimeException("Could not find or access fml method"); + } + try { + @SuppressWarnings("unchecked") + final T res = (T) $method.invoke(instance, params); + return res; + } catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException e) { + throw new RuntimeException("Could not invoke fml method"); + } + } + + private static T getFMLField(final Class $class, final String name, final Object instance, final boolean declared) { + if ($class==null) + throw new RuntimeException("Could not find fml class"); + Field $field; + try { + $field = declared ? $class.getDeclaredField(name) : $class.getField(name); + $field.setAccessible(true); + } catch (final Exception e) { + throw new RuntimeException("Could not find or access fml field"); + } + try { + @SuppressWarnings("unchecked") + final T res = (T) $field.get(instance); + return res; + } catch (IllegalAccessException|IllegalArgumentException e) { + throw new RuntimeException("Could not get fml field"); + } + } + + private static void loadVersionImpl(final File modFile) { + if (modFile==null) + throw new RuntimeException("Could not specify mod file."); + + ZipFile file = null; + InputStream stream = null; + try { + final Object[] data = invokeFMLMethod(getFMLClass("relauncher.FMLInjectionData"), "data", new Class[0], null, new Object[0], false); + final String mccversion0 = (String) data[4]; + final String mccversion = getVersion(mccversion0); + + if (mccversion==null) + throw new RuntimeException(String.format("Version %s is not supported! Supported version is %s.", mccversion0, versions)); + + final File minecraftDir = (File) data[6]; + final File modsDir = new File(minecraftDir, "mods"); + + final File canonicalModsDir = modsDir.getCanonicalFile(); + final File versionSpecificModsDir = new File(canonicalModsDir, mccversion); + final File modVersionSpecific = new File(versionSpecificModsDir, Reference.MODID); + + final String jarname = String.format("%s.jar", mccversion); + final File destMod = new File(modVersionSpecific, jarname); + + file = new ZipFile(modFile); + final ZipEntry entry = file.getEntry(jarname); + if (entry==null) + throw new RuntimeException("Could not find version-specific file: "+jarname); + stream = file.getInputStream(entry); + + FileUtils.copyInputStreamToFile(stream, destMod); + Launch.classLoader.addURL(destMod.toURI().toURL()); + } catch (final IOException e) { + throw new RuntimeException("Could not load version-specific file.", e); + } finally { + IOUtils.closeQuietly(file); + IOUtils.closeQuietly(stream); + } + } + + public static void loadVersionFromFMLMod() { + final Object loader = invokeFMLMethod(getFMLClass("common.Loader"), "instance", new Class[0], null, new Object[0], false); + final Object container = invokeFMLMethod(getFMLClass("common.Loader"), "activeModContainer", new Class[0], loader, new Object[0], false); + final File modFile = invokeFMLMethod(getFMLClass("common.ModContainer"), "getSource", new Class[0], container, new Object[0], false); + loadVersionImpl(modFile); + } + + public static void loadVersionFromCoreMod(final Class coreModClass) { + File modFile = null; + @SuppressWarnings("unchecked") + final List tweakers = (List) Launch.blackboard.get("Tweaks"); + if (tweakers!=null) { + final Class fmlPlugin = getFMLClass("relauncher.CoreModManager$FMLPluginWrapper"); + for (final ITweaker tweaker : tweakers) + if (fmlPlugin.isInstance(tweaker)) { + final Object coreModInstance = getFMLField(fmlPlugin, "coreModInstance", tweaker, true); + if (coreModClass.isInstance(coreModInstance)) + modFile = getFMLField(fmlPlugin, "location", tweaker, true); + } + } + loadVersionImpl(modFile); + } +} diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/Compat.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/Compat.java new file mode 100644 index 0000000..8039b37 --- /dev/null +++ b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/Compat.java @@ -0,0 +1,159 @@ +package net.teamfruit.serverobserver; + +import java.net.SocketAddress; +import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; + +import javax.annotation.Nonnull; + +import org.lwjgl.opengl.GL11; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.ISound; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiDisconnected; +import net.minecraft.client.gui.GuiMultiplayer; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.ServerListEntryNormal; +import net.minecraft.client.multiplayer.ServerData; +import net.minecraft.client.multiplayer.ServerList; +import net.minecraft.init.SoundEvents; +import net.minecraft.network.NetworkManager; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundCategory; +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.fml.client.FMLClientHandler; +import net.teamfruit.serverobserver.GuiHandler.SkeletonButtonDrawInside; + +public class Compat implements ICompat { + public static final @Nonnull ICompat compat = new Compat(); + + @Override + public void color(final float colorRed, final float colorGreen, final float colorBlue, final float colorAlpha) { + GL11.glColor4f(colorRed, colorGreen, colorBlue, colorAlpha); + } + + @Override + public List getButtonList(final InitGuiEvent e) { + return e.getButtonList(); + } + + @Override + public FontRenderer font(final Minecraft mc) { + return mc.fontRenderer; + } + + @Override + public int getHeight(final GuiDisconnected dcgui) { + return dcgui.height/2+dcgui.textHeight/2+font(dcgui.mc).FONT_HEIGHT+25; + } + + @Override + public GuiScreen getParentScreen(final GuiDisconnected dcgui) { + return dcgui.parentScreen; + } + + @Override + public GuiButton getButton(final ActionPerformedEvent e) { + return e.getButton(); + } + + @Override + public int getSelected(final GuiMultiplayer mpgui) { + return mpgui.serverListSelector.getSelected(); + } + + @Override + public void connectToServer(final GuiScreen mpgui, final ServerData serverData) { + FMLClientHandler.instance().connectToServer(mpgui, serverData); + } + + @Override + public boolean getPinged(final ServerData serverData) { + return serverData.pinged; + } + + @Override + public void setPinged(final ServerData serverData, final boolean pinged) { + serverData.pinged = pinged; + } + + @Override + public void ping(final GuiMultiplayer mpgui, final ServerData serverData) throws Exception { + mpgui.getOldServerPinger().ping(serverData); + } + + @Override + public String getDefaultSound() { + return SoundEvents.ENTITY_EXPERIENCE_ORB_PICKUP.getSoundName().toString(); + } + + @Override + public void playSound(final Minecraft mc, final ResourceLocation sound, final float pitch) { + mc.getSoundHandler().playSound(new PositionedSoundRecord(sound, SoundCategory.MASTER, 0.25F, pitch, false, 0, ISound.AttenuationType.NONE, 0.0F, 0.0F, 0.0F)); + } + + @Override + public void selectServer(final GuiMultiplayer mpgui, final int index) { + mpgui.selectServer(index); + } + + @Override + public ServerData getServerData(final GuiMultiplayer mpgui, final int index) { + return mpgui.getServerList().getServerData(index); + } + + @Override + public ServerList getServerList(final GuiMultiplayer mpgui) { + return mpgui.getServerList(); + } + + @Override + public GuiButton createSkeletonButton(final int buttonId, final int x, final int y, final int widthIn, final int heightIn, final String buttonText, final SkeletonButtonDrawInside inside) { + return new SkeletonButton(this, buttonId, x, y, widthIn, heightIn, buttonText, inside); + } + + @Override + public ThreadPoolExecutor getThreadPool() { + return ServerListEntryNormal.EXECUTOR; + } + + @Override + public NetworkManager getClientToServerNetworkManager() { + return FMLClientHandler.instance().getClientToServerNetworkManager(); + } + + @Override + public SocketAddress getSocketAddress(final NetworkManager netManager) { + return netManager.getRemoteAddress(); + } + + public static class SkeletonButton extends GuiButton { + private final SkeletonButtonDrawInside inside; + private final ICompat compat; + + public SkeletonButton(final ICompat compat, final int buttonId, final int x, final int y, final int widthIn, final int heightIn, final String buttonText, final SkeletonButtonDrawInside inside) { + super(buttonId, x, y, widthIn, heightIn, buttonText); + this.inside = inside; + this.compat = compat; + } + + protected boolean isHovered; + + @Override + public void drawButton(final Minecraft mc, final int mouseX, final int mouseY, final float partialTicks) { + if (this.visible) { + this.compat.color(1.0F, 1.0F, 1.0F, 1.0F); + final int x = this.x; + final int y = this.y; + this.isHovered = mouseX>=x&&mouseY>=y&&mouseX configElements, final String modID, final boolean allRequireWorldRestart, final boolean allRequireMcRestart, final String title) { + super(parentScreen, CompatConfigElement.getConfigElements(configElements), modID, allRequireWorldRestart, allRequireMcRestart, GuiConfig.getAbridgedConfigPath(title)); + } + } + + public static class CompatConfigElement { + public final IConfigElement element; + + public CompatConfigElement(final IConfigElement element) { + this.element = element; + } + + public static List getConfigElements(final List elements) { + return Lists.transform(elements, t -> t==null ? null : t.element); + } + + public static CompatConfigElement fromCategory(final ConfigCategory category) { + return new CompatConfigElement(new ConfigElement(category)); + } + + public static CompatConfigElement fromProperty(final Property prop) { + return new CompatConfigElement(new ConfigElement(prop)); + } + } + + public static abstract class CompatModGuiFactory implements IModGuiFactory { + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public boolean hasConfigGui() { + return mainConfigGuiClassCompat()!=null; + } + + public abstract @Nullable Class mainConfigGuiClassCompat(); + + @Override + public GuiScreen createConfigGui(final GuiScreen parentScreen) { + return createConfigGuiCompat(parentScreen); + } + + public abstract GuiScreen createConfigGuiCompat(GuiScreen parentScreen); + } +} diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java new file mode 100644 index 0000000..5eec16c --- /dev/null +++ b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/CompatHandler.java @@ -0,0 +1,93 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.event.ConfigChangedEvent; +import net.minecraftforge.fml.common.eventhandler.Event; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent; + +public abstract class CompatHandler { + public abstract void preInit(final File root); + + public void init() { + // FMLCommonHandler.instance().bus().register(this); + MinecraftForge.EVENT_BUS.register(this); + } + + public static class CompatEvent { + protected final T event; + + public CompatEvent(final T event) { + this.event = event; + } + + public void setCanceled(final boolean cancel) { + this.event.setCanceled(cancel); + } + } + + public static class CompatOnConfigChangedEvent extends CompatEvent { + public CompatOnConfigChangedEvent(final ConfigChangedEvent.OnConfigChangedEvent event) { + super(event); + } + + public String getModID() { + return this.event.getModID(); + } + } + + public static class CompatClientTickEvent extends CompatEvent { + public CompatClientTickEvent(final ClientTickEvent event) { + super(event); + } + } + + @SubscribeEvent + public void onConfigChanged(final @Nonnull ConfigChangedEvent.OnConfigChangedEvent eventArgs) { + onConfigChangedCompat(new CompatOnConfigChangedEvent(eventArgs)); + } + + public abstract void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs); + + @SubscribeEvent + public void open(final InitGuiEvent.Post e) { + openCompat(e); + } + + public abstract void openCompat(final InitGuiEvent.Post e); + + @SubscribeEvent + public void draw(final DrawScreenEvent.Post e) { + drawCompat(e); + } + + public abstract void drawCompat(final DrawScreenEvent.Post e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Pre e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Pre e); + + @SubscribeEvent + public void action(final ActionPerformedEvent.Post e) { + actionCompat(e); + } + + public abstract void actionCompat(final ActionPerformedEvent.Post e); + + @SubscribeEvent + public void tickclient(final @Nonnull ClientTickEvent e) { + tickclientCompat(new CompatClientTickEvent(e)); + } + + public abstract void tickclientCompat(final @Nonnull CompatClientTickEvent e); +} \ No newline at end of file diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/IProxy.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/IProxy.java deleted file mode 100644 index 72a66f2..0000000 --- a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/IProxy.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -public interface IProxy { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/IProxyL.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/IProxyL.java deleted file mode 100644 index 0116e65..0000000 --- a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/IProxyL.java +++ /dev/null @@ -1,17 +0,0 @@ -package net.teamfruit.serverobserver; - -import javax.annotation.Nonnull; - -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; - -public interface IProxyL { - - void preInit(@Nonnull FMLPreInitializationEvent event); - - void init(@Nonnull FMLInitializationEvent event); - - void postInit(@Nonnull FMLPostInitializationEvent event); - -} \ No newline at end of file diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/ServerObserver.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/ServerObserver.java deleted file mode 100644 index d1da0c9..0000000 --- a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/ServerObserver.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.Map; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.Mod.Instance; -import net.minecraftforge.fml.common.SidedProxy; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; -import net.minecraftforge.fml.common.network.NetworkCheckHandler; -import net.minecraftforge.fml.relauncher.Side; - -@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) -public class ServerObserver { - @Instance(Reference.MODID) - public static @Nullable ServerObserver instance; - - static { - UniversalVersioner.loadVersion(); - } - - @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - public static @Nullable IProxy proxy; - - @NetworkCheckHandler - public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { - return true; - } - - @EventHandler - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - if (proxy!=null) - proxy.preInit(event); - } - - @EventHandler - public void init(final @Nonnull FMLInitializationEvent event) { - if (proxy!=null) - proxy.init(event); - } - - @EventHandler - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - if (proxy!=null) - proxy.postInit(event); - } -} diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/ServerObserverL.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/ServerObserverL.java deleted file mode 100644 index 0694a51..0000000 --- a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/ServerObserverL.java +++ /dev/null @@ -1,52 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.util.Map; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - -import cpw.mods.fml.common.Mod; -import cpw.mods.fml.common.Mod.EventHandler; -import cpw.mods.fml.common.Mod.Instance; -import cpw.mods.fml.common.SidedProxy; -import cpw.mods.fml.common.event.FMLInitializationEvent; -import cpw.mods.fml.common.event.FMLPostInitializationEvent; -import cpw.mods.fml.common.event.FMLPreInitializationEvent; -import cpw.mods.fml.common.network.NetworkCheckHandler; -import cpw.mods.fml.relauncher.Side; - -@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION, guiFactory = Reference.GUI_FACTORY) -public class ServerObserverL { - @Instance(Reference.MODID) - public static @Nullable ServerObserverL instance; - - static { - UniversalVersioner.loadVersion(); - } - - @SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT) - public static @Nullable IProxyL proxy; - - @NetworkCheckHandler - public boolean checkModList(final @Nonnull Map versions, final @Nonnull Side side) { - return true; - } - - @EventHandler - public void preInit(final @Nonnull FMLPreInitializationEvent event) { - if (proxy!=null) - proxy.preInit(event); - } - - @EventHandler - public void init(final @Nonnull FMLInitializationEvent event) { - if (proxy!=null) - proxy.init(event); - } - - @EventHandler - public void postInit(final @Nonnull FMLPostInitializationEvent event) { - if (proxy!=null) - proxy.postInit(event); - } -} diff --git a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/UniversalVersioner.java b/common/sources/compat/src/main/java/net/teamfruit/serverobserver/UniversalVersioner.java deleted file mode 100644 index b0a0f7d..0000000 --- a/common/sources/compat/src/main/java/net/teamfruit/serverobserver/UniversalVersioner.java +++ /dev/null @@ -1,109 +0,0 @@ -package net.teamfruit.serverobserver; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Map.Entry; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; - -import com.google.common.collect.ImmutableMap; - -import net.minecraft.launchwrapper.Launch; - -public class UniversalVersioner { - public static final ImmutableMap versions = ImmutableMap. builder() - .put("1.7", "1.7.10") - .put("1.8", "1.8.9") - .put("1.9", "1.9.4") - .put("1.10", "1.10.2") - .put("1.11", "1.11.2") - .put("1.12", "1.12.2") - .build(); - - public static String getVersion(final String mccversion) { - for (final Entry entry : UniversalVersioner.versions.entrySet()) { - final String key = entry.getKey(); - if (StringUtils.startsWith(mccversion, key)) - return entry.getValue(); - } - return null; - } - - private static T invoke(final String afterFmlPath, final String name, final Class[] types, final Object instance, final Object[] params) { - Class $class; - try { - $class = Class.forName("net.minecraftforge.fml."+afterFmlPath); - } catch (final ClassNotFoundException e1) { - try { - $class = Class.forName("cpw.mods.fml."+afterFmlPath); - } catch (final ClassNotFoundException e2) { - throw new RuntimeException("Could not load fml class"); - } - } - if ($class==null) - throw new RuntimeException("Could not find fml class"); - Method $method; - try { - $method = $class.getMethod(name, types); - } catch (final Exception e) { - throw new RuntimeException("Could not find or access fml method"); - } - try { - @SuppressWarnings("unchecked") - final T res = (T) $method.invoke(instance, params); - return res; - } catch (IllegalAccessException|IllegalArgumentException|InvocationTargetException e) { - throw new RuntimeException("Could not invoke fml method"); - } - } - - public static void loadVersion() { - final Object loader = invoke("common.Loader", "instance", new Class[0], null, new Object[0]); - final Object container = invoke("common.Loader", "activeModContainer", new Class[0], loader, new Object[0]); - final Object[] data = invoke("relauncher.FMLInjectionData", "data", new Class[0], null, new Object[0]); - final String mccversion0 = (String) data[4]; - final String mccversion = getVersion(mccversion0); - - if (mccversion==null) - throw new RuntimeException(String.format("Version %s is not supported! Supported version is %s.", mccversion0, versions)); - - final File minecraftDir = (File) data[6]; - final File modsDir = new File(minecraftDir, "mods"); - if (container!=null) { - final File modFile = invoke("common.ModContainer", "getSource", new Class[0], container, new Object[0]); - if (modFile!=null) { - ZipFile file = null; - InputStream stream = null; - try { - final File canonicalModsDir = modsDir.getCanonicalFile(); - final File versionSpecificModsDir = new File(canonicalModsDir, mccversion); - final File modVersionSpecific = new File(versionSpecificModsDir, Reference.MODID); - - final String jarname = String.format("%s.jar", mccversion); - final File destMod = new File(modVersionSpecific, jarname); - - file = new ZipFile(modFile); - final ZipEntry entry = file.getEntry(jarname); - if (entry==null) - throw new RuntimeException("Could not find version-specific file: "+jarname); - stream = file.getInputStream(entry); - - FileUtils.copyInputStreamToFile(stream, destMod); - Launch.classLoader.addURL(destMod.toURI().toURL()); - } catch (final IOException e) { - new RuntimeException("Could not load version-specific file.", e); - } finally { - IOUtils.closeQuietly(file); - IOUtils.closeQuietly(stream); - } - } - } - } -} diff --git a/sources/base/src/main/java/net/teamfruit/serverobserver/CompatProxy.java b/sources/base/src/main/java/net/teamfruit/serverobserver/CompatProxy.java new file mode 100644 index 0000000..74c7e5f --- /dev/null +++ b/sources/base/src/main/java/net/teamfruit/serverobserver/CompatProxy.java @@ -0,0 +1,29 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import org.apache.logging.log4j.Logger; + +public interface CompatProxy { + public static interface CompatFMLPreInitializationEvent { + Logger getModLog(); + + File getSuggestedConfigurationFile(); + + File getModConfigurationDirectory(); + } + + void preInit(final @Nonnull CompatFMLPreInitializationEvent event); + + public static interface CompatFMLInitializationEvent { + } + + void init(final @Nonnull CompatFMLInitializationEvent event); + + public static interface CompatFMLPostInitializationEvent { + } + + void postInit(final @Nonnull CompatFMLPostInitializationEvent event); +} \ No newline at end of file diff --git a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java b/sources/universal/src/main/java/net/teamfruit/serverobserver/ClientProxy.java similarity index 68% rename from 1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java rename to sources/universal/src/main/java/net/teamfruit/serverobserver/ClientProxy.java index 3c7bb02..0fcbaf5 100644 --- a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ClientProxy.java +++ b/sources/universal/src/main/java/net/teamfruit/serverobserver/ClientProxy.java @@ -8,13 +8,10 @@ import org.apache.commons.io.FileUtils; import net.minecraft.client.Minecraft; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; public class ClientProxy extends CommonProxy { @Override - public void preInit(final @Nonnull FMLPreInitializationEvent event) { + public void preInit(final @Nonnull CompatFMLPreInitializationEvent event) { super.preInit(event); final File cfgDir = event.getModConfigurationDirectory(); final File modCfgDir = new File(cfgDir, Reference.MODID); @@ -31,14 +28,14 @@ public void preInit(final @Nonnull FMLPreInitializationEvent event) { } @Override - public void init(final @Nonnull FMLInitializationEvent event) { + public void init(final @Nonnull CompatFMLInitializationEvent event) { super.init(event); // Event Register CoreHandler.instance.init(); } @Override - public void postInit(final @Nonnull FMLPostInitializationEvent event) { + public void postInit(final @Nonnull CompatFMLPostInitializationEvent event) { super.postInit(event); Config.getConfig().save(); } diff --git a/sources/universal/src/main/java/net/teamfruit/serverobserver/CommonProxy.java b/sources/universal/src/main/java/net/teamfruit/serverobserver/CommonProxy.java new file mode 100644 index 0000000..f28bcff --- /dev/null +++ b/sources/universal/src/main/java/net/teamfruit/serverobserver/CommonProxy.java @@ -0,0 +1,15 @@ +package net.teamfruit.serverobserver; + +public class CommonProxy implements CompatProxy { + @Override + public void preInit(final CompatFMLPreInitializationEvent event) { + } + + @Override + public void init(final CompatFMLInitializationEvent event) { + } + + @Override + public void postInit(final CompatFMLPostInitializationEvent event) { + } +} diff --git a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java b/sources/universal/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java similarity index 59% rename from 1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java rename to sources/universal/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java index 7a0daf5..337deb9 100644 --- a/1.12.2/sources/compat/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java +++ b/sources/universal/src/main/java/net/teamfruit/serverobserver/ConfigGuiFactory.java @@ -2,7 +2,6 @@ import java.util.ArrayList; import java.util.List; -import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -13,34 +12,33 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraftforge.common.config.ConfigCategory; -import net.minecraftforge.common.config.ConfigElement; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; -import net.minecraftforge.fml.client.IModGuiFactory; -import net.minecraftforge.fml.client.config.GuiConfig; -import net.minecraftforge.fml.client.config.IConfigElement; +import net.teamfruit.serverobserver.CompatConfigs.CompatConfigElement; +import net.teamfruit.serverobserver.CompatConfigs.CompatGuiConfig; +import net.teamfruit.serverobserver.CompatConfigs.CompatModGuiFactory; /** * コンフィグGUI * * @author Kamesuta */ -public class ConfigGuiFactory implements IModGuiFactory { +public class ConfigGuiFactory extends CompatModGuiFactory { - public static class ConfigGui extends GuiConfig { + public static class ConfigGui extends CompatGuiConfig { public ConfigGui(final @Nullable GuiScreen parent) { super(parent, getConfigElements(), Reference.MODID, false, false, I18n.format("serverobserver.config")); } - private static @Nonnull List getConfigElements() { - final List list = new ArrayList(); + private static @Nonnull List getConfigElements() { + final List list = new ArrayList(); getConfigElements(list, Config.getConfig().getBase()); getConfigElements(list, Config.getConfig().getBaseDynamic()); return list; } - private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { + private static @Nonnull List getConfigElements(final List list, final ConfigBase cb) { ConfigCategory general = null; for (final String cat : cb.getCategoryNames()) { @@ -54,15 +52,15 @@ public ConfigGui(final @Nullable GuiScreen parent) { if (cc.isChild()) continue; - list.add(new ConfigElement(cc)); + list.add(CompatConfigElement.fromCategory(cc)); } // General項目をトップに表示します if (general!=null) { for (final ConfigCategory cc : general.getChildren()) - list.add(new ConfigElement(cc)); + list.add(CompatConfigElement.fromCategory(cc)); for (final Property prop : general.values()) - list.add(new ConfigElement(prop)); + list.add(CompatConfigElement.fromProperty(prop)); } return list; @@ -75,17 +73,12 @@ public void initialize(final @Nullable Minecraft minecraftInstance) { } @Override - public @Nullable Set runtimeGuiCategories() { - return null; + public Class mainConfigGuiClassCompat() { + return ConfigGui.class; } @Override - public boolean hasConfigGui() { - return true; - } - - @Override - public GuiScreen createConfigGui(final GuiScreen parentScreen) { + public GuiScreen createConfigGuiCompat(final GuiScreen parentScreen) { return new ConfigGui(parentScreen); } } \ No newline at end of file diff --git a/sources/universal/src/main/java/net/teamfruit/serverobserver/CoreHandler.java b/sources/universal/src/main/java/net/teamfruit/serverobserver/CoreHandler.java new file mode 100644 index 0000000..857e716 --- /dev/null +++ b/sources/universal/src/main/java/net/teamfruit/serverobserver/CoreHandler.java @@ -0,0 +1,52 @@ +package net.teamfruit.serverobserver; + +import java.io.File; + +import javax.annotation.Nonnull; + +import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent; +import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent; +import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent; + +public class CoreHandler extends CompatHandler { + public static final @Nonnull CoreHandler instance = new CoreHandler(); + + public final @Nonnull Config configHandler = Config.getConfig(); + public final @Nonnull GuiHandler guiHandler = new GuiHandler(Compat.compat); + + @Override + public void preInit(final File root) { + this.guiHandler.init(root); + } + + @Override + public void onConfigChangedCompat(final @Nonnull CompatOnConfigChangedEvent eventArgs) { + for (final ConfigBase base : ConfigBase.configChangeHandlers) + base.onConfigChanged(eventArgs.getModID()); + } + + @Override + public void openCompat(final InitGuiEvent.Post e) { + this.guiHandler.open(e); + } + + @Override + public void drawCompat(final DrawScreenEvent.Post e) { + this.guiHandler.draw(e); + } + + @Override + public void actionCompat(final ActionPerformedEvent.Pre e) { + this.guiHandler.action(e); + } + + @Override + public void actionCompat(final ActionPerformedEvent.Post e) { + this.guiHandler.action(e); + } + + @Override + public void tickclientCompat(final @Nonnull CompatClientTickEvent e) { + this.guiHandler.tickclient(); + } +} \ No newline at end of file