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 18, 2024
2 parents bb5ac86 + 97d2086 commit 8fd7041
Show file tree
Hide file tree
Showing 79 changed files with 2,119 additions and 242 deletions.
14 changes: 10 additions & 4 deletions adapters/BasicAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ dependencies {
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("net.kyori:adventure-api:4.13.1")
compileOnly("net.kyori:adventure-text-minimessage:4.13.1")
compileOnly("net.kyori:adventure-api:4.15.0")
compileOnly("net.kyori:adventure-text-minimessage:4.15.0")

// External dependencies
compileOnly("org.geysermc.floodgate:api:2.2.0-SNAPSHOT")
Expand All @@ -48,6 +48,13 @@ java {
val javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = "$targetJavaVersion"
}
}

val copyTemplates by tasks.registering(Copy::class) {
Expand All @@ -70,6 +77,7 @@ task<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("buildAndMove")

group = "build"
description = "Builds the jar and moves it to the server folder"
outputs.upToDateWhen { false }

// Move the jar from the build/libs folder to the server/plugins folder
doLast {
Expand All @@ -85,8 +93,6 @@ task<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("buildRelease")
group = "build"
description = "Builds the jar and renames it"



doLast {
// Rename the jar to remove the version and -all
val jar = file("build/libs/%s-%s-all.jar".format(project.name, project.version))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlin.time.Duration.Companion.milliseconds

@Entry("boss_bar", "Boss Bar", Colors.GREEN, "carbon:progress-bar")
/**
* The `Boss Bar` is a display that shows a bar at the top of the screen.
* The `BossBarEntry` is a display that shows a bar at the top of the screen.
*
* ## How could this be used?
* This could be used to show objectives in a quest, or to show the progress of a task.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package me.gabber235.typewriter.entries.audience

import com.google.gson.annotations.SerializedName
import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.adapters.modifiers.Page
import me.gabber235.typewriter.entry.PageType
import me.gabber235.typewriter.entry.Ref
import me.gabber235.typewriter.entry.cinematic.isPlayingCinematic
import me.gabber235.typewriter.entry.entries.AudienceEntry
import me.gabber235.typewriter.entry.entries.AudienceFilter
import me.gabber235.typewriter.entry.entries.AudienceFilterEntry
import me.gabber235.typewriter.entry.ref
import me.gabber235.typewriter.events.AsyncCinematicEndEvent
import me.gabber235.typewriter.events.AsyncCinematicStartEvent
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler

@Entry(
"cinematic_audience",
"Filters an audience based on if they are in a cinematic",
Colors.MEDIUM_SEA_GREEN,
"mdi:movie"
)
/**
* The `Cinematic Audience` entry filters an audience based on if they are in a cinematic.
*
* If no cinematic is referenced, it will filter based on if any cinematic is active.
*
* ## How could this be used?
* This could be used to hide the sidebar or boss bar when a cinematic is playing.
*/
class CinematicAudienceEntry(
override val id: String = "",
override val name: String = "",
override val children: List<Ref<AudienceEntry>> = emptyList(),
@Help("When not set it will filter based on if any cinematic is active.")
@Page(PageType.CINEMATIC)
@SerializedName("cinematic")
val pageId: String = "",
@Help("When inverted, the audience will be filtered when not in a cinematic.")
val inverted: Boolean = false
) : AudienceFilterEntry {
override fun display(): AudienceFilter = CinematicAudienceFilter(
ref(),
pageId,
inverted,
)
}

class CinematicAudienceFilter(
ref: Ref<out AudienceFilterEntry>,
private val pageId: String,
private val inverted: Boolean,
) : AudienceFilter(ref) {
override fun filter(player: Player): Boolean {
val inCinematic = if (pageId.isNotBlank()) player.isPlayingCinematic(pageId) else player.isPlayingCinematic()
return if (inverted) !inCinematic else inCinematic
}

@EventHandler
fun onCinematicStart(event: AsyncCinematicStartEvent) {
if (pageId.isNotBlank() && event.pageId != pageId) return
event.player.updateFilter(!inverted)
}

@EventHandler
fun onCinematicEnd(event: AsyncCinematicEndEvent) {
if (pageId.isNotBlank() && event.pageId != pageId) return
event.player.updateFilter(inverted)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.gabber235.typewriter.entries.audience

import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Colored
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.adapters.modifiers.MultiLine
import me.gabber235.typewriter.adapters.modifiers.Placeholder
import me.gabber235.typewriter.entry.Ref
import me.gabber235.typewriter.entry.entries.*
import me.gabber235.typewriter.entry.ref
import me.gabber235.typewriter.extensions.placeholderapi.parsePlaceholders
import org.bukkit.entity.Player

@Entry("sidebar", "Display a sidebar for players", Colors.DARK_ORANGE, "mdi:page-layout-sidebar-right")
/**
* The `SidebarEntry` is a display that shows a sidebar to players.
*
* To display lines on the sidebar, use the `SidebarLinesEntry` as its descendants.
*
* ## How could this be used?
* This could be used to show a list of objectives, or the region a player is in.
*/
class SimpleSidebarEntry(
override val id: String = "",
override val name: String = "",
override val children: List<Ref<AudienceEntry>> = emptyList(),
override val title: String = "",
) : SidebarEntry {
override fun display(): AudienceFilter = PassThroughFilter(ref())
}

@Entry("simple_sidebar_lines", "Lines for a sidebar", Colors.ORANGE_RED, "bi:layout-text-sidebar")
/**
* The `SimpleSidebarLinesEntry` is a display that shows lines on a sidebar.
*
* Separating lines with a newline character will display them on separate lines.
*
* ## How could this be used?
* This could be used to show a list of objectives, or the region a player is in.
*/
class SimpleSidebarLinesEntry(
override val id: String = "",
override val name: String = "",
@Help("The lines to display on the sidebar. Separate lines with a newline character.")
@Colored
@Placeholder
@MultiLine
val lines: String = "",
) : SidebarLinesEntry {
override fun lines(player: Player): String = lines.parsePlaceholders(player)
override fun display(): AudienceDisplay = PassThroughDisplay()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.gabber235.typewriter.entries.cinematic

import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChangeGameState
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerCloseWindow
import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Segments
Expand All @@ -8,22 +10,15 @@ import me.gabber235.typewriter.entry.cinematic.SimpleCinematicAction
import me.gabber235.typewriter.entry.entries.CinematicAction
import me.gabber235.typewriter.entry.entries.CinematicEntry
import me.gabber235.typewriter.entry.entries.Segment
import me.gabber235.typewriter.utils.EffectStateProvider
import me.gabber235.typewriter.utils.PlayerState
import me.gabber235.typewriter.utils.ThreadType.SYNC
import me.gabber235.typewriter.utils.restore
import me.gabber235.typewriter.utils.state
import me.gabber235.typewriter.extensions.packetevents.sendPacketTo
import org.bukkit.entity.Player
import org.bukkit.potion.PotionEffect
import org.bukkit.potion.PotionEffectType.BLINDNESS

@Entry("blinding_cinematic", "Blind the player so the screen looks black", Colors.CYAN, "heroicons-solid:eye-off")
/**
* The `Blinding Cinematic` entry is used to blind the player so the screen looks black.
*
* ## How could this be used?
* When starting a cinematic, if you have a [Camera Cinematic Entry](./camera_cinematic)
* where you wait for a few frames to get it loading in.
* Make the screen look black for the player during a cinematic.
*/
class BlindingCinematicEntry(
override val id: String,
Expand All @@ -48,40 +43,27 @@ data class BlindingSegment(

class BlindingCinematicAction(
private val player: Player,
entry: BlindingCinematicEntry,
private val entry: BlindingCinematicEntry,
) : SimpleCinematicAction<BlindingSegment>() {

private var state: PlayerState? = null

override val segments: List<BlindingSegment> = entry.segments

override suspend fun startSegment(segment: BlindingSegment) {
super.startSegment(segment)
state = player.state(EffectStateProvider(BLINDNESS))
override suspend fun tickSegment(segment: BlindingSegment, frame: Int) {
super.tickSegment(segment, frame)

SYNC.switchContext {
player.addPotionEffect(PotionEffect(BLINDNESS, 10000000, 1, false, false, false))
}
val packet = WrapperPlayServerChangeGameState(WrapperPlayServerChangeGameState.Reason.WIN_GAME, 1f)
packet.sendPacketTo(player)
}

override suspend fun stopSegment(segment: BlindingSegment) {
super.stopSegment(segment)
restoreState()
val packet = WrapperPlayServerCloseWindow(0)
packet.sendPacketTo(player)
}

private suspend fun restoreState() {
val state = state ?: return
this.state = null
SYNC.switchContext {
player.restore(state)
}
}

override suspend fun teardown() {
super.teardown()

if (state != null) {
restoreState()
}
val packet = WrapperPlayServerCloseWindow(0)
packet.sendPacketTo(player)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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.display.TextDisplayMeta
import me.tofaa.entitylib.meta.types.DisplayMeta
import org.bukkit.GameMode
import org.bukkit.Location
import org.bukkit.Particle
Expand Down Expand Up @@ -161,7 +161,6 @@ class CameraCinematicAction(
this blockPacket PacketType.Play.Client.CLICK_WINDOW_BUTTON
this blockPacket PacketType.Play.Client.USE_ITEM
this blockPacket PacketType.Play.Client.INTERACT_ENTITY

}

private suspend fun Player.teardown() {
Expand Down Expand Up @@ -206,7 +205,7 @@ private suspend inline fun Player.teleportIfNeeded(
location: Location,
) {
if (frame % 10 == 0 || location.distanceSquared(location) > MAX_DISTANCE_SQUARED) SYNC.switchContext {
teleport(location.highUpLocation)
teleport(location)
allowFlight = true
isFlying = true
}
Expand Down Expand Up @@ -236,7 +235,7 @@ private class DisplayCameraAction(
}

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

0 comments on commit 8fd7041

Please sign in to comment.