Add basic channel and chat bridge.

This commit is contained in:
Logan Gorence
2021-12-22 01:38:22 +00:00
parent be7df6dcc6
commit 69380906e6
8 changed files with 144 additions and 14 deletions

View File

@ -1,10 +1,8 @@
package cloud.kubelet.foundation.core
import cloud.kubelet.foundation.core.command.BackupCommand
import io.papermc.paper.event.player.ChatEvent
import net.kyori.adventure.text.Component
import org.bukkit.command.CommandExecutor
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.plugin.java.JavaPlugin
import java.nio.file.Path
@ -23,7 +21,9 @@ class FoundationCorePlugin : JavaPlugin(), Listener {
}
return _pluginDataPath
}
private set(value) { _pluginDataPath = value }
private set(value) {
_pluginDataPath = value
}
override fun onEnable() {
pluginDataPath = dataFolder.toPath()
@ -41,7 +41,7 @@ class FoundationCorePlugin : JavaPlugin(), Listener {
val log = slF4JLogger
log.info("Features:")
Util.printFeatureStatus(log, "Backup: ", BACKUP_ENABLED)
Util.printFeatureStatus(log, "Backup", BACKUP_ENABLED)
}
private fun registerCommandExecutor(name: String, executor: CommandExecutor) {
@ -49,8 +49,11 @@ class FoundationCorePlugin : JavaPlugin(), Listener {
command.setExecutor(executor)
}
@EventHandler
// TODO: Disabling chat reformatting until I do something with it and figure out how to make it
// be less disruptive.
/*@EventHandler
private fun onChatMessage(e: ChatEvent) {
return
e.isCancelled = true
val name = e.player.displayName()
val component = Component.empty()
@ -60,7 +63,7 @@ class FoundationCorePlugin : JavaPlugin(), Listener {
.append(Component.text(' '))
.append(e.message())
server.sendMessage(component)
}
}*/
companion object {
private const val BACKUPS_DIRECTORY = "backups"

View File

@ -3,5 +3,5 @@ package cloud.kubelet.foundation.core
import net.kyori.adventure.text.format.TextColor
object TextColors {
val AMARANTH_PINK = TextColor.fromHexString("#F7A8B8")
val AMARANTH_PINK = TextColor.fromHexString("#F7A8B8")!!
}

View File

@ -3,6 +3,7 @@ package cloud.kubelet.foundation.core
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.format.TextColor
import org.slf4j.Logger
import java.nio.file.Path
object Util {
private val leftBracket: Component = Component.text('[')
@ -14,15 +15,50 @@ object Util {
logger.info("{}: {}", feature, if (state) "Enabled" else "Disabled")
}
fun formatSystemMessage(message: String?): Component {
fun formatSystemMessage(message: String): Component {
return formatSystemMessage(TextColors.AMARANTH_PINK, message)
}
fun formatSystemMessage(prefixColor: TextColor?, message: String?): Component {
fun formatSystemMessage(prefixColor: TextColor, message: String): Component {
return leftBracket
.append(foundationName.color(prefixColor))
.append(rightBracket)
.append(whitespace)
.append(Component.text(message!!))
.append(Component.text(message))
}
/**
* Copy the default configuration from the resource [resourceName] into the directory [targetPath].
* @param targetPath The output directory as a path, it must exist before calling this.
* @param resourceName Path to resource, it should be in the root of the `resources` directory,
* without the leading slash.
*/
fun copyDefaultConfig(log: Logger, targetPath: Path, resourceName: String): Path {
if (resourceName.startsWith("/")) {
throw IllegalArgumentException("resourceName starts with slash")
}
if (!targetPath.toFile().exists()) {
throw Exception("Configuration output path does not exist!")
}
val outPath = targetPath.resolve(resourceName)
val outFile = outPath.toFile()
if (outFile.exists()) {
log.debug("Configuration file already exists.")
return outPath
}
val resourceStream = javaClass.getResourceAsStream("/$resourceName")
?: throw Exception("Configuration resource does not exist!")
val outputStream = outFile.outputStream()
resourceStream.use {
outputStream.use {
log.info("Copied default configuration to $outPath")
resourceStream.copyTo(outputStream)
}
}
return outPath
}
}

View File

@ -0,0 +1,10 @@
# Authentication configuration for the bridge.
authentication:
# Token from the Discord Bot developer's page.
token: abc123
# Channel configuration for the bridge.
channel:
# Channel ID, can be copied by turning on Developer Mode in User Settings -> Advanced. The ID can
# then be copied by right-clicking the channel and selecting "Copy ID".
id: 123456789