fix actions not sending / receiving properly

This commit is contained in:
nikky 2018-05-24 23:10:06 +02:00
parent fcd1a148a2
commit 9c52df1f98
14 changed files with 35 additions and 32 deletions

View File

@ -47,16 +47,19 @@ object EventHandler {
@SubscribeEvent
@JvmStatic
fun commandEvent(e: CommandEvent) {
logger.info("commandEvent ${e.sender.javaClass.simpleName}")
logger.info("commandEvent ${e.sender.javaClass.typeName}")
instance.log("DEBUG","commandEvent ${e.sender.javaClass.simpleName}")
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 {
e.sender is DedicatedServer -> cfg.outgoing.systemUser
else -> e.sender.displayName.unformattedText
}
instance.log("DEBUG","sender $sender")
val args = e.parameters.joinToString(" ")
val type = when {
e.command is CommandEmote -> USER_ACTION
e.command.name == "me" -> USER_ACTION
e.command.name.equals("me", true) -> USER_ACTION
e.command is CommandBroadcast -> ""
else -> return
}

View File

@ -47,7 +47,7 @@ object MatterLink : IMatterLink() {
@Mod.EventHandler
fun serverStarting(event: FMLServerStartingEvent) {
logger.debug("Registering server commands")
log("DEBUG", "Registering server commands")
event.registerServerCommand(CommandMatterlink())
start()
}

2
api

@ -1 +1 @@
Subproject commit 063ad04b24623b28a2850eb1543ae07a2608e87a
Subproject commit 8a034b55ebbb234fec29470271029b1f7bc950d3

View File

@ -37,15 +37,14 @@ fun String.lazyFormat(env: Map<String, () -> String>): String {
val String.stripColorOut: String
get() =
if (cfg.outgoing.stripColors)
this.replace("§.".toRegex(), "")
this.replace("§.?".toRegex(RegexOption.UNIX_LINES), "")
else
this
val String.stripColorIn: String
get() =
if (cfg.incoming.stripColors)
this.replace("§.".toRegex(), "")
get() = if (cfg.incoming.stripColors)
this.replace("§.?".toRegex(), "")
else
this

View File

@ -12,7 +12,8 @@ object BridgeCommandRegistry {
private val commandMap: HashMap<String, IBridgeCommand> = hashMapOf()
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
val cmd = input.text.substring(1).split(' ', ignoreCase = false, limit = 2)
@ -23,11 +24,11 @@ object BridgeCommandRegistry {
fun register(alias: String, cmd: IBridgeCommand): Boolean {
if (alias.isBlank() || commandMap.containsKey(alias)) {
instance.error("Failed to register command: '${alias}'")
instance.error("Failed to register command: '$alias'")
return false
}
if (!cmd.validate()) {
instance.error("Failed to validate command: '${alias}'")
instance.error("Failed to validate command: '$alias'")
return false
}
//TODO: maybe write alias to command here ?

View File

@ -35,7 +35,7 @@ data class CustomCommand(
if (!canExecute(userId, server)) {
MessageHandlerInst.transmit(
ApiMessage(
text = "$user is not permitted to perform command: $alias".stripColorOut
_text = "$user is not permitted to perform command: $alias".stripColorOut
)
)
return false
@ -45,8 +45,7 @@ data class CustomCommand(
return when (type) {
CommandType.EXECUTE -> {
//uses a new commandsender for each user
// TODO: cache CommandSenders
// uses a new commandsender for each use
val commandSender = instance.commandSenderFor(user, userId, server, execOp ?: false)
val cmd = "$execute $args"
commandSender.execute(cmd) || commandSender.reply.isNotBlank()
@ -54,7 +53,7 @@ data class CustomCommand(
CommandType.RESPONSE -> {
MessageHandlerInst.transmit(
ApiMessage(
text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
_text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
)
)
true

View File

@ -2,6 +2,7 @@ package matterlink.bridge.command
import matterlink.api.ApiMessage
import matterlink.bridge.MessageHandlerInst
import matterlink.stripColorOut
object HelpCommand : IBridgeCommand {
override val help: String = "Returns the help string for the given command. Syntax: help <command>"
@ -17,7 +18,7 @@ object HelpCommand : IBridgeCommand {
}
MessageHandlerInst.transmit(
ApiMessage(
text = msg
_text = msg.stripColorOut
)
)
return true

View File

@ -10,9 +10,9 @@ interface IBridgeCommand {
fun execute(alias: String, user: String, userId: String, server: String, args: 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
instance.info("return $canExec")
instance.trace("canExecute return $canExec")
return canExec
}

View File

@ -26,7 +26,7 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
reply = text
MessageHandlerInst.transmit(
ApiMessage(
text = text.stripColorOut
_text = text.stripColorOut
)
)
}

View File

@ -10,9 +10,9 @@ object ChatProcessor {
val message = msg.trim()
when {
message.isNotBlank() -> MessageHandlerInst.transmit(ApiMessage(
username = user.stripColorOut,
text = message.stripColorOut,
event = event)
_username = user.stripColorOut,
_text = message.stripColorOut,
_event = event)
)
else -> instance.warn("WARN: dropped blank message by '$user'")
}

View File

@ -23,7 +23,7 @@ object DeathHandler {
val damageEmoji = emojis[random.nextInt(emojis.size)]
msg += " $damageEmoji"
}
MessageHandlerInst.transmit(ApiMessage(text = msg))
MessageHandlerInst.transmit(ApiMessage(_text = msg))
}
}
}

View File

@ -19,8 +19,8 @@ object JoinLeaveHandler {
)
MessageHandlerInst.transmit(
ApiMessage(
text = msg,
event = JOIN_LEAVE
_text = msg,
_event = JOIN_LEAVE
)
)
}
@ -36,8 +36,8 @@ object JoinLeaveHandler {
)
MessageHandlerInst.transmit(
ApiMessage(
text = msg,
event = JOIN_LEAVE
_text = msg,
_event = JOIN_LEAVE
)
)
}

View File

@ -13,7 +13,7 @@ object ProgressHandler {
val usr = name.stripColorOut.antiping
MessageHandlerInst.transmit(
ApiMessage(
text = "$usr $message $display".stripColorOut
_text = "$usr $message $display".stripColorOut
)
)
}

View File

@ -110,7 +110,7 @@ class UpdateChecker : Thread() {
instance.warn("Mod out of date! New $version available at ${latest.downloadURL}")
MessageHandlerInst.transmit(
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}"
)
)
}