release 1.1.2

This commit is contained in:
Nikky 2018-02-10 15:38:58 +01:00 committed by Unknown
commit dd1c923e6b
12 changed files with 142 additions and 99 deletions

View File

@ -20,82 +20,78 @@ import net.minecraftforge.fml.common.gameevent.TickEvent
//FORGE-DEPENDENT
@Mod.EventBusSubscriber
class EventWrapper {
companion object JavaIsDumb {
object EventWrapper {
//MC-VERSION & FORGE DEPENDENT
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AdvancementEvent) {
if (e.advancement.display == null) return
val name = e.entityPlayer.name
val text = "has made the advancement ${e.advancement.displayText.unformattedText}"
ProgressHandler.handleProgress(name, text)
//MC-VERSION & FORGE DEPENDENT
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AdvancementEvent) {
if (e.advancement.display == null) return
val name = e.entityPlayer.name
val text = "has made the advancement ${e.advancement.displayText.unformattedText}"
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
@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
}
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 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()
}
}

View File

@ -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}")
formatting = FormattingOptions(
chat = config.getString(
"chat",
CATEGORY_FORMATTING,
CATEGORY_FORMATTING_INCOMING,
formatting.chat,
"Generic chat event, just talking"
),
joinLeave = config.getString(
"joinLeave",
CATEGORY_FORMATTING,
CATEGORY_FORMATTING_INCOMING,
formatting.joinLeave,
"Join and leave events from other gateways"
),
action = config.getString(
"action",
CATEGORY_FORMATTING,
CATEGORY_FORMATTING_INCOMING,
formatting.action,
"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")
connect = ConnectOptions(
url = config.getString(

View File

@ -39,7 +39,7 @@ subprojects {
minecraft {
version = mc_version + "-" + forge_version
runDir = "run"
runDir = "../run"
mappings = mcp_mappings

View File

@ -7,3 +7,13 @@ private const val ZWSP: Char = '\u200b'
fun String.antiping(): String {
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
}

View File

@ -3,6 +3,7 @@ package matterlink.bridge
import matterlink.config.cfg
import matterlink.antiping
import com.google.gson.Gson
import matterlink.mapFormat
const val USER_ACTION: String = "user_action"
const val JOIN_LEAVE: String = "join_leave"
@ -36,20 +37,16 @@ data class ApiMessage(
}
fun format(fmt: String): String {
var result = fmt
result = result.helpFormat("{username}", username)
result = result.helpFormat("{text}", text)
result = result.helpFormat("{gateway}", gateway)
result = result.helpFormat("{channel}", channel)
result = result.helpFormat("{protocol}", protocol)
result = result.helpFormat("{username:antiping}", username.antiping())
return result
}
return fmt.mapFormat(
mapOf(
"{username}" to username,
"{text}" to text,
"{gateway}" to gateway,
"{channel}" to channel,
"{protocol}" to protocol,
"{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
}
}

View File

@ -4,13 +4,15 @@ var cfg: IMatterLinkConfig? = null
abstract class IMatterLinkConfig {
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_COMMAND = "command"
var relay: RelayOptions = RelayOptions()
var connect: ConnectOptions = ConnectOptions()
var formatting: FormattingOptions = FormattingOptions()
var formattingJoinLeave: FormattingJoinLeave = FormattingJoinLeave()
var command: CommandOptions = CommandOptions()
data class RelayOptions(
@ -26,6 +28,11 @@ abstract class IMatterLinkConfig {
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(
val url: String = "http://localhost:4242",
val authToken: String = "",

View File

@ -2,14 +2,17 @@ package matterlink.handlers
import matterlink.bridge.ApiMessage
import matterlink.bridge.MessageHandler
import matterlink.logger
object ChatHandler {
fun handleChat(user: String, msg: String) {
val message = msg.trim()
if (message.isNotBlank())
MessageHandler.transmit(ApiMessage(
when {
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
username = user,
text = message
))
else -> logger.warn("dropped blank message by '$user'")
}
}
}

View File

@ -5,14 +5,20 @@ import matterlink.bridge.ApiMessage
import matterlink.bridge.JOIN_LEAVE
import matterlink.bridge.MessageHandler
import matterlink.config.cfg
import matterlink.mapFormat
object JoinLeaveHandler {
fun handleJoin(player: String) {
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(
username = cfg!!.relay.systemUser,
text = "$user has connected to the server.",
text = msg,
event = JOIN_LEAVE
))
}
@ -20,10 +26,15 @@ object JoinLeaveHandler {
fun handleLeave(player: String) {
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(
username = cfg!!.relay.systemUser,
text = "$user has disconnected from the server.",
text = msg,
event = JOIN_LEAVE
))
}

View File

@ -1 +1 @@
mod_version = 1.1.1
mod_version = 1.1.2