From ef9a3e9a0ccc33e2fce812ff742189da8bae467a Mon Sep 17 00:00:00 2001 From: Edelweiss Date: Sun, 18 Feb 2024 21:07:22 -0600 Subject: [PATCH] More edits and finalize implementation, add owo_lib for future ui --- build.gradle | 3 +++ gradle.properties | 3 ++- .../playerex/mixin/LevelPropertiesMixin.java | 1 - .../edelweiss/playerex/PlayerEXDirectorsCut.kt | 3 +-- .../edelweiss/playerex/cache/PlayerEXCache.kt | 8 ++++---- .../playerex/cache/PlayerEXCacheProvider.kt | 18 +++++------------- .../playerex/commands/PlayerEXCacheCommands.kt | 16 ++++++++-------- 7 files changed, 23 insertions(+), 29 deletions(-) diff --git a/build.gradle b/build.gradle index 01101698..f3cd3137 100644 --- a/build.gradle +++ b/build.gradle @@ -61,6 +61,9 @@ dependencies { modImplementation "maven.modrinth:projectile-damage-attribute:${project.projectile_damage_attribute_version}-fabric" modImplementation include("maven.modrinth:AdditionalEntityAttributes:${project.additional_entity_attributes_version}") + + annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}") + include "io.wispforest:owo-sentinel:${project.owo_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index dc02876b..6335ada3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,4 +16,5 @@ archives_base_name=playerex-directors-cut fabric_version=0.92.0+1.20.1 cardinal_components_version=5.2.2 additional_entity_attributes_version=1.7.0+1.20.0 -projectile_damage_attribute_version=3.2.2+1.20.1 \ No newline at end of file +projectile_damage_attribute_version=3.2.2+1.20.1 +owo_version=0.11.2+1.20 \ No newline at end of file diff --git a/src/main/java/com/edelweiss/playerex/mixin/LevelPropertiesMixin.java b/src/main/java/com/edelweiss/playerex/mixin/LevelPropertiesMixin.java index f624b9da..aa08b1be 100644 --- a/src/main/java/com/edelweiss/playerex/mixin/LevelPropertiesMixin.java +++ b/src/main/java/com/edelweiss/playerex/mixin/LevelPropertiesMixin.java @@ -13,7 +13,6 @@ import net.minecraft.world.level.LevelInfo; import net.minecraft.world.level.LevelProperties; import net.minecraft.world.level.storage.SaveVersionInfo; -import org.jetbrains.annotations.NotNull; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; diff --git a/src/main/kotlin/com/edelweiss/playerex/PlayerEXDirectorsCut.kt b/src/main/kotlin/com/edelweiss/playerex/PlayerEXDirectorsCut.kt index 11e88682..83d61ea7 100644 --- a/src/main/kotlin/com/edelweiss/playerex/PlayerEXDirectorsCut.kt +++ b/src/main/kotlin/com/edelweiss/playerex/PlayerEXDirectorsCut.kt @@ -8,8 +8,7 @@ import org.slf4j.LoggerFactory object PlayerEXDirectorsCut : ModInitializer { const val MODID: String = "playerex" - - val logger = LoggerFactory.getLogger(MODID) + val LOGGER = LoggerFactory.getLogger(MODID)!! private fun registerCommands() = CommandRegistrationCallback.EVENT.register { dispatcher, _, _ -> val head = PlayerEXCommands.registerHead(dispatcher) diff --git a/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCache.kt b/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCache.kt index f249b8af..cb6eff76 100644 --- a/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCache.kt +++ b/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCache.kt @@ -8,7 +8,7 @@ interface PlayerEXCache { companion object { /** Registers the provided cached value to the server. */ fun register(key: CachedPlayerValue): CachedPlayerValue { - PlayerEXDirectorsCut.logger.debug("Cached Value has been registered: <{} :: #id: {}>", key, key.id()) + PlayerEXDirectorsCut.LOGGER.debug("Cached Value has been registered: <{} :: #id: {}>", key, key.id()) return PlayerEXCacheInternal.register(key) } @@ -27,14 +27,14 @@ interface PlayerEXCache { fun get(playerName: String, key: CachedPlayerValue) {} /** Returns all offline & online player UUIDs. */ - fun playerIDs(): Set + fun playerIDs(): Collection /** Returns all offline & online player names. */ - fun playerNames(): Set + fun playerNames(): Collection /** Checks if the player with the UUID is in the cache or not. */ fun isPlayerCached(uuid: UUID): Boolean /** Checks if the player with the name is in the cache or not. */ - fun isPlayerCached(playerName: String) + fun isPlayerCached(playerName: String): Boolean } \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCacheProvider.kt b/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCacheProvider.kt index e6b3d761..18647b0c 100644 --- a/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCacheProvider.kt +++ b/src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCacheProvider.kt @@ -8,21 +8,13 @@ class PlayerEXCacheProvider( private val internal: PlayerEXCacheInternal? = PlayerEXCacheInternal.ifCachePresent(server, null) { cache -> cache } ) : PlayerEXCache { /** Checks if the cache is "empty", as in being `null`. */ - fun isEmpty(): Boolean = this.internal == null + fun isEmpty() = this.internal == null - override fun playerIDs(): Set { - TODO("Not yet implemented") - } + override fun playerIDs() = this.internal!!.playerIDs(this.server) - override fun playerNames(): Set { - TODO("Not yet implemented") - } + override fun playerNames() = this.internal!!.playerNames(this.server) - override fun isPlayerCached(uuid: UUID): Boolean { - TODO("Not yet implemented") - } + override fun isPlayerCached(uuid: UUID) = this.internal!!.isPlayerCached(uuid) - override fun isPlayerCached(playerName: String) { - TODO("Not yet implemented") - } + override fun isPlayerCached(playerName: String) = this.internal!!.isPlayerCached(playerName) } \ No newline at end of file diff --git a/src/main/kotlin/com/edelweiss/playerex/commands/PlayerEXCacheCommands.kt b/src/main/kotlin/com/edelweiss/playerex/commands/PlayerEXCacheCommands.kt index f31b46f7..be03bea4 100644 --- a/src/main/kotlin/com/edelweiss/playerex/commands/PlayerEXCacheCommands.kt +++ b/src/main/kotlin/com/edelweiss/playerex/commands/PlayerEXCacheCommands.kt @@ -38,12 +38,12 @@ object PlayerEXCacheCommands { private fun nullKeyMessage(id: T): () -> MutableText = { Text.literal("$id -> ").formatted(Formatting.RED) } - private fun playerIDMessage(cache: PlayerEXCacheInternal, id: Either?, function: () -> MutableText): () -> MutableText = { + private fun playerIDMessage(cache: PlayerEXCacheInternal, stringOrUUID: Either?, function: () -> MutableText): () -> MutableText = { var formattedID = "" - id?.ifLeft { name -> - formattedID = "UUID: ${cache.playerNameToUUID[name]}\n" + "Name: $id" + stringOrUUID?.ifLeft { name -> + formattedID = "UUID: ${cache.playerNameToUUID[name]}\n" + "Name: $name" }?.ifRight { - uuid -> formattedID = "UUID: $id\n" + "Name: ${cache.playerNameToUUID.inverse()[uuid]}" + uuid -> formattedID = "UUID: $uuid\n" + "Name: ${cache.playerNameToUUID.inverse()[uuid]}" } Text.literal("$formattedID\n").formatted(Formatting.GREEN) .append(function()) @@ -66,14 +66,14 @@ object PlayerEXCacheCommands { val uuidOrString: Either? = if (id is String) Either.left(id) else { if (id is UUID) Either.right(id) else null } var fetchedValue: Any? = null + uuidOrString?.ifLeft { fetchedValue = cache.get(server, id as String, value) } + uuidOrString?.ifRight { fetchedValue = cache.get(server, id as UUID, value) } + ctx.source.sendFeedback( - playerIDMessage(cache, uuidOrString) { Text.literal("[$identifier] is ($value)").formatted(Formatting.WHITE) }, + playerIDMessage(cache, uuidOrString) { Text.literal("[$identifier] is ($fetchedValue)").formatted(Formatting.WHITE) }, false ) - uuidOrString?.ifLeft { fetchedValue = cache.get(server, id as String, value) } - uuidOrString?.ifRight { fetchedValue = cache.get(server, id as UUID, value) } - if (fetchedValue is Number) return@ifCachePresent abs(fetchedValue as Int) % 16 return@ifCachePresent 1