fix NPE in configuration loading and set more sane default url

This commit is contained in:
NikkyAI 2018-02-08 13:56:38 +01:00 committed by Unknown
parent 57ab69a898
commit 8d04b002bb
2 changed files with 9 additions and 9 deletions

View File

@ -44,7 +44,7 @@ object MatterLink {
logger = event.modLog logger = event.modLog
logger.info("Building bridge!") logger.info("Building bridge!")
MatterLinkConfig() MatterLinkConfig(event.suggestedConfigurationFile)
} }
@Mod.EventHandler @Mod.EventHandler

View File

@ -1,11 +1,11 @@
package matterlink package matterlink
import net.minecraftforge.common.config.Configuration import net.minecraftforge.common.config.Configuration
import java.util.regex.Pattern import java.io.File
var cfg: MatterLinkConfig? = null var cfg: MatterLinkConfig? = null
class MatterLinkConfig() { class MatterLinkConfig(file: File) {
private val CATEGORY_RELAY_OPTIONS = "relay" private val CATEGORY_RELAY_OPTIONS = "relay"
private val CATEGORY_FORMATTING = "formatting" private val CATEGORY_FORMATTING = "formatting"
private val CATEGORY_CONNECTION = "connection" private val CATEGORY_CONNECTION = "connection"
@ -14,7 +14,7 @@ class MatterLinkConfig() {
val relay: RelayOptions val relay: RelayOptions
val connect: ConnectOptions val connect: ConnectOptions
val formatting: FormattingOptions val formatting: FormattingOptions
//val command: CommandOptions val command: CommandOptions
data class RelayOptions( data class RelayOptions(
val systemUser: String, val systemUser: String,
@ -40,8 +40,8 @@ class MatterLinkConfig() {
) )
init { init {
MatterLink.logger.info("Reading bridge blueprints...") MatterLink.logger.info("Reading bridge blueprints... from {}", file)
val config = Configuration() val config = Configuration(file)
config.addCustomCategoryComment(CATEGORY_RELAY_OPTIONS, "Relay options") config.addCustomCategoryComment(CATEGORY_RELAY_OPTIONS, "Relay options")
relay = RelayOptions( relay = RelayOptions(
@ -72,7 +72,7 @@ class MatterLinkConfig() {
) )
) )
/*config.addCustomCategoryComment(CATEGORY_COMMAND,"User commands") config.addCustomCategoryComment(CATEGORY_COMMAND,"User commands")
command = CommandOptions( command = CommandOptions(
prefix = config.getString( prefix = config.getString(
"commandPrefix", "commandPrefix",
@ -81,7 +81,7 @@ class MatterLinkConfig() {
"Prefix for MC bridge commands. Accepts a single non-alphanumeric character." "Prefix for MC bridge commands. Accepts a single non-alphanumeric character."
//Pattern.compile("[^0-9A-Za-z/]") //Pattern.compile("[^0-9A-Za-z/]")
) )
)*/ )
config.addCustomCategoryComment(CATEGORY_FORMATTING, "Formatting options: " + config.addCustomCategoryComment(CATEGORY_FORMATTING, "Formatting options: " +
"Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}") "Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
@ -111,7 +111,7 @@ class MatterLinkConfig() {
url = config.getString( url = config.getString(
"connectURL", "connectURL",
CATEGORY_CONNECTION, CATEGORY_CONNECTION,
"http://example.com:1234", "localhost:4242",
"The URL or IP address of the bridge server" "The URL or IP address of the bridge server"
), ),
authToken = config.getString( authToken = config.getString(