Skip to content

Commit f13533a

Browse files
committed
Setup instructions
1 parent 8251c17 commit f13533a

File tree

7 files changed

+172
-4
lines changed

7 files changed

+172
-4
lines changed

src/main/java/net/shadowfacts/discordchat/DCConfig.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class DCConfig {
4646
public static String playerLeaveMessageFormat = "MC \u00BB $1 left the game";
4747

4848
@ConfigProperty(category = "discord", comment = "The token used to identify your bot to Discord.\nRequired")
49-
public static String bottoken = "";
49+
public static String botToken = "";
5050

5151
@ConfigProperty(category = "discord", comment = "The server ID to connect to.")
5252
public static String serverId = "";
@@ -62,7 +62,7 @@ public static void init(File configDir) {
6262

6363
public static void load() {
6464
ConfigManager.instance.load(DiscordChat.modId);
65-
if (bottoken.isEmpty() || serverId.isEmpty() || Arrays.equals(channels, new String[0])) {
65+
if (botToken.isEmpty() || serverId.isEmpty() || Arrays.equals(channels, new String[0])) {
6666
DiscordChat.log.warn("Missing required information, disabling DiscordChat");
6767
DiscordChat.log.warn("Please go to config/shadowfacts/DiscordChat.cfg and fill out the required fields and restart Minecraft to enable DiscordChat");
6868
enabled = false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package net.shadowfacts.discordchat;
2+
3+
import com.google.common.base.Charsets;
4+
import org.apache.commons.io.IOUtils;
5+
6+
import java.io.*;
7+
8+
/**
9+
* @author shadowfacts
10+
*/
11+
public class DCPrivateProps {
12+
13+
private static File privateProperties;
14+
15+
public static boolean setup = false;
16+
17+
public static void save() {
18+
try {
19+
privateProperties.createNewFile();
20+
try (Writer out = new OutputStreamWriter(new BufferedOutputStream(new FileOutputStream(privateProperties)), Charsets.UTF_8)) {
21+
out.write("setup=" + Boolean.toString(setup));
22+
}
23+
} catch (IOException e) {
24+
throw new RuntimeException(e);
25+
}
26+
}
27+
28+
public static void init(File configDir) {
29+
try {
30+
privateProperties = new File(configDir, "shadowfacts/DiscordChat.private");
31+
if (!privateProperties.exists()) {
32+
save();
33+
} else {
34+
String line = IOUtils.readLines(new FileInputStream(privateProperties)).get(0);
35+
String[] bits = line.split("=");
36+
if ("setup".equals(bits[0])) {
37+
setup = Boolean.parseBoolean(bits[1]);
38+
}
39+
}
40+
} catch (IOException e) {
41+
throw new RuntimeException(e);
42+
}
43+
}
44+
45+
}

src/main/java/net/shadowfacts/discordchat/DiscordChat.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import net.minecraftforge.fml.common.Mod;
55
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
66
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
7+
import net.minecraftforge.fml.relauncher.Side;
8+
import net.shadowfacts.discordchat.client.ClientSetupHandler;
79
import net.shadowfacts.discordchat.discord.DiscordThread;
810
import net.shadowfacts.shadowmc.util.LogHelper;
911

@@ -22,14 +24,27 @@ public class DiscordChat {
2224
public void preInit(FMLPreInitializationEvent event) {
2325
DCConfig.init(event.getModConfigurationDirectory());
2426

27+
DCPrivateProps.init(event.getModConfigurationDirectory());
28+
2529
if (DCConfig.enabled) {
2630
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
31+
32+
if (!DCPrivateProps.setup && event.getSide() == Side.CLIENT) {
33+
MinecraftForge.EVENT_BUS.register(new ClientSetupHandler());
34+
}
2735
}
2836
}
2937

3038
@Mod.EventHandler
3139
public void serverStarting(FMLServerStartingEvent event) {
32-
DiscordThread.runThread();
40+
if (DCPrivateProps.setup) {
41+
log.info("Connecting to the Discord server...");
42+
43+
DiscordThread.runThread();
44+
} else {
45+
log.error("DiscordChat has not been setup. Follow the instructions (https://git.io/vrGte) and change setup to true in config/shadowfacts/private.properties");
46+
DCConfig.enabled = false;
47+
}
3348
}
3449

3550
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.shadowfacts.discordchat.client;
2+
3+
import net.minecraft.client.gui.GuiMainMenu;
4+
import net.minecraftforge.client.event.GuiOpenEvent;
5+
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
6+
import net.shadowfacts.discordchat.DCPrivateProps;
7+
8+
/**
9+
* @author shadowfacts
10+
*/
11+
public class ClientSetupHandler {
12+
13+
@SubscribeEvent
14+
public void onGuiOpen(GuiOpenEvent event) {
15+
if (!DCPrivateProps.setup && event.gui instanceof GuiMainMenu) {
16+
event.gui = GUISetup.create();
17+
}
18+
}
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package net.shadowfacts.discordchat.client;
2+
3+
import net.minecraft.client.Minecraft;
4+
import net.minecraft.client.gui.GuiMainMenu;
5+
import net.minecraft.client.gui.GuiScreen;
6+
import net.minecraft.client.renderer.GlStateManager;
7+
import net.shadowfacts.discordchat.DCConfig;
8+
import net.shadowfacts.discordchat.DCPrivateProps;
9+
import net.shadowfacts.shadowlib.util.DesktopUtils;
10+
import net.shadowfacts.shadowmc.gui.component.GUIComponentText;
11+
import net.shadowfacts.shadowmc.gui.component.button.GUIButtonText;
12+
import net.shadowfacts.shadowmc.gui.mcwrapper.GuiScreenWrapper;
13+
import net.shadowfacts.shadowmc.gui.mcwrapper.MCBaseGUI;
14+
import net.shadowfacts.shadowmc.util.MouseButton;
15+
import net.shadowfacts.shadowmc.util.StringHelper;
16+
17+
import java.net.URISyntaxException;
18+
19+
/**
20+
* @author shadowfacts
21+
*/
22+
public class GUISetup extends MCBaseGUI {
23+
24+
public GUISetup(GuiScreenWrapper wrapper) {
25+
super(wrapper);
26+
27+
String line1 = StringHelper.localize("dc.gui.setup.line1");
28+
String line2 = StringHelper.localize("dc.gui.setup.line2");
29+
30+
addChild(new GUIComponentText(-(mc.fontRendererObj.getStringWidth(line1) / 2), 10, line1));
31+
addChild(new GUIComponentText(-(mc.fontRendererObj.getStringWidth(line2) / 2), mc.fontRendererObj.FONT_HEIGHT + 14, line2));
32+
33+
addChild(new GUIButtonText(-100, 40, 200, 20, this::handleInstructions, StringHelper.localize("dc.gui.setup.instructions")));
34+
addChild(new GUIButtonText(-100, 70, 200, 20, this::handleFinished, StringHelper.localize("dc.gui.setup.finished")));
35+
addChild(new GUIButtonText(-100, 100, 200, 20, this::handleSkip, StringHelper.localize("dc.gui.setup.skip")));
36+
}
37+
38+
@Override
39+
public void setInitialized(boolean initialized) {
40+
super.setInitialized(initialized);
41+
updatePosition(width / 2, y);
42+
}
43+
44+
private boolean handleInstructions(GUIButtonText button, MouseButton mouseButton) {
45+
try {
46+
DesktopUtils.openWebpage("https://git.io/vrGte");
47+
} catch (URISyntaxException ignored) {}
48+
return true;
49+
}
50+
51+
private boolean handleFinished(GUIButtonText button, MouseButton mouseButton) {
52+
DCPrivateProps.setup = true;
53+
DCPrivateProps.save();
54+
DCConfig.load();
55+
Minecraft.getMinecraft().displayGuiScreen(new GuiMainMenu());
56+
return true;
57+
}
58+
59+
private boolean handleSkip(GUIButtonText button, MouseButton mouseButton) {
60+
DCPrivateProps.setup = true;
61+
DCPrivateProps.save();
62+
Minecraft.getMinecraft().displayGuiScreen(new GuiMainMenu());
63+
return true;
64+
}
65+
66+
@Override
67+
public void draw(int mouseX, int mouseY, float partialTicks) {
68+
// because something else disables GL_TEXTURE_2D without using the GlStateManager
69+
GlStateManager.disableTexture2D();
70+
GlStateManager.enableTexture2D();
71+
72+
super.draw(mouseX, mouseY, partialTicks);
73+
}
74+
75+
public static GuiScreen create() {
76+
GuiScreenWrapper wrapper = new GuiScreenWrapper();
77+
GUISetup gui = new GUISetup(wrapper);
78+
gui.setZLevel(0);
79+
wrapper.gui = gui;
80+
return wrapper;
81+
}
82+
83+
}

src/main/java/net/shadowfacts/discordchat/discord/DiscordThread.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void run() {
3939
try {
4040
try {
4141
jda = new JDABuilder()
42-
.setBotToken(DCConfig.bottoken)
42+
.setBotToken(DCConfig.botToken)
4343
.addListener(new MainListener())
4444
.buildBlocking();
4545
} catch (LoginException | IllegalArgumentException e) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dc.gui.setup.skip=Skip (already setup)
2+
dc.gui.setup.finished=Finished
3+
dc.gui.setup.instructions=Instructions
4+
dc.gui.setup.line1=Follow the instructions linked below,
5+
dc.gui.setup.line2=then click Finished.

0 commit comments

Comments
 (0)