Skip to content

Commit

Permalink
Merge pull request #130 from gabber235/develop
Browse files Browse the repository at this point in the history
Small tweaks and bugfixes
  • Loading branch information
gabber235 authored Feb 2, 2024
2 parents d2b6688 + f75402a commit ad0a6eb
Show file tree
Hide file tree
Showing 224 changed files with 9,253 additions and 1,380 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-adapter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
name: Build ${{ inputs.adapter }} Adapter
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/build-development-jars-and-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ on:
branches:
- main
paths:
- 'plugins/**'
- 'plugin/**'
- 'adapters/**'
- 'app/**'
- '.github/workflows/build-development-jars-and-publish.yml'
workflow_dispatch:

Expand All @@ -27,8 +28,8 @@ jobs:
id: vars
run: |
version=$(cat version.txt)
short_sha=$(echo $GITHUB_SHA | cut -c1-7)
full_version="${version}-dev-${short_sha}"
run_number=${{ github.run_number }}
full_version="${version}-dev-${run_number}"
echo $full_version > version.txt
echo "version=$full_version" >> $GITHUB_OUTPUT
- name: Build Plugin
Expand Down Expand Up @@ -65,6 +66,14 @@ jobs:
uses: ./.github/actions/build-adapter
with:
adapter: WorldGuardAdapter
- name: Build ZNPCsPlus Adapter
uses: ./.github/actions/build-adapter
with:
adapter: ZNPCsPlusAdapter
- name: Build FancyNpcs Adapter
uses: ./.github/actions/build-adapter
with:
adapter: FancyNpcsAdapter
- name: Publish Development Jars
uses: Kir-Antipov/[email protected]
id: publish
Expand All @@ -83,7 +92,7 @@ jobs:
purpur
game-versions: |
1.19.4
[1.20, 1.20.2]
[1.20, 1.20.4]
- name: Notify Discord
uses: sarisia/actions-status-discord@v1
with:
Expand Down
19 changes: 19 additions & 0 deletions .github/workflows/build-jars-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jobs:
- adapters/VaultAdapter/**
worldguard_adapter:
- adapters/WorldGuardAdapter/**
znpcs_adapter:
- adapters/ZNPCsPlusAdapter/**
fancynpcs_adapter:
- adapters/FancyNpcsAdapter/**
build-plugin:
name: Build Typewriter Plugin
Expand Down Expand Up @@ -107,3 +111,18 @@ jobs:
with:
adapter: WorldGuardAdapter

build-adapter-znpcs:
name: Build ZNPCsPlus Adapter
needs: changes
if: needs.changes.outputs.znpcs_adapter == 'true'
uses: ./.github/workflows/build-adapter.yml
with:
adapter: ZNPCsPlusAdapter

build-adapter-fancynpcs:
name: Build FancyNpcs Adapter
needs: changes
if: needs.changes.outputs.fancynpcs_adapter == 'true'
uses: ./.github/workflows/build-adapter.yml
with:
adapter: FancyNpcsAdapter
11 changes: 11 additions & 0 deletions .github/workflows/build-jars-on-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ jobs:
with:
adapter: WorldGuardAdapter

build-adapter-znpcs:
name: Build ZNPCsPlus Adapter
uses: ./.github/workflows/build-adapter.yml
with:
adapter: ZNPCsPlusAdapter

build-adapter-fancynpcs:
name: Build FancyNpcs Adapter
uses: ./.github/workflows/build-adapter.yml
with:
adapter: FancyNpcsAdapter
29 changes: 29 additions & 0 deletions .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Generate Sponsors README
on:
workflow_dispatch:
schedule:
# This is a cron schedule, it will run every day at 15:30. You can change this to whatever you want.x
- cron: 30 15 * * 0-6
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Checkout the repository
- name: Checkout 🛎️
uses: actions/checkout@v2

# Generate the sponsors
- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1
with:
token: ${{ secrets.PAT }}
file: 'README.md'
minimum: 1000

# Deploy the changes back to the main branch of the repository
- name: Deploy to GitHub Pages 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: main
# As we're deploying changes to our markdown files, this needs to be . to push the root directory back to the repository.
folder: '.'
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ The plugin can also be extended using adapters, which are [pre-made](https://gab

To get started with Typewriter, see the [Getting Started](#getting-started) section.

### Sponsors

Thanks to the following sponsors for supporting this project:
<!-- sponsors -->
<!-- sponsors -->

### Examples

![cinematic](readme/cinematic.gif)
Expand Down
2 changes: 1 addition & 1 deletion adapters/BasicAdapter/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.util.capitalizeDecapitalize.capitalizeAsciiOnly

plugins {
kotlin("jvm") version "1.8.20"
kotlin("jvm") version "1.9.22"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

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.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import me.gabber235.typewriter.adapters.TypewriteAdapter
* The Basic Adapter contains all the essential entries for Typewriter.
* In most cases, it should be installed with Typewriter.
* If you haven't installed Typewriter or the adapter yet,
* please follow the [Installation Guide](/docs/Installation-Guide)
* please follow the [Installation Guide](../../docs/02-installation-guide.md)
* first.
*/
object BasicAdapter : TypewriteAdapter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,32 @@ class RemoveItemActionEntry(
override fun execute(player: Player) {
super.execute(player)

player.inventory.removeItemAnySlot(item.build(player))
// Because item.build() can return a identical looking item but with different data,
// we need to compare the items

val itemWithoutAmount = item.copy(amount = Optional.empty())

val items = player.inventory.contents.withIndex().filter {
itemWithoutAmount.isSameAs(player, it.value)
}.iterator()

println(items)

var toRemove = item.amount.orElse(1)

while (toRemove > 0 && items.hasNext()) {
val (index, item) = items.next()
if (item == null) continue
val amount = item.amount
if (amount > toRemove) {
item.amount = amount - toRemove
player.inventory.setItem(index, item)
break
} else {
toRemove -= amount
player.inventory.setItem(index, null)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package me.gabber235.typewriter.entries.action

import com.github.shynixn.mccoroutine.bukkit.launch
import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.entry.Criteria
import me.gabber235.typewriter.entry.Modifier
import me.gabber235.typewriter.entry.entries.ActionEntry
import me.gabber235.typewriter.plugin
import me.gabber235.typewriter.utils.Icons
import org.bukkit.Location
import org.bukkit.Material
import org.bukkit.entity.Player

@Entry("set_block", "Set a block at a location", Colors.RED, Icons.CUBE)
/**
* The `SetBlockActionEntry` is an action that sets a block at a specific location.
*
* :::caution
* This will set the block for all the players on the server, not just the player who triggered the action.
* It will modify the world, so be careful when using this action.
* :::
*
* ## How could this be used?
*
* This action can be useful in a variety of situations. You can use it to create structures, set traps, or any other custom block placements you want to make. The possibilities are endless!
*/
class SetBlockActionEntry(
override val id: String = "",
override val name: String = "",
override val criteria: List<Criteria> = emptyList(),
override val modifiers: List<Modifier> = emptyList(),
override val triggers: List<String> = emptyList(),
@Help("The material of the block to set.")
val material: Material = Material.AIR,
@Help("The location to set the block at.")
val location: Location = Location(null, 0.0, 0.0, 0.0),
) : ActionEntry {
override fun execute(player: Player) {
super.execute(player)

plugin.launch {
location.block.type = material
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package me.gabber235.typewriter.entries.action

import me.gabber235.typewriter.adapters.Colors
import me.gabber235.typewriter.adapters.Entry
import me.gabber235.typewriter.adapters.modifiers.Help
import me.gabber235.typewriter.entry.Criteria
import me.gabber235.typewriter.entry.Modifier
import me.gabber235.typewriter.entry.entries.ActionEntry
import me.gabber235.typewriter.utils.Icons
import me.gabber235.typewriter.utils.Item
import org.bukkit.entity.Player

@Entry("set_item", "Set an item in a specific slot", Colors.RED, Icons.WAND_SPARKLES)
/**
* The `Set Item Action` is an action that sets an item in a specific slot in the player's inventory.
*
* ## How could this be used?
*
* This can be used to equip a player with an elytra, or give them a weapon.
*/
class SetItemActionEntry(
override val id: String = "",
override val name: String = "",
override val criteria: List<Criteria>,
override val modifiers: List<Modifier>,
override val triggers: List<String> = emptyList(),
@Help("The item to set.")
val item: Item = Item.Empty,
@Help("The slot to set the item in.")
val slot: Int = 0,
) : ActionEntry {
override fun execute(player: Player) {
super.execute(player)

player.inventory.setItem(slot, item.build(player))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,22 @@ class BlindingCinematicAction(

override suspend fun stopSegment(segment: BlindingSegment) {
super.stopSegment(segment)
restoreState()
}

private suspend fun restoreState() {
val state = state ?: return
this.state = null
withContext(plugin.minecraftDispatcher) {
player.restore(state)
}
}

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

if (state != null) {
restoreState()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import me.gabber235.typewriter.extensions.protocollib.BoatType
import me.gabber235.typewriter.extensions.protocollib.ClientEntity
import me.gabber235.typewriter.extensions.protocollib.spectateEntity
import me.gabber235.typewriter.extensions.protocollib.stopSpectatingEntity
import me.gabber235.typewriter.logger
import me.gabber235.typewriter.plugin
import me.gabber235.typewriter.utils.*
import me.gabber235.typewriter.utils.GenericPlayerStateProvider.*
Expand Down Expand Up @@ -87,16 +88,6 @@ class CameraCinematicAction(
override suspend fun setup() {
super.setup()

segments = entry.segments.map { segment ->
if (player.isFloodgate) {
TeleportCameraSegmentAction(player, segment)
} else {
val hasSegmentBefore = entry.segments.any { it isActiveAt (segment.startFrame - 1) }
BoatCameraSegmentAction(player, segment, hasSegmentBefore)
}
}
segments.forEach { it.setup() }

originalState = player.state(
LOCATION,
ALLOW_FLIGHT,
Expand All @@ -114,7 +105,29 @@ class CameraCinematicAction(
it.hidePlayer(plugin, player)
player.hidePlayer(plugin, it)
}

// Move the player before to the first location. This will spawn the boats in the correct world.
// And gives the client time to load the chunks.
val firstLocation = entry.segments.firstOrNull()?.path?.firstOrNull()?.location
firstLocation?.let {
player.teleport(it)
}
}


segments = entry.segments.mapNotNull { segment ->
if (segment.path.isEmpty()) {
logger.warning("Camera segment has no path in ${entry.id}, skipping.")
return@mapNotNull null
}
if (player.isFloodgate) {
TeleportCameraSegmentAction(player, segment)
} else {
val hasSegmentBefore = entry.segments.any { it isActiveAt (segment.startFrame - 1) }
BoatCameraSegmentAction(player, segment, hasSegmentBefore)
}
}
segments.forEach { it.setup() }
}

override suspend fun tick(frame: Int) {
Expand Down Expand Up @@ -194,7 +207,7 @@ private suspend inline fun Player.teleportIfNeeded(
plugin.minecraftDispatcher
) {
teleport(location.clone().apply {
y += 10
y += 2
})
allowFlight = true
isFlying = true
Expand Down
Loading

0 comments on commit ad0a6eb

Please sign in to comment.