Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge changes to master --release #620

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "com.github.shynixn"
version = "9.13.1"
version = "9.14.0"

repositories {
mavenCentral()
Expand Down
4 changes: 4 additions & 0 deletions docs/wiki/docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ Events define what actions to execute on certain events.
The following events are supported:

* leftClick
* leftClickSneak
* rightClick
* rightClickSneak
* ridingSneak
* spawn
* despawn

For example the ``leftClick`` event gets executed when a player left-clicks on the pet. However, it may not be the owner, who clicks on a pet, therefore you need
to check if the player is the owner first as a condition.
Expand Down
27 changes: 26 additions & 1 deletion src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import com.github.shynixn.petblocks.contract.Pet
import com.github.shynixn.petblocks.contract.PetActionExecutionService
import com.github.shynixn.petblocks.entity.PetMeta
import com.github.shynixn.petblocks.enumeration.DropType
import com.github.shynixn.petblocks.enumeration.PetVisibility
import com.github.shynixn.petblocks.exception.PetBlocksPetDisposedException
import com.github.shynixn.petblocks.impl.physic.ArmorstandEntityComponent
import com.github.shynixn.petblocks.impl.physic.MathComponent
Expand Down Expand Up @@ -229,6 +228,32 @@ class PetEntityImpl(
}
}

/**
* Spawn is initiated.
*/
fun onSpawn(player: Player){
cancellationTokenLongRunning.isCancelled = true
val spawnEvent = pet.template.events["spawn"]
if (spawnEvent != null) {
plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) {
petActionExecutionService.executeAction(player, pet, spawnEvent, CancellationToken())
}
}
}

/**
* Despawn is initiated.
*/
fun onDespawn(player: Player){
cancellationTokenLongRunning.isCancelled = true
val despawnEvent = pet.template.events["despawn"]
if (despawnEvent != null) {
plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) {
petActionExecutionService.executeAction(player, pet, despawnEvent, CancellationToken())
}
}
}

/**
* Moves to the given location.
*/
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ class PetImpl(
// Remove pet if the player does not have any spawn permission.
while (!isDisposed) {
if (!player.hasPermission(Permission.SPAWN.text)) {
petEntity?.remove()
petEntity = null
petMeta.isSpawned = false
remove()
}

delay(5000)
Expand Down Expand Up @@ -317,8 +315,7 @@ class PetImpl(
val petWorld = location.world

if (playerWorld != petWorld) {
petEntity!!.remove()
petEntity = null
remove()
}
}

Expand Down Expand Up @@ -368,6 +365,7 @@ class PetImpl(
return
}

petEntity!!.onDespawn(player)
petEntity!!.remove()
petEntity = null
petMeta.isSpawned = false
Expand All @@ -394,7 +392,7 @@ class PetImpl(

petEntity = petEntityFactory.createPetEntity(this, petMeta)
petMeta.isSpawned = true

petEntity?.onSpawn(player)

plugin.launch {
if (petMeta.ridingState == PetRidingState.HAT) {
Expand Down
16 changes: 13 additions & 3 deletions src/main/resources/pets/pet_classic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ events:
run:
- "/petblocks velocity %petblocks_pet_name% %petblocks_js_jsonKnockback_x% 0.2 %petblocks_js_jsonKnockback_z% %petblocks_eventPlayer_name%"
leftClickSneak:
actions: # You can add/remove actions as you want here.
actions: # You can add/remove actions as you want here.
- name: "Open the pet GUI"
condition:
type: STRING_EQUALS
Expand All @@ -110,7 +110,7 @@ events:
- "/petblocks select %petblocks_pet_name%"
- "/petblock"
rightClick:
actions: # You can add/remove actions as you want here.
actions: # You can add/remove actions as you want here.
- name: "Start riding pet"
condition:
type: STRING_EQUALS
Expand All @@ -121,7 +121,7 @@ events:
run:
- "/petblocks ride %petblocks_pet_name%"
rightClickSneak:
actions: # You can add/remove actions as you want here.
actions: # You can add/remove actions as you want here.
- name: "Open the pet GUI"
condition:
type: STRING_EQUALS
Expand All @@ -140,6 +140,16 @@ events:
level: "PLAYER"
run:
- "/petblocks unmount %petblocks_pet_name%"
spawn:
actions:
- name: "Delay Action"
type: "DELAY"
ticks: 20
despawn:
actions:
- name: "Delay Action"
type: "DELAY"
ticks: 20

#
# Defines the action a pet should perform in an interval on its own.
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/pets/pet_flying_dolphin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ events:
level: "PLAYER"
run:
- "/petblocks unmount %petblocks_pet_name%"
spawn:
actions:
- name: "Delay Action"
type: "DELAY"
ticks: 20
despawn:
actions:
- name: "Delay Action"
type: "DELAY"
ticks: 20

#
# Defines the action a pet should perform in an interval on its own.
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/pets/pet_mining.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ events:
level: "PLAYER"
run:
- "/petblocks unmount %petblocks_pet_name%"
spawn:
actions:
- name: "Delay Action"
type: "DELAY"
ticks: 20
despawn:
actions:
- name: "Delay Action"
type: "DELAY"
ticks: 20

#
# Defines the action a pet should perform in an interval on its own.
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin-legacy.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PetBlocks
version: 9.13.1
version: 9.14.0
author: Shynixn
main: com.github.shynixn.petblocks.PetBlocksPlugin
softdepend: [ PlaceholderAPI, HeadDatabase]
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: PetBlocks
version: 9.13.1
version: 9.14.0
author: Shynixn
main: com.github.shynixn.petblocks.PetBlocksPlugin
softdepend: [ PlaceholderAPI, HeadDatabase]
Expand Down
Loading