Skip to content

Commit

Permalink
feat(config): attempt to auto start on server start
Browse files Browse the repository at this point in the history
  • Loading branch information
iGoodie committed Jun 2, 2020
1 parent a64aa9a commit d322f08
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.programmer.igoodie.twitchspawn.command.StreamerArgumentType;
import net.programmer.igoodie.twitchspawn.command.TwitchSpawnCommand;
import net.programmer.igoodie.twitchspawn.configuration.ConfigManager;
import net.programmer.igoodie.twitchspawn.configuration.PreferencesConfig;
import net.programmer.igoodie.twitchspawn.network.NetworkManager;
import net.programmer.igoodie.twitchspawn.network.packet.StatusChangedPacket;
import net.programmer.igoodie.twitchspawn.tracer.TraceManager;
Expand Down Expand Up @@ -86,6 +87,11 @@ public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
TwitchSpawnCommand.register(event.getCommandDispatcher());

if (ConfigManager.PREFERENCES.autoStart == PreferencesConfig.AutoStartEnum.ENABLED) {
LOGGER.info("Auto-start is enabled. Attempting to start tracers.");
TRACE_MANAGER.start();
}
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public enum MessageDisplay {
DISABLED, TITLES, CHAT
}

public enum AutoStartEnum {
DISABLED, ENABLED
}

public static PreferencesConfig create(File file) {
try {
// File is not there, create an empty file
Expand Down Expand Up @@ -52,6 +56,7 @@ public static PreferencesConfig create(File file) {
preferencesConfig.notificationVolume = config.get("notificationVolume");
preferencesConfig.notificationPitch = config.get("notificationPitch");
preferencesConfig.notificationDelay = config.getInt("notificationDelay");
preferencesConfig.autoStart = getEnum(config, "autoStart", AutoStartEnum.class);

config.close();

Expand Down Expand Up @@ -110,6 +115,7 @@ private static ConfigSpec getSpecs() {
return (value == -1.0) || (0.0 <= value && value <= 1.0);
});
spec.defineInRange("notificationDelay", 5000, 0, Integer.MAX_VALUE);
defineEnum(spec, "autoStart", AutoStartEnum.DISABLED, AutoStartEnum.class);

return spec;
}
Expand Down Expand Up @@ -161,4 +167,6 @@ private static String defaultScript() {
public double notificationPitch;
public int notificationDelay;

public AutoStartEnum autoStart;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ notificationPitch = 1.0
# Unit of it is milliseconds (5000 milliseconds = 5 seconds)
# Min: 0
notificationDelay = 5000

# Attempt to auto-start the mod when the server/world is starting
# Connection issues will be resulted in mod to stop. However, you can still start it manually.
# Either "enabled" or "disabled"
autoStart = "disabled"

0 comments on commit d322f08

Please sign in to comment.