refactorio
This commit is contained in:
parent
cdcc79fcaf
commit
00b1969754
|
@ -27,38 +27,41 @@ object EventHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun progressEvent(e: AchievementEvent) {
|
fun progressEvent(e: AchievementEvent) {
|
||||||
val name = e.entityPlayer.name
|
ProgressHandler.handleProgress(
|
||||||
val text = "has earned the achievement ${e.achievement.statName.unformattedText}"
|
name = e.entityPlayer.name,
|
||||||
ProgressHandler.handleProgress(name, text)
|
display = e.achievement.statName.unformattedText,
|
||||||
|
type = "achievement"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
fun chatEvent(e: ServerChatEvent) {
|
||||||
val user = e.username
|
ChatProcessor.sendToBridge(
|
||||||
val msg = e.message
|
user = e.username,
|
||||||
ChatProcessor.sendToBridge(user, msg,"")
|
msg = e.message,
|
||||||
|
event = ""
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun commandEvent(e: CommandEvent) {
|
||||||
val sender =
|
val sender = when {
|
||||||
when {
|
e.sender is EntityPlayer -> e.sender.name
|
||||||
e.sender is EntityPlayer -> e.sender.name
|
e.sender is DedicatedServer -> cfg.relay.systemUser
|
||||||
e.sender is DedicatedServer -> cfg.relay.systemUser
|
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
||||||
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
else -> return
|
||||||
else -> return
|
}
|
||||||
}
|
|
||||||
val args = e.parameters.joinToString(" ")
|
val args = e.parameters.joinToString(" ")
|
||||||
val type = when {
|
val type = when {
|
||||||
e.command is CommandEmote -> USER_ACTION
|
e.command is CommandEmote -> USER_ACTION
|
||||||
e.command is CommandBroadcast -> ""
|
e.command is CommandBroadcast -> ""
|
||||||
else -> return
|
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) {
|
fun deathEvent(e: LivingDeathEvent) {
|
||||||
if (e.entityLiving is EntityPlayer) {
|
if (e.entityLiving is EntityPlayer) {
|
||||||
DeathHandler.handleDeath(
|
DeathHandler.handleDeath(
|
||||||
e.entityLiving.name,
|
player = e.entityLiving.name,
|
||||||
e.entityLiving.combatTracker.deathMessage.unformattedText,
|
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
||||||
damageType = e.source.damageType
|
damageType = e.source.damageType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,38 +27,41 @@ object EventHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun progressEvent(e: AchievementEvent) {
|
fun progressEvent(e: AchievementEvent) {
|
||||||
val name = e.entityPlayer.name
|
ProgressHandler.handleProgress(
|
||||||
val text = "has earned the achievement ${e.achievement.statName.unformattedText}"
|
name = e.entityPlayer.name,
|
||||||
ProgressHandler.handleProgress(name, text)
|
display = e.achievement.statName.unformattedText,
|
||||||
|
type = "achievement"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
fun chatEvent(e: ServerChatEvent) {
|
||||||
val user = e.username
|
ChatProcessor.sendToBridge(
|
||||||
val msg = e.message
|
user = e.username,
|
||||||
ChatProcessor.sendToBridge(user, msg,"")
|
msg = e.message,
|
||||||
|
event = ""
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun commandEvent(e: CommandEvent) {
|
||||||
val sender =
|
val sender = when {
|
||||||
when {
|
e.sender is EntityPlayer -> e.sender.name
|
||||||
e.sender is EntityPlayer -> e.sender.name
|
e.sender is DedicatedServer -> cfg.relay.systemUser
|
||||||
e.sender is DedicatedServer -> cfg.relay.systemUser
|
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
||||||
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
else -> return
|
||||||
else -> return
|
}
|
||||||
}
|
|
||||||
val args = e.parameters.joinToString(" ")
|
val args = e.parameters.joinToString(" ")
|
||||||
val type = when {
|
val type = when {
|
||||||
e.command is CommandEmote -> USER_ACTION
|
e.command is CommandEmote -> USER_ACTION
|
||||||
e.command is CommandBroadcast -> ""
|
e.command is CommandBroadcast -> ""
|
||||||
else -> return
|
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) {
|
fun deathEvent(e: LivingDeathEvent) {
|
||||||
if (e.entityLiving is EntityPlayer) {
|
if (e.entityLiving is EntityPlayer) {
|
||||||
DeathHandler.handleDeath(
|
DeathHandler.handleDeath(
|
||||||
e.entityLiving.name,
|
player = e.entityLiving.name,
|
||||||
e.entityLiving.combatTracker.deathMessage.unformattedText,
|
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
||||||
damageType = e.source.damageType
|
damageType = e.source.damageType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,38 +28,41 @@ object EventHandler {
|
||||||
@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
|
ProgressHandler.handleProgress(
|
||||||
val text = "has made the advancement ${e.advancement.displayText.unformattedText}"
|
name = e.entityPlayer.name,
|
||||||
ProgressHandler.handleProgress(name, text)
|
display = e.advancement.displayText.unformattedText,
|
||||||
|
type = "advancement"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun chatEvent(e: ServerChatEvent) {
|
fun chatEvent(e: ServerChatEvent) {
|
||||||
val user = e.username
|
ChatProcessor.sendToBridge(
|
||||||
val msg = e.message
|
user = e.username,
|
||||||
ChatProcessor.sendToBridge(user, msg,"")
|
msg = e.message,
|
||||||
|
event = ""
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
//FORGE-DEPENDENT
|
//FORGE-DEPENDENT
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun commandEvent(e: CommandEvent) {
|
||||||
val sender =
|
val sender = when {
|
||||||
when {
|
e.sender is EntityPlayer -> e.sender.name
|
||||||
e.sender is EntityPlayer -> e.sender.name
|
e.sender is DedicatedServer -> cfg!!.relay.systemUser
|
||||||
e.sender is DedicatedServer -> cfg!!.relay.systemUser
|
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
||||||
e.sender is TileEntityCommandBlock -> "CommandBlock"
|
else -> return
|
||||||
else -> return
|
}
|
||||||
}
|
|
||||||
val args = e.parameters.joinToString(" ")
|
val args = e.parameters.joinToString(" ")
|
||||||
val type = when {
|
val type = when {
|
||||||
e.command is CommandEmote -> USER_ACTION
|
e.command is CommandEmote -> USER_ACTION
|
||||||
e.command is CommandBroadcast -> ""
|
e.command is CommandBroadcast -> ""
|
||||||
else -> return
|
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) {
|
fun deathEvent(e: LivingDeathEvent) {
|
||||||
if (e.entityLiving is EntityPlayer) {
|
if (e.entityLiving is EntityPlayer) {
|
||||||
DeathHandler.handleDeath(
|
DeathHandler.handleDeath(
|
||||||
e.entityLiving.name,
|
player = e.entityLiving.name,
|
||||||
e.entityLiving.combatTracker.deathMessage.unformattedText,
|
deathMessage = e.entityLiving.combatTracker.deathMessage.unformattedText,
|
||||||
damageType = e.source.damageType
|
damageType = e.source.damageType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,8 +111,9 @@ object MessageHandler {
|
||||||
//open a connection
|
//open a connection
|
||||||
val client = HttpClients.createDefault()
|
val client = HttpClients.createDefault()
|
||||||
val post = HttpPost(cfg.connect.url + "/api/message")
|
val post = HttpPost(cfg.connect.url + "/api/message")
|
||||||
|
val json = message.encode()
|
||||||
post.entity = StringEntity(message.encode(), ContentType.APPLICATION_JSON)
|
instance.trace("Transmitting $json")
|
||||||
|
post.entity = StringEntity(json, ContentType.APPLICATION_JSON)
|
||||||
post.authorize()
|
post.authorize()
|
||||||
|
|
||||||
val response = client.execute(post)
|
val response = client.execute(post)
|
||||||
|
|
|
@ -10,7 +10,8 @@ object ChatProcessor {
|
||||||
when {
|
when {
|
||||||
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
|
message.isNotBlank() -> MessageHandler.transmit(ApiMessage(
|
||||||
username = user,
|
username = user,
|
||||||
text = message
|
text = message,
|
||||||
|
event = event
|
||||||
))
|
))
|
||||||
else -> instance.warn("WARN: dropped blank message by '$user'")
|
else -> instance.warn("WARN: dropped blank message by '$user'")
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@ import matterlink.config.cfg
|
||||||
|
|
||||||
object ProgressHandler {
|
object ProgressHandler {
|
||||||
|
|
||||||
fun handleProgress(name: String, text: String) {
|
fun handleProgress(name: String, display: String, type: String) {
|
||||||
if (!cfg.relay.advancements) return
|
if (!cfg.relay.advancements) return
|
||||||
val usr = name.antiping()
|
val usr = name.antiping()
|
||||||
MessageHandler.transmit(ApiMessage(
|
MessageHandler.transmit(ApiMessage(
|
||||||
username = cfg.relay.systemUser,
|
username = cfg.relay.systemUser,
|
||||||
text = "$usr $text"
|
text = "$usr has earned the $type $display"
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue