diff --git a/src/main/java/moe/yuyui/mcstreamerbot/CommonProxy.java b/src/main/java/moe/yuyui/mcstreamerbot/CommonProxy.java index 0767451..92f3d08 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/CommonProxy.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/CommonProxy.java @@ -1,6 +1,7 @@ package moe.yuyui.mcstreamerbot; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; @@ -14,16 +15,17 @@ public class CommonProxy { // preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the // GameRegistry." (Remove if not needed) public void preInit(FMLPreInitializationEvent event) { - Config.synchronizeConfiguration(event.getSuggestedConfigurationFile()); + Config.configuration = new Configuration(event.getSuggestedConfigurationFile()); + Config.synchronizeConfiguration(); - MinecraftStreamerBotIntegration.LOG.info("MCStreamerBot is meowing in version " + Tags.VERSION); + MCStreamerBot.LOG.info("MCStreamerBot is meowing in version " + Tags.VERSION); } // load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed) public void init(FMLInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new OnWorldJoin()); MinecraftForge.EVENT_BUS.register(new OnWorldLeave()); - MinecraftStreamerBotIntegration.LOG.info("Loaded MCStreamerBot"); + MCStreamerBot.LOG.info("Loaded MCStreamerBot"); } // postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed) diff --git a/src/main/java/moe/yuyui/mcstreamerbot/Config.java b/src/main/java/moe/yuyui/mcstreamerbot/Config.java index feb47d9..fd19c06 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/Config.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/Config.java @@ -1,25 +1,26 @@ package moe.yuyui.mcstreamerbot; -import java.io.File; - import net.minecraftforge.common.config.Configuration; public class Config { - private static final String CATEGORY_WEBSOCKET = "websocket"; + public static final String CATEGORY_WEBSOCKET = "websocket"; public static int portNumber = 8069; public static String ipAddress = "127.0.0.1"; public static String authToken = ""; + public static Configuration configuration; - public static void synchronizeConfiguration(File configFile) { - Configuration configuration = new Configuration(configFile); - configuration.addCustomCategoryComment("General", "General configuration of the bot"); + public static void synchronizeConfiguration() { + configuration.addCustomCategoryComment(CATEGORY_WEBSOCKET, "Configuration for the websocket"); portNumber = configuration - .getInt("port", CATEGORY_WEBSOCKET, portNumber, 1024, 65535, "The port that the websocket will listen on"); + .getInt("Port", CATEGORY_WEBSOCKET, portNumber, 1024, 65535, "The Port that the websocket will listen on"); ipAddress = configuration - .getString("ip", CATEGORY_WEBSOCKET, ipAddress, "The ip that the websocket will listen on"); - authToken = configuration - .getString("authToken", CATEGORY_WEBSOCKET, authToken, "The authentication token for the websocket"); + .getString("IP Address", CATEGORY_WEBSOCKET, ipAddress, "The IP Address that the websocket will listen on"); + authToken = configuration.getString( + "Authentication Token", + CATEGORY_WEBSOCKET, + authToken, + "The authentication token for the websocket. Leave empty to disable authentication."); if (configuration.hasChanged()) { configuration.save(); diff --git a/src/main/java/moe/yuyui/mcstreamerbot/MinecraftStreamerBotIntegration.java b/src/main/java/moe/yuyui/mcstreamerbot/MCStreamerBot.java similarity index 87% rename from src/main/java/moe/yuyui/mcstreamerbot/MinecraftStreamerBotIntegration.java rename to src/main/java/moe/yuyui/mcstreamerbot/MCStreamerBot.java index 20c45d3..f0acd69 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/MinecraftStreamerBotIntegration.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/MCStreamerBot.java @@ -12,15 +12,15 @@ import cpw.mods.fml.common.event.FMLServerStartingEvent; import moe.yuyui.mcstreamerbot.common.EventListener; @Mod( - modid = MinecraftStreamerBotIntegration.MODID, - version = Tags.VERSION, - name = "MyMod", - acceptedMinecraftVersions = "[1.7.10]") -public class MinecraftStreamerBotIntegration { + modid = MCStreamerBot.MODID, + version = "1.0.1-" + Tags.VERSION, + name = "MCStreamerBot", + acceptedMinecraftVersions = "[1.7.10]", + guiFactory = "moe.yuyui." + MCStreamerBot.MODID + ".gui.MCStreamerBotGuiFactory") +public class MCStreamerBot { public static final String MODID = "mcstreamerbot"; public static final Logger LOG = LogManager.getLogger(MODID); - public static EventListener eventListener; @SidedProxy(clientSide = "moe.yuyui.mcstreamerbot.ClientProxy", serverSide = "moe.yuyui.mcstreamerbot.CommonProxy") diff --git a/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldJoin.java b/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldJoin.java index 2c9af56..e0fbb9b 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldJoin.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldJoin.java @@ -8,7 +8,7 @@ import net.minecraftforge.event.entity.EntityJoinWorldEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import moe.yuyui.mcstreamerbot.Config; -import moe.yuyui.mcstreamerbot.MinecraftStreamerBotIntegration; +import moe.yuyui.mcstreamerbot.MCStreamerBot; import moe.yuyui.mcstreamerbot.common.EventListener; import moe.yuyui.mcstreamerbot.common.WSServer; @@ -18,16 +18,16 @@ public class OnWorldJoin { public void onEntityJoinWorld(EntityJoinWorldEvent event) { if (event.entity == Minecraft.getMinecraft().thePlayer && Minecraft.getMinecraft() .isIntegratedServerRunning() && event.world.isRemote) { - if (MinecraftStreamerBotIntegration.eventListener != null) { - if (MinecraftStreamerBotIntegration.eventListener.isAlive()) { + if (MCStreamerBot.eventListener != null) { + if (MCStreamerBot.eventListener.isAlive()) { return; } } try { - MinecraftStreamerBotIntegration.eventListener = new EventListener( + MCStreamerBot.eventListener = new EventListener( new WSServer(new InetSocketAddress(Config.ipAddress, Config.portNumber), Config.authToken)); } catch (NoSuchAlgorithmException e) { - MinecraftStreamerBotIntegration.LOG.error("Your computer does not support SHA-256 hashing"); + MCStreamerBot.LOG.error("Your computer does not support SHA-256 hashing"); } } } diff --git a/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldLeave.java b/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldLeave.java index b0ccd08..4778661 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldLeave.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/events/minecraft/OnWorldLeave.java @@ -3,14 +3,14 @@ package moe.yuyui.mcstreamerbot.events.minecraft; import net.minecraftforge.event.world.WorldEvent; import cpw.mods.fml.common.eventhandler.SubscribeEvent; -import moe.yuyui.mcstreamerbot.MinecraftStreamerBotIntegration; +import moe.yuyui.mcstreamerbot.MCStreamerBot; public class OnWorldLeave { @SubscribeEvent public void onPlayerLeave(WorldEvent.Unload event) { try { - MinecraftStreamerBotIntegration.eventListener.end(); + MCStreamerBot.eventListener.end(); } catch (InterruptedException | NullPointerException ignored) {} } diff --git a/src/main/java/moe/yuyui/mcstreamerbot/gui/MCStreamerBotGuiConfig.java b/src/main/java/moe/yuyui/mcstreamerbot/gui/MCStreamerBotGuiConfig.java new file mode 100644 index 0000000..f499f09 --- /dev/null +++ b/src/main/java/moe/yuyui/mcstreamerbot/gui/MCStreamerBotGuiConfig.java @@ -0,0 +1,38 @@ +package moe.yuyui.mcstreamerbot.gui; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.common.config.ConfigElement; + +import cpw.mods.fml.client.config.GuiConfig; +import moe.yuyui.mcstreamerbot.Config; +import moe.yuyui.mcstreamerbot.MCStreamerBot; + +public class MCStreamerBotGuiConfig extends GuiConfig { + + public MCStreamerBotGuiConfig(GuiScreen parent) { + super( + parent, + new ConfigElement<>(Config.configuration.getCategory(Config.CATEGORY_WEBSOCKET)).getChildElements(), + MCStreamerBot.MODID, + true, + false, + "Configure the Websocket."); + titleLine2 = "Make sure you know what you're doing ;)"; + } + + @Override + public void initGui() { + super.initGui(); + } + + @Override + public void drawScreen(int mouseX, int mouseY, float partialTicks) { + super.drawScreen(mouseX, mouseY, partialTicks); + } + + @Override + protected void actionPerformed(GuiButton button) { + super.actionPerformed(button); + } +} diff --git a/src/main/java/moe/yuyui/mcstreamerbot/gui/MCStreamerBotGuiFactory.java b/src/main/java/moe/yuyui/mcstreamerbot/gui/MCStreamerBotGuiFactory.java new file mode 100644 index 0000000..ca0db1f --- /dev/null +++ b/src/main/java/moe/yuyui/mcstreamerbot/gui/MCStreamerBotGuiFactory.java @@ -0,0 +1,32 @@ +package moe.yuyui.mcstreamerbot.gui; + +import java.util.Set; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; + +import cpw.mods.fml.client.IModGuiFactory; + +public class MCStreamerBotGuiFactory implements IModGuiFactory { + + @Override + public void initialize(Minecraft minecraftInstance) { + + } + + @Override + public Class mainConfigGuiClass() { + return MCStreamerBotGuiConfig.class; + } + + @Override + public Set runtimeGuiCategories() { + return null; + } + + @Override + public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) { + return null; + } + +}