Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/gabber235/TypeWriter int…
Browse files Browse the repository at this point in the history
…o develop
  • Loading branch information
Marten-Mrfc committed Feb 19, 2024
2 parents 59558f2 + 08b7dd4 commit a806db5
Show file tree
Hide file tree
Showing 29 changed files with 221 additions and 231 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build-documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ name: Deploy to GitHub Pages
on:
push:
branches:
- main
- develop
paths:
- "documentation/**"

jobs:
deploy:
Expand Down
27 changes: 0 additions & 27 deletions .github/workflows/test-build-documentation.yml

This file was deleted.

5 changes: 4 additions & 1 deletion adapters/BasicAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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/")
}
Expand All @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -235,9 +236,10 @@ private class DisplayCameraAction(
}

private fun createEntity(): WrapperEntity {
return EntityLib.createEntity(UUID.randomUUID(), EntityTypes.ITEM_DISPLAY).meta<DisplayMeta> {
positionRotationInterpolationDuration = BASE_INTERPOLATION
}
return EntityLib.getApi<SpigotEntityLibAPI>().createEntity<WrapperEntity>(EntityTypes.TEXT_DISPLAY)
.meta<TextDisplayMeta> {
positionRotationInterpolationDuration = BASE_INTERPOLATION
}
}

private fun setupPath(segment: CameraSegment) {
Expand All @@ -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)
}

Expand All @@ -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)
Expand All @@ -307,8 +309,8 @@ private class DisplayCameraAction(

override suspend fun stop() {
player.stopSpectatingEntity()
entity.despawn()
entity.remove()
EntityLib.removeEntity(entity)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,7 +36,10 @@ fun onPlayerNearLocation(event: PlayerMoveEvent, query: Query<PlayerNearLocation
if (!event.hasChangedBlock()) return

query findWhere { entry ->
!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
}

Expand Down
2 changes: 0 additions & 2 deletions adapters/VaultAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
13 changes: 11 additions & 2 deletions plugin/src/main/kotlin/me/gabber235/typewriter/Typewriter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<EntryDatabase>().initialize()
get<StagingManager>().initialize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -72,7 +73,7 @@ sealed interface FieldModifier {
}

interface ModifierComputer {
fun compute(field: Field, info: FieldInfo): FieldModifier?
fun compute(field: Field, info: FieldInfo): Result<FieldModifier?>

/**
* Checks if the given field is a list and tries to compute the modifier for the list's type.
Expand All @@ -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)
}

/**
Expand All @@ -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)
Expand All @@ -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)
}

/**
Expand All @@ -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
}
}
}

Expand Down Expand Up @@ -155,5 +165,13 @@ private val computers: List<ModifierComputer> 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) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,25 +17,19 @@ annotation class Capture(val capturer: KClass<out Capturer<*>>)
object CaptureModifierComputer : StaticModifierComputer<Capture> {
override val annotationClass: Class<Capture> = Capture::class.java

override fun computeModifier(annotation: Capture, info: FieldInfo): FieldModifier? {
override fun computeModifier(annotation: Capture, info: FieldInfo): Result<FieldModifier?> {
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ 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

object ColoredModifierComputer : StaticModifierComputer<Colored> {
override val annotationClass: Class<Colored> = 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<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 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"))
}
}
Loading

0 comments on commit a806db5

Please sign in to comment.