tellコマンド修正

This commit is contained in:
morioka22
2020-06-28 15:39:31 +09:00
parent b508374cb5
commit 10bd1a470d
3 changed files with 73 additions and 2 deletions

View File

@ -26,10 +26,28 @@ class BungeeDiscordChat : Plugin(), Listener{
var lunachat:Boolean = false
var discord = DiscordBot()
companion object {
lateinit var instance: Plugin
private set
}
override fun onEnable() {
//tell commandを置き換える
for (command in arrayOf(
"tell", "msg", "message", "m", "w", "t")) {
proxy.pluginManager.registerCommand(
this, TellCommand(this, command))
}
//reply commandを置き換える
for (command in arrayOf("reply", "r")) {
proxy.pluginManager.registerCommand(
this, ReplyCommand(this, command))
}
loadConfig()
logger.info("Config Loaded")
proxy.pluginManager.registerListener(this, this)
instance = this
discord.system(":ballot_box_with_check: Bot起動")
discord.chat(":ballot_box_with_check: **サーバーが起動しました**")
}

View File

@ -1,4 +1,12 @@
package mc.mec.bungeediscordchat.commands.PrivateMessage
class ReplyCommand {
import mc.mec.bungeediscordchat.BungeeDiscordChat
import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.plugin.Command
class ReplyCommand(parent: BungeeDiscordChat, name: String?) : Command(name) {
private val parent: BungeeDiscordChat = parent
override fun execute(p0: CommandSender?, p1: Array<out String>?) {
}
}

View File

@ -1,4 +1,49 @@
package mc.mec.bungeediscordchat.commands.PrivateMessage
class TellCommand {
import mc.mec.bungeediscordchat.BungeeDiscordChat
import net.md_5.bungee.api.ChatColor
import net.md_5.bungee.api.CommandSender
import net.md_5.bungee.api.plugin.Command
class TellCommand(parent: BungeeDiscordChat, name: String?) : Command(name) {
private val parent: BungeeDiscordChat = parent
override fun execute(sender: CommandSender?, args: Array<out String>?) {
if (sender == null) { return }
if (args?.size!! < 1) {
sendMessage(sender, ChatColor.RED.toString() + "使用方法 : /tell <player> <message>")
return
}
if (args[0] == sender.name) {
sendMessage(sender, ChatColor.RED.toString() + "自分自身にメッセージを送ることはできません。")
}
val parent = BungeeDiscordChat.instance
val receiver = parent.proxy.getPlayer(args[0])
if (receiver == null) {
sendMessage(sender, ChatColor.RED.toString() + "送信先のプレイヤーが見つかりません。")
return
}
val str = StringBuilder()
for (i in 1..(args.size)) {
str.append(args[i] + " ")
}
val message = str.toString().trim()
sendMessage(receiver, "<${sender.name}> " + message)
}
/**
* 指定した対象にメッセージを送信する
* @param receiver 送信先
* @param message メッセージ
*/
fun sendMessage(receiver: CommandSender, message: String?) {
if (message == null) return
receiver.sendMessage(message)
}
}