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