Fixed all compile errors

- Removed all hacky code (for now)
- Removed other dependencies because I kept getting load errors, mostly related to the examination api
- Added some dependencies because I kept getting load errors, mostly related to the examination api
- Removed use of Channel.extraIdentifiers because it would not accept it, claiming that the ListConfigData class file is broken
This commit is contained in:
Norbi Peti 2023-04-24 23:53:00 +02:00
parent f909eb4779
commit 5d0bd37b28
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
14 changed files with 44 additions and 60 deletions

View file

@ -8,7 +8,7 @@ name := "Chroma-Discord"
version := "1.1" version := "1.1"
scalaVersion := "3.1.0" scalaVersion := "3.2.2"
resolvers += "spigot-repo" at "https://hub.spigotmc.org/nexus/content/repositories/snapshots/" resolvers += "spigot-repo" at "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
resolvers += "jitpack.io" at "https://jitpack.io" resolvers += "jitpack.io" at "https://jitpack.io"
@ -18,19 +18,21 @@ resolvers += Resolver.mavenLocal
// assembly / assemblyOption := (assembly / assemblyOption).value.copy(includeScala = false) // assembly / assemblyOption := (assembly / assemblyOption).value.copy(includeScala = false)
libraryDependencies ++= Seq( libraryDependencies ++= Seq(
"org.spigotmc" % "spigot" % "1.19.4-R0.1-SNAPSHOT" % Provided,
"io.papermc.paper" % "paper-api" % "1.19.4-R0.1-SNAPSHOT" % Provided, "io.papermc.paper" % "paper-api" % "1.19.4-R0.1-SNAPSHOT" % Provided,
"com.discord4j" % "discord4j-core" % "3.2.2", "com.discord4j" % "discord4j-core" % "3.2.3",
"org.slf4j" % "slf4j-jdk14" % "1.7.36",
"com.vdurmont" % "emoji-java" % "5.1.1", "com.vdurmont" % "emoji-java" % "5.1.1",
"org.mockito" % "mockito-core" % "4.6.1", "org.mockito" % "mockito-core" % "5.2.0",
// https://mvnrepository.com/artifact/org.immutables/value
"org.immutables" % "value" % "2.9.0" % "provided",
"com.github.TBMCPlugins.ChromaCore" % "Chroma-Core" % "v2.0.0-SNAPSHOT" % Provided, "com.github.TBMCPlugins.ChromaCore" % "Chroma-Core" % "v2.0.0-SNAPSHOT" % Provided,
"net.ess3" % "EssentialsX" % "2.17.1" % Provided, "net.ess3" % "EssentialsX" % "2.17.1" % Provided,
"net.luckperms" % "api" % "5.4" % Provided, "net.luckperms" % "api" % "5.4" % Provided,
// https://mvnrepository.com/artifact/com.mojang/brigadier
"com.mojang" % "brigadier" % "1.0.500" % "provided",
// https://mvnrepository.com/artifact/net.kyori/examination-api
"net.kyori" % "examination-api" % "1.3.0" % "provided",
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
"org.jetbrains.kotlin" % "kotlin-stdlib" % "1.8.20" % "provided"
) )
assembly / assemblyJarName := "Chroma-Discord.jar" assembly / assemblyJarName := "Chroma-Discord.jar"
@ -44,6 +46,7 @@ assembly / assemblyMergeStrategy := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
// https://stackoverflow.com/a/55557287/457612 // https://stackoverflow.com/a/55557287/457612
case "module-info.class" => MergeStrategy.discard case "module-info.class" => MergeStrategy.discard
case "META-INF/versions/9/module-info.class" => MergeStrategy.discard
case x => (assembly / assemblyMergeStrategy).value(x) case x => (assembly / assemblyMergeStrategy).value(x)
} }

View file

@ -1 +1 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.1")

View file

@ -1,17 +0,0 @@
package buttondevteam.discordplugin
import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import buttondevteam.discordplugin.util.DPState
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.appender.AbstractAppender
import org.apache.logging.log4j.core.filter.LevelRangeFilter
import org.apache.logging.log4j.core.layout.PatternLayout
import org.apache.logging.log4j.core.{Filter, LogEvent}
class BukkitLogWatcher private[discordplugin]() extends AbstractAppender("ChromaDiscord",
LevelRangeFilter.createFilter(Level.INFO, Level.INFO, Filter.Result.ACCEPT, Filter.Result.DENY),
PatternLayout.createDefaultLayout) {
override def append(logEvent: LogEvent): Unit =
if (logEvent.getMessage.getFormattedMessage.contains("Attempting to restart with "))
MinecraftChatModule.state = DPState.RESTARTING_SERVER
}

View file

@ -1,7 +1,7 @@
package buttondevteam.discordplugin package buttondevteam.discordplugin
import buttondevteam.lib.TBMCCoreAPI import buttondevteam.lib.TBMCCoreAPI
import buttondevteam.lib.architecture.{Component, ConfigData, IHaveConfig, ReadOnlyConfigData} import buttondevteam.lib.architecture.{Component, ConfigData, IHaveConfig}
import discord4j.common.util.Snowflake import discord4j.common.util.Snowflake
import discord4j.core.`object`.entity.channel.{Channel, MessageChannel} import discord4j.core.`object`.entity.channel.{Channel, MessageChannel}
import discord4j.core.`object`.entity.{Guild, Message, Role} import discord4j.core.`object`.entity.{Guild, Message, Role}
@ -182,7 +182,7 @@ object DPUtils {
DiscordPlugin.dc.getChannelById(id).onErrorResume(e => { DiscordPlugin.dc.getChannelById(id).onErrorResume(e => {
getLogger.warning(s"Failed to get channel data for $key=$id - ${e.getMessage}") getLogger.warning(s"Failed to get channel data for $key=$id - ${e.getMessage}")
Mono.empty[Channel] Mono.empty[Channel]
}).filter(ch => ch.isInstanceOf[MessageChannel]).cast(classOf[MessageChannel]]) }).filter(ch => ch.isInstanceOf[MessageChannel]).cast(classOf[MessageChannel])
} }
def getMessageChannel(config: ConfigData[Snowflake]): Mono[MessageChannel] = def getMessageChannel(config: ConfigData[Snowflake]): Mono[MessageChannel] =

View file

@ -26,8 +26,6 @@ import discord4j.core.{DiscordClientBuilder, GatewayDiscordClient}
import discord4j.gateway.ShardInfo import discord4j.gateway.ShardInfo
import discord4j.rest.interaction.Interactions import discord4j.rest.interaction.Interactions
import discord4j.store.jdk.JdkStoreService import discord4j.store.jdk.JdkStoreService
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.core.Logger
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.configuration.file.YamlConfiguration import org.bukkit.configuration.file.YamlConfiguration
import org.mockito.internal.util.MockUtil import org.mockito.internal.util.MockUtil
@ -59,7 +57,6 @@ import scala.jdk.OptionConverters.*
def manager: Command2DC = _manager def manager: Command2DC = _manager
private var starting = false private var starting = false
private var logWatcher: BukkitLogWatcher = null
/** /**
* The prefix to use with Discord commands like /role. It only works in the bot channel. * The prefix to use with Discord commands like /role. It only works in the bot channel.
*/ */
@ -206,10 +203,7 @@ import scala.jdk.OptionConverters.*
manager.registerCommand(new ConnectCommand, applicationId, guildId) manager.registerCommand(new ConnectCommand, applicationId, guildId)
TBMCCoreAPI.SendUnsentExceptions() TBMCCoreAPI.SendUnsentExceptions()
TBMCCoreAPI.SendUnsentDebugMessages() TBMCCoreAPI.SendUnsentDebugMessages()
val blw = new BukkitLogWatcher // TODO: Removed log watcher (responsible for detecting restarts)
blw.start()
LogManager.getRootLogger.asInstanceOf[Logger].addAppender(blw)
logWatcher = blw
if (!TBMCCoreAPI.IsTestServer) DiscordPlugin.dc.updatePresence(ClientPresence.online(ClientActivity.playing("Minecraft"))).subscribe() if (!TBMCCoreAPI.IsTestServer) DiscordPlugin.dc.updatePresence(ClientPresence.online(ClientActivity.playing("Minecraft"))).subscribe()
else DiscordPlugin.dc.updatePresence(ClientPresence.online(ClientActivity.playing("testing"))).subscribe() else DiscordPlugin.dc.updatePresence(ClientPresence.online(ClientActivity.playing("testing"))).subscribe()
getLogger.info("Loaded!") getLogger.info("Loaded!")
@ -244,7 +238,6 @@ import scala.jdk.OptionConverters.*
try { try {
DiscordPlugin.SafeMode = true // Stop interacting with Discord DiscordPlugin.SafeMode = true // Stop interacting with Discord
ChromaBot.enabled = false ChromaBot.enabled = false
LogManager.getRootLogger.asInstanceOf[Logger].removeAppender(logWatcher)
timings.printElapsed("Logging out...") timings.printElapsed("Logging out...")
DiscordPlugin.dc.logout.block DiscordPlugin.dc.logout.block
DiscordPlugin.mainServer = null //Allow ReadyEvent again DiscordPlugin.mainServer = null //Allow ReadyEvent again

View file

@ -2,6 +2,7 @@ package buttondevteam.discordplugin.commands
import buttondevteam.discordplugin.DiscordPlugin import buttondevteam.discordplugin.DiscordPlugin
import buttondevteam.lib.chat.Command2 import buttondevteam.lib.chat.Command2
import buttondevteam.lib.chat.commands.SubcommandData
import discord4j.common.util.Snowflake import discord4j.common.util.Snowflake
import discord4j.core.`object`.command.ApplicationCommandOption import discord4j.core.`object`.command.ApplicationCommandOption
import discord4j.discordjson.json.{ApplicationCommandOptionData, ApplicationCommandRequest} import discord4j.discordjson.json.{ApplicationCommandOptionData, ApplicationCommandRequest}
@ -14,7 +15,7 @@ class Command2DC extends Command2[ICommand2DC, Command2DCSender]('/', false) {
} }
def registerCommand(command: ICommand2DC, appId: Long, guildId: Option[Long] = None): Unit = { def registerCommand(command: ICommand2DC, appId: Long, guildId: Option[Long] = None): Unit = {
super.registerCommand(command) //Needs to be configurable for the helps super.registerCommandSuper(command) //Needs to be configurable for the helps
val greetCmdRequest = ApplicationCommandRequest.builder() val greetCmdRequest = ApplicationCommandRequest.builder()
.name(command.getCommandPath) //TODO: Main path .name(command.getCommandPath) //TODO: Main path
.description("Connect your Minecraft account.") //TODO: Description .description("Connect your Minecraft account.") //TODO: Description
@ -32,7 +33,7 @@ class Command2DC extends Command2[ICommand2DC, Command2DCSender]('/', false) {
} }
} }
override def hasPermission(sender: Command2DCSender, command: ICommand2DC, method: Method): Boolean = { override def hasPermission(sender: Command2DCSender, data: SubcommandData[ICommand2DC, Command2DCSender]): Boolean = {
//return !command.isModOnly() || sender.getMessage().getAuthor().hasRole(DiscordPlugin.plugin.modRole().get()); //TODO: modRole may be null; more customisable way? //return !command.isModOnly() || sender.getMessage().getAuthor().hasRole(DiscordPlugin.plugin.modRole().get()); //TODO: modRole may be null; more customisable way?
true true
} }

View file

@ -71,7 +71,7 @@ class ChannelconCommand(private val module: MinecraftChatModule) extends IComman
DPUtils.reply(message, Mono.empty, "cannot find toggle. Toggles:\n" + togglesString.get).subscribe() DPUtils.reply(message, Mono.empty, "cannot find toggle. Toggles:\n" + togglesString.get).subscribe()
return true return true
} }
val add: Boolean = !(cc.brtoggles.contains(bt)) val add: Boolean = !cc.brtoggles.contains(bt)
if (add) { if (add) {
cc.brtoggles += bt cc.brtoggles += bt
} }
@ -106,8 +106,7 @@ class ChannelconCommand(private val module: MinecraftChatModule) extends IComman
if (MCChatCustom.hasCustomChat(message.getChannelId)) { if (MCChatCustom.hasCustomChat(message.getChannelId)) {
return respond(sender, "this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.") return respond(sender, "this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.")
} }
val chan: Optional[Channel] = Channel.getChannels.filter(ch => ch.getIdentifier.equalsIgnoreCase(channelID) val chan: Optional[Channel] = Channel.getChannels.filter(ch => ch.getIdentifier.equalsIgnoreCase(channelID)).findAny // TODO: Removed erroring shit
|| util.Arrays.stream(ch.extraIdentifiers.get).anyMatch(cid => cid.equalsIgnoreCase(channelID))).findAny
if (!chan.isPresent) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW) if (!chan.isPresent) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW)
DPUtils.reply(message, channel, "MC channel with ID '" + channelID + "' not found! The ID is the command for it without the /.").subscribe() DPUtils.reply(message, channel, "MC channel with ID '" + channelID + "' not found! The ID is the command for it without the /.").subscribe()
return true return true

View file

@ -228,14 +228,10 @@ object MCChatUtils {
else lastmsgdata.message = null else lastmsgdata.message = null
return () return ()
} // Don't set the whole object to null, the player and channel information should be preserved } // Don't set the whole object to null, the player and channel information should be preserved
for (data <- if (channel.isInstanceOf[PrivateChannel]) MCChatPrivate.lastmsgPerUser val channelData = if (channel.isInstanceOf[PrivateChannel]) MCChatPrivate.lastmsgPerUser else MCChatCustom.lastmsgCustom
else MCChatCustom.lastmsgCustom) { channelData.collectFirst({ case data if data.channel.getId.asLong == channel.getId.asLong => data })
if (data.channel.getId.asLong == channel.getId.asLong) { .foreach(data => data.message = null)
data.message = null //If the above didn't find anything, it's sending a message to a non-chat channel
return ()
}
}
//If it gets here, it's sending a message to a non-chat channel
} }
def addStaticExcludedPlugin(event: Class[_ <: Event], plugin: String): util.HashSet[String] = def addStaticExcludedPlugin(event: Class[_ <: Event], plugin: String): util.HashSet[String] =

View file

@ -1,7 +1,6 @@
package buttondevteam.discordplugin.mcchat package buttondevteam.discordplugin.mcchat
import buttondevteam.discordplugin.* import buttondevteam.discordplugin.*
import buttondevteam.discordplugin.DPUtils.{FluxExtensions, MonoExtensions}
import buttondevteam.discordplugin.mcchat.sender.{DiscordConnectedPlayer, DiscordPlayer, DiscordPlayerSender} import buttondevteam.discordplugin.mcchat.sender.{DiscordConnectedPlayer, DiscordPlayer, DiscordPlayerSender}
import buttondevteam.lib.TBMCSystemChatEvent import buttondevteam.lib.TBMCSystemChatEvent
import buttondevteam.lib.player.{TBMCPlayer, TBMCPlayerBase, TBMCYEEHAWEvent} import buttondevteam.lib.player.{TBMCPlayer, TBMCPlayerBase, TBMCYEEHAWEvent}

View file

@ -1,11 +1,10 @@
package buttondevteam.discordplugin.mcchat package buttondevteam.discordplugin.mcchat
import buttondevteam.core.component.channel.Channel import buttondevteam.core.component.channel.Channel
import buttondevteam.discordplugin.DPUtils.{MonoExtensions, SpecExtensions}
import buttondevteam.discordplugin.mcchat.sender.DiscordConnectedPlayer import buttondevteam.discordplugin.mcchat.sender.DiscordConnectedPlayer
import buttondevteam.discordplugin.util.DPState import buttondevteam.discordplugin.util.DPState
import buttondevteam.discordplugin.{ChannelconBroadcast, DPUtils, DiscordPlugin} import buttondevteam.discordplugin.{ChannelconBroadcast, DPUtils, DiscordPlugin}
import buttondevteam.lib.architecture.{Component, ConfigData, ReadOnlyConfigData} import buttondevteam.lib.architecture.{Component, ConfigData}
import buttondevteam.lib.{TBMCCoreAPI, TBMCSystemChatEvent} import buttondevteam.lib.{TBMCCoreAPI, TBMCSystemChatEvent}
import com.google.common.collect.Lists import com.google.common.collect.Lists
import discord4j.common.util.Snowflake import discord4j.common.util.Snowflake

View file

@ -3,6 +3,7 @@ package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.mcchat.MinecraftChatModule import buttondevteam.discordplugin.mcchat.MinecraftChatModule
import discord4j.core.`object`.entity.User import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel import discord4j.core.`object`.entity.channel.MessageChannel
import net.kyori.adventure.text.Component
import org.bukkit.* import org.bukkit.*
import org.bukkit.attribute.{Attribute, AttributeInstance, AttributeModifier} import org.bukkit.attribute.{Attribute, AttributeInstance, AttributeModifier}
import org.bukkit.entity.{Entity, Player} import org.bukkit.entity.{Entity, Player}
@ -49,12 +50,12 @@ object DiscordConnectedPlayer {
* @param user May be null. * @param user May be null.
* @param channel May not be null. * @param channel May not be null.
* @param uniqueId The UUID of the player. * @param uniqueId The UUID of the player.
* @param name The Minecraft name of the player. * @param playerName The Minecraft name of the player.
* @param module The MinecraftChatModule or null if testing. * @param module The MinecraftChatModule or null if testing.
*/ */
abstract class DiscordConnectedPlayer(user: User, channel: MessageChannel, val uniqueId: UUID, val name: String, val module: MinecraftChatModule) extends DiscordSenderBase(user, channel) with IMCPlayer[DiscordConnectedPlayer] { abstract class DiscordConnectedPlayer(user: User, channel: MessageChannel, val uniqueId: UUID, val playerName: String, val module: MinecraftChatModule) extends DiscordSenderBase(user, channel) with IMCPlayer[DiscordConnectedPlayer] {
private var loggedIn = false private var loggedIn = false
private var displayName: String = name private var displayName: String = playerName
private var location: Location = if (module == null) null else Bukkit.getWorlds.get(0).getSpawnLocation private var location: Location = if (module == null) null else Bukkit.getWorlds.get(0).getSpawnLocation
private val basePlayer: OfflinePlayer = if (module == null) null else Bukkit.getOfflinePlayer(uniqueId) private val basePlayer: OfflinePlayer = if (module == null) null else Bukkit.getOfflinePlayer(uniqueId)
@ -98,7 +99,7 @@ abstract class DiscordConnectedPlayer(user: User, channel: MessageChannel, val u
def isLoggedIn: Boolean = this.loggedIn def isLoggedIn: Boolean = this.loggedIn
override def getName: String = this.name override def getName: String = this.playerName
def getBasePlayer: OfflinePlayer = this.basePlayer def getBasePlayer: OfflinePlayer = this.basePlayer
@ -196,6 +197,8 @@ abstract class DiscordConnectedPlayer(user: User, channel: MessageChannel, val u
override def getInventory: PlayerInventory = inventory override def getInventory: PlayerInventory = inventory
override def name(): Component = Component.text(playerName)
//noinspection ScalaDeprecation //noinspection ScalaDeprecation
/*@SuppressWarnings(Array("deprecation")) override def spigot: super.Spigot = new super.Spigot() { /*@SuppressWarnings(Array("deprecation")) override def spigot: super.Spigot = new super.Spigot() {
override def getRawAddress: InetSocketAddress = null override def getRawAddress: InetSocketAddress = null

View file

@ -32,7 +32,7 @@ abstract class DiscordPlayerSender(user: User, channel: MessageChannel, var play
super.sendMessage(message) super.sendMessage(message)
} }
override def sendMessage(messages: Array[String]): Unit = { override def sendMessage(messages: Array[? <: String]): Unit = {
player.sendMessage(messages*) player.sendMessage(messages*)
super.sendMessage(messages) super.sendMessage(messages)
} }

View file

@ -3,18 +3,19 @@ package buttondevteam.discordplugin.mcchat.sender
import buttondevteam.discordplugin.DiscordPlugin import buttondevteam.discordplugin.DiscordPlugin
import discord4j.core.`object`.entity.User import discord4j.core.`object`.entity.User
import discord4j.core.`object`.entity.channel.MessageChannel import discord4j.core.`object`.entity.channel.MessageChannel
import net.kyori.adventure.text.{Component, ComponentBuilder, TextComponent}
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.permissions.{PermissibleBase, Permission, PermissionAttachment, PermissionAttachmentInfo} import org.bukkit.permissions.{PermissibleBase, Permission, PermissionAttachment, PermissionAttachmentInfo}
import org.bukkit.plugin.Plugin import org.bukkit.plugin.Plugin
import org.bukkit.{Bukkit, Server} import org.bukkit.{Bukkit, Server}
import reactor.core.publisher.Mono import reactor.core.publisher.Mono
import scala.jdk.OptionConverters._
import scala.jdk.OptionConverters.*
import java.util import java.util
class DiscordSender(user: User, channel: MessageChannel, pname: String) extends DiscordSenderBase(user, channel) with CommandSender { class DiscordSender(user: User, channel: MessageChannel, pname: String) extends DiscordSenderBase(user, channel) with CommandSender {
private val perm = new PermissibleBase(this) private val perm = new PermissibleBase(this)
private val name: String = Option(pname) private val senderName: String = Option(pname)
.orElse(Option(user).flatMap(u => u.asMember(DiscordPlugin.mainServer.getId) .orElse(Option(user).flatMap(u => u.asMember(DiscordPlugin.mainServer.getId)
.onErrorResume(_ => Mono.empty).blockOptional().toScala .onErrorResume(_ => Mono.empty).blockOptional().toScala
.map(u => u.getDisplayName))) .map(u => u.getDisplayName)))
@ -56,7 +57,9 @@ class DiscordSender(user: User, channel: MessageChannel, pname: String) extends
override def getServer: Server = Bukkit.getServer override def getServer: Server = Bukkit.getServer
override def getName: String = name override def getName: String = senderName
override def name(): Component = Component.text(senderName)
//override def spigot(): CommandSender.Spigot = new CommandSender.Spigot //override def spigot(): CommandSender.Spigot = new CommandSender.Spigot
override def spigot(): CommandSender.Spigot = ??? override def spigot(): CommandSender.Spigot = ???

View file

@ -10,6 +10,8 @@ import org.bukkit.Bukkit
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.scheduler.BukkitTask import org.bukkit.scheduler.BukkitTask
import java.util.UUID
/** /**
* *
* @param user May be null. * @param user May be null.
@ -62,5 +64,8 @@ abstract class DiscordSenderBase protected(var user: User, var channel: MessageC
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e, DiscordPlugin.plugin) TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e, DiscordPlugin.plugin)
} }
override def sendMessage(messages: Array[String]): Unit = sendMessage(String.join("\n", messages: _*)) override def sendMessage(messages: Array[? <: String]): Unit = sendMessage(String.join("\n", messages: _*))
override def sendMessage(sender: UUID, message: String): Unit = sendMessage(message)
override def sendMessage(sender: UUID, messages: Array[? <: String]): Unit = sendMessage(messages)
} }