refactorio

This commit is contained in:
NikkyAI 2018-02-17 18:16:06 +01:00
parent cdcc79fcaf
commit 00b1969754
6 changed files with 64 additions and 53 deletions

View File

@ -27,38 +27,41 @@ object EventHandler {
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AchievementEvent) {
val name = e.entityPlayer.name
val text = "has earned the achievement ${e.achievement.statName.unformattedText}"
ProgressHandler.handleProgress(name, text)
ProgressHandler.handleProgress(
name = e.entityPlayer.name,
display = e.achievement.statName.unformattedText,
type = "achievement"
)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun chatEvent(e: ServerChatEvent) {
val user = e.username
val msg = e.message
ChatProcessor.sendToBridge(user, msg,"")
ChatProcessor.sendToBridge(
user = e.username,
msg = e.message,
event = ""
)
}
//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 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
}
ChatProcessor.sendToBridge(sender, args, type)
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
}
@ -68,8 +71,8 @@ object EventHandler {
fun deathEvent(e: LivingDeathEvent) {
if (e.entityLiving is EntityPlayer) {
DeathHandler.handleDeath(
e.entityLiving.name,
e.entityLiving.combatTracker.deathMessage.unformattedText,
player = e.entityLiving.name,
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
damageType = e.source.damageType
)
}

View File

@ -27,38 +27,41 @@ object EventHandler {
@SubscribeEvent
@JvmStatic
fun progressEvent(e: AchievementEvent) {
val name = e.entityPlayer.name
val text = "has earned the achievement ${e.achievement.statName.unformattedText}"
ProgressHandler.handleProgress(name, text)
ProgressHandler.handleProgress(
name = e.entityPlayer.name,
display = e.achievement.statName.unformattedText,
type = "achievement"
)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun chatEvent(e: ServerChatEvent) {
val user = e.username
val msg = e.message
ChatProcessor.sendToBridge(user, msg,"")
ChatProcessor.sendToBridge(
user = e.username,
msg = e.message,
event = ""
)
}
//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 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
}
ChatProcessor.sendToBridge(sender, args, type)
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
}
@ -68,8 +71,8 @@ object EventHandler {
fun deathEvent(e: LivingDeathEvent) {
if (e.entityLiving is EntityPlayer) {
DeathHandler.handleDeath(
e.entityLiving.name,
e.entityLiving.combatTracker.deathMessage.unformattedText,
player = e.entityLiving.name,
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
damageType = e.source.damageType
)
}

View File

@ -28,38 +28,41 @@ object EventHandler {
@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)
ProgressHandler.handleProgress(
name = e.entityPlayer.name,
display = e.advancement.displayText.unformattedText,
type = "advancement"
)
}
//FORGE-DEPENDENT
@SubscribeEvent
@JvmStatic
fun chatEvent(e: ServerChatEvent) {
val user = e.username
val msg = e.message
ChatProcessor.sendToBridge(user, msg,"")
ChatProcessor.sendToBridge(
user = e.username,
msg = e.message,
event = ""
)
}
//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 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
}
ChatProcessor.sendToBridge(sender, args, type)
ChatProcessor.sendToBridge(user = sender, msg = args, event = type)
}
@ -69,8 +72,8 @@ object EventHandler {
fun deathEvent(e: LivingDeathEvent) {
if (e.entityLiving is EntityPlayer) {
DeathHandler.handleDeath(
e.entityLiving.name,
e.entityLiving.combatTracker.deathMessage.unformattedText,
player = e.entityLiving.name,
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
damageType = e.source.damageType
)
}

View File

@ -111,8 +111,9 @@ object MessageHandler {
//open a connection
val client = HttpClients.createDefault()
val post = HttpPost(cfg.connect.url + "/api/message")
post.entity = StringEntity(message.encode(), ContentType.APPLICATION_JSON)
val json = message.encode()
instance.trace("Transmitting $json")
post.entity = StringEntity(json, ContentType.APPLICATION_JSON)
post.authorize()
val response = client.execute(post)

View File

@ -10,7 +10,8 @@ object ChatProcessor {
when {
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
username = user,
text = message
text = message,
event = event
))
else -> instance.warn("WARN: dropped blank message by '$user'")
}

View File

@ -7,12 +7,12 @@ import matterlink.config.cfg
object ProgressHandler {
fun handleProgress(name: String, text: String) {
fun handleProgress(name: String, display: String, type: String) {
if (!cfg.relay.advancements) return
val usr = name.antiping()
MessageHandler.transmit(ApiMessage(
username = cfg.relay.systemUser,
text = "$usr $text"
text = "$usr has earned the $type $display"
))
}
}