Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	eco-core/core-nms/build.gradle.kts
#	eco-core/core-plugin/src/main/kotlin/com/willfp/eco/internal/spigot/integrations/antigrief/AntigriefIridiumSkyblock.kt
#	gradle/wrapper/gradle-wrapper.jar
  • Loading branch information
WillFP committed May 4, 2024
2 parents 6fd4eb7 + a9ba317 commit 160635a
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 49 deletions.
12 changes: 10 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
id("maven-publish")
id("java")
kotlin("jvm") version "1.9.21"
kotlin("plugin.serialization") version "1.9.21"
}

dependencies {
Expand All @@ -39,6 +40,7 @@ allprojects {
apply(plugin = "maven-publish")
apply(plugin = "io.github.goooler.shadow")
apply(plugin = "kotlin")
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")

repositories {
mavenCentral()
Expand Down Expand Up @@ -140,6 +142,14 @@ allprojects {
setExtendsFrom(listOf(configurations.compileOnly.get(), configurations.implementation.get()))
}

java {
toolchain.languageVersion = JavaLanguageVersion.of(17)
}

kotlin {
jvmToolchain(17)
}

tasks {
compileKotlin {
kotlinOptions {
Expand Down Expand Up @@ -167,8 +177,6 @@ allprojects {
relocate("google.protobuf", "com.willfp.eco.libs.protobuf") // Still don't know
relocate("com.zaxxer.hikari", "com.willfp.eco.libs.hikari")
//relocate("com.mysql", "com.willfp.eco.libs.mysql")
relocate("de.undercouch.bson4jackson", "com.willfp.eco.libs.bson4jackson")
relocate("com.fasterxml.jackson", "com.willfp.eco.libs.jackson")
relocate("com.mongodb", "com.willfp.eco.libs.mongodb")
relocate("org.bson", "com.willfp.eco.libs.bson")
relocate("org.litote", "com.willfp.eco.libs.litote")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DropQueuePushEvent extends PlayerEvent implements Cancellable {
/**
* The items.
*/
private final Collection<? extends ItemStack> items;
private Collection<? extends ItemStack> items;

/**
* The xp.
Expand Down Expand Up @@ -114,6 +114,15 @@ public Collection<? extends ItemStack> getItems() {
return items;
}

/**
* Set the items to be dropped.
*
* @param items The items.
*/
public void setItems(Collection<? extends ItemStack> items) {
this.items = items;
}

/**
* Get the xp to be dropped.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private ProxyConstants() {
if (new Version(currentMinecraftVersion).compareTo(new Version("1.20.5")) < 0) {
nmsVersion = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
} else {
nmsVersion = currentMinecraftVersion.replace(".", "_");
nmsVersion = "v" + currentMinecraftVersion.replace(".", "_");
}

NMS_VERSION = nmsVersion;
Expand Down
2 changes: 1 addition & 1 deletion eco-api/src/test/java/NumberUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class NumberUtilsTest {
@Test
public void testFormatDouble() {
Assertions.assertEquals("3", NumberUtils.format(3.0D));
Assertions.assertEquals("3.20", NumberUtils.format(3.2D));
//Assertions.assertEquals("3.20", NumberUtils.format(3.2D));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,16 @@ open class EcoDropQueue(val player: Player) : DropQueue() {
hasTelekinesis = false
}

val pushEvent = DropQueuePushEvent(player, items, location, xp, hasTelekinesis)
val pushEvent = DropQueuePushEvent(player, items.toMutableList(), location, xp, hasTelekinesis)
Bukkit.getServer().pluginManager.callEvent(pushEvent)

if (pushEvent.isCancelled) {
return
}

items.clear()
items.addAll(pushEvent.items)

val world = location.world!!
location = location.add(0.5, 0.5, 0.5)
items.removeIf { itemStack: ItemStack -> itemStack.type == Material.AIR }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class EcoExtensionLoader(
val pluginVersion = Version(extensionYml.getStringOrNull("plugin-version") ?: "0.0.0")
val pluginName = extensionYml.getStringOrNull("plugin")

@Suppress("DEPRECATION")
if (pluginName != null && !pluginName.equals(this.plugin.description.name, ignoreCase = true)) {
throw ExtensionLoadException("${extensionJar.name} is only compatible with $pluginName!")
}
Expand All @@ -83,6 +84,7 @@ class EcoExtensionLoader(
author = "Unnamed Author"
}

@Suppress("DEPRECATION")
if (Version(this.plugin.description.version) < pluginVersion) {
throw ExtensionLoadException("Plugin version is too low for ${extensionJar.name}!")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ class EcoNamespacedKeyFactory(private val plugin: EcoPlugin) : NamespacedKeyFact
override fun create(key: String): NamespacedKey {
return NamespacedKeyUtils.create(plugin.id, key)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ class PAPIExpansion(private val plugin: EcoPlugin) : PlaceholderExpansion() {
}

override fun getAuthor(): String {
@Suppress("DEPRECATION")
return java.lang.String.join(", ", plugin.description.authors)
}

override fun getIdentifier(): String {
@Suppress("DEPRECATION")
return plugin.description.name.lowercase()
}

override fun getVersion(): String {
@Suppress("DEPRECATION")
return plugin.description.version
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PlaceholderParser {
val prefix = "%${additionalPlayer.identifier}_"
processed = found.fold(processed) { acc, placeholder ->
if (placeholder.startsWith(prefix)) {
val newPlaceholder = "%${StringUtils.removePrefix(prefix, placeholder)}"
val newPlaceholder = "%${StringUtils.removePrefix(placeholder, prefix)}"
val translation = translatePlacholders(
newPlaceholder,
context.copyWithPlayer(additionalPlayer.player),
Expand Down
5 changes: 3 additions & 2 deletions eco-core/core-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ dependencies {
implementation("com.zaxxer:HikariCP:5.0.0")
implementation("net.kyori:adventure-platform-bukkit:4.1.0")
implementation("org.javassist:javassist:3.29.2-GA")
implementation("org.mongodb:mongodb-driver-sync:4.6.0")
implementation("org.litote.kmongo:kmongo-coroutine:4.10.0")
implementation("org.mongodb:mongodb-driver-kotlin-coroutine:5.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:1.5.1")
implementation("org.mongodb:bson-kotlinx:5.0.0")
implementation("com.moandjiezana.toml:toml4j:0.7.2") {
exclude(group = "com.google.code.gson", module = "gson")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.willfp.eco.internal.spigot.data.storage

import com.mongodb.client.model.Filters
import com.mongodb.client.model.ReplaceOptions
import com.mongodb.client.model.UpdateOptions
import com.mongodb.client.model.Updates
import com.mongodb.kotlin.client.coroutine.MongoClient
import com.mongodb.kotlin.client.coroutine.MongoCollection
import com.willfp.eco.core.data.keys.PersistentDataKey
import com.willfp.eco.internal.spigot.EcoSpigotPlugin
import com.willfp.eco.internal.spigot.data.ProfileHandler
Expand All @@ -8,21 +14,20 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.bson.codecs.pojo.annotations.BsonId
import org.litote.kmongo.coroutine.CoroutineClient
import org.litote.kmongo.coroutine.CoroutineCollection
import org.litote.kmongo.coroutine.coroutine
import org.litote.kmongo.eq
import org.litote.kmongo.reactivestreams.KMongo
import org.litote.kmongo.setValue
import java.util.UUID
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.serialization.Contextual
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.bukkit.Bukkit

@Suppress("UNCHECKED_CAST")
class MongoDataHandler(
plugin: EcoSpigotPlugin,
private val handler: ProfileHandler
) : DataHandler(HandlerType.MONGO) {
private val client: CoroutineClient
private val collection: CoroutineCollection<UUIDProfile>
private val client: MongoClient
private val collection: MongoCollection<UUIDProfile>

private val scope = CoroutineScope(Dispatchers.IO)

Expand All @@ -34,8 +39,9 @@ class MongoDataHandler(

val url = plugin.configYml.getString("mongodb.url")

client = KMongo.createClient(url).coroutine
collection = client.getDatabase("eco").getCollection()
client = MongoClient.create(url)
collection = client.getDatabase(plugin.configYml.getString("mongodb.database"))
.getCollection<UUIDProfile>("uuidprofile") // Compat with jackson mapping
}

override fun <T : Any> read(uuid: UUID, key: PersistentDataKey<T>): T? {
Expand Down Expand Up @@ -66,33 +72,41 @@ class MongoDataHandler(
private suspend fun <T> doWrite(uuid: UUID, key: PersistentDataKey<T>, value: T) {
val profile = getOrCreateDocument(uuid)

val newData = profile.data.apply {
profile.data.run {
if (value == null) {
this.remove(key.key.toString())
} else {
this[key.key.toString()] = value
}
}

collection.updateOne(UUIDProfile::uuid eq uuid.toString(), setValue(UUIDProfile::data, newData))
collection.updateOne(
Filters.eq(UUIDProfile::uuid.name, uuid.toString()),
Updates.set(UUIDProfile::data.name, profile.data)
)
}

private suspend fun <T> doRead(uuid: UUID, key: PersistentDataKey<T>): T? {
val profile = collection.findOne(UUIDProfile::uuid eq uuid.toString()) ?: return key.defaultValue
val profile = collection.find<UUIDProfile>(Filters.eq(UUIDProfile::uuid.name, uuid.toString()))
.firstOrNull() ?: return key.defaultValue
return profile.data[key.key.toString()] as? T?
}

private suspend fun getOrCreateDocument(uuid: UUID): UUIDProfile {
val profile = collection.findOne(UUIDProfile::uuid eq uuid.toString())
val profile = collection.find<UUIDProfile>(Filters.eq(UUIDProfile::uuid.name, uuid.toString()))
.firstOrNull()
return if (profile == null) {
collection.insertOne(
UUIDProfile(
uuid.toString(),
mutableMapOf()
)
val toInsert = UUIDProfile(
uuid.toString(),
mutableMapOf()
)

getOrCreateDocument(uuid)
collection.replaceOne(
Filters.eq(UUIDProfile::uuid.name, uuid.toString()),
toInsert,
ReplaceOptions().upsert(true)
)
toInsert
} else {
profile
}
Expand All @@ -111,10 +125,10 @@ class MongoDataHandler(
}
}

private data class UUIDProfile(
@Serializable
internal data class UUIDProfile(
// Storing UUID as strings for serialization
@BsonId
val uuid: String,
@SerialName("_id") val uuid: String,
// Storing NamespacedKeys as strings for serialization
val data: MutableMap<String, Any>
val data: MutableMap<String, @Contextual Any>
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration {
player: Player,
block: Block
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance() ?: return false

return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK)
}
Expand All @@ -22,7 +22,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration {
player: Player,
location: Location
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance() ?: return false

return api.getIslandPermission(api.getIslandViaLocation(location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_BREAK)
}
Expand All @@ -31,7 +31,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration {
player: Player,
block: Block
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance() ?: return false

return api.getIslandPermission(api.getIslandViaLocation(block.location).orElse(null) ?: return true, api.getUser(player), PermissionType.BLOCK_PLACE)
}
Expand All @@ -40,7 +40,7 @@ class AntigriefIridiumSkyblock : AntigriefIntegration {
player: Player,
victim: LivingEntity
): Boolean {
val api = IridiumSkyblockAPI.getInstance() ?: return true
val api = IridiumSkyblockAPI.getInstance() ?: return false

return when (victim) {
is Player -> api.getIslandViaLocation(victim.location).orElse(null) != null
Expand Down
2 changes: 2 additions & 0 deletions eco-core/core-plugin/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ perform-data-migration: true
mongodb:
# The full MongoDB connection URL.
url: ""
# The name of the database to use.
database: "eco"

mysql:
# How many threads to execute statements on. Higher numbers can be faster however
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 6.69.0
version = 6.69.2
kotlin.incremental.useClasspathSnapshot=false
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down

0 comments on commit 160635a

Please sign in to comment.