Skip to content
This repository has been archived by the owner on Jan 5, 2020. It is now read-only.

Commit

Permalink
fix actions not sending / receiving properly
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed May 24, 2018
1 parent fcd1a14 commit 9c52df1
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 32 deletions.
9 changes: 6 additions & 3 deletions 1.12.2/src/main/kotlin/matterlink/EventHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion 1.12.2/src/main/kotlin/matterlink/MatterLink.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion api
11 changes: 5 additions & 6 deletions core/src/main/kotlin/matterlink/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ 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(), "")
else
this
get() = if (cfg.incoming.stripColors)
this.replace("§.?".toRegex(), "")
else
this


val Exception.stackTraceString: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,16 +45,15 @@ 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()
}
CommandType.RESPONSE -> {
MessageHandlerInst.transmit(
ApiMessage(
text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
_text = (response?.lazyFormat(getReplacements(user, userId, server, args))?.stripColorOut ?: "")
)
)
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>"
Expand All @@ -17,7 +18,7 @@ object HelpCommand : IBridgeCommand {
}
MessageHandlerInst.transmit(
ApiMessage(
text = msg
_text = msg.stripColorOut
)
)
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/kotlin/matterlink/handlers/ChatProcessor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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'")
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/matterlink/handlers/DeathHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
8 changes: 4 additions & 4 deletions core/src/main/kotlin/matterlink/handlers/JoinLeaveHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ object JoinLeaveHandler {
)
MessageHandlerInst.transmit(
ApiMessage(
text = msg,
event = JOIN_LEAVE
_text = msg,
_event = JOIN_LEAVE
)
)
}
Expand All @@ -36,8 +36,8 @@ object JoinLeaveHandler {
)
MessageHandlerInst.transmit(
ApiMessage(
text = msg,
event = JOIN_LEAVE
_text = msg,
_event = JOIN_LEAVE
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object ProgressHandler {
val usr = name.stripColorOut.antiping
MessageHandlerInst.transmit(
ApiMessage(
text = "$usr $message $display".stripColorOut
_text = "$usr $message $display".stripColorOut
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/kotlin/matterlink/update/UpdateChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
)
}
Expand Down

0 comments on commit 9c52df1

Please sign in to comment.