restructure config
This commit is contained in:
parent
572c326f4c
commit
c426e625d3
|
@ -1,17 +1,15 @@
|
||||||
package matterlink.config
|
package matterlink.config
|
||||||
|
|
||||||
import matterlink.instance
|
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
var cfg: BaseConfig? = null
|
var cfg: BaseConfig? = null
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
abstract class BaseConfig {
|
abstract class BaseConfig {
|
||||||
companion object {
|
companion object {
|
||||||
private val CATEGORY_RELAY_OPTIONS = "relay"
|
private val CATEGORY_RELAY_OPTIONS = "relay"
|
||||||
private val CATEGORY_FORMATTING_INCOMING = "formatting"
|
private val CATEGORY_FORMATTING_INCOMING = "formatting"
|
||||||
private val CATEGORY_FORMATTING_JOIN_LEAVE = "formatting_join_leave"
|
private val CATEGORY_JOIN_LEAVE = "join_leave"
|
||||||
private val CATEGORY_CONNECTION = "connection"
|
private val CATEGORY_CONNECTION = "connection"
|
||||||
private val CATEGORY_COMMAND = "command"
|
private val CATEGORY_COMMAND = "command"
|
||||||
private val CATEGORY_DEATH = "death"
|
private val CATEGORY_DEATH = "death"
|
||||||
|
@ -20,15 +18,13 @@ abstract class BaseConfig {
|
||||||
var relay: RelayOptions = RelayOptions()
|
var relay: RelayOptions = RelayOptions()
|
||||||
var connect: ConnectOptions = ConnectOptions()
|
var connect: ConnectOptions = ConnectOptions()
|
||||||
var formatting: FormattingOptions = FormattingOptions()
|
var formatting: FormattingOptions = FormattingOptions()
|
||||||
var formattingJoinLeave: FormattingJoinLeave = FormattingJoinLeave()
|
var joinLeave: FormattingJoinLeave = FormattingJoinLeave()
|
||||||
var command: CommandOptions = CommandOptions()
|
var command: CommandOptions = CommandOptions()
|
||||||
var death: DeathOptions = DeathOptions()
|
var death: DeathOptions = DeathOptions()
|
||||||
|
|
||||||
data class RelayOptions(
|
data class RelayOptions(
|
||||||
var systemUser: String = "Server",
|
var systemUser: String = "Server",
|
||||||
var deathEvents: Boolean = true,
|
var advancements: Boolean = true
|
||||||
var advancements: Boolean = true,
|
|
||||||
var joinLeave: Boolean = true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class FormattingOptions(
|
data class FormattingOptions(
|
||||||
|
@ -38,6 +34,8 @@ abstract class BaseConfig {
|
||||||
)
|
)
|
||||||
|
|
||||||
data class FormattingJoinLeave(
|
data class FormattingJoinLeave(
|
||||||
|
var showJoin: Boolean = true,
|
||||||
|
var showLeave: Boolean = true,
|
||||||
var joinServer: String = "{username:antiping} has connected to the server",
|
var joinServer: String = "{username:antiping} has connected to the server",
|
||||||
var leaveServer: String = "{username:antiping} has disconnected from the server"
|
var leaveServer: String = "{username:antiping} has disconnected from the server"
|
||||||
)
|
)
|
||||||
|
@ -54,6 +52,7 @@ abstract class BaseConfig {
|
||||||
)
|
)
|
||||||
|
|
||||||
data class DeathOptions(
|
data class DeathOptions(
|
||||||
|
var showDeath: Boolean = true,
|
||||||
var showDamageType: Boolean = true,
|
var showDamageType: Boolean = true,
|
||||||
var damageTypeMapping: Map<String, String> = mapOf(
|
var damageTypeMapping: Map<String, String> = mapOf(
|
||||||
"inFire" to "\uD83D\uDD25", //🔥
|
"inFire" to "\uD83D\uDD25", //🔥
|
||||||
|
@ -107,23 +106,11 @@ abstract class BaseConfig {
|
||||||
relay.systemUser,
|
relay.systemUser,
|
||||||
"Name of the server user (used by death and advancement messages and the /say command)"
|
"Name of the server user (used by death and advancement messages and the /say command)"
|
||||||
),
|
),
|
||||||
deathEvents = getBoolean(
|
|
||||||
"deathEvents",
|
|
||||||
category,
|
|
||||||
relay.deathEvents,
|
|
||||||
"Relay player death messages"
|
|
||||||
),
|
|
||||||
advancements = getBoolean(
|
advancements = getBoolean(
|
||||||
"advancements",
|
"advancements",
|
||||||
category,
|
category,
|
||||||
relay.advancements,
|
relay.advancements,
|
||||||
"Relay player advancements"
|
"Relay player advancements"
|
||||||
),
|
|
||||||
joinLeave = getBoolean(
|
|
||||||
"joinLeave",
|
|
||||||
category,
|
|
||||||
relay.joinLeave,
|
|
||||||
"Relay when a player joins or leaves the game"
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -170,21 +157,35 @@ abstract class BaseConfig {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
category = CATEGORY_FORMATTING_JOIN_LEAVE
|
category = CATEGORY_JOIN_LEAVE
|
||||||
addCustomCategoryComment(CATEGORY_FORMATTING_JOIN_LEAVE, "Server -> Gateway" +
|
addCustomCategoryComment(CATEGORY_JOIN_LEAVE, "Server -> Gateway" +
|
||||||
"Formatting options: " +
|
"Formatting options: " +
|
||||||
"Available variables: {username}, {username:antiping}")
|
"Available variables: {username}, {username:antiping}")
|
||||||
formattingJoinLeave = FormattingJoinLeave(
|
joinLeave = FormattingJoinLeave(
|
||||||
|
|
||||||
|
showJoin = getBoolean(
|
||||||
|
"showJoin",
|
||||||
|
category,
|
||||||
|
joinLeave.showJoin,
|
||||||
|
"Relay when a player joins the game"
|
||||||
|
),
|
||||||
|
|
||||||
|
showLeave = getBoolean(
|
||||||
|
"showLeave",
|
||||||
|
category,
|
||||||
|
joinLeave.showLeave,
|
||||||
|
"Relay when a player leaves the game"
|
||||||
|
),
|
||||||
joinServer = getString(
|
joinServer = getString(
|
||||||
"joinServer",
|
"joinServer",
|
||||||
category,
|
category,
|
||||||
formattingJoinLeave.joinServer,
|
joinLeave.joinServer,
|
||||||
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||||
),
|
),
|
||||||
leaveServer = getString(
|
leaveServer = getString(
|
||||||
"leaveServer",
|
"leaveServer",
|
||||||
category,
|
category,
|
||||||
formattingJoinLeave.leaveServer,
|
joinLeave.leaveServer,
|
||||||
"user leave message sent to other gateways, available variables: {username}, {username:antiping}"
|
"user leave message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -214,6 +215,12 @@ abstract class BaseConfig {
|
||||||
category = CATEGORY_DEATH
|
category = CATEGORY_DEATH
|
||||||
addCustomCategoryComment(category, "Death message settings")
|
addCustomCategoryComment(category, "Death message settings")
|
||||||
death = DeathOptions(
|
death = DeathOptions(
|
||||||
|
showDeath = getBoolean(
|
||||||
|
"showDeath",
|
||||||
|
category,
|
||||||
|
death.showDeath,
|
||||||
|
"Relay player death messages"
|
||||||
|
),
|
||||||
showDamageType = getBoolean(
|
showDamageType = getBoolean(
|
||||||
"showDamageType",
|
"showDamageType",
|
||||||
category,
|
category,
|
||||||
|
@ -224,11 +231,12 @@ abstract class BaseConfig {
|
||||||
"damageTypeMapping",
|
"damageTypeMapping",
|
||||||
category,
|
category,
|
||||||
death.damageTypeMapping.map { entry ->
|
death.damageTypeMapping.map { entry ->
|
||||||
"${entry.key}=${entry.value}" }
|
"${entry.key}=${entry.value}"
|
||||||
|
}
|
||||||
.toTypedArray(),
|
.toTypedArray(),
|
||||||
"Damage type mapping for everything else, " +
|
"Damage type mapping for everything else, " +
|
||||||
"\nseperate value and key with '=', " +
|
"\nseperate value and key with '=', " +
|
||||||
"\nseperate multiple values with spaces"
|
"\nseperate multiple values with spaces\n"
|
||||||
).associate {
|
).associate {
|
||||||
val key = it.substringBefore('=')
|
val key = it.substringBefore('=')
|
||||||
val value = it.substringAfter('=')
|
val value = it.substringAfter('=')
|
||||||
|
|
|
@ -14,7 +14,7 @@ object DeathHandler {
|
||||||
deathMessage: String,
|
deathMessage: String,
|
||||||
damageType: String
|
damageType: String
|
||||||
) {
|
) {
|
||||||
if (cfg!!.relay.deathEvents) {
|
if (cfg!!.death.showDeath) {
|
||||||
var msg = deathMessage.replace(player, player.antiping())
|
var msg = deathMessage.replace(player, player.antiping())
|
||||||
if(cfg!!.death.showDamageType) {
|
if(cfg!!.death.showDamageType) {
|
||||||
val emojis = cfg!!.death.damageTypeMapping[damageType]?.split(' ') ?: listOf("\uD83D\uDC7B unknown type '$damageType'")
|
val emojis = cfg!!.death.damageTypeMapping[damageType]?.split(' ') ?: listOf("\uD83D\uDC7B unknown type '$damageType'")
|
||||||
|
|
|
@ -9,8 +9,8 @@ import matterlink.mapFormat
|
||||||
|
|
||||||
object JoinLeaveHandler {
|
object JoinLeaveHandler {
|
||||||
fun handleJoin(player: String) {
|
fun handleJoin(player: String) {
|
||||||
if (cfg!!.relay.joinLeave) {
|
if (cfg!!.joinLeave.showJoin) {
|
||||||
val msg = cfg!!.formattingJoinLeave.joinServer.mapFormat(
|
val msg = cfg!!.joinLeave.joinServer.mapFormat(
|
||||||
mapOf(
|
mapOf(
|
||||||
"{username}" to player,
|
"{username}" to player,
|
||||||
"{username:antiping}" to player.antiping()
|
"{username:antiping}" to player.antiping()
|
||||||
|
@ -25,8 +25,8 @@ object JoinLeaveHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleLeave(player: String) {
|
fun handleLeave(player: String) {
|
||||||
if (cfg!!.relay.joinLeave) {
|
if (cfg!!.joinLeave.showLeave) {
|
||||||
val msg = cfg!!.formattingJoinLeave.leaveServer.mapFormat(
|
val msg = cfg!!.joinLeave.leaveServer.mapFormat(
|
||||||
mapOf(
|
mapOf(
|
||||||
"{username}" to player,
|
"{username}" to player,
|
||||||
"{username:antiping}" to player.antiping()
|
"{username:antiping}" to player.antiping()
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
mod_version = 1.2.4a
|
mod_version = 1.3
|
Loading…
Reference in New Issue