allow `execute` commands to run as op
This commit is contained in:
parent
1400627187
commit
07bc1736e6
|
@ -63,7 +63,7 @@ object MatterLink : IMatterLink() {
|
|||
override fun log(level: String, formatString: String, vararg data: Any) =
|
||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
||||
|
||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
||||
override fun commandSenderFor(user: String, userId: String, server: String, op: Boolean) = MatterLinkCommandSender(user, userId, server, op)
|
||||
|
||||
override val mcVersion: String = MCVERSION
|
||||
override val modVersion: String = MODVERSION
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.world.World
|
|||
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String, op: Boolean) : IMinecraftCommandSender(user, userId, server, op), ICommandSender {
|
||||
private var level: Int = 0
|
||||
|
||||
override fun execute(cmdString: String): Boolean {
|
||||
|
|
|
@ -63,7 +63,7 @@ object MatterLink : IMatterLink() {
|
|||
override fun log(level: String, formatString: String, vararg data: Any) =
|
||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
||||
|
||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
||||
override fun commandSenderFor(user: String, userId: String, server: String, op: Boolean) = MatterLinkCommandSender(user, userId, server, op)
|
||||
|
||||
override val mcVersion: String = MCVERSION
|
||||
override val modVersion: String = MODVERSION
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraft.world.World
|
|||
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String, op: Boolean) : IMinecraftCommandSender(user, userId, server, op), ICommandSender {
|
||||
|
||||
override fun execute(cmdString: String): Boolean {
|
||||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||
|
|
|
@ -65,7 +65,7 @@ object MatterLink : IMatterLink() {
|
|||
override fun log(level: String, formatString: String, vararg data: Any) =
|
||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
||||
|
||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
||||
override fun commandSenderFor(user: String, userId: String, server: String, op: Boolean) = MatterLinkCommandSender(user, userId, server, op)
|
||||
|
||||
override val mcVersion: String = MCVERSION
|
||||
override val modVersion: String = MODVERSION
|
||||
|
|
|
@ -9,8 +9,7 @@ import net.minecraft.world.World
|
|||
import net.minecraftforge.fml.common.FMLCommonHandler
|
||||
import javax.annotation.Nonnull
|
||||
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
||||
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String, op: Boolean) : IMinecraftCommandSender(user, userId, server, op), ICommandSender {
|
||||
override fun execute(cmdString: String): Boolean {
|
||||
return 0 < FMLCommonHandler.instance().minecraftServerInstance.commandManager.executeCommand(
|
||||
this,
|
||||
|
|
|
@ -65,7 +65,7 @@ class MatterLink : IMatterLink() {
|
|||
override fun log(level: String, formatString: String, vararg data: Any) =
|
||||
logger.log(Level.toLevel(level, Level.INFO), formatString, *data)
|
||||
|
||||
override fun commandSenderFor(user: String, userId: String, server: String) = MatterLinkCommandSender(user, userId, server)
|
||||
override fun commandSenderFor(user: String, userId: String, server: String, op: Boolean) = MatterLinkCommandSender(user, userId, server, op)
|
||||
|
||||
override val mcVersion: String = MCVERSION
|
||||
override val modVersion: String = MODVERSION
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.util.ChunkCoordinates
|
|||
import net.minecraft.util.IChatComponent
|
||||
import net.minecraft.world.World
|
||||
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String) : IMinecraftCommandSender(user, userId, server), ICommandSender {
|
||||
class MatterLinkCommandSender(user: String, userId: String, server: String, op: Boolean) : IMinecraftCommandSender(user, userId, server, op), ICommandSender {
|
||||
|
||||
private var level: Int = 0
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ abstract class IMatterLink {
|
|||
abstract val modVersion: String
|
||||
abstract val forgeVersion: String
|
||||
|
||||
abstract fun commandSenderFor(user: String, userId: String, server: String): IMinecraftCommandSender
|
||||
abstract fun commandSenderFor(user: String, userId: String, server: String, op: Boolean): IMinecraftCommandSender
|
||||
|
||||
abstract fun wrappedSendToPlayers(msg: String)
|
||||
|
||||
|
|
|
@ -14,7 +14,8 @@ data class CustomCommand(
|
|||
override val help: String = "",
|
||||
val allowArgs: Boolean = true,
|
||||
val timeout: Int = 20,
|
||||
val defaultCommand: Boolean? = null
|
||||
val defaultCommand: Boolean? = null,
|
||||
val execOp: Boolean? = null
|
||||
) : IBridgeCommand {
|
||||
val alias: String
|
||||
get() = BridgeCommandRegistry.getName(this)!!
|
||||
|
@ -41,8 +42,9 @@ data class CustomCommand(
|
|||
CommandType.EXECUTE -> {
|
||||
//uses a new commandsender for each user
|
||||
// TODO: cache CommandSenders
|
||||
val commandSender = instance.commandSenderFor(user, userId, server)
|
||||
commandSender.execute("$execute $args") || commandSender.reply.isNotBlank()
|
||||
val commandSender = instance.commandSenderFor(user, userId, server, execOp ?: false)
|
||||
val cmd = "$execute $args"
|
||||
commandSender.execute(cmd) || commandSender.reply.isNotBlank()
|
||||
}
|
||||
CommandType.RESPONSE -> {
|
||||
MessageHandlerInst.transmit(ApiMessage()
|
||||
|
@ -58,7 +60,7 @@ data class CustomCommand(
|
|||
*/
|
||||
override fun validate(): Boolean {
|
||||
val typeCheck = when (type) {
|
||||
CommandType.EXECUTE -> execute?.isNotBlank() ?: false
|
||||
CommandType.EXECUTE -> execute != null
|
||||
CommandType.RESPONSE -> response?.isNotBlank() ?: false
|
||||
}
|
||||
if (!typeCheck) return false
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package matterlink.bridge.command
|
||||
|
||||
import matterlink.config.PermissionConfig
|
||||
import matterlink.instance
|
||||
|
||||
interface IBridgeCommand {
|
||||
val help: String
|
||||
|
@ -9,7 +10,10 @@ interface IBridgeCommand {
|
|||
fun execute(alias: String, user: String, userId: String, server: String, args: String): Boolean
|
||||
|
||||
fun canExecute(userId: String, server: String): Boolean {
|
||||
return getPermLevel(userId, server) >= permLevel
|
||||
instance.info("this: $this canExecute: $userId server: $server permLevel: $permLevel")
|
||||
val canExec = getPermLevel(userId, server) >= permLevel
|
||||
instance.info("return $canExec")
|
||||
return canExec
|
||||
}
|
||||
|
||||
fun validate() = true
|
||||
|
|
|
@ -3,7 +3,7 @@ package matterlink.bridge.command
|
|||
import matterlink.api.ApiMessage
|
||||
import matterlink.bridge.MessageHandlerInst
|
||||
|
||||
abstract class IMinecraftCommandSender(val user: String, val userId: String, val server: String) {
|
||||
abstract class IMinecraftCommandSender(val user: String, val userId: String, val server: String, val op: Boolean) {
|
||||
/**
|
||||
* @param cmdString The command to execute with its arguments
|
||||
*
|
||||
|
@ -14,8 +14,8 @@ abstract class IMinecraftCommandSender(val user: String, val userId: String, val
|
|||
val accountName = "$user (id=$userId server=$server)"
|
||||
|
||||
fun canExecute(commandName: String): Boolean {
|
||||
if(op) return true
|
||||
val command = BridgeCommandRegistry[commandName] ?: return false
|
||||
|
||||
return command.canExecute(userId, server)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod_name = MatterLink
|
||||
mod_version = 1.5.8
|
||||
mod_version = 1.5.9
|
||||
forgelin_version = 1.6.0
|
||||
curse_id = 287323
|
||||
curse_release_type = beta
|
Loading…
Reference in New Issue