Fixes for Java/Scala compatibility bugs

This commit is contained in:
Norbi Peti 2023-04-24 22:54:33 +02:00
parent 5e1f378ec7
commit 260a67506a
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
13 changed files with 32 additions and 19 deletions

View file

@ -247,7 +247,7 @@
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<noprefix.version>1.0.1</noprefix.version>
<noprefix.version>2.0.0</noprefix.version>
<kotlin.version>1.8.20</kotlin.version>
</properties>
<scm>

View file

@ -26,7 +26,7 @@ import kotlin.properties.Delegates
]
)
class ScheduledRestartCommand : ICommand2MC() {
private var restartCounter = 0
public var restartCounter = 0
private lateinit var restartTask: BukkitTask
@Volatile

View file

@ -9,6 +9,7 @@ import org.bukkit.event.Event
import java.util.function.Supplier
object ChromaUtils {
@JvmStatic
fun getDisplayName(sender: CommandSender): String {
return when (sender) {
is IHaveFancyName -> sender.fancyName
@ -17,6 +18,7 @@ object ChromaUtils {
}
}
@JvmStatic
fun getFullDisplayName(sender: CommandSender): String {
return when (sender) {
is IHaveFancyName -> sender.fancyFullName
@ -24,6 +26,7 @@ object ChromaUtils {
}
}
@JvmStatic
fun convertNumber(number: Number, targetcl: Class<out Number>): Number {
return when {
targetcl == Long::class.javaPrimitiveType || Long::class.java.isAssignableFrom(targetcl) -> number.toLong()

View file

@ -14,40 +14,41 @@ import org.bukkit.event.HandlerList
*/
class TBMCChatEvent(
channel: Channel,
private val cm: ChatMessage,
public val chatMessage: ChatMessage,
rtr: RecipientTestResult
) : TBMCChatEventBase(channel, cm.message, rtr.score, rtr.groupID!!) {
) : TBMCChatEventBase(channel, chatMessage.message, rtr.score, rtr.groupID!!) {
private val isIgnoreSenderPermissions: Boolean get() = cm.permCheck !== cm.sender
private val isIgnoreSenderPermissions: Boolean get() = chatMessage.permCheck !== chatMessage.sender
/**
* This will allow the sender of the message if [.isIgnoreSenderPermissions] is true.
*/
override fun shouldSendTo(sender: CommandSender): Boolean {
return if (isIgnoreSenderPermissions && sender == cm.sender) true else super.shouldSendTo(sender) //Allow sending the message no matter what
return if (isIgnoreSenderPermissions && sender == chatMessage.sender) true else super.shouldSendTo(sender) //Allow sending the message no matter what
}
/**
* This will allow the sender of the message if [.isIgnoreSenderPermissions] is true.
*/
override fun getMCScore(sender: CommandSender): Int {
return if (isIgnoreSenderPermissions && sender == cm.sender) score else super.getMCScore(sender) //Send in the correct group no matter what
return if (isIgnoreSenderPermissions && sender == chatMessage.sender) score else super.getMCScore(sender) //Send in the correct group no matter what
}
/**
* This will allow the sender of the message if [.isIgnoreSenderPermissions] is true.
*/
override fun getGroupID(sender: CommandSender): String? {
return if (isIgnoreSenderPermissions && sender == cm.sender) groupID else super.getGroupID(sender) //Send in the correct group no matter what
return if (isIgnoreSenderPermissions && sender == chatMessage.sender) groupID else super.getGroupID(sender) //Send in the correct group no matter what
}
override fun getHandlers(): HandlerList {
return handlerList
}
val sender: CommandSender get() = cm.sender
val user: ChromaGamerBase get() = cm.user
val origin: String get() = cm.origin
val sender: CommandSender get() = chatMessage.sender
val user: ChromaGamerBase get() = chatMessage.user
val origin: String get() = chatMessage.origin
val isFromCommand get() = chatMessage.isFromCommand
companion object {
val handlerList = HandlerList()

View file

@ -25,9 +25,9 @@ class TBMCSystemChatEvent(
}
class BroadcastTarget private constructor(val name: String) {
companion object {
private val targets = HashSet<BroadcastTarget?>()
@JvmField
val ALL = BroadcastTarget("ALL")
@JvmStatic
@ -42,11 +42,13 @@ class TBMCSystemChatEvent(
targets.remove(target)
}
@JvmStatic
operator fun get(name: String?): BroadcastTarget? {
return targets.stream().filter { bt: BroadcastTarget? -> bt!!.name.equals(name, ignoreCase = true) }
.findAny().orElse(null)
}
@JvmStatic
fun stream(): Stream<BroadcastTarget?> {
return targets.stream()
}

View file

@ -37,7 +37,7 @@ abstract class ButtonPlugin : JavaPlugin() {
/**
* Called before the components are unregistered
*/
protected fun pluginPreDisable() {}
protected open fun pluginPreDisable() {}
override fun onEnable() {
if (!reloadIConfig()) {
logger.warning("Please fix the issues and restart the server to load the plugin.")

View file

@ -91,7 +91,7 @@ class IHaveConfig(
if (data == null) datamap[path] = ListConfigData(
this,
path,
def,
ArrayList(def),
elementGetter ?: Function { it as T },
elementSetter ?: Function { it },
readOnly

View file

@ -1,21 +1,21 @@
package buttondevteam.lib.architecture
import buttondevteam.lib.architecture.config.IConfigData
import java.util.ArrayList
import java.util.function.Function
import java.util.function.Predicate
import java.util.function.UnaryOperator
import kotlin.collections.List as KList
class ListConfigData<T> internal constructor(
config: IHaveConfig?,
path: String,
primitiveDef: kotlin.collections.List<*>,
primitiveDef: ArrayList<*>,
private val elementGetter: Function<Any?, T>,
private val elementSetter: Function<T, Any?>,
readOnly: Boolean
) : IConfigData<ListConfigData<T>.List> {
val listConfig: ConfigData<List> =
ConfigData(config, path, primitiveDef, { List((it as KList<*>).toMutableList()) }, { it }, readOnly)
ConfigData(config, path, primitiveDef, { List((it as ArrayList<*>).toMutableList()) }, { it }, readOnly)
override val path: String get() = listConfig.path

View file

@ -66,6 +66,7 @@ class ChatMessage internal constructor(
}
companion object {
@JvmStatic
fun builder(sender: CommandSender, user: ChromaGamerBase, message: String): ChatMessageBuilder {
return ChatMessageBuilder(
sender, user, message,

View file

@ -374,8 +374,8 @@ abstract class Command2<TC : ICommand2<TP>, TP : Command2Sender>(
* @param command The exact name of the command
* @return A command node
*/
fun getCommandNode(command: String): CoreCommandNode<TP, NoOpSubcommandData> { // TODO: What should this return? No-op? Executable? What's the use case?
return dispatcher.root.getChild(command).core()
fun getCommandNode(command: String): CoreCommandNode<TP, NoOpSubcommandData>? { // TODO: What should this return? No-op? Executable? What's the use case?
return dispatcher.root.getChild(command)?.core()
}
/**

View file

@ -25,6 +25,7 @@ object TBMCChatAPI {
* @return The event cancelled state
*/
@JvmOverloads
@JvmStatic
fun sendChatMessage(cm: ChatMessage, channel: Channel = cm.user.channel.get()): Boolean {
if (!channelList.contains(channel)) throw RuntimeException(
"Channel " + channel.displayName.get() + " not registered!"

View file

@ -240,6 +240,7 @@ abstract class ChromaGamerBase {
* @param foldername The folder to get the class from (like "minecraft")
* @return The type for the given folder name or null if not found
*/
@JvmStatic
fun getTypeForFolder(foldername: String?): Class<out ChromaGamerBase>? {
synchronized(staticDataMap) {
return staticDataMap.filter { (_, value) -> value.folder.equals(foldername, ignoreCase = true) }
@ -302,6 +303,7 @@ abstract class ChromaGamerBase {
*
* @param converter The converter that returns an object corresponding to the sender or null, if it's not the right type.
*/
@JvmStatic
fun addConverter(converter: Function<CommandSender, Optional<out ChromaGamerBase>>) {
senderConverters.add(0, converter)
}
@ -312,6 +314,7 @@ abstract class ChromaGamerBase {
* @param sender The sender to use
* @return A user as returned by a converter or null if none can supply it
*/
@JvmStatic
fun getFromSender(sender: CommandSender): ChromaGamerBase? { // TODO: Use Command2Sender
for (converter in senderConverters) {
val ocg = converter.apply(sender)

View file

@ -44,6 +44,7 @@ abstract class TBMCPlayerBase : ChromaGamerBase() {
* @param cl The type of the player
* @return The requested player object
*/
@JvmStatic
fun <T : TBMCPlayerBase> getPlayer(uuid: UUID, cl: Class<T>): T {
val player = getUser(uuid.toString(), cl)
check(player.uniqueId == uuid) { "Player UUID differs after converting from and to string..." }
@ -57,6 +58,7 @@ abstract class TBMCPlayerBase : ChromaGamerBase() {
* @return The [TBMCPlayer] object for the player
*/
@Suppress("deprecation")
@JvmStatic
fun <T : TBMCPlayerBase> getFromName(name: String, cl: Class<T>): T {
val p = Bukkit.getOfflinePlayer(name)
return getPlayer(p.uniqueId, cl)