Skip to content

Commit

Permalink
Merge pull request #595 from Shynixn/development
Browse files Browse the repository at this point in the history
Merge changes to master --release
  • Loading branch information
Shynixn authored Jul 13, 2024
2 parents 142acfb + d762ae1 commit 4c9ae23
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 57 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
12 changes: 6 additions & 6 deletions 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.9.0"
version = "9.10.0"

repositories {
mavenCentral()
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/wiki/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Allows values should be set in the ``config.yml``.
Changes who can see the pet.

* Name: Identifier of a pet
* Types: Possibles values: ``ALL``, ``OWNER``
* Types: Possibles values: ``ALL``, ``OWNER``, ``NOBODY``
* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block.

### /petblocks loop
Expand Down
36 changes: 18 additions & 18 deletions docs/wiki/docs/placeholders.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ The following placeholders are available in PetBlocks and can also be used via P
This results into placeholders such as e.g. ``%petblocks_pet_displayName_1%`` or ``%petblocks_pet_displayName_selected%``. This is only relevant in external plugins. For actions in PetBlocks, you can directly use the placeholders below.


| Player PlaceHolders | Description |
|---------------------------------|-------------------------------------------------|
| %petblocks_owner_name% | Player name of the owner of a pet. |
| %petblocks_owner_displayName% | Player displayName of the owner of a pet. |
| %petblocks_owner_locationWorld% | Name of the world the owner of a pet is inside. |
| %petblocks_owner_locationX% | X coordinate of the owner of a pet. |
| %petblocks_owner_locationY% | Y coordinate of the owner of a pet. |
| %petblocks_owner_locationZ% | Z coordinate of the owner of a pet. |
| %petblocks_owner_locationYaw% | Yaw rotation of the owner of a pet. |
| %petblocks_owner_locationPitch% | Yaw rotation of the owner of a pet. |
| %petblocks_owner_itemMainHand_type% | Name of the item type in the owner's main hand |
| Player PlaceHolders | Description |
|--------------------------------|------------------------------------------------------|
| %petblocks_owner_name% | Player name of the owner of a pet. |
| %petblocks_owner_displayName% | Player displayName of the owner of a pet. |
| %petblocks_owner_locationWorld% | Name of the world the owner of a pet is inside. |
| %petblocks_owner_locationX% | X coordinate of the owner of a pet. |
| %petblocks_owner_locationY% | Y coordinate of the owner of a pet. |
| %petblocks_owner_locationZ% | Z coordinate of the owner of a pet. |
| %petblocks_owner_locationYaw% | Yaw rotation of the owner of a pet. |
| %petblocks_owner_locationPitch% | Yaw rotation of the owner of a pet. |
| %petblocks_owner_itemMainHand_type% | Name of the item type in the owner's main hand |
| %petblocks_owner_isFlying% | True if the owner is currently flying, false if not. |

| Pet PlaceHolders | Description |
|---------------------------------|----------------------------------------------------------------------------------------------------|
| %petblocks_pet_name% | Id of a pet |
| %petblocks_pet_displayName% | Displayname of a pet |
| %petblocks_pet_distanceToOwner% | Distance from the pet to the owner. If the owner is in another world, this value becomes very high. |
| %petblocks_pet_exists% | True if the pet exists, false if not. |
| %petblocks_pet_isSpawned% | True if the pet is spawned, false if not. |
| %petblocks_pet_template% | Name of the template a pet uses. |
| %petblocks_pet_visibility% | Visibility Type a pet uses. |
Expand All @@ -49,13 +49,13 @@ The following placeholders are available in PetBlocks and can also be used via P
| %petblocks_eventPlayer_name% | Player name of the event trigger player. |
| %petblocks_eventPlayer_displayName% | Player displayName of the event trigger player. |
| %petblocks_eventPlayer_locationWorld% | Name of the world event trigger player of a pet is inside. |
| %petblocks_eventPlayer_locationX% | X coordinate of the event trigger player. |
| %petblocks_eventPlayer_locationY% | Y coordinate of the event trigger player. |
| %petblocks_eventPlayer_locationZ% | Z coordinate of the event trigger player. |
| %petblocks_eventPlayer_locationYaw% | Yaw rotation of the event trigger player. |
| %petblocks_eventPlayer_locationPitch% | Yaw rotation of the event trigger player. |
| %petblocks_eventPlayer_locationX% | X coordinate of the event trigger player. |
| %petblocks_eventPlayer_locationY% | Y coordinate of the event trigger player. |
| %petblocks_eventPlayer_locationZ% | Z coordinate of the event trigger player. |
| %petblocks_eventPlayer_locationYaw% | Yaw rotation of the event trigger player. |
| %petblocks_eventPlayer_locationPitch% | Yaw rotation of the event trigger player. |
| %petblocks_eventPlayer_itemMainHand_type% | Name of the item type in the players's main hand |

| %petblocks_eventPlayer_isFlying% | True if the player is currently flying, false if not. |

| GUI PlaceHolders | Description |
|-------------------------------------------|------------------------------------------------------------|
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ object PetBlocksLanguage {
/** Makes the owner wear the pet. **/
var hatCommandHint : String = "Makes the owner wear the pet."

/** [&9PetBlocks&f] The visibility of pet %1$1s has been changed. **/
var visibilityChangedMessage : String = "[&9PetBlocks&f] The visibility of pet %1$1s has been changed."
/** [&9PetBlocks&f] The visibility of pet %1$1s has been changed to %2$1s. **/
var visibilityChangedMessage : String = "[&9PetBlocks&f] The visibility of pet %1$1s has been changed to %2$1s."

/** [&9PetBlocks&f] &cYou do not have permission to edit the pets of other players. **/
var manipulateOtherMessage : String = "[&9PetBlocks&f] &cYou do not have permission to edit the pets of other players."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package com.github.shynixn.petblocks.enumeration

enum class PetVisibility {
ALL,
OWNER
OWNER,
NOBODY
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class PlaceHolder(val fullPlaceHolder: String) {
PLAYER_OWNER_LOCATION_YAW("%petblocks_owner_locationYaw%"),
PLAYER_OWNER_LOCATION_PITCH("%petblocks_owner_locationPitch%"),
PLAYER_OWNER_ITEMMAINHAND_TYPE("%petblocks_owner_itemMainHand_type%"),
PLAYER_OWNER_ISFLYING("%petblocks_owner_isFlying%"),

// Event Player
EVENT_PLAYER_OWNER_NAME("%petblocks_eventPlayer_name%"),
Expand All @@ -22,12 +23,12 @@ enum class PlaceHolder(val fullPlaceHolder: String) {
EVENT_PLAYER_OWNER_LOCATION_YAW("%petblocks_eventPlayer_locationYaw%"),
EVENT_PLAYER_OWNER_LOCATION_PITCH("%petblocks_eventPlayer_locationPitch%"),
EVENT_PLAYER_OWNER_ITEMMAINHAND_TYPE("%petblocks_eventPlayer_itemMainHand_type%"),
EVENT_PLAYER_OWNER_ISFLYING("%petblocks_eventPlayer_isFlying%"),

// Pet PlaceHolders
PET_NAME("%petblocks_pet_name%"),
PET_DISPLAYNAME("%petblocks_pet_displayName%"),
PET_DISTANCETOOWNER("%petblocks_pet_distanceToOwner%"),
PET_EXISTS("%petblocks_pet_exists%"),
PET_ISSPAWNED("%petblocks_pet_isSpawned%"),
PET_TEMPLATE("%petblocks_pet_template%"),
PET_VISIBILITY("%petblocks_pet_visibility%"),
Expand Down
27 changes: 12 additions & 15 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,26 +362,23 @@ 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 {
val rayTraceResult = rayTracingService.rayTraceMotion(location.toVector3d(), Vector3d(0.0, -1.0, 0.0))
return rayTraceResult.hitBlock
}

/**
* If owner parameter is not null, only the owner receives packets.
*/
fun updateVisibility(visibility: PetVisibility, owner: Player, location: Location) {
for (player in playerComponent.visiblePlayers) {
if (visibility == PetVisibility.OWNER && player != owner) {
playerComponent.onRemoveMinecraft.forEach { e -> e.invoke(player, location) }
} else if (visibility == PetVisibility.ALL && player != owner) {
playerComponent.onSpawnMinecraft.forEach { e -> e.invoke(player, location) }
}
}
}

/**
* Updates the displayName in the world.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class PetImpl(
petMeta.visibility = value

if (previousVisibility != value && petEntity != null) {
petEntity!!.updateVisibility(visibility, player, location)
petEntity!!.playerComponent.forceMinecraftTick()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ class PetBlocksCommandExecutor @Inject constructor(
sender: CommandSender, pet: Pet, visibility: PetVisibility
) {
pet.visibility = visibility
sender.sendPluginMessage(String.format(PetBlocksLanguage.visibilityChangedMessage, visibility.name))
sender.sendPluginMessage(String.format(PetBlocksLanguage.visibilityChangedMessage, pet.name, visibility))
}

private fun setPetLoop(sender: CommandSender, pet: Pet, loop: String) {
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PlayerComponent(
* Render distance blocks.
*/
renderDistanceBlocks: Int = 70,
private val pet : Pet
private val pet: Pet
) : PhysicComponent {
var lastTimeRenderUpdate = 0L

Expand All @@ -38,6 +38,14 @@ class PlayerComponent(
*/
val onRemoveMinecraft: MutableList<(Player, Location) -> Unit> = arrayListOf()

/**
* Forces to perform rendering logic immediately.
*/
fun forceMinecraftTick() {
lastTimeRenderUpdate = 0L
tickMinecraft()
}

override fun tickMinecraft() {
val currentTime = Date().time

Expand All @@ -47,11 +55,15 @@ class PlayerComponent(
val players = HashSet<Player>()
val location = physicsComponent.position.toLocation()
for (player in location.world!!.players) {
if (pet.visibility == PetVisibility.NOBODY) {
continue
}

if (player.location.distanceSquared(location) <= renderVisibilityDistance) {
if (!visiblePlayers.contains(player)) {
if( pet.visibility == PetVisibility.ALL){
if (pet.visibility == PetVisibility.ALL) {
onSpawnMinecraft.forEach { e -> e.invoke(player, location) }
}else if(pet.visibility == PetVisibility.OWNER && player == pet.player){
} else if (pet.visibility == PetVisibility.OWNER && player == pet.player) {
onSpawnMinecraft.forEach { e -> e.invoke(player, location) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PetBlocksPlaceHolderProvider(
)
}
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_ITEMMAINHAND_TYPE) { player -> "minecraft:" + player.inventory.itemInMainHand.type.name.lowercase() }
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_ISFLYING) { player -> player.isFlying.toString() }

// Event Player
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_NAME) { player: Player -> player.name }
Expand Down Expand Up @@ -109,6 +110,7 @@ class PetBlocksPlaceHolderProvider(
)
}
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_ITEMMAINHAND_TYPE) { player -> "minecraft:" + player.inventory.itemInMainHand.type.name.lowercase() }
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_ISFLYING) { player -> player.isFlying.toString() }

// Pet
registerPetPlaceHolder(PlaceHolder.PET_NAME) { pet -> pet.name }
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/en_us.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ petCalledMessage=[&9PetBlocks&f] Pet with name %1$1s has been called.
petSpawnedMessage=[&9PetBlocks&f] Pet with name %1$1s has been spawned.
petDespawnedMessage=[&9PetBlocks&f] Pet with name %1$1s has been removed.
visibilityTypeNotFoundMessage=[&9PetBlocks&f] &cOnly the visibility types %1$1s are supported.
visibilityChangedMessage=[&9PetBlocks&f] The visibility of pet %1$1s has been changed.
visibilityChangedMessage=[&9PetBlocks&f] The visibility of pet %1$1s has been changed to %2$1s.
petSkinTypeChangedMessage=[&9PetBlocks&f] The skinType of pet %1$1s has been changed.
petSkinNbtChanged=[&9PetBlocks&f] The skin of pet %1$1s has been changed.
petSkinTypeNotFound=[&9PetBlocks&f] &cMaterial %1$1s not found.
Expand Down
24 changes: 24 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 Expand Up @@ -145,6 +153,22 @@ loops:
level: "SERVER"
run:
- "/petblocks moveToOwner %petblocks_pet_name% 0.2 %petblocks_owner_name%"
- name: "Hide the pet while player is flying"
condition:
type: JAVASCRIPT
js: "%petblocks_owner_isFlying% && '%petblocks_pet_visibility%' != 'NOBODY'"
type: "COMMAND"
level: "SERVER"
run:
- "/petblocks visibility %petblocks_pet_name% NOBODY %petblocks_owner_name%"
- name: "Show the pet while player is not flying"
condition:
type: JAVASCRIPT
js: "!%petblocks_owner_isFlying% && '%petblocks_pet_visibility%' == 'NOBODY'"
type: "COMMAND"
level: "SERVER"
run:
- "/petblocks visibility %petblocks_pet_name% ALL %petblocks_owner_name%"
- name: "Switch to idle if the pet is beside the player"
condition:
type: NUMBER_LESS_THAN
Expand Down
Loading

0 comments on commit 4c9ae23

Please sign in to comment.