Skip to content

Commit

Permalink
More edits and finalize implementation, add owo_lib for future ui
Browse files Browse the repository at this point in the history
  • Loading branch information
bibi-reden committed Feb 19, 2024
1 parent 6ecc6bf commit ef9a3e9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
projectile_damage_attribute_version=3.2.2+1.20.1
owo_version=0.11.2+1.20
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/edelweiss/playerex/cache/PlayerEXCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface PlayerEXCache {
companion object {
/** Registers the provided cached value to the server. */
fun <V>register(key: CachedPlayerValue<V>): CachedPlayerValue<V> {
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)
}

Expand All @@ -27,14 +27,14 @@ interface PlayerEXCache {
fun <V>get(playerName: String, key: CachedPlayerValue<V>) {}

/** Returns all offline & online player UUIDs. */
fun playerIDs(): Set<UUID>
fun playerIDs(): Collection<UUID>

/** Returns all offline & online player names. */
fun playerNames(): Set<String>
fun playerNames(): Collection<String>

/** 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID> {
TODO("Not yet implemented")
}
override fun playerIDs() = this.internal!!.playerIDs(this.server)

override fun playerNames(): Set<String> {
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ object PlayerEXCacheCommands {

private fun <T>nullKeyMessage(id: T): () -> MutableText = { Text.literal("$id -> <null_key>").formatted(Formatting.RED) }

private fun playerIDMessage(cache: PlayerEXCacheInternal, id: Either<String, UUID>?, function: () -> MutableText): () -> MutableText = {
private fun playerIDMessage(cache: PlayerEXCacheInternal, stringOrUUID: Either<String, UUID>?, function: () -> MutableText): () -> MutableText = {
var formattedID = "<invalid_id>"
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())
Expand All @@ -66,14 +66,14 @@ object PlayerEXCacheCommands {
val uuidOrString: Either<String, UUID>? = 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
Expand Down

0 comments on commit ef9a3e9

Please sign in to comment.