Skip to content

Commit

Permalink
#586 Added rideSneak event.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Jul 13, 2024
1 parent 7b87c40 commit 212c942
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 12 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/petblocks-bukkit-api/build/
/petblocks-bukkit-plugin/build/
.idea
.gradle
build
10 changes: 5 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ dependencies {
compileOnly("com.arcaniax:HeadDatabase-API:1.3.1")

// Library dependencies with legacy compatibility, we can use more up-to-date version in the plugin.yml
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.16.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.16.0")
runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.16.0")
runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.16.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-api:2.18.0")
implementation("com.github.shynixn.mccoroutine:mccoroutine-bukkit-core:2.18.0")
runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-api:2.18.0")
runtimeOnly("com.github.shynixn.mccoroutine:mccoroutine-folia-core:2.18.0")
implementation("com.google.inject:guice:5.0.1")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.3.0")
implementation("com.fasterxml.jackson.core:jackson-databind:2.2.3")
Expand All @@ -47,7 +47,7 @@ dependencies {
// Custom dependencies
implementation("com.github.shynixn.shygui:shygui:1.0.0")
implementation("com.github.shynixn.mcutils:common:2024.19")
implementation("com.github.shynixn.mcutils:packet:2024.30")
implementation("com.github.shynixn.mcutils:packet:2024.32")
implementation("com.github.shynixn.mcutils:database:2024.2")
implementation("com.github.shynixn.mcutils:pathfinder:2024.3")
implementation("com.github.shynixn.mcutils:guice:2024.2")
Expand Down
14 changes: 10 additions & 4 deletions docs/wiki/docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,16 @@ Example for static values are ``name``, ``version`` and all initial pet settings

## Events

Events define what happens on certain events. Currently only leftClick and rightClick on the pet is supported. These
actions get
executed when a player left-clicks on the pet. However, it may not be the owner, who clicks on a pet, therefore it needs
to be checked if you only want to allow certain actions for the owner of the pet.
Events define what actions to execute on certain events.

The following events are supported:

* leftClick
* rightClick
* ridingSneak

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.

Example:

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/com/github/shynixn/petblocks/impl/PetEntityImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import org.bukkit.*
import org.bukkit.block.Block
import org.bukkit.entity.Player
import org.bukkit.plugin.Plugin
import org.bukkit.util.Vector
import java.util.*
import java.util.logging.Level
import kotlin.collections.ArrayList
Expand Down Expand Up @@ -60,6 +59,7 @@ class PetEntityImpl(
private var cancellationTokenLoop = CancellationToken()
private var cancellationTokenLongRunning = CancellationToken()
private var lastRideUpdate = 0L
private var lastSneakUpdate = 0L
var isBreakingBlock = false

// Mover
Expand Down Expand Up @@ -321,7 +321,7 @@ class PetEntityImpl(
/**
* Gets called when the player is riding the entity.
*/
fun ride(player: Player, forward: Double, isJumping: Boolean) {
fun ride(player: Player, forward: Double, isJumping: Boolean, isSneaking: Boolean) {
cancellationTokenLongRunning.isCancelled = true

val current = Date().time
Expand Down Expand Up @@ -362,6 +362,16 @@ class PetEntityImpl(
physicsComponent.position.pitch = 0.0
physicsComponent.position.yaw = player.location.yaw.toDouble()
}

if (isSneaking && current - lastSneakUpdate >= 200) {
lastSneakUpdate = current
val sneakEvent = pet.template.events["ridingSneak"]
if (sneakEvent != null) {
plugin.launch(plugin.minecraftDispatcher + object : CoroutineTimings() {}) {
petActionExecutionService.executeAction(player, pet, sneakEvent, CancellationToken())
}
}
}
}

private fun isOnGround(location: Location): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class PetListener @Inject constructor(
if (packet is PacketInSteerVehicle) {
plugin.launch {
val physicObject = physicObjectService.findPhysicObjectById(packet.entityId) as PetEntityImpl?
physicObject?.ride(event.player, packet.forward, packet.isJumping)
physicObject?.ride(event.player, packet.forward, packet.isJumping, packet.isShift)
}
return
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/pets/pet_classic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ events:
run:
- "/petblocks select %petblocks_pet_name%"
- "/petblock"
ridingSneak:
# Gets called when an owner presses SHIFT while riding their pet.
actions:
- name: "Dismount the pet"
type: "COMMAND"
level: "PLAYER"
run:
- "/petblocks unmount %petblocks_pet_name%"

#
# Defines the action a pet should perform in an interval on its own.
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/pets/pet_flying_dolphin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ events:
run:
- "/petblocks select %petblocks_pet_name%"
- "/petblock"
ridingSneak:
# Gets called when an owner presses SHIFT while riding their pet.
actions:
- name: "Dismount the pet"
type: "COMMAND"
level: "PLAYER"
run:
- "/petblocks unmount %petblocks_pet_name%"

#
# Defines the action a pet should perform in an interval on its own.
Expand Down
9 changes: 9 additions & 0 deletions src/main/resources/pets/pet_mining.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ events:
- "/tell %petblocks_owner_name% Pet %petblocks_pet_displayName% &rstarts to mine a tunnel."
- "/petblocks snap %petblocks_pet_name% %petblocks_owner_name%" # Snap is useful for straight tunnels.
- "/petblocks loop %petblocks_pet_name% mineTunnel2x2 %petblocks_owner_name%"
ridingSneak:
# Gets called when an owner presses SHIFT while riding their pet.
actions:
- name: "Dismount the pet"
type: "COMMAND"
level: "PLAYER"
run:
- "/petblocks unmount %petblocks_pet_name%"

#
# Defines the action a pet should perform in an interval on its own.
#
Expand Down

0 comments on commit 212c942

Please sign in to comment.