fix actions not sending / receiving properly
This commit is contained in:
parent
fcd1a148a2
commit
9c52df1f98
|
@ -47,16 +47,19 @@ object EventHandler {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun commandEvent(e: CommandEvent) {
|
fun commandEvent(e: CommandEvent) {
|
||||||
logger.info("commandEvent ${e.sender.javaClass.simpleName}")
|
instance.log("DEBUG","commandEvent ${e.sender.javaClass.simpleName}")
|
||||||
logger.info("commandEvent ${e.sender.javaClass.typeName}")
|
instance.log("DEBUG","commandEvent ${e.sender.javaClass.typeName}")
|
||||||
|
instance.log("DEBUG","command ${e.command.aliases}")
|
||||||
|
instance.log("DEBUG","command ${e.command.name}")
|
||||||
val sender = when {
|
val sender = when {
|
||||||
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
e.sender is DedicatedServer -> cfg.outgoing.systemUser
|
||||||
else -> e.sender.displayName.unformattedText
|
else -> e.sender.displayName.unformattedText
|
||||||
}
|
}
|
||||||
|
instance.log("DEBUG","sender $sender")
|
||||||
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.name == "me" -> USER_ACTION
|
e.command.name.equals("me", true) -> USER_ACTION
|
||||||
e.command is CommandBroadcast -> ""
|
e.command is CommandBroadcast -> ""
|
||||||
else -> return
|
else -> return
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ object MatterLink : IMatterLink() {
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
fun serverStarting(event: FMLServerStartingEvent) {
|
fun serverStarting(event: FMLServerStartingEvent) {
|
||||||
logger.debug("Registering server commands")
|
log("DEBUG", "Registering server commands")
|
||||||
event.registerServerCommand(CommandMatterlink())
|
event.registerServerCommand(CommandMatterlink())
|
||||||
start()
|
start()
|
||||||
}
|
}
|
||||||
|
|
2
api
2
api
|
@ -1 +1 @@
|
||||||
Subproject commit 063ad04b24623b28a2850eb1543ae07a2608e87a
|
Subproject commit 8a034b55ebbb234fec29470271029b1f7bc950d3
|
|
@ -37,17 +37,16 @@ fun String.lazyFormat(env: Map<String, () -> String>): String {
|
||||||
val String.stripColorOut: String
|
val String.stripColorOut: String
|
||||||
get() =
|
get() =
|
||||||
if (cfg.outgoing.stripColors)
|
if (cfg.outgoing.stripColors)
|
||||||
this.replace("§.".toRegex(), "")
|
this.replace("§.?".toRegex(RegexOption.UNIX_LINES), "")
|
||||||
else
|
else
|
||||||
this
|
this
|
||||||
|
|
||||||
|
|
||||||
val String.stripColorIn: String
|
val String.stripColorIn: String
|
||||||
get() =
|
get() = if (cfg.incoming.stripColors)
|
||||||
if (cfg.incoming.stripColors)
|
this.replace("§.?".toRegex(), "")
|
||||||
this.replace("§.".toRegex(), "")
|
else
|
||||||
else
|
this
|
||||||
this
|
|
||||||
|
|
||||||
|
|
||||||
val Exception.stackTraceString: String
|
val Exception.stackTraceString: String
|
||||||
|
|
|
@ -12,7 +12,8 @@ object BridgeCommandRegistry {
|
||||||
private val commandMap: HashMap<String, IBridgeCommand> = hashMapOf()
|
private val commandMap: HashMap<String, IBridgeCommand> = hashMapOf()
|
||||||
|
|
||||||
fun handleCommand(input: ApiMessage): Boolean {
|
fun handleCommand(input: ApiMessage): Boolean {
|
||||||
if (!cfg.command.enable) return false
|
if (!cfg.command.enable || input.text.isBlank()) return false
|
||||||
|
|
||||||
if (input.text[0] != cfg.command.prefix[0] || input.text.length < 2) return false
|
if (input.text[0] != cfg.command.prefix[0] || input.text.length < 2) return false
|
||||||
|
|
||||||
val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
|
val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
|
||||||
|
@ -23,11 +24,11 @@ object BridgeCommandRegistry {
|
||||||
|
|
||||||
fun register(alias: String, cmd: IBridgeCommand): Boolean {
|
fun register(alias: String, cmd: IBridgeCommand): Boolean {
|
||||||
if (alias.isBlank() || commandMap.containsKey(alias)) {
|
if (alias.isBlank() || commandMap.containsKey(alias)) {
|
||||||
instance.error("Failed to register command: '${alias}'")
|
instance.error("Failed to register command: '$alias'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (!cmd.validate()) {
|
if (!cmd.validate()) {
|
||||||
instance.error("Failed to validate command: '${alias}'")
|
instance.error("Failed to validate command: '$alias'")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
//TODO: maybe write alias to command here ?
|
//TODO: maybe write alias to command here ?
|
||||||
|
|
|
@ -35,7 +35,7 @@ data class CustomCommand(
|
||||||
if (!canExecute(userId, server)) {
|
if (!canExecute(userId, server)) {
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = "$user is not permitted to perform command: $alias".stripColorOut
|
_text = "$user is not permitted to perform command: $alias".stripColorOut
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return false
|
return false
|
||||||
|
@ -45,8 +45,7 @@ data class CustomCommand(
|
||||||
|
|
||||||
return when (type) {
|
return when (type) {
|
||||||
CommandType.EXECUTE -> {
|
CommandType.EXECUTE -> {
|
||||||
//uses a new commandsender for each user
|
// uses a new commandsender for each use
|
||||||
// TODO: cache CommandSenders
|
|
||||||
val commandSender = instance.commandSenderFor(user, userId, server, execOp ?: false)
|
val commandSender = instance.commandSenderFor(user, userId, server, execOp ?: false)
|
||||||
val cmd = "$execute $args"
|
val cmd = "$execute $args"
|
||||||
commandSender.execute(cmd) || commandSender.reply.isNotBlank()
|
commandSender.execute(cmd) || commandSender.reply.isNotBlank()
|
||||||
|
@ -54,7 +53,7 @@ data class CustomCommand(
|
||||||
CommandType.RESPONSE -> {
|
CommandType.RESPONSE -> {
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
|
_text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
true
|
true
|
||||||
|
|
|
@ -2,6 +2,7 @@ package matterlink.bridge.command
|
||||||
|
|
||||||
import matterlink.api.ApiMessage
|
import matterlink.api.ApiMessage
|
||||||
import matterlink.bridge.MessageHandlerInst
|
import matterlink.bridge.MessageHandlerInst
|
||||||
|
import matterlink.stripColorOut
|
||||||
|
|
||||||
object HelpCommand : IBridgeCommand {
|
object HelpCommand : IBridgeCommand {
|
||||||
override val help: String = "Returns the help string for the given command. Syntax: help <command>"
|
override val help: String = "Returns the help string for the given command. Syntax: help <command>"
|
||||||
|
@ -17,7 +18,7 @@ object HelpCommand : IBridgeCommand {
|
||||||
}
|
}
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = msg
|
_text = msg.stripColorOut
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -10,9 +10,9 @@ interface IBridgeCommand {
|
||||||
fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean
|
fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean
|
||||||
|
|
||||||
fun canExecute(userId: String, server: String): Boolean {
|
fun canExecute(userId: String, server: String): Boolean {
|
||||||
instance.info("this: $this canExecute: $userId server: $server permLevel: $permLevel")
|
instance.trace("canExecute this: $this canExecute: $userId server: $server permLevel: $permLevel")
|
||||||
val canExec = getPermLevel(userId, server) >= permLevel
|
val canExec = getPermLevel(userId, server) >= permLevel
|
||||||
instance.info("return $canExec")
|
instance.trace("canExecute return $canExec")
|
||||||
return canExec
|
return canExec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
|
||||||
reply = text
|
reply = text
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = text.stripColorOut
|
_text = text.stripColorOut
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,9 @@ object ChatProcessor {
|
||||||
val message = msg.trim()
|
val message = msg.trim()
|
||||||
when {
|
when {
|
||||||
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage(
|
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage(
|
||||||
username = user.stripColorOut,
|
_username = user.stripColorOut,
|
||||||
text = message.stripColorOut,
|
_text = message.stripColorOut,
|
||||||
event = event)
|
_event = event)
|
||||||
)
|
)
|
||||||
else -> instance.warn("WARN: dropped blank message by '$user'")
|
else -> instance.warn("WARN: dropped blank message by '$user'")
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ object DeathHandler {
|
||||||
val damageEmoji = emojis[random.nextInt(emojis.size)]
|
val damageEmoji = emojis[random.nextInt(emojis.size)]
|
||||||
msg += " $damageEmoji"
|
msg += " $damageEmoji"
|
||||||
}
|
}
|
||||||
MessageHandlerInst.transmit(ApiMessage(text = msg))
|
MessageHandlerInst.transmit(ApiMessage(_text = msg))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,8 @@ object JoinLeaveHandler {
|
||||||
)
|
)
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = msg,
|
_text = msg,
|
||||||
event = JOIN_LEAVE
|
_event = JOIN_LEAVE
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,8 @@ object JoinLeaveHandler {
|
||||||
)
|
)
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = msg,
|
_text = msg,
|
||||||
event = JOIN_LEAVE
|
_event = JOIN_LEAVE
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ object ProgressHandler {
|
||||||
val usr = name.stripColorOut.antiping
|
val usr = name.stripColorOut.antiping
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = "$usr $message $display".stripColorOut
|
_text = "$usr $message $display".stripColorOut
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ class UpdateChecker : Thread() {
|
||||||
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
|
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
|
||||||
MessageHandlerInst.transmit(
|
MessageHandlerInst.transmit(
|
||||||
ApiMessage(
|
ApiMessage(
|
||||||
text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"
|
_text = "MatterLink out of date! You are $count $version behind! Please download new version from ${latest.downloadURL}"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue