-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3afb144
commit e98acd5
Showing
10 changed files
with
218 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 5 additions & 11 deletions
16
src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/BotCommands.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
package org.kraftwerk28.spigot_tg_bridge | ||
|
||
import org.kraftwerk28.spigot_tg_bridge.Constants as C | ||
import org.bukkit.configuration.file.YamlConfiguration | ||
|
||
class Commands(plugin: Plugin) { | ||
class Commands(yamlCfg: YamlConfiguration) { | ||
val time: String | ||
val online: String | ||
init { | ||
plugin.config.run { | ||
time = getString( | ||
C.FIELDS.COMMANDS.TIME, | ||
C.DEFS.COMMANDS.TIME | ||
)!! | ||
online = getString( | ||
C.FIELDS.COMMANDS.ONLINE, | ||
C.DEFS.COMMANDS.ONLINE | ||
)!! | ||
yamlCfg.run { | ||
time = getString("commands.time", "time")!! | ||
online = getString("commands.online", "online")!! | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/CommandHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.kraftwerk28.spigot_tg_bridge | ||
|
||
import org.bukkit.command.Command | ||
import org.bukkit.command.CommandExecutor | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.command.ConsoleCommandSender | ||
import org.kraftwerk28.spigot_tg_bridge.Constants as C | ||
|
||
class CommandHandler(private val plugin: Plugin) : CommandExecutor { | ||
override fun onCommand( | ||
sender: CommandSender, | ||
command: Command, | ||
label: String, | ||
args: Array<out String> | ||
): Boolean { | ||
if (sender !is ConsoleCommandSender) return false | ||
return when (label) { | ||
C.COMMANDS.PLUGIN_RELOAD -> { | ||
plugin.reload() | ||
true | ||
} | ||
else -> false | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/kotlin/org/kraftwerk28/spigot_tg_bridge/Configuration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package org.kraftwerk28.spigot_tg_bridge | ||
|
||
import org.bukkit.configuration.file.YamlConfiguration | ||
import java.io.File | ||
import org.kraftwerk28.spigot_tg_bridge.Constants as C | ||
|
||
class Configuration(plugin: Plugin) { | ||
private lateinit var yamlCfg: YamlConfiguration | ||
|
||
var isEnabled: Boolean = false | ||
var logFromMCtoTG: Boolean = false | ||
var telegramMessageFormat: String = "" | ||
var serverStartMessage: String? = null | ||
var serverStopMessage: String? = null | ||
|
||
// Telegram bot stuff | ||
var botToken: String = "" | ||
var botUsername: String = "" | ||
var allowedChats: List<Long> = listOf() | ||
var logFromTGtoMC: Boolean = false | ||
var allowWebhook: Boolean = false | ||
var webhookConfig: Map<String, Any>? = null | ||
|
||
var logJoinLeave: Boolean = false | ||
var joinString: String? = null | ||
var leaveString: String? = null | ||
var logDeath: Boolean = false | ||
var logPlayerAsleep: Boolean = false | ||
var onlineString: String = "" | ||
var nobodyOnlineString: String = "" | ||
|
||
lateinit var commands: Commands | ||
|
||
init { | ||
reload(plugin) | ||
} | ||
|
||
fun reload(plugin: Plugin) { | ||
val cfgFile = File(plugin.dataFolder, C.configFilename); | ||
if (!cfgFile.exists()) { | ||
cfgFile.parentFile.mkdirs() | ||
plugin.saveResource(C.configFilename, false); | ||
throw Exception() | ||
} | ||
|
||
yamlCfg = YamlConfiguration() | ||
yamlCfg.load(cfgFile) | ||
|
||
yamlCfg.run { | ||
isEnabled = getBoolean("enable", true) | ||
logFromTGtoMC = getBoolean("logFromTGtoMC", true) | ||
logFromMCtoTG = getBoolean("logFromMCtoTG", true) | ||
telegramMessageFormat = getString("telegramMessageFormat", "<%username%>: %message%")!! | ||
allowedChats = getLongList("chats") | ||
serverStartMessage = getString("serverStartMessage") | ||
serverStopMessage = getString("serverStopMessage") | ||
|
||
botToken = getString("botToken") ?: throw Exception(C.WARN.noToken) | ||
botUsername = getString("botUsername") ?: throw Exception(C.WARN.noUsername) | ||
|
||
allowWebhook = getBoolean("useWebhook", false) | ||
val whCfg = get("webhookConfig") | ||
if (whCfg is Map<*, *>) { | ||
@Suppress("UNCHECKED_CAST") | ||
webhookConfig = whCfg as Map<String, Any>? | ||
} | ||
|
||
logJoinLeave = getBoolean("logJoinLeave", false) | ||
onlineString = getString("strings.online", "Online")!! | ||
nobodyOnlineString = getString("strings.offline", "Nobody online")!! | ||
joinString = getString("strings.joined", "joined") | ||
leaveString = getString("strings.left", "left") | ||
logDeath = getBoolean("logPlayerDeath", false) | ||
logPlayerAsleep = getBoolean("logPlayerAsleep", false) | ||
|
||
} | ||
|
||
commands = Commands(yamlCfg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.