formattable join/leave messages and version bump
also some more cleanup and refactoring for adding mc versions
This commit is contained in:
parent
969b64bb90
commit
c3abe0c8e5
|
@ -20,82 +20,78 @@ import net.minecraftforge.fml.common.gameevent.TickEvent
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
class EventWrapper {
|
object EventWrapper {
|
||||||
companion object JavaIsDumb {
|
|
||||||
|
|
||||||
//MC-VERSION & FORGE DEPENDENT
|
//MC-VERSION & FORGE DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun progressEvent(e: AdvancementEvent) {
|
fun progressEvent(e: AdvancementEvent) {
|
||||||
if (e.advancement.display == null) return
|
if (e.advancement.display == null) return
|
||||||
val name = e.entityPlayer.name
|
val name = e.entityPlayer.name
|
||||||
val text = "has made the advancement ${e.advancement.displayText.unformattedText}"
|
val text = "has made the advancement ${e.advancement.displayText.unformattedText}"
|
||||||
ProgressHandler.handleProgress(name, text)
|
ProgressHandler.handleProgress(name, text)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
@JvmStatic
|
||||||
|
fun chatEvent(e: ServerChatEvent) {
|
||||||
|
val user = e.username
|
||||||
|
val msg = e.message
|
||||||
|
ChatHandler.handleChat(user, msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
@JvmStatic
|
||||||
|
fun commandEvent(e: CommandEvent) {
|
||||||
|
val sender =
|
||||||
|
when {
|
||||||
|
e.sender is EntityPlayer -> e.sender.name
|
||||||
|
e.sender is DedicatedServer -> cfg!!.relay.systemUser
|
||||||
|
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
||||||
|
else -> return
|
||||||
|
}
|
||||||
|
val args = e.parameters.joinToString(" ")
|
||||||
|
val type = when {
|
||||||
|
e.command is CommandEmote -> USER_ACTION
|
||||||
|
e.command is CommandBroadcast -> ""
|
||||||
|
else -> return
|
||||||
}
|
}
|
||||||
|
CommandHandler.handleCommand(sender, args, type)
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
}
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
|
||||||
val user = e.username
|
|
||||||
val msg = e.message
|
|
||||||
ChatHandler.handleChat(user, msg)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun deathEvent(e: LivingDeathEvent) {
|
||||||
val sender =
|
if (e.entityLiving is EntityPlayer) {
|
||||||
when {
|
DeathHandler.handleDeath(
|
||||||
e.sender is EntityPlayer -> e.sender.name
|
e.entityLiving.name,
|
||||||
e.sender is DedicatedServer -> cfg!!.relay.systemUser
|
e.entityLiving.combatTracker.deathMessage.unformattedText
|
||||||
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
)
|
||||||
else -> return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e.command is CommandEmote || e.command is CommandBroadcast) {
|
|
||||||
val args = e.parameters.joinToString(" ")
|
|
||||||
val type =
|
|
||||||
when {
|
|
||||||
e.command is CommandEmote -> USER_ACTION
|
|
||||||
else -> ""
|
|
||||||
}
|
|
||||||
CommandHandler.handleCommand(sender, args, type)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun deathEvent(e: LivingDeathEvent) {
|
|
||||||
if (e.entityLiving is EntityPlayer) {
|
|
||||||
DeathHandler.handleDeath(
|
|
||||||
e.entityLiving.name,
|
|
||||||
e.entityLiving.combatTracker.deathMessage.unformattedText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
|
|
||||||
JoinLeaveHandler.handleJoin(e.player.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
|
|
||||||
JoinLeaveHandler.handleLeave(e.player.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
|
||||||
@SubscribeEvent
|
|
||||||
@JvmStatic
|
|
||||||
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
|
|
||||||
ServerChatHandler.writeIncomingToChat()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
@JvmStatic
|
||||||
|
fun joinEvent(e: PlayerEvent.PlayerLoggedInEvent) {
|
||||||
|
JoinLeaveHandler.handleJoin(e.player.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
@JvmStatic
|
||||||
|
fun leaveEvent(e: PlayerEvent.PlayerLoggedOutEvent) {
|
||||||
|
JoinLeaveHandler.handleLeave(e.player.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
//FORGE-DEPENDENT
|
||||||
|
@SubscribeEvent
|
||||||
|
@JvmStatic
|
||||||
|
fun serverTickEvent(e: TickEvent.ServerTickEvent) {
|
||||||
|
ServerChatHandler.writeIncomingToChat()
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -57,29 +57,48 @@ class MatterLinkConfig(file: File) : IMatterLinkConfig() {
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
config.addCustomCategoryComment(CATEGORY_FORMATTING, "Formatting options: " +
|
config.addCustomCategoryComment(CATEGORY_FORMATTING_INCOMING, "Gateway -> Server" +
|
||||||
|
"Formatting options: " +
|
||||||
"Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
|
"Available variables: {username}, {text}, {gateway}, {channel}, {protocol}, {username:antiping}")
|
||||||
formatting = FormattingOptions(
|
formatting = FormattingOptions(
|
||||||
chat = config.getString(
|
chat = config.getString(
|
||||||
"chat",
|
"chat",
|
||||||
CATEGORY_FORMATTING,
|
CATEGORY_FORMATTING_INCOMING,
|
||||||
formatting.chat,
|
formatting.chat,
|
||||||
"Generic chat event, just talking"
|
"Generic chat event, just talking"
|
||||||
),
|
),
|
||||||
joinLeave = config.getString(
|
joinLeave = config.getString(
|
||||||
"joinLeave",
|
"joinLeave",
|
||||||
CATEGORY_FORMATTING,
|
CATEGORY_FORMATTING_INCOMING,
|
||||||
formatting.joinLeave,
|
formatting.joinLeave,
|
||||||
"Join and leave events from other gateways"
|
"Join and leave events from other gateways"
|
||||||
),
|
),
|
||||||
action = config.getString(
|
action = config.getString(
|
||||||
"action",
|
"action",
|
||||||
CATEGORY_FORMATTING,
|
CATEGORY_FORMATTING_INCOMING,
|
||||||
formatting.action,
|
formatting.action,
|
||||||
"User actions (/me) sent by users from other gateways"
|
"User actions (/me) sent by users from other gateways"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
config.addCustomCategoryComment(CATEGORY_FORMATTING_JOIN_LEAVE, "Server -> Gateway" +
|
||||||
|
"Formatting options: " +
|
||||||
|
"Available variables: {username}, {username:antiping}")
|
||||||
|
formattingJoinLeave = FormattingJoinLeave(
|
||||||
|
joinServer = config.getString(
|
||||||
|
"joinServer",
|
||||||
|
CATEGORY_FORMATTING_JOIN_LEAVE,
|
||||||
|
formattingJoinLeave.joinServer,
|
||||||
|
"user join message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||||
|
),
|
||||||
|
leaveServer = config.getString(
|
||||||
|
"leaveServer",
|
||||||
|
CATEGORY_FORMATTING_JOIN_LEAVE,
|
||||||
|
formattingJoinLeave.leaveServer,
|
||||||
|
"user leave message sent to other gateways, available variables: {username}, {username:antiping}"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
config.addCustomCategoryComment(CATEGORY_CONNECTION, "Connection settings")
|
config.addCustomCategoryComment(CATEGORY_CONNECTION, "Connection settings")
|
||||||
connect = ConnectOptions(
|
connect = ConnectOptions(
|
||||||
url = config.getString(
|
url = config.getString(
|
||||||
|
|
|
@ -39,7 +39,7 @@ subprojects {
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
version = mc_version + "-" + forge_version
|
version = mc_version + "-" + forge_version
|
||||||
runDir = "run"
|
runDir = "../run"
|
||||||
|
|
||||||
mappings = mcp_mappings
|
mappings = mcp_mappings
|
||||||
|
|
||||||
|
|
|
@ -7,3 +7,13 @@ private const val ZWSP: Char = '\u200b'
|
||||||
fun String.antiping(): String {
|
fun String.antiping(): String {
|
||||||
return this[0].toString() + ZWSP + this.substring(1)
|
return this[0].toString() + ZWSP + this.substring(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun String.mapFormat(env: Map<String, String>): String {
|
||||||
|
var result = this
|
||||||
|
env.forEach { key, value ->
|
||||||
|
if (result.contains(key)) {
|
||||||
|
result = result.replace(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package matterlink.bridge
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
import matterlink.antiping
|
import matterlink.antiping
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import matterlink.mapFormat
|
||||||
|
|
||||||
const val USER_ACTION: String = "user_action"
|
const val USER_ACTION: String = "user_action"
|
||||||
const val JOIN_LEAVE: String = "join_leave"
|
const val JOIN_LEAVE: String = "join_leave"
|
||||||
|
@ -36,20 +37,16 @@ data class ApiMessage(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun format(fmt: String): String {
|
fun format(fmt: String): String {
|
||||||
var result = fmt
|
return fmt.mapFormat(
|
||||||
result = result.helpFormat("{username}", username)
|
mapOf(
|
||||||
result = result.helpFormat("{text}", text)
|
"{username}" to username,
|
||||||
result = result.helpFormat("{gateway}", gateway)
|
"{text}" to text,
|
||||||
result = result.helpFormat("{channel}", channel)
|
"{gateway}" to gateway,
|
||||||
result = result.helpFormat("{protocol}", protocol)
|
"{channel}" to channel,
|
||||||
result = result.helpFormat("{username:antiping}", username.antiping())
|
"{protocol}" to protocol,
|
||||||
return result
|
"{username:antiping}" to username.antiping()
|
||||||
}
|
)
|
||||||
|
)
|
||||||
|
|
||||||
private fun String.helpFormat(name: String, value: String): String {
|
|
||||||
if (this.contains(name)) {
|
|
||||||
return this.replace(name, value)
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,13 +4,15 @@ var cfg: IMatterLinkConfig? = null
|
||||||
|
|
||||||
abstract class IMatterLinkConfig {
|
abstract class IMatterLinkConfig {
|
||||||
protected val CATEGORY_RELAY_OPTIONS = "relay"
|
protected val CATEGORY_RELAY_OPTIONS = "relay"
|
||||||
protected val CATEGORY_FORMATTING = "formatting"
|
protected val CATEGORY_FORMATTING_INCOMING = "formatting"
|
||||||
|
protected val CATEGORY_FORMATTING_JOIN_LEAVE = "formatting_join_leave"
|
||||||
protected val CATEGORY_CONNECTION = "connection"
|
protected val CATEGORY_CONNECTION = "connection"
|
||||||
protected val CATEGORY_COMMAND = "command"
|
protected val CATEGORY_COMMAND = "command"
|
||||||
|
|
||||||
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 command: CommandOptions = CommandOptions()
|
var command: CommandOptions = CommandOptions()
|
||||||
|
|
||||||
data class RelayOptions(
|
data class RelayOptions(
|
||||||
|
@ -26,6 +28,11 @@ abstract class IMatterLinkConfig {
|
||||||
val action: String = "§5* {username} {text}"
|
val action: String = "§5* {username} {text}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
data class FormattingJoinLeave(
|
||||||
|
val joinServer: String = "{username:antiping} has connected to the server",
|
||||||
|
val leaveServer: String = "{username:antiping} has disconnected from the server"
|
||||||
|
)
|
||||||
|
|
||||||
data class ConnectOptions(
|
data class ConnectOptions(
|
||||||
val url: String = "http://localhost:4242",
|
val url: String = "http://localhost:4242",
|
||||||
val authToken: String = "",
|
val authToken: String = "",
|
||||||
|
|
|
@ -2,14 +2,17 @@ package matterlink.handlers
|
||||||
|
|
||||||
import matterlink.bridge.ApiMessage
|
import matterlink.bridge.ApiMessage
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.MessageHandler
|
||||||
|
import matterlink.logger
|
||||||
|
|
||||||
object ChatHandler {
|
object ChatHandler {
|
||||||
fun handleChat(user: String, msg: String) {
|
fun handleChat(user: String, msg: String) {
|
||||||
val message = msg.trim()
|
val message = msg.trim()
|
||||||
if (message.isNotBlank())
|
when {
|
||||||
MessageHandler.transmit(ApiMessage(
|
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
|
||||||
username = user,
|
username = user,
|
||||||
text = message
|
text = message
|
||||||
))
|
))
|
||||||
|
else -> logger.warn("dropped blank message by '$user'")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,14 +5,20 @@ import matterlink.bridge.ApiMessage
|
||||||
import matterlink.bridge.JOIN_LEAVE
|
import matterlink.bridge.JOIN_LEAVE
|
||||||
import matterlink.bridge.MessageHandler
|
import matterlink.bridge.MessageHandler
|
||||||
import matterlink.config.cfg
|
import matterlink.config.cfg
|
||||||
|
import matterlink.mapFormat
|
||||||
|
|
||||||
object JoinLeaveHandler {
|
object JoinLeaveHandler {
|
||||||
fun handleJoin(player: String) {
|
fun handleJoin(player: String) {
|
||||||
if (cfg!!.relay.joinLeave) {
|
if (cfg!!.relay.joinLeave) {
|
||||||
val user = player.antiping()
|
val msg = cfg!!.formattingJoinLeave.joinServer.mapFormat(
|
||||||
|
mapOf(
|
||||||
|
"{username}" to player,
|
||||||
|
"{username:antiping}" to player.antiping()
|
||||||
|
)
|
||||||
|
)
|
||||||
MessageHandler.transmit(ApiMessage(
|
MessageHandler.transmit(ApiMessage(
|
||||||
username = cfg!!.relay.systemUser,
|
username = cfg!!.relay.systemUser,
|
||||||
text = "$user has connected to the server.",
|
text = msg,
|
||||||
event = JOIN_LEAVE
|
event = JOIN_LEAVE
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
@ -20,10 +26,15 @@ object JoinLeaveHandler {
|
||||||
|
|
||||||
fun handleLeave(player: String) {
|
fun handleLeave(player: String) {
|
||||||
if (cfg!!.relay.joinLeave) {
|
if (cfg!!.relay.joinLeave) {
|
||||||
val user = player.antiping()
|
val msg = cfg!!.formattingJoinLeave.leaveServer.mapFormat(
|
||||||
|
mapOf(
|
||||||
|
"{username}" to player,
|
||||||
|
"{username:antiping}" to player.antiping()
|
||||||
|
)
|
||||||
|
)
|
||||||
MessageHandler.transmit(ApiMessage(
|
MessageHandler.transmit(ApiMessage(
|
||||||
username = cfg!!.relay.systemUser,
|
username = cfg!!.relay.systemUser,
|
||||||
text = "$user has disconnected from the server.",
|
text = msg,
|
||||||
event = JOIN_LEAVE
|
event = JOIN_LEAVE
|
||||||
))
|
))
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
mod_version = 1.1.1
|
mod_version = 1.1.2
|
||||||
|
|
Loading…
Reference in New Issue