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