Fix all Scala errors!

This commit is contained in:
Norbi Peti 2021-03-09 03:41:04 +01:00
parent a0a7f756c4
commit a84cd4e8e3
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
9 changed files with 69 additions and 60 deletions

View file

@ -24,7 +24,7 @@ object DiscordPlayerSender {
}).useConstructor(user, channel, player, module)) }).useConstructor(user, channel, player, module))
} }
abstract class DiscordPlayerSender(val user: User, val channel: MessageChannel, var player: Player, val module: Nothing) extends DiscordSenderBase(user, channel) with IMCPlayer[DiscordPlayerSender] { abstract class DiscordPlayerSender(user: User, channel: MessageChannel, var player: Player, val module: Nothing) extends DiscordSenderBase(user, channel) with IMCPlayer[DiscordPlayerSender] {
val vanillaCmdListener = new VCMDWrapper(VCMDWrapper.createListener(this, player, module)) val vanillaCmdListener = new VCMDWrapper(VCMDWrapper.createListener(this, player, module))
override def getVanillaCmdListener: VCMDWrapper = this.vanillaCmdListener override def getVanillaCmdListener: VCMDWrapper = this.vanillaCmdListener

View file

@ -72,7 +72,7 @@ object PlayerListWatcher {
else lookupConstructor = null else lookupConstructor = null
mock = Mockito.mock(dplc, Mockito.withSettings.defaultAnswer(new Answer[AnyRef]() { // Cannot call super constructor mock = Mockito.mock(dplc, Mockito.withSettings.defaultAnswer(new Answer[AnyRef]() { // Cannot call super constructor
@throws[Throwable] @throws[Throwable]
override def answer(invocation: InvocationOnMock): Any = { override def answer(invocation: InvocationOnMock): AnyRef = {
val method = invocation.getMethod val method = invocation.getMethod
if (!(method.getName == "sendMessage")) { if (!(method.getName == "sendMessage")) {
if (method.getName == "sendAll") { if (method.getName == "sendAll") {

View file

@ -107,7 +107,7 @@ class FunModule extends Component[DiscordPlugin] with Listener {
* Answers for a recognized question. Selected randomly. * Answers for a recognized question. Selected randomly.
*/ */
final private val serverReadyAnswers: ConfigData[util.ArrayList[String]] = final private val serverReadyAnswers: ConfigData[util.ArrayList[String]] =
getConfig.getData("serverReadyAnswers", () => Lists.newArrayList(FunModule.serverReadyStrings): _*) getConfig.getData("serverReadyAnswers", () => Lists.newArrayList(FunModule.serverReadyStrings: _*))
private def createUsableServerReadyStrings(): Unit = private def createUsableServerReadyStrings(): Unit =
IntStream.range(0, serverReadyAnswers.get.size).forEach((i: Int) => FunModule.usableServerReadyStrings.add(i.toShort)) IntStream.range(0, serverReadyAnswers.get.size).forEach((i: Int) => FunModule.usableServerReadyStrings.add(i.toShort))

View file

@ -44,12 +44,14 @@ object MCChatCustom {
MCChatUtils.lastmsgfromd.remove(channel.asLong) MCChatUtils.lastmsgfromd.remove(channel.asLong)
val count = lastmsgCustom.size val count = lastmsgCustom.size
lastmsgCustom.filterInPlace(lmd => { lastmsgCustom.filterInPlace(lmd => {
if (lmd.channel.getId.asLong != channel.asLong) return true if (lmd.channel.getId.asLong != channel.asLong) true
lmd.mcchannel match { else {
case room: ChatRoom => room.leaveRoom(lmd.dcp) lmd.mcchannel match {
case _ => case room: ChatRoom => room.leaveRoom(lmd.dcp)
case _ =>
}
false
} }
false
}) })
lastmsgCustom.size < count lastmsgCustom.size < count
} }

View file

@ -148,13 +148,14 @@ class MCChatListener(val module: MinecraftChatModule) extends Listener {
&& e.getGroupID() == lmd.groupID) { //Check if this is the group we want to test - #58 && e.getGroupID() == lmd.groupID) { //Check if this is the group we want to test - #58
if (e.shouldSendTo(lmd.dcp)) { //Check original user's permissions if (e.shouldSendTo(lmd.dcp)) { //Check original user's permissions
doit(lmd) doit(lmd)
true
} }
else { else {
lmd.channel.createMessage("The user no longer has permission to view the channel, connection removed.").subscribe lmd.channel.createMessage("The user no longer has permission to view the channel, connection removed.").subscribe
return false //If the user no longer has permission, remove the connection false //If the user no longer has permission, remove the connection
} }
} }
true else true
}) })
} }
} catch { } catch {
@ -382,7 +383,7 @@ class MCChatListener(val module: MinecraftChatModule) extends Listener {
false false
} }
else { else {
val cmb = ChatMessage.builder(dsender, user, dmessage + getAttachmentText()).fromCommand(false) val cmb = ChatMessage.builder(dsender, user, dmessage + getAttachmentText).fromCommand(false)
if (clmd != null) if (clmd != null)
TBMCChatAPI.SendChatMessage(cmb.permCheck(clmd.dcp).build, clmd.mcchannel) TBMCChatAPI.SendChatMessage(cmb.permCheck(clmd.dcp).build, clmd.mcchannel)
else else
@ -415,7 +416,7 @@ class MCChatListener(val module: MinecraftChatModule) extends Listener {
val cmd = dmessage.substring(1) val cmd = dmessage.substring(1)
val cmdlowercased = cmd.toLowerCase val cmdlowercased = cmd.toLowerCase
if (dsender.isInstanceOf[DiscordSender] && notWhitelisted(cmdlowercased)) { // Command not whitelisted if (dsender.isInstanceOf[DiscordSender] && notWhitelisted(cmdlowercased)) { // Command not whitelisted
dsender.sendMessage("Sorry, you can only access these commands from here:\n" + whitelistedCommands() + dsender.sendMessage("Sorry, you can only access these commands from here:\n" + whitelistedCommands +
(if (user.getConnectedID(classOf[TBMCPlayer]) == null) (if (user.getConnectedID(classOf[TBMCPlayer]) == null)
"\nTo access your commands, first please connect your accounts, using /connect in " + DPUtils.botmention "\nTo access your commands, first please connect your accounts, using /connect in " + DPUtils.botmention
+ "\nThen y" else "\nY") + "ou can access all of your regular commands (even offline) in private chat: DM me `mcchat`!") + "\nThen y" else "\nY") + "ou can access all of your regular commands (even offline) in private chat: DM me `mcchat`!")

View file

@ -22,7 +22,7 @@ import reactor.core.scala.publisher.SMono
import java.net.InetAddress import java.net.InetAddress
import java.util import java.util
import java.util._ import java.util.UUID
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
import java.util.logging.Level import java.util.logging.Level
@ -137,12 +137,11 @@ object MCChatUtils {
*/ */
def forCustomAndAllMCChat(action: SMono[MessageChannel] => SMono[_], @Nullable toggle: ChannelconBroadcast, hookmsg: Boolean): SMono[_] = { def forCustomAndAllMCChat(action: SMono[MessageChannel] => SMono[_], @Nullable toggle: ChannelconBroadcast, hookmsg: Boolean): SMono[_] = {
if (notEnabled) return SMono.empty if (notEnabled) return SMono.empty
val list = val list = List(if (!GeneralEventBroadcasterModule.isHooked || !hookmsg)
List(if (!GeneralEventBroadcasterModule.isHooked || !hookmsg) forPublicPrivateChat(action) else SMono.empty) ++
forPublicPrivateChat(action) else SMono.empty) ++ (if (toggle == null) MCChatCustom.lastmsgCustom
(if (toggle == null) MCChatCustom.lastmsgCustom else MCChatCustom.lastmsgCustom.filter(cc => (cc.toggles & (1 << toggle.id)) != 0))
else MCChatCustom.lastmsgCustom.filter(cc => (cc.toggles & (1 << toggle.id)) != 0)) .map(_.channel).map(SMono.just).map(action)
.map(_.channel).map(SMono.just).map(action)
SMono.whenDelayError(list) SMono.whenDelayError(list)
} }

View file

@ -1,6 +1,6 @@
package buttondevteam.discordplugin.mcchat package buttondevteam.discordplugin.mcchat
import buttondevteam.discordplugin.DPUtils.FluxExtensions import buttondevteam.discordplugin.DPUtils.{FluxExtensions, MonoExtensions}
import buttondevteam.discordplugin._ import buttondevteam.discordplugin._
import buttondevteam.lib.TBMCSystemChatEvent import buttondevteam.lib.TBMCSystemChatEvent
import buttondevteam.lib.player.{TBMCPlayer, TBMCPlayerBase, TBMCYEEHAWEvent} import buttondevteam.lib.player.{TBMCPlayer, TBMCPlayerBase, TBMCYEEHAWEvent}
@ -15,8 +15,7 @@ import org.bukkit.event.player.PlayerLoginEvent.Result
import org.bukkit.event.player._ import org.bukkit.event.player._
import org.bukkit.event.server.{BroadcastMessageEvent, TabCompleteEvent} import org.bukkit.event.server.{BroadcastMessageEvent, TabCompleteEvent}
import org.bukkit.event.{EventHandler, EventPriority, Listener} import org.bukkit.event.{EventHandler, EventPriority, Listener}
import reactor.core.publisher.Flux import reactor.core.scala.publisher.{SFlux, SMono}
import reactor.core.scala.publisher.SMono
class MCListener(val module: MinecraftChatModule) extends Listener { class MCListener(val module: MinecraftChatModule) extends Listener {
final private val muteRole = DPUtils.roleData(module.getConfig, "muteRole", "Muted") final private val muteRole = DPUtils.roleData(module.getConfig, "muteRole", "Muted")
@ -35,8 +34,8 @@ class MCListener(val module: MinecraftChatModule) extends Listener {
val p = e.getPlayer val p = e.getPlayer
val dp = TBMCPlayerBase.getPlayer(p.getUniqueId, classOf[TBMCPlayer]).getAs(classOf[DiscordPlayer]) val dp = TBMCPlayerBase.getPlayer(p.getUniqueId, classOf[TBMCPlayer]).getAs(classOf[DiscordPlayer])
if (dp != null) if (dp != null)
DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID)).flatMap(user => DiscordPlugin.dc.getUserById(Snowflake.of(dp.getDiscordID)).^^().flatMap(user =>
user.getPrivateChannel.flatMap(chan => module.chatChannelMono.flatMap(cc => { user.getPrivateChannel.^^().flatMap(chan => module.chatChannelMono.flatMap(cc => {
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID, DiscordPlayerSender.create(user, chan, p, module)) MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID, DiscordPlayerSender.create(user, chan, p, module))
MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID, DiscordPlayerSender.create(user, cc, p, module)) //Stored per-channel MCChatUtils.addSender(MCChatUtils.OnlineSenders, dp.getDiscordID, DiscordPlayerSender.create(user, cc, p, module)) //Stored per-channel
SMono.empty SMono.empty
@ -130,8 +129,8 @@ class MCListener(val module: MinecraftChatModule) extends Listener {
val t = event.getBuffer.substring(i + 1) //0 if not found val t = event.getBuffer.substring(i + 1) //0 if not found
if (!t.startsWith("@")) return if (!t.startsWith("@")) return
val token = t.substring(1) val token = t.substring(1)
val x = DiscordPlugin.mainServer.getMembers.flatMap((m) => Flux.just(m.getUsername, m.getNickname.orElse(""))) val x = DiscordPlugin.mainServer.getMembers.^^().flatMap(m => SFlux.just(m.getUsername, m.getNickname.orElse("")))
.filter((s) => s.startsWith(token)).map((s) => "@" + s).doOnNext(event.getCompletions.add(_)).blockLast .filter(_.startsWith(token)).map("@" + _).doOnNext(event.getCompletions.add(_)).blockLast()
} }
@EventHandler def onCommandSend(event: PlayerCommandSendEvent): Boolean = event.getCommands.add("g") @EventHandler def onCommandSend(event: PlayerCommandSendEvent): Boolean = event.getCommands.add("g")

View file

@ -129,6 +129,7 @@ class MinecraftChatModule extends Component[DiscordPlugin] {
UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"), this) UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"), this)
MCChatCustom.addCustomChat(ch.asInstanceOf[MessageChannel], groupid, mcch.get, user, dcp, toggles, MCChatCustom.addCustomChat(ch.asInstanceOf[MessageChannel], groupid, mcch.get, user, dcp, toggles,
brtoggles.asScala.map(TBMCSystemChatEvent.BroadcastTarget.get).filter(Objects.nonNull).toSet) brtoggles.asScala.map(TBMCSystemChatEvent.BroadcastTarget.get).filter(Objects.nonNull).toSet)
()
}) })
} }
} }

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.role package buttondevteam.discordplugin.role
import buttondevteam.core.ComponentManager import buttondevteam.core.ComponentManager
import buttondevteam.discordplugin.DPUtils.{FluxExtensions, MonoExtensions}
import buttondevteam.discordplugin.{DPUtils, DiscordPlugin} import buttondevteam.discordplugin.{DPUtils, DiscordPlugin}
import buttondevteam.lib.architecture.{Component, ComponentMetadata} import buttondevteam.lib.architecture.{Component, ComponentMetadata}
import discord4j.core.`object`.entity.Role import discord4j.core.`object`.entity.Role
@ -8,10 +9,10 @@ import discord4j.core.`object`.entity.channel.MessageChannel
import discord4j.core.event.domain.role.{RoleCreateEvent, RoleDeleteEvent, RoleEvent, RoleUpdateEvent} import discord4j.core.event.domain.role.{RoleCreateEvent, RoleDeleteEvent, RoleEvent, RoleUpdateEvent}
import discord4j.rest.util.Color import discord4j.rest.util.Color
import org.bukkit.Bukkit import org.bukkit.Bukkit
import reactor.core.publisher.Mono import reactor.core.scala.publisher.SMono
import java.util.Collections import java.util.Collections
import java.util.stream.Collectors import scala.jdk.CollectionConverters.SeqHasAsJava
/** /**
* Automatically collects roles with a certain color. * Automatically collects roles with a certain color.
@ -23,31 +24,31 @@ import java.util.stream.Collectors
if (grm == null) return if (grm == null) return
val GameRoles = grm.GameRoles val GameRoles = grm.GameRoles
val logChannel = grm.logChannel.get val logChannel = grm.logChannel.get
val notMainServer = (r: Role) => r.getGuildId.asLong != DiscordPlugin.mainServer.getId.asLong val notMainServer = (_: Role).getGuildId.asLong != DiscordPlugin.mainServer.getId.asLong
roleEvent match { roleEvent match {
case roleCreateEvent: RoleCreateEvent => Bukkit.getScheduler.runTaskLaterAsynchronously(DiscordPlugin.plugin, () => { case roleCreateEvent: RoleCreateEvent => Bukkit.getScheduler.runTaskLaterAsynchronously(DiscordPlugin.plugin, () => {
def foo(): Unit = { val role = roleCreateEvent.getRole
val role = roleCreateEvent.getRole if (!notMainServer(role)) {
if (notMainServer(role)) return grm.isGameRole(role).flatMap(b => {
grm.isGameRole(role).flatMap((b: Boolean) => { if (!b) SMono.empty //Deleted or not a game role
def foo(b: Boolean): Mono[_] = { else {
if (!b) return Mono.empty //Deleted or not a game role
GameRoles.add(role.getName) GameRoles.add(role.getName)
if (logChannel != null) return logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Added " + role.getName + " as game role. If you don't want this, change the role's color from the game role color.")) if (logChannel != null)
Mono.empty logChannel.flatMap(_.createMessage("Added " + role.getName + " as game role." +
" If you don't want this, change the role's color from the game role color.").^^())
else
SMono.empty
} }
foo(b)
}).subscribe }).subscribe
()
} }
foo()
}, 100) }, 100)
case roleDeleteEvent: RoleDeleteEvent => case roleDeleteEvent: RoleDeleteEvent =>
val role = roleDeleteEvent.getRole.orElse(null) val role = roleDeleteEvent.getRole.orElse(null)
if (role == null) return if (role == null) return
if (notMainServer(role)) return if (notMainServer(role)) return
if (GameRoles.remove(role.getName) && logChannel != null) logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Removed " + role.getName + " as a game role.")).subscribe if (GameRoles.remove(role.getName) && logChannel != null)
logChannel.flatMap(_.createMessage("Removed " + role.getName + " as a game role.").^^()).subscribe
case roleUpdateEvent: RoleUpdateEvent => case roleUpdateEvent: RoleUpdateEvent =>
if (!roleUpdateEvent.getOld.isPresent) { if (!roleUpdateEvent.getOld.isPresent) {
grm.logWarn("Old role not stored, cannot update game role!") grm.logWarn("Old role not stored, cannot update game role!")
@ -56,20 +57,25 @@ import java.util.stream.Collectors
val or = roleUpdateEvent.getOld.get val or = roleUpdateEvent.getOld.get
if (notMainServer(or)) return if (notMainServer(or)) return
val cr = roleUpdateEvent.getCurrent val cr = roleUpdateEvent.getCurrent
grm.isGameRole(cr).flatMap((b: Boolean) => { grm.isGameRole(cr).flatMap(isGameRole => {
def foo(b: Boolean): Mono[_] = { if (!isGameRole)
if (!b) if (GameRoles.remove(or.getName) && logChannel != null) return logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Removed " + or.getName + " as a game role because its color changed.")) if (GameRoles.remove(or.getName) && logChannel != null)
else { logChannel.flatMap(_.createMessage("Removed " + or.getName + " as a game role because its color changed.").^^())
if (GameRoles.contains(or.getName) && or.getName == cr.getName) return Mono.empty else
val removed = GameRoles.remove(or.getName) //Regardless of whether it was a game role SMono.empty
GameRoles.add(cr.getName) //Add it because it has no color else if (GameRoles.contains(or.getName) && or.getName == cr.getName)
if (logChannel != null) if (removed) return logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Changed game role from " + or.getName + " to " + cr.getName + ".")) SMono.empty
else return logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Added " + cr.getName + " as game role because it has the color of one.")) else {
} val removed = GameRoles.remove(or.getName) //Regardless of whether it was a game role
Mono.empty GameRoles.add(cr.getName) //Add it because it has no color
if (logChannel != null)
if (removed)
logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Changed game role from " + or.getName + " to " + cr.getName + ".").^^())
else
logChannel.flatMap((ch: MessageChannel) => ch.createMessage("Added " + cr.getName + " as game role because it has the color of one.").^^())
else
SMono.empty
} }
foo(b)
}).subscribe }).subscribe
case _ => case _ =>
} }
@ -82,7 +88,7 @@ import java.util.stream.Collectors
override protected def enable(): Unit = { override protected def enable(): Unit = {
getPlugin.manager.registerCommand(command) getPlugin.manager.registerCommand(command)
GameRoles = DiscordPlugin.mainServer.getRoles.filterWhen(this.isGameRole _).map(_.getName).collect(Collectors.toList).block GameRoles = DiscordPlugin.mainServer.getRoles.^^().filterWhen(this.isGameRole).map(_.getName).collectSeq().block().asJava
} }
override protected def disable(): Unit = getPlugin.manager.unregisterCommand(command) override protected def disable(): Unit = getPlugin.manager.unregisterCommand(command)
@ -97,11 +103,12 @@ import java.util.stream.Collectors
*/ */
final private val roleColor = getConfig.getConfig[Color]("roleColor").`def`(Color.of(149, 165, 166)).getter((rgb: Any) => Color.of(Integer.parseInt(rgb.asInstanceOf[String].substring(1), 16))).setter((color: Color) => String.format("#%08x", color.getRGB)).buildReadOnly final private val roleColor = getConfig.getConfig[Color]("roleColor").`def`(Color.of(149, 165, 166)).getter((rgb: Any) => Color.of(Integer.parseInt(rgb.asInstanceOf[String].substring(1), 16))).setter((color: Color) => String.format("#%08x", color.getRGB)).buildReadOnly
private def isGameRole(r: Role): Mono[Boolean] = { private def isGameRole(r: Role): SMono[Boolean] = {
if (r.getGuildId.asLong != DiscordPlugin.mainServer.getId.asLong) return Mono.just(false) //Only allow on the main server if (r.getGuildId.asLong != DiscordPlugin.mainServer.getId.asLong) return SMono.just(false) //Only allow on the main server
val rc = roleColor.get val rc = roleColor.get
if (r.getColor equals rc) if (r.getColor equals rc)
DiscordPlugin.dc.getSelf.flatMap((u) => u.asMember(DiscordPlugin.mainServer.getId)).flatMap((m) => m.hasHigherRoles(Collections.singleton(r.getId))).defaultIfEmpty(false) //Below one of our roles DiscordPlugin.dc.getSelf.flatMap(u => u.asMember(DiscordPlugin.mainServer.getId)).^^()
else Mono.just(false) .flatMap(_.hasHigherRoles(Collections.singleton(r.getId)).^^().asInstanceOf).defaultIfEmpty(false) //Below one of our roles
else SMono.just(false)
} }
} }