From aa07567fb9fd54200b108c4a53cf6733d1424eea Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Sun, 18 Feb 2024 07:12:28 +0100 Subject: [PATCH 1/5] Upgrade EntityLib --- adapters/BasicAdapter/build.gradle.kts | 5 ++++- .../entries/cinematic/CameraCinematicEntry.kt | 22 ++++++++++--------- adapters/VaultAdapter/build.gradle.kts | 2 -- plugin/build.gradle.kts | 2 +- .../me/gabber235/typewriter/Typewriter.kt | 13 +++++++++-- .../extensions/packetevents/PlayerPackets.kt | 7 +++--- 6 files changed, 32 insertions(+), 19 deletions(-) diff --git a/adapters/BasicAdapter/build.gradle.kts b/adapters/BasicAdapter/build.gradle.kts index e6058081c4..1c5ad06ffb 100644 --- a/adapters/BasicAdapter/build.gradle.kts +++ b/adapters/BasicAdapter/build.gradle.kts @@ -16,6 +16,9 @@ repositories { maven("https://oss.sonatype.org/content/groups/public/") maven("https://libraries.minecraft.net/") maven { url = uri("https://repo.papermc.io/repository/maven-public/") } + // PacketEvents + maven("https://repo.codemc.io/repository/maven-releases/") + // Anvil GUI (Sub dependency of LirandAPI) maven("https://repo.codemc.io/repository/maven-snapshots/") maven("https://repo.opencollab.dev/maven-snapshots/") } @@ -29,7 +32,7 @@ dependencies { // Already included in the TypeWriter plugin compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.0-RC") compileOnly("com.github.dyam0:LirandAPI:96cc59d4fb") - compileOnly("com.github.Tofaa2.EntityLib:EntityLib:1.2.4-SNAPSHOT") + compileOnly("com.github.Tofaa2.EntityLib:spigot:2.0.1-SNAPSHOT") compileOnly("net.kyori:adventure-api:4.15.0") compileOnly("net.kyori:adventure-text-minimessage:4.15.0") diff --git a/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/cinematic/CameraCinematicEntry.kt b/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/cinematic/CameraCinematicEntry.kt index e703e59e9e..5de20ffaa6 100644 --- a/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/cinematic/CameraCinematicEntry.kt +++ b/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/cinematic/CameraCinematicEntry.kt @@ -19,8 +19,9 @@ import me.gabber235.typewriter.utils.* import me.gabber235.typewriter.utils.GenericPlayerStateProvider.* import me.gabber235.typewriter.utils.ThreadType.SYNC import me.tofaa.entitylib.EntityLib -import me.tofaa.entitylib.entity.WrapperEntity -import me.tofaa.entitylib.meta.types.DisplayMeta +import me.tofaa.entitylib.meta.display.TextDisplayMeta +import me.tofaa.entitylib.spigot.SpigotEntityLibAPI +import me.tofaa.entitylib.wrapper.WrapperEntity import org.bukkit.GameMode import org.bukkit.Location import org.bukkit.Particle @@ -235,9 +236,10 @@ private class DisplayCameraAction( } private fun createEntity(): WrapperEntity { - return EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ITEM_DISPLAY).meta { - positionRotationInterpolationDuration = BASE_INTERPOLATION - } + return EntityLib.getApi().createEntity(EntityTypes.TEXT_DISPLAY) + .meta { + positionRotationInterpolationDuration = BASE_INTERPOLATION + } } private fun setupPath(segment: CameraSegment) { @@ -250,13 +252,13 @@ private class DisplayCameraAction( override suspend fun startSegment(segment: CameraSegment) { setupPath(segment) - entity.addViewer(player.uniqueId) SYNC.switchContext { player.teleport(path.first().location) } entity.spawn(path.first().location.toPacketLocation()) + entity.addViewer(player.uniqueId) player.spectateEntity(entity) } @@ -281,22 +283,22 @@ private class DisplayCameraAction( private suspend fun switchSeamless() { val newEntity = createEntity() - newEntity.addViewer(player.uniqueId) newEntity.spawn(path.first().location.toPacketLocation()) + newEntity.addViewer(player.uniqueId) SYNC.switchContext { player.teleport(path.first().location) player.spectateEntity(newEntity) } + entity.despawn() entity.remove() - EntityLib.removeEntity(entity) entity = newEntity } private suspend fun switchWithStop() { player.stopSpectatingEntity() - entity.remove() + entity.despawn() entity.addViewer(player.uniqueId) SYNC.switchContext { player.teleport(path.first().location) @@ -307,8 +309,8 @@ private class DisplayCameraAction( override suspend fun stop() { player.stopSpectatingEntity() + entity.despawn() entity.remove() - EntityLib.removeEntity(entity) } } diff --git a/adapters/VaultAdapter/build.gradle.kts b/adapters/VaultAdapter/build.gradle.kts index 772184cdaf..0792927896 100644 --- a/adapters/VaultAdapter/build.gradle.kts +++ b/adapters/VaultAdapter/build.gradle.kts @@ -18,8 +18,6 @@ repositories { maven { url = uri("https://repo.papermc.io/repository/maven-public/") } maven("https://repo.codemc.io/repository/maven-snapshots/") maven("https://repo.opencollab.dev/maven-snapshots/") - maven("https://jitpack.io/") - // Adapter Specific } diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index c214a41332..b1d9d9c20b 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -49,7 +49,7 @@ dependencies { compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT") implementation("com.github.dyam0:LirandAPI:96cc59d4fb") - implementation("com.github.Tofaa2.EntityLib:EntityLib:1.2.4-SNAPSHOT") + implementation("com.github.Tofaa2.EntityLib:spigot:2.0.1-SNAPSHOT") // Doesn't want to load properly using the spigot api. implementation("io.ktor:ktor-server-core-jvm:2.3.6") diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/Typewriter.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/Typewriter.kt index 75781eb01d..328d32f400 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/Typewriter.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/Typewriter.kt @@ -25,7 +25,9 @@ import me.gabber235.typewriter.snippets.SnippetDatabaseImpl import me.gabber235.typewriter.ui.* import me.gabber235.typewriter.utils.createBukkitDataParser import me.gabber235.typewriter.utils.syncCommands +import me.tofaa.entitylib.APIConfig import me.tofaa.entitylib.EntityLib +import me.tofaa.entitylib.spigot.SpigotEntityLibPlatform import org.bukkit.plugin.Plugin import org.koin.core.component.KoinComponent import org.koin.core.component.get @@ -98,8 +100,15 @@ class Typewriter : KotlinPlugin(), KoinComponent { server.pluginManager.disablePlugin(this) return } - EntityLib.init(PacketEvents.getAPI()) - EntityLib.setEntityIdProvider(entityId::getAndIncrement) + + val platform = SpigotEntityLibPlatform(this) + val settings = APIConfig(PacketEvents.getAPI()) + .debugMode() + .useAsyncEvents() + .usePlatformLogger() + .tickTickables() + + EntityLib.init(platform, settings) get().initialize() get().initialize() diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/extensions/packetevents/PlayerPackets.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/extensions/packetevents/PlayerPackets.kt index ced6beee01..9d88600e7a 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/extensions/packetevents/PlayerPackets.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/extensions/packetevents/PlayerPackets.kt @@ -7,10 +7,9 @@ import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerCa import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation.EntityAnimationType.SWING_MAIN_ARM import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityAnimation.EntityAnimationType.SWING_OFF_HAND -import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityRotation import me.gabber235.typewriter.capture.capturers.ArmSwing -import me.tofaa.entitylib.entity.WrapperEntity import me.tofaa.entitylib.meta.EntityMeta +import me.tofaa.entitylib.wrapper.WrapperEntity import org.bukkit.Location import org.bukkit.entity.Player @@ -38,9 +37,11 @@ fun Player.swingArm(entityId: Int, armSwing: ArmSwing) { } inline fun WrapperEntity.meta(editor: E.() -> Unit): WrapperEntity { - val meta = meta + val meta = entityMeta if (meta is E) { + meta.setNotifyAboutChanges(false) editor(meta) + meta.setNotifyAboutChanges(true) } return this } From 57aafab0eda15f40d9bdb9cef90c4e5d423f3642 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Mon, 19 Feb 2024 08:56:06 +0100 Subject: [PATCH 2/5] [86bxhhrym] Bind confirmation key for recording --- .../gabber235/typewriter/capture/CinematicRecorder.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/capture/CinematicRecorder.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/capture/CinematicRecorder.kt index d4bd37051e..62131f974f 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/capture/CinematicRecorder.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/capture/CinematicRecorder.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.CompletableDeferred import lirand.api.extensions.events.SimpleListener import lirand.api.extensions.events.listen import lirand.api.extensions.events.unregister +import me.gabber235.typewriter.entry.dialogue.confirmationKey import me.gabber235.typewriter.entry.entries.CinematicStartTrigger import me.gabber235.typewriter.entry.triggerFor import me.gabber235.typewriter.events.AsyncCinematicEndEvent @@ -15,7 +16,6 @@ import net.kyori.adventure.key.Key import net.kyori.adventure.sound.Sound import org.bukkit.entity.Player import org.bukkit.event.Listener -import org.bukkit.event.player.PlayerSwapHandItemsEvent import java.util.* @@ -56,7 +56,7 @@ class CinematicRecorder( val completer = CompletableDeferred() val bossBar = BossBar.bossBar( - "Waiting ${capturer.title}: Press to start recording".asMini(), + "Waiting ${capturer.title}: Press ${confirmationKey.keybind} to start recording".asMini(), 1f, BossBar.Color.BLUE, BossBar.Overlay.PROGRESS @@ -65,20 +65,18 @@ class CinematicRecorder( player.playSound(Sound.sound(Key.key("block.beacon.activate"), Sound.Source.MASTER, 1f, 1f)) val listener = SimpleListener() - plugin.listen(listener, block = this::onSwapHandItems) + confirmationKey.listen(listener, player.uniqueId, block = this::onConfirmation) plugin.listen(listener, block = this::onTick) plugin.listen(listener, block = this::onCinematicEnd) return RecordingData(completer, bossBar, listener) } - private fun onSwapHandItems(event: PlayerSwapHandItemsEvent) { - if (event.player.uniqueId != player.uniqueId) return + private fun onConfirmation() { if (data == null) return if (state != RecordingState.WAITING_FOR_START) return startCinematic() - event.isCancelled = true } private fun startCinematic() { From 719046ca801485823e31f6d945d6541ab5cc740d Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Mon, 19 Feb 2024 10:19:10 +0100 Subject: [PATCH 3/5] Make modifiers more ressilient --- .../typewriter/adapters/FieldModifiers.kt | 32 ++++++++++--- .../modifiers/CaptureModifierComputer.kt | 19 +++----- .../modifiers/ColoredModifierComputer.kt | 17 ++++--- .../EntrySelectorModifierComputer.kt | 47 ------------------- .../modifiers/GeneratedModifierComputer.kt | 17 ++++--- .../modifiers/HelpModifierComputer.kt | 5 +- .../typewriter/adapters/modifiers/Icon.kt | 5 +- .../modifiers/MaterialModifierComputer.kt | 19 ++++---- .../modifiers/MultiLineModifierComputer.kt | 17 ++++--- .../modifiers/OnlyTagsModifierComputer.kt | 29 ++++++++++++ .../modifiers/PageModifierComputer.kt | 15 +++--- .../modifiers/PlaceholderModifierComputer.kt | 15 +++--- .../modifiers/RegexModifierComputer.kt | 15 +++--- .../modifiers/SegmentModifierComputer.kt | 19 ++++---- .../modifiers/SizeModifierComputer.kt | 5 +- .../modifiers/SnakeCaseModifierComputer.kt | 15 +++--- .../modifiers/StaticModifierComputer.kt | 45 +++++++++++------- .../modifiers/WithRotationModifierComputer.kt | 17 ++++--- .../me/gabber235/typewriter/utils/Result.kt | 1 + 19 files changed, 177 insertions(+), 177 deletions(-) delete mode 100644 plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/EntrySelectorModifierComputer.kt create mode 100644 plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/OnlyTagsModifierComputer.kt diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/FieldModifiers.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/FieldModifiers.kt index adb0291c08..2b3e3a4c30 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/FieldModifiers.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/FieldModifiers.kt @@ -2,6 +2,7 @@ package me.gabber235.typewriter.adapters import com.google.gson.JsonObject import me.gabber235.typewriter.adapters.modifiers.* +import me.gabber235.typewriter.logger import java.lang.reflect.Field @@ -72,7 +73,7 @@ sealed interface FieldModifier { } interface ModifierComputer { - fun compute(field: Field, info: FieldInfo): FieldModifier? + fun compute(field: Field, info: FieldInfo): Result /** * Checks if the given field is a list and tries to compute the modifier for the list's type. @@ -83,7 +84,8 @@ interface ModifierComputer { */ fun innerComputeForList(field: Field, info: FieldInfo): FieldModifier? { if (info !is ListField) return null - return compute(field, info.type)?.let { FieldModifier.InnerListModifier(it) } + val modifier = compute(field, info.type).getOrNull() ?: return null + return FieldModifier.InnerListModifier(modifier) } /** @@ -95,8 +97,8 @@ interface ModifierComputer { */ fun innerComputeForMap(field: Field, info: FieldInfo): FieldModifier? { if (info !is MapField) return null - val keyModifier = compute(field, info.key) - val valueModifier = compute(field, info.value) + val keyModifier = compute(field, info.key).onFailure { return null }.getOrNull() + val valueModifier = compute(field, info.value).onFailure { return null }.getOrNull() if (keyModifier == null && valueModifier == null) return null return FieldModifier.InnerMapModifier(keyModifier, valueModifier) @@ -112,7 +114,10 @@ interface ModifierComputer { fun innerComputeForCustom(field: Field, info: FieldInfo): FieldModifier? { if (info !is CustomField) return null val customInfo = info.fieldInfo ?: return null - return compute(field, customInfo)?.let { FieldModifier.InnerCustomModifier(it) } + val modifier = compute(field, customInfo) + .getOrNull() + ?: return null + return FieldModifier.InnerCustomModifier(modifier) } /** @@ -123,7 +128,12 @@ interface ModifierComputer { * @param info The info of the field */ fun innerCompute(field: Field, info: FieldInfo): FieldModifier? { - return innerComputeForList(field, info) ?: innerComputeForMap(field, info) ?: innerComputeForCustom(field, info) + return when (info) { + is ListField -> innerComputeForList(field, info) + is MapField -> innerComputeForMap(field, info) + is CustomField -> innerComputeForCustom(field, info) + else -> null + } } } @@ -155,5 +165,13 @@ private val computers: List by lazy { * display the field differently. */ fun computeFieldModifiers(field: Field, info: FieldInfo) { - computers.mapNotNull { it.compute(field, info) }.forEach { it.appendModifier(info) } + computers.mapNotNull { computer -> + val result = computer.compute(field, info) + if (result.isSuccess) { + result.getOrNull() + } else { + logger.warning("Failed to compute modifier ${computer::class.simpleName} for field ${field.name} in ${field.declaringClass.simpleName}: ${result.exceptionOrNull()?.message}") + null + } + }.forEach { it.appendModifier(info) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/CaptureModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/CaptureModifierComputer.kt index d50a795508..cd1033300c 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/CaptureModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/CaptureModifierComputer.kt @@ -4,7 +4,8 @@ import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.capture.Capturer import me.gabber235.typewriter.capture.CapturerCreator -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok import kotlin.reflect.KClass import kotlin.reflect.full.companionObject import kotlin.reflect.full.isSubclassOf @@ -16,25 +17,19 @@ annotation class Capture(val capturer: KClass>) object CaptureModifierComputer : StaticModifierComputer { override val annotationClass: Class = Capture::class.java - override fun computeModifier(annotation: Capture, info: FieldInfo): FieldModifier? { + override fun computeModifier(annotation: Capture, info: FieldInfo): Result { val capturer = annotation.capturer val name = capturer.qualifiedName - - if (name == null) { - logger.warning("Capturer ${capturer.jvmName} does not have a qualified name! It must be a non-local non-anonymous class.") - return null - } + ?: return failure("Capturer ${capturer.jvmName} does not have a qualified name! It must be a non-local non-anonymous class.") if (capturer.companionObject == null) { - logger.warning("Capturer ${capturer.jvmName} needs to have a companion object which extends CapturerCreator<${capturer.simpleName}>! It has no companion object.") - return null + return failure("Capturer ${capturer.jvmName} needs to have a companion object which extends CapturerCreator<${capturer.simpleName}>! It has no companion object.") } if (capturer.companionObject?.isSubclassOf(CapturerCreator::class) != true) { - logger.warning("Capturer ${capturer.jvmName} needs to have a companion object which extends CapturerCreator<${capturer.simpleName}>! Forgot to extend CapturerCreator?") - return null + return failure("Capturer ${capturer.jvmName} needs to have a companion object which extends CapturerCreator<${capturer.simpleName}>! Forgot to extend CapturerCreator?") } - return FieldModifier.DynamicModifier("capture", name) + return ok(FieldModifier.DynamicModifier("capture", name)) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/ColoredModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/ColoredModifierComputer.kt index 0b0cfe1740..ac308a6e8d 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/ColoredModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/ColoredModifierComputer.kt @@ -4,7 +4,8 @@ import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) annotation class Colored @@ -12,20 +13,18 @@ annotation class Colored object ColoredModifierComputer : StaticModifierComputer { override val annotationClass: Class = Colored::class.java - override fun computeModifier(annotation: Colored, info: FieldInfo): FieldModifier { - // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + override fun computeModifier(annotation: Colored, info: FieldInfo): Result { + // If the field is wrapped in a list or other container, we try if the inner type can be modified + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("Colored annotation can only be used on strings (including in lists or maps)!") - return FieldModifier.StaticModifier("colored") + return failure("Colored annotation can only be used on strings (including in lists or maps)!") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("Colored annotation can only be used on strings (including in lists or maps)!") - return FieldModifier.StaticModifier("colored") + return failure("Colored annotation can only be used on strings (including in lists or maps)!") } - return FieldModifier.StaticModifier("colored") + return ok(FieldModifier.StaticModifier("colored")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/EntrySelectorModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/EntrySelectorModifierComputer.kt deleted file mode 100644 index 9223186c50..0000000000 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/EntrySelectorModifierComputer.kt +++ /dev/null @@ -1,47 +0,0 @@ -package me.gabber235.typewriter.adapters.modifiers - -import me.gabber235.typewriter.adapters.* -import me.gabber235.typewriter.adapters.FieldModifier.DynamicModifier -import me.gabber235.typewriter.entry.Entry -import me.gabber235.typewriter.logger -import kotlin.reflect.KClass - -@Deprecated("Use Ref instead") -@Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY) -annotation class EntryIdentifier(val entry: KClass) - - -object EntrySelectorModifierComputer : StaticModifierComputer { - override val annotationClass: Class = EntryIdentifier::class.java - - override fun computeModifier(annotation: EntryIdentifier, info: FieldInfo): FieldModifier? { - // If the field is wrapped in a list or other container we try if the inner type can be modified - innerComputeForMap(annotation, info)?.let { return it } - innerComputeForMap(annotation, info)?.let { return it } - - val entry = annotation.entry - // Get the tag from the entry with annotation @Tags - val tag = entry.annotations.find { it is Tags }?.let { (it as Tags).tags.firstOrNull() } - if (tag == null) { - logger.warning("WARNING: Entry ${entry.simpleName} does not have a tag. It is needed for the StaticEntryIdentifier") - return null - } - - // If it is a list we want to add a modifier to the list itself so the interface knows - // that it should be a list of entries and allow the user to select multiple entries - innerComputeForList(annotation, info)?.let { - return FieldModifier.MultiModifier(it, DynamicModifier("entry-list", tag)) - } - - if (info !is PrimitiveField) { - logger.warning("StaticEntryIdentifier can only be used on a string field") - return null - } - if (info.type != PrimitiveFieldType.STRING) { - logger.warning("StaticEntryIdentifier can only be used on a string field") - return null - } - - return DynamicModifier("entry", tag) - } -} \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/GeneratedModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/GeneratedModifierComputer.kt index e3d347fe08..adbde8591c 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/GeneratedModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/GeneratedModifierComputer.kt @@ -4,7 +4,8 @@ import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) annotation class Generated @@ -12,20 +13,18 @@ annotation class Generated object GeneratedModifierComputer : StaticModifierComputer { override val annotationClass: Class = Generated::class.java - override fun computeModifier(annotation: Generated, info: FieldInfo): FieldModifier? { - // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + override fun computeModifier(annotation: Generated, info: FieldInfo): Result { + // If the field is wrapped in a list or other container, we try if the inner type can be modified + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("Generated annotation can only be used on strings (including in lists or maps)!") - return null + return failure("Generated annotation can only be used on strings (including in lists or maps)!") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("Generated annotation can only be used on strings (including in lists or maps)!") - return null + return failure("Generated annotation can only be used on strings (including in lists or maps)!") } - return FieldModifier.StaticModifier("generated") + return ok(FieldModifier.StaticModifier("generated")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/HelpModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/HelpModifierComputer.kt index 30ee53bbcc..4f5488c1f3 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/HelpModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/HelpModifierComputer.kt @@ -3,6 +3,7 @@ package me.gabber235.typewriter.adapters.modifiers import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.FieldModifier.DynamicModifier +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) annotation class Help(val text: String) @@ -10,7 +11,7 @@ annotation class Help(val text: String) object HelpModifierComputer : StaticModifierComputer { override val annotationClass: Class = Help::class.java - override fun computeModifier(annotation: Help, info: FieldInfo): FieldModifier { - return DynamicModifier("help", annotation.text) + override fun computeModifier(annotation: Help, info: FieldInfo): Result { + return ok(DynamicModifier("help", annotation.text)) } } diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/Icon.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/Icon.kt index be58c018cd..22c0e221fd 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/Icon.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/Icon.kt @@ -2,6 +2,7 @@ package me.gabber235.typewriter.adapters.modifiers import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER) annotation class Icon(val icon: String) @@ -9,7 +10,7 @@ annotation class Icon(val icon: String) object IconModifierComputer : StaticModifierComputer { override val annotationClass: Class = Icon::class.java - override fun computeModifier(annotation: Icon, info: FieldInfo): FieldModifier { - return FieldModifier.DynamicModifier("icon", annotation.icon) + override fun computeModifier(annotation: Icon, info: FieldInfo): Result { + return ok(FieldModifier.DynamicModifier("icon", annotation.icon)) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MaterialModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MaterialModifierComputer.kt index c950e7f32c..586c2812ef 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MaterialModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MaterialModifierComputer.kt @@ -3,7 +3,8 @@ package me.gabber235.typewriter.adapters.modifiers import me.gabber235.typewriter.adapters.CustomField import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok enum class MaterialProperty { ITEM, @@ -30,22 +31,20 @@ annotation class MaterialProperties(vararg val properties: MaterialProperty) object MaterialPropertiesModifierComputer : StaticModifierComputer { override val annotationClass: Class = MaterialProperties::class.java - override fun computeModifier(annotation: MaterialProperties, info: FieldInfo): FieldModifier? { - // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + override fun computeModifier(annotation: MaterialProperties, info: FieldInfo): Result { + // If the field is wrapped in a list or other container, we try if the inner type can be modified + innerCompute(annotation, info)?.let { return ok(it) } if (info !is CustomField) { - logger.warning("MaterialProperties annotation can only be used on custom fields") - return null + return failure("MaterialProperties annotation can only be used on custom fields") } if (info.editor != "material") { - logger.warning("MaterialProperties annotation can only be used materials (not on ${info.editor})") - return null + return failure("MaterialProperties annotation can only be used materials (not on ${info.editor})") } - return FieldModifier.DynamicModifier( + return ok(FieldModifier.DynamicModifier( "material_properties", annotation.properties.joinToString(";") { it.name.lowercase() } - ) + )) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MultiLineModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MultiLineModifierComputer.kt index 0b57b9d777..a9036bc941 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MultiLineModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/MultiLineModifierComputer.kt @@ -5,7 +5,8 @@ import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.FieldModifier.StaticModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY) annotation class MultiLine @@ -13,19 +14,17 @@ annotation class MultiLine object MultiLineModifierComputer : StaticModifierComputer { override val annotationClass: Class = MultiLine::class.java - override fun computeModifier(annotation: MultiLine, info: FieldInfo): FieldModifier? { - // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + override fun computeModifier(annotation: MultiLine, info: FieldInfo): Result { + // If the field is wrapped in a list or other container, we try if the inner type can be modified + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("MultiLine annotation can only be used on strings") - return null + return failure("MultiLine annotation can only be used on strings") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("MultiLine annotation can only be used on strings") - return null + return failure("MultiLine annotation can only be used on strings") } - return StaticModifier("multiline") + return ok(StaticModifier("multiline")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/OnlyTagsModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/OnlyTagsModifierComputer.kt new file mode 100644 index 0000000000..68e8688003 --- /dev/null +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/OnlyTagsModifierComputer.kt @@ -0,0 +1,29 @@ +package me.gabber235.typewriter.adapters.modifiers + +import me.gabber235.typewriter.adapters.CustomField +import me.gabber235.typewriter.adapters.FieldInfo +import me.gabber235.typewriter.adapters.FieldModifier +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok + +@Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER) +annotation class OnlyTags(vararg val tags: String) + +object OnlyTagsModifierComputer : StaticModifierComputer { + override val annotationClass: Class = OnlyTags::class.java + + override fun computeModifier(annotation: OnlyTags, info: FieldInfo): Result { + // If the field is wrapped in a list or other container, we try if the inner type can be modified + innerCompute(annotation, info)?.let { return ok(it) } + + if (info !is CustomField) { + return failure("OnlyTags annotation can only be used on Refs (including in lists or maps)!") + } + + if (info.editor != "entryReference") { + return failure("OnlyTags annotation can only be used on Refs (including in lists or maps)!") + } + + return ok(FieldModifier.DynamicModifier("only_tags", annotation.tags.joinToString(","))) + } +} \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PageModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PageModifierComputer.kt index 7f08632965..fb2014ade0 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PageModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PageModifierComputer.kt @@ -5,7 +5,8 @@ import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType import me.gabber235.typewriter.entry.PageType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER) annotation class Page(val type: PageType) @@ -13,19 +14,17 @@ annotation class Page(val type: PageType) object PageModifierComputer : StaticModifierComputer { override val annotationClass: Class = Page::class.java - override fun computeModifier(annotation: Page, info: FieldInfo): FieldModifier? { - innerCompute(annotation, info)?.let { return it } + override fun computeModifier(annotation: Page, info: FieldInfo): Result { + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("Page annotation can only be used on primitive fields") - return null + return failure("Page annotation can only be used on primitive fields") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("Page annotation can only be used on string fields") - return null + return failure("Page annotation can only be used on string fields") } - return FieldModifier.DynamicModifier("page", annotation.type.id) + return ok(FieldModifier.DynamicModifier("page", annotation.type.id)) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PlaceholderModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PlaceholderModifierComputer.kt index c176dfc142..1375aa33de 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PlaceholderModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/PlaceholderModifierComputer.kt @@ -4,7 +4,8 @@ import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) @@ -13,20 +14,18 @@ annotation class Placeholder object PlaceholderModifierComputer : StaticModifierComputer { override val annotationClass: Class = Placeholder::class.java - override fun computeModifier(annotation: Placeholder, info: FieldInfo): FieldModifier { + override fun computeModifier(annotation: Placeholder, info: FieldInfo): Result { // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("Placeholder annotation can only be used on strings (including in lists or maps)!") - return FieldModifier.StaticModifier("placeholder") + return failure("Placeholder annotation can only be used on strings (including in lists or maps)!") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("Placeholder annotation can only be used on strings (including in lists or maps)!") - return FieldModifier.StaticModifier("placeholder") + return failure("Placeholder annotation can only be used on strings (including in lists or maps)!") } - return FieldModifier.StaticModifier("placeholder") + return ok(FieldModifier.StaticModifier("placeholder")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/RegexModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/RegexModifierComputer.kt index 0c64e0cdb8..01c566ac5c 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/RegexModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/RegexModifierComputer.kt @@ -4,27 +4,26 @@ import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) annotation class Regex object RegexModifierComputer : StaticModifierComputer { override val annotationClass: Class = Regex::class.java - override fun computeModifier(annotation: Regex, info: FieldInfo): FieldModifier { + override fun computeModifier(annotation: Regex, info: FieldInfo): Result { // If the field is wrapped in a list or other container, we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("Regex annotation can only be used on strings (including in lists or maps)!") - return FieldModifier.StaticModifier("regex") + return failure("Regex annotation can only be used on strings (including in lists or maps)!") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("Regex annotation can only be used on strings (including in lists or maps)!") - return FieldModifier.StaticModifier("regex") + return failure("Regex annotation can only be used on strings (including in lists or maps)!") } - return FieldModifier.StaticModifier("regex") + return ok(FieldModifier.StaticModifier("regex")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SegmentModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SegmentModifierComputer.kt index ca107f6551..0bd2afe562 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SegmentModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SegmentModifierComputer.kt @@ -4,7 +4,8 @@ import com.google.gson.JsonObject import me.gabber235.typewriter.adapters.* import me.gabber235.typewriter.adapters.FieldModifier.DynamicModifier import me.gabber235.typewriter.adapters.FieldModifier.InnerListModifier -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER) annotation class Segments(val color: String = Colors.CYAN, val icon: String = "fa6-solid:star") @@ -12,26 +13,22 @@ annotation class Segments(val color: String = Colors.CYAN, val icon: String = "f object SegmentModifierComputer : StaticModifierComputer { override val annotationClass: Class = Segments::class.java - override fun computeModifier(annotation: Segments, info: FieldInfo): FieldModifier? { + override fun computeModifier(annotation: Segments, info: FieldInfo): Result { if (info !is ListField) { - logger.warning("Segment annotation can only be used on lists") - return null + return failure("Segment annotation can only be used on lists") } val type = info.type if (type !is ObjectField) { - logger.warning("Segment annotation can only be used on lists of objects") - return null + return failure("Segment annotation can only be used on lists of objects") } val startFrame = type.fields["startFrame"] val endFrame = type.fields["endFrame"] if (startFrame !is PrimitiveField || endFrame !is PrimitiveField) { - logger.warning("Segment annotation can only be used on lists of objects with startFrame and endFrame fields") - return null + return failure("Segment annotation can only be used on lists of objects with startFrame and endFrame fields") } if (startFrame.type != PrimitiveFieldType.INTEGER || endFrame.type != PrimitiveFieldType.INTEGER) { - logger.warning("Segment annotation can only be used on lists of objects with startFrame and endFrame fields of type int") - return null + return failure("Segment annotation can only be used on lists of objects with startFrame and endFrame fields of type int") } val color = annotation.color @@ -42,7 +39,7 @@ object SegmentModifierComputer : StaticModifierComputer { addProperty("icon", icon) } - return InnerListModifier(DynamicModifier("segment", data)) + return ok(InnerListModifier(DynamicModifier("segment", data))) } } diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SizeModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SizeModifierComputer.kt index 3ab29e3f77..690d1bdd91 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SizeModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SizeModifierComputer.kt @@ -2,6 +2,7 @@ package me.gabber235.typewriter.adapters.modifiers import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.PROPERTY, AnnotationTarget.FIELD, AnnotationTarget.VALUE_PARAMETER) annotation class Min(val value: Int) @@ -23,8 +24,8 @@ object MinModifierComputer : StaticModifierComputer { ) as List> - override fun computeModifier(annotation: Min, info: FieldInfo): FieldModifier { - return FieldModifier.DynamicModifier("min", annotation.value) + override fun computeModifier(annotation: Min, info: FieldInfo): Result { + return ok(FieldModifier.DynamicModifier("min", annotation.value)) } } diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SnakeCaseModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SnakeCaseModifierComputer.kt index 38454b3f1c..753fb799aa 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SnakeCaseModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/SnakeCaseModifierComputer.kt @@ -5,7 +5,8 @@ import me.gabber235.typewriter.adapters.FieldModifier import me.gabber235.typewriter.adapters.FieldModifier.StaticModifier import me.gabber235.typewriter.adapters.PrimitiveField import me.gabber235.typewriter.adapters.PrimitiveFieldType -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) @@ -14,19 +15,17 @@ annotation class SnakeCase object SnakeCaseModifierComputer : StaticModifierComputer { override val annotationClass: Class = SnakeCase::class.java - override fun computeModifier(annotation: SnakeCase, info: FieldInfo): FieldModifier? { + override fun computeModifier(annotation: SnakeCase, info: FieldInfo): Result { // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + innerCompute(annotation, info)?.let { return ok(it) } if (info !is PrimitiveField) { - logger.warning("SnakeCase annotation can only be used on strings (including in lists or maps)!") - return null + return failure("SnakeCase annotation can only be used on strings (including in lists or maps)!") } if (info.type != PrimitiveFieldType.STRING) { - logger.warning("SnakeCase annotation can only be used on strings (including in lists or maps)!") - return null + return failure("SnakeCase annotation can only be used on strings (including in lists or maps)!") } - return StaticModifier("snake_case") + return ok(StaticModifier("snake_case")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/StaticModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/StaticModifierComputer.kt index 04e2ddd423..54f9fcd2e4 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/StaticModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/StaticModifierComputer.kt @@ -1,6 +1,7 @@ package me.gabber235.typewriter.adapters.modifiers import me.gabber235.typewriter.adapters.* +import me.gabber235.typewriter.utils.ok import java.lang.reflect.Field import kotlin.reflect.full.findAnnotations import kotlin.reflect.full.findParameterByName @@ -27,15 +28,15 @@ interface StaticModifierComputer : ModifierComputer { val annotationClass: Class val innerAnnotationFinders: List> get() = emptyList() - fun computeModifier(annotation: A, info: FieldInfo): FieldModifier? + fun computeModifier(annotation: A, info: FieldInfo): Result - override fun compute(field: Field, info: FieldInfo): FieldModifier? { + override fun compute(field: Field, info: FieldInfo): Result { findAnnotation(field, annotationClass)?.let { annotation -> return computeModifier(annotation, info) } if (info !is ListField && info !is MapField && info !is ObjectField) { - return null + return ok(null) } innerAnnotationFinders.forEach { finder -> @@ -43,19 +44,26 @@ interface StaticModifierComputer : ModifierComputer { val innerAnnotation = finder.transformer(annotation) if (info is ListField && finder.types.contains(InnerModifierType.LIST)) { - computeModifier(innerAnnotation, info.type)?.let { return FieldModifier.InnerListModifier(it) } + computeModifier(innerAnnotation, info.type).onSuccess { modifier -> + return ok(modifier?.let { FieldModifier.InnerListModifier(it) }) + } + .onFailure { return ok(null) } } if (info is MapField && finder.types.contains(InnerModifierType.MAP)) { - val keyModifier = computeModifier(innerAnnotation, info.key) - val valueModifier = computeModifier(innerAnnotation, info.value) + val keyModifier = computeModifier(innerAnnotation, info.key).onFailure { return ok(null) }.getOrNull() + val valueModifier = + computeModifier(innerAnnotation, info.value).onFailure { return ok(null) }.getOrNull() - return FieldModifier.InnerMapModifier(keyModifier, valueModifier) + return ok(FieldModifier.InnerMapModifier(keyModifier, valueModifier)) } if (info is ObjectField && finder.types.contains(InnerModifierType.OBJECT)) { - computeModifier(innerAnnotation, info)?.let { return FieldModifier.InnerCustomModifier(it) } + computeModifier(innerAnnotation, info).onSuccess { modifier -> + return ok(modifier?.let { FieldModifier.InnerCustomModifier(it) }) + } + .onFailure { return ok(null) } } } - return null + return ok(null) } fun findAnnotation(field: Field, annotationClass: Class): T? { @@ -85,7 +93,8 @@ interface StaticModifierComputer : ModifierComputer { */ fun innerComputeForList(annotation: A, info: FieldInfo): FieldModifier? { if (info !is ListField) return null - return computeModifier(annotation, info.type)?.let { FieldModifier.InnerListModifier(it) } + val modifier = computeModifier(annotation, info.type).getOrNull() ?: return null + return FieldModifier.InnerListModifier(modifier) } /** @@ -97,8 +106,8 @@ interface StaticModifierComputer : ModifierComputer { */ fun innerComputeForMap(annotation: A, info: FieldInfo): FieldModifier? { if (info !is MapField) return null - val keyModifier = computeModifier(annotation, info.key) - val valueModifier = computeModifier(annotation, info.value) + val keyModifier = computeModifier(annotation, info.key).getOrNull() + val valueModifier = computeModifier(annotation, info.value).getOrNull() if (keyModifier == null && valueModifier == null) return null return FieldModifier.InnerMapModifier(keyModifier, valueModifier) @@ -114,7 +123,8 @@ interface StaticModifierComputer : ModifierComputer { fun innerComputeForCustom(annotation: A, info: FieldInfo): FieldModifier? { if (info !is CustomField) return null val customInfo = info.fieldInfo ?: return null - return computeModifier(annotation, customInfo)?.let { FieldModifier.InnerCustomModifier(it) } + val modifier = computeModifier(annotation, customInfo).getOrNull() ?: return null + return FieldModifier.InnerCustomModifier(modifier) } /** @@ -125,9 +135,12 @@ interface StaticModifierComputer : ModifierComputer { * @param info The info of the field */ fun innerCompute(annotation: A, info: FieldInfo): FieldModifier? { - return innerComputeForList(annotation, info) - ?: innerComputeForMap(annotation, info) - ?: innerComputeForCustom(annotation, info) + return when (info) { + is ListField -> innerComputeForList(annotation, info) + is MapField -> innerComputeForMap(annotation, info) + is CustomField -> innerComputeForCustom(annotation, info) + else -> null + } } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/WithRotationModifierComputer.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/WithRotationModifierComputer.kt index 59322d4f7a..1c23067335 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/WithRotationModifierComputer.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/adapters/modifiers/WithRotationModifierComputer.kt @@ -3,7 +3,8 @@ package me.gabber235.typewriter.adapters.modifiers import me.gabber235.typewriter.adapters.CustomField import me.gabber235.typewriter.adapters.FieldInfo import me.gabber235.typewriter.adapters.FieldModifier -import me.gabber235.typewriter.logger +import me.gabber235.typewriter.utils.failure +import me.gabber235.typewriter.utils.ok @Target(AnnotationTarget.FIELD, AnnotationTarget.PROPERTY, AnnotationTarget.VALUE_PARAMETER) annotation class WithRotation @@ -11,19 +12,17 @@ annotation class WithRotation object WithRotationModifierComputer : StaticModifierComputer { override val annotationClass: Class = WithRotation::class.java - override fun computeModifier(annotation: WithRotation, info: FieldInfo): FieldModifier? { - // If the field is wrapped in a list or other container we try if the inner type can be modified - innerCompute(annotation, info)?.let { return it } + override fun computeModifier(annotation: WithRotation, info: FieldInfo): Result { + // If the field is wrapped in a list or other container, we try if the inner type can be modified + innerCompute(annotation, info)?.let { return ok(it) } if (info !is CustomField) { - logger.warning("WithRotation annotation can only be used on locations (including in lists or maps)!") - return null + return failure("WithRotation annotation can only be used on locations (including in lists or maps)!") } if (info.editor != "location") { - logger.warning("WithRotation annotation can only be used on locations (including in lists or maps)!") - return null + return failure("WithRotation annotation can only be used on locations (including in lists or maps)!") } - return FieldModifier.StaticModifier("with_rotation") + return ok(FieldModifier.StaticModifier("with_rotation")) } } \ No newline at end of file diff --git a/plugin/src/main/kotlin/me/gabber235/typewriter/utils/Result.kt b/plugin/src/main/kotlin/me/gabber235/typewriter/utils/Result.kt index 889b6318c1..79c9480c18 100644 --- a/plugin/src/main/kotlin/me/gabber235/typewriter/utils/Result.kt +++ b/plugin/src/main/kotlin/me/gabber235/typewriter/utils/Result.kt @@ -3,6 +3,7 @@ package me.gabber235.typewriter.utils fun ok(value: T): Result = Result.success(value) fun failure(error: String): Result = Result.failure(Exception(error)) +fun failure(error: Throwable): Result = Result.failure(error) inline operator fun Result.invoke(onFailure: (Result) -> Nothing): O { From 9368e959e3ee800449b9e415f5125cfe8519d934 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Mon, 19 Feb 2024 10:22:00 +0100 Subject: [PATCH 4/5] Build documenatiation on develop --- .github/workflows/build-documentation.yml | 4 ++- .../workflows/test-build-documentation.yml | 27 ------------------- 2 files changed, 3 insertions(+), 28 deletions(-) delete mode 100644 .github/workflows/test-build-documentation.yml diff --git a/.github/workflows/build-documentation.yml b/.github/workflows/build-documentation.yml index b4ef918544..cfc51f3872 100644 --- a/.github/workflows/build-documentation.yml +++ b/.github/workflows/build-documentation.yml @@ -3,7 +3,9 @@ name: Deploy to GitHub Pages on: push: branches: - - main + - develop + paths: + - "documentation/**" jobs: deploy: diff --git a/.github/workflows/test-build-documentation.yml b/.github/workflows/test-build-documentation.yml deleted file mode 100644 index aaec265060..0000000000 --- a/.github/workflows/test-build-documentation.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Test Documentation deployment - -on: - pull_request: - branches: - - main - paths: - - "documentation/**" - -jobs: - test-deploy: - name: Test Documentation deployment - runs-on: ubuntu-latest - concurrency: test-documentation-deployment - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: npm - cache-dependency-path: ./documentation/package-lock.json - - name: Install dependencies - run: npm ci - working-directory: ./documentation - - name: Test build website - run: npm run build - working-directory: ./documentation From 08b7dd4d56e6c513ef7a740db2b28f7854295235 Mon Sep 17 00:00:00 2001 From: Gabber235 Date: Mon, 19 Feb 2024 10:23:42 +0100 Subject: [PATCH 5/5] Fix player near location detection --- .../entries/event/PlayerNearLocationEventEntry.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/event/PlayerNearLocationEventEntry.kt b/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/event/PlayerNearLocationEventEntry.kt index 70339e5356..77962f301d 100644 --- a/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/event/PlayerNearLocationEventEntry.kt +++ b/adapters/BasicAdapter/src/main/kotlin/me/gabber235/typewriter/entries/event/PlayerNearLocationEventEntry.kt @@ -1,5 +1,6 @@ package me.gabber235.typewriter.entries.event +import lirand.api.extensions.math.blockLocation import me.gabber235.typewriter.adapters.Colors import me.gabber235.typewriter.adapters.Entry import me.gabber235.typewriter.adapters.modifiers.Help @@ -35,7 +36,10 @@ fun onPlayerNearLocation(event: PlayerMoveEvent, query: Query - !event.from.isInRange(entry.location, entry.range) && event.to.isInRange(entry.location, entry.range) + !event.from.blockLocation.isInRange( + entry.location, + entry.range + ) && event.to.blockLocation.isInRange(entry.location, entry.range) } startDialogueWithOrNextDialogue event.player }