mirror of
https://github.com/amalthea-mc/spigot-tg-bridge.git
synced 2024-11-08 19:51:04 +00:00
chore: refactoring
This commit is contained in:
parent
72bbb0a189
commit
f8e13d037c
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
|
@ -45,13 +45,13 @@ class Bot(plugin: Plugin) : TelegramLongPollingBot() {
|
||||
)
|
||||
}
|
||||
|
||||
public fun sendMessageToTGFrom(username: String, text: String) {
|
||||
fun sendMessageToTGFrom(username: String, text: String) {
|
||||
allowedChats.forEach {
|
||||
execute(SendMessage(it, mcMessageStr(username, text)))
|
||||
}
|
||||
}
|
||||
|
||||
public fun broadcastToTG(text: String) {
|
||||
fun broadcastToTG(text: String) {
|
||||
allowedChats.forEach {
|
||||
execute(SendMessage(it, text))
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class MessageListener(plugin: Plugin) : Listener {
|
||||
init { this.plugin = plugin }
|
||||
|
||||
@EventHandler
|
||||
public fun onPlayerChat1(event: AsyncPlayerChatEvent) {
|
||||
fun onPlayerChat1(event: AsyncPlayerChatEvent) {
|
||||
plugin?.tgBot?.sendMessageToTGFrom(
|
||||
event.player.displayName,
|
||||
event.message
|
||||
|
@ -4,35 +4,31 @@ import org.bukkit.plugin.java.JavaPlugin
|
||||
import org.telegram.telegrambots.ApiContextInitializer
|
||||
import org.telegram.telegrambots.meta.TelegramBotsApi
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
|
||||
class Plugin : JavaPlugin() {
|
||||
var tgBot: Bot? = null
|
||||
override fun onEnable() {
|
||||
super.onEnable()
|
||||
if (!File("plugins/${name}/config.yml").exists()) {
|
||||
logger.warning("No config file found! Saving default one.")
|
||||
saveDefaultConfig()
|
||||
return
|
||||
}
|
||||
logger.info(config.getLongList("chats").toString())
|
||||
|
||||
ApiContextInitializer.init()
|
||||
val botsApi = TelegramBotsApi()
|
||||
tgBot = Bot(this)
|
||||
botsApi.registerBot(tgBot)
|
||||
|
||||
server.pluginManager.registerEvents(MessageListener(this), this)
|
||||
val startMsg = config.getString("serverStartMessage")
|
||||
if (startMsg != null)
|
||||
tgBot?.broadcastToTG(startMsg)
|
||||
|
||||
val startMsg = config.getString("serverStartMessage", null)
|
||||
if (startMsg != null) tgBot?.broadcastToTG(startMsg)
|
||||
logger.info("Plugin started")
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
super.onDisable()
|
||||
val stopMsg = config.getString("serverStopMessage")
|
||||
if (stopMsg != null)
|
||||
tgBot?.broadcastToTG(stopMsg)
|
||||
val stopMsg = config.getString("serverStopMessage", null)
|
||||
if (stopMsg != null) tgBot?.broadcastToTG(stopMsg)
|
||||
logger.info("Plugin stopped")
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user