feature: release 0.0.7

This commit is contained in:
kraftwerk28 2020-07-11 19:22:11 +03:00
parent d6dd9cb4a1
commit 7ba216f98c
8 changed files with 73 additions and 13 deletions

View File

@ -28,9 +28,15 @@
| logJoinLeave | If true, plugin will send corresponding messages to chats, when player joins or leaves server | boolean | :x: | true | | logJoinLeave | If true, plugin will send corresponding messages to chats, when player joins or leaves server | boolean | :x: | true |
| logFromMCtoTG | If true, plugin will send messages from players on server, to Telegram chats | boolean | :x: | true | | logFromMCtoTG | If true, plugin will send messages from players on server, to Telegram chats | boolean | :x: | true |
| logFromTGtoMC | If true, plugin will send messages from chats, to Minecraft server | boolean | :x: | true | | logFromTGtoMC | If true, plugin will send messages from chats, to Minecraft server | boolean | :x: | true |
| logPlayerDeath | If true, plugin will send message to Telegram if player died | boolean | :x: | false |
| logPlayerAsleep | If true, plugin will send message to Telegram if player fell asleep | boolean | :x: | false |
| strings | Dictionary of tokens - strings for plugin i18n | Map<string, string> | :x: | See default config | | strings | Dictionary of tokens - strings for plugin i18n | Map<string, string> | :x: | See default config |
| commands | Dictionary of command text used in Telegram bot | Map<string, string> | :x: | See default config |
## Commands: ## Commands:
Commands are customizeable through config, but there are default values for them as well
| Command | Description | | Command | Description |
|:-------:|:------------| |:-------:|:------------|
| `/online` | Get players, currently online | | `/online` | Get players, currently online |

View File

@ -1,3 +1,14 @@
import org.yaml.snakeyaml.Yaml
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.26'
}
}
plugins { plugins {
id 'java' id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.60' id 'org.jetbrains.kotlin.jvm' version '1.3.60'
@ -5,10 +16,10 @@ plugins {
} }
group 'org.kraftwerk28' group 'org.kraftwerk28'
version '0.0.4-SNAPSHOT' def pluginConfigFile = new File("src/main/resources/plugin.yml").newInputStream()
def cfg = (Map<String, Object>)new Yaml().load(pluginConfigFile)
//def defaultOutDir = "$System.env.HOME/MinecraftServers/spigot_1.15.2/plugins/" def v = cfg.get("version")
//rootProject.libsDirName = System.getenv("OUT_DIR") ?: defaultOutDir version "$v-SNAPSHOT"
repositories { repositories {
maven { maven {
@ -23,6 +34,15 @@ repositories {
mavenCentral() mavenCentral()
} }
def plugDir = "MinecraftServers/spigot_1.15.2/plugins/"
def homeDir = System.properties['user.home']
task cpArtifacts(type: Copy) {
from shadowJar
into "$homeDir/$plugDir"
}
shadowJar.finalizedBy cpArtifacts
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '4.12' testImplementation group: 'junit', name: 'junit', version: '4.12'
@ -30,8 +50,8 @@ dependencies {
implementation group: 'org.telegram', name: 'telegrambots', version: '4.6' implementation group: 'org.telegram', name: 'telegrambots', version: '4.6'
implementation 'com.vdurmont:emoji-java:5.1.1' implementation 'com.vdurmont:emoji-java:5.1.1'
def tgBotVer = '5.0.0' // def tgBotVer = '5.0.0'
implementation "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:$tgBotVer" // implementation "io.github.kotlin-telegram-bot.kotlin-telegram-bot:telegram:$tgBotVer"
} }
compileKotlin { compileKotlin {

View File

@ -87,9 +87,9 @@ class Bot(private var plugin: Plugin) : TelegramLongPollingBot() {
} }
fun broadcastToTG(text: String) { fun broadcastToTG(text: String) {
allowedChats.forEach { allowedChats.forEach { chatID ->
try { try {
val msg = SendMessage(it, text).setParseMode(ParseMode.HTML) val msg = SendMessage(chatID, text).setParseMode(ParseMode.HTML)
execute(msg) execute(msg)
} catch (e: TelegramApiException) { } catch (e: TelegramApiException) {
} }
@ -118,4 +118,8 @@ class Bot(private var plugin: Plugin) : TelegramLongPollingBot() {
(if (user.firstName.length < 2) null else user.firstName) (if (user.firstName.length < 2) null else user.firstName)
?: user.userName ?: user.userName
?: user.lastName ?: user.lastName
private fun telegramUserMention(user: User): String =
if (user.userName != null) "@${user.userName}"
else "<a href=\"tg://user?id=${user.id}\">${user.firstName ?: user.lastName}</a>"
} }

View File

@ -12,6 +12,8 @@ object Constants {
val SERVER_START_MSG = "serverStartMessage" val SERVER_START_MSG = "serverStartMessage"
val SERVER_STOP_MSG = "serverStopMessage" val SERVER_STOP_MSG = "serverStopMessage"
val LOG_JOIN_LEAVE = "logJoinLeave" val LOG_JOIN_LEAVE = "logJoinLeave"
val LOG_PLAYER_DEATH = "logPlayerDeath"
val LOG_PLAYER_ASLEEP = "logPlayerAsleep"
object STRINGS { object STRINGS {
val ONLINE = "strings.online" val ONLINE = "strings.online"
val OFFLINE = "strings.offline" val OFFLINE = "strings.offline"
@ -27,6 +29,8 @@ object Constants {
val logFromMCtoTG = false val logFromMCtoTG = false
val logFromTGtoMC = false val logFromTGtoMC = false
val logJoinLeave = false val logJoinLeave = false
val logPlayerDeath = false
val logPlayerAsleep = false
object COMMANDS { object COMMANDS {
val TIME = "/time" val TIME = "/time"
val ONLINE = "/online" val ONLINE = "/online"

View File

@ -2,7 +2,9 @@ package org.kraftwerk28.spigot_tg_bridge
import org.bukkit.event.EventHandler import org.bukkit.event.EventHandler
import org.bukkit.event.Listener import org.bukkit.event.Listener
import org.bukkit.event.entity.PlayerDeathEvent
import org.bukkit.event.player.AsyncPlayerChatEvent import org.bukkit.event.player.AsyncPlayerChatEvent
import org.bukkit.event.player.PlayerBedEnterEvent
import org.bukkit.event.player.PlayerJoinEvent import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerQuitEvent import org.bukkit.event.player.PlayerQuitEvent
import org.kraftwerk28.spigot_tg_bridge.Constants as C import org.kraftwerk28.spigot_tg_bridge.Constants as C
@ -12,13 +14,18 @@ class EventHandler(private val plugin: Plugin) : Listener {
private val joinStr: String private val joinStr: String
private val leftStr: String private val leftStr: String
private val logJoinLeave: Boolean private val logJoinLeave: Boolean
private val logDeathMessage: Boolean
private val logPlayerAsleep: Boolean
init { init {
plugin.config.run { plugin.config.run {
joinStr = getString(C.FIELDS.STRINGS.JOINED, C.DEFS.playerJoined)!! joinStr = getString(C.FIELDS.STRINGS.JOINED, C.DEFS.playerJoined)!!
leftStr = getString(C.FIELDS.STRINGS.LEFT, C.DEFS.playerLeft)!! leftStr = getString(C.FIELDS.STRINGS.LEFT, C.DEFS.playerLeft)!!
logJoinLeave = getBoolean(C.FIELDS.LOG_JOIN_LEAVE, C.DEFS.logJoinLeave) logJoinLeave = getBoolean(C.FIELDS.LOG_JOIN_LEAVE, C.DEFS.logJoinLeave)
logDeathMessage = getBoolean(C.FIELDS.LOG_PLAYER_DEATH, C.DEFS.logPlayerDeath)
logPlayerAsleep = getBoolean(C.FIELDS.LOG_PLAYER_ASLEEP, C.DEFS.logPlayerAsleep)
} }
plugin.logger.info("Log death message: $logDeathMessage")
} }
@EventHandler @EventHandler
@ -43,4 +50,22 @@ class EventHandler(private val plugin: Plugin) : Listener {
val text = "<b>${escapeHTML(event.player.displayName)}</b> $leftStr." val text = "<b>${escapeHTML(event.player.displayName)}</b> $leftStr."
plugin.tgBot?.broadcastToTG(text) plugin.tgBot?.broadcastToTG(text)
} }
@EventHandler
fun onPlayerDied(event: PlayerDeathEvent) {
if (!logDeathMessage) return
event.deathMessage?.let {
val plName = event.entity.displayName
val text = it.replace(plName, "<b>$plName</b>")
plugin.tgBot?.broadcastToTG(text)
}
}
@EventHandler
fun onPlayerAsleep(event: PlayerBedEnterEvent) {
if (!logPlayerAsleep) return
if (event.bedEnterResult != PlayerBedEnterEvent.BedEnterResult.OK) return
val text = "<b>${event.player.displayName}</b> fell asleep."
plugin.tgBot?.broadcastToTG(text)
}
} }

View File

@ -5,6 +5,3 @@ import org.telegram.telegrambots.meta.api.objects.User
fun escapeHTML(s: String): String = fun escapeHTML(s: String): String =
s.replace("&", "&amp;").replace(">", "&gt;").replace("<", "&lt;") s.replace("&", "&amp;").replace(">", "&gt;").replace("<", "&lt;")
fun telegramUserMention(user: User): String =
if (user.userName != null) "@${user.userName}"
else "<a href=\"tg://user?id=${user.id}\">${user.firstName ?: user.lastName}</a>"

View File

@ -7,9 +7,13 @@ serverStopMessage: 'Server stopped.'
logJoinLeave: true logJoinLeave: true
logFromMCtoTG: true logFromMCtoTG: true
logFromTGtoMC: true logFromTGtoMC: true
logPlayerDeath: false
logPlayerAsleep: false
strings: strings:
online: '<b>Online</b>' online: '<b>Online</b>'
nobodyOnline: '<b>Nobody online...</b>' nobodyOnline: '<b>Nobody online...</b>'
joined: 'joined' joined: 'joined'
left: 'left' left: 'left'
commands:
time: '/time'
online: '/online'

View File

@ -1,5 +1,5 @@
name: SpigotTGBridge name: SpigotTGBridge
version: 0.0.6 version: 0.0.7
api-version: '1.15' api-version: '1.15'
main: org.kraftwerk28.spigot_tg_bridge.Plugin main: org.kraftwerk28.spigot_tg_bridge.Plugin
description: Telegram <-> Minecraft communication plugin for Spigot. description: Telegram <-> Minecraft communication plugin for Spigot.