ms/packages/bukkit/src/chat.ts
MiaoWoo d0a0e2dd71 feat: compatible 1.8.8 chat
Signed-off-by: MiaoWoo <admin@yumc.pw>
2020-09-24 13:48:14 +08:00

24 lines
876 B
TypeScript

import { chat } from '@ccms/api'
import { provideSingleton } from '@ccms/container'
import bukkitChat from './enhance/chat'
@provideSingleton(chat.Chat)
export class BukkitChat extends chat.Chat {
sendJson(sender: any, json: string | object, type = 0) {
bukkitChat.send(sender, typeof json === "string" ? json : JSON.stringify(json), type)
}
sendMessage(sender: any, message: string) {
this.sendJson(sender, { text: message }, 0)
}
sendActionBar(sender: any, message: string) {
this.sendJson(sender, { text: message }, 2)
}
sendTitle(sender: any, title: string, subtitle: string = '', fadeIn: number = 20, time: number = 100, fadeOut: number = 20) {
try {
sender.sendTitle(title, subtitle, fadeIn, time, fadeOut)
} catch (error) {
sender.sendTitle(title, subtitle)
}
}
}