Skip to content

Commit

Permalink
#575 Updated to release verison and fixed velocitry rel.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Jul 26, 2024
1 parent c17afff commit 4120826
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 97 deletions.
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.10.0"
version = "9.11.0"

repositories {
mavenCentral()
Expand Down
3 changes: 2 additions & 1 deletion docs/wiki/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ Launches the pet into the given direction.
### /petblocks velocityrel

```
/petblocks velocityrel <name> <mx> <my> <mz> [player]
/petblocks velocityrel <name> <mx> <my> <mz> [oy] [player]
```

Launches the pet into the current looking direction with the given multipliers.
Expand All @@ -205,6 +205,7 @@ Launches the pet into the current looking direction with the given multipliers.
* MX: Multiplier in X direction. Try to set it to 1 first.
* MY: Multiplier in Y direction. Try to set it to 1 first.
* MZ: Multiplier in Z direction. Try to set it to 1 first.
* OY: Optional overwrite for the base y value. If you set this to 0.5 or higher, the pet always gets launched upwards.
* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block.


Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/github/shynixn/petblocks/contract/Pet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ interface Pet {
/**
* Offset from the ground.
*/
var groundOffset : Double
var groundOffset: Double

/**
* Calculated variables which can be used in subsequent operations by placeholders.
* Storage of arbitrary data in the pet.
*/
val javaScriptMemory: MutableMap<String, String>
val memory: MutableMap<String, String>

/**
* Calls the pet to the player. Spawns the pet if it is not spawned, and places the pet
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/github/shynixn/petblocks/entity/PetMeta.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class PetMeta {
*/
var physics: PhysicSettings = PhysicSettings()

/**
* Stored arbitrary data.
*/
val memory: MutableMap<String, String> = HashMap()

/**
* Last persisted location of the pet.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,12 @@ class PetImpl(
}

/**
* Calculated variables which can be used in subsequent operations by placeholders.
* Storage of arbitrary data in the pet.
*/
override var javaScriptMemory: MutableMap<String, String> = HashMap()
override val memory: MutableMap<String, String>
get() {
return petMeta.memory
}

/**
* Calls the pet to the player. Spawns the pet if it is not spawned, and places the pet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,17 +464,21 @@ class PetBlocksCommandExecutor @Inject constructor(
toolTip { PetBlocksLanguage.velocityRelCommandHint }
builder().argument("name").tabs(petNamesTabs).argument("mx").validator(mustBeDouble)
.tabs { listOf("<mx>") }.argument("my").validator(mustBeDouble).tabs { listOf("<my>") }
.argument("mz")
.validator(mustBeDouble).tabs { listOf("<mz>") }
.argument("mz").validator(mustBeDouble).tabs { listOf("<mz>") }
.executePlayer(senderHasToBePlayer) { player, name, x, y, z ->
setRelativeVelocityToPet(
player, petMustExist(player, name), Vector(x, y, z)
player, petMustExist(player, name), Vector(x, y, z), "-"
)
}.argument("oy").tabs { listOf("<oy>", "-") }
.executePlayer(senderHasToBePlayer) { player, name, x, y, z, oy ->
setRelativeVelocityToPet(
player, petMustExist(player, name), Vector(x, y, z), oy
)
}.argument("player").validator(playerMustExist).tabs(onlinePlayerTabs)
.permission(manipulateOtherPermission).permissionMessage(manipulateOtherPermissionMessage)
.execute { commandSender, name, x, y, z, player ->
.execute { commandSender, name, x, y, z, oy, player ->
setRelativeVelocityToPet(
commandSender, petMustExist(player, name), Vector(x, y, z)
commandSender, petMustExist(player, name), Vector(x, y, z), oy
)
}
}
Expand All @@ -484,9 +488,8 @@ class PetBlocksCommandExecutor @Inject constructor(
builder().argument("name").tabs(petNamesTabs).argument("material").validator(materialMustExist)
.tabs(materialTabs).executePlayer(senderHasToBePlayer) { player, name, material ->
setSkinType(player, petMustExist(player, name), material, 0)
}
.argument("durability").validator(mustBeInt)
.tabs(materialTabs).executePlayer(senderHasToBePlayer) { player, name, material, durability ->
}.argument("durability").validator(mustBeInt).tabs(materialTabs)
.executePlayer(senderHasToBePlayer) { player, name, material, durability ->
setSkinType(player, petMustExist(player, name), material, durability)
}.argument("player").validator(playerMustExist).tabs(onlinePlayerTabs)
.permission(manipulateOtherPermission).permissionMessage(manipulateOtherPermissionMessage)
Expand Down Expand Up @@ -745,12 +748,10 @@ class PetBlocksCommandExecutor @Inject constructor(
subCommand("variable") {
permission(Permission.VARIABLE)
toolTip { PetBlocksLanguage.variableCommandHint }
builder().argument("name").tabs(petNamesTabs)
.argument("key").tabs { listOf("<key>") }.argument("value").tabs { listOf("<value>") }
.executePlayer(senderHasToBePlayer) { player, name, key, value ->
builder().argument("name").tabs(petNamesTabs).argument("key").tabs { listOf("<key>") }.argument("value")
.tabs { listOf("<value>") }.executePlayer(senderHasToBePlayer) { player, name, key, value ->
setMemoryVariable(player, petMustExist(player, name), key, value)
}
.argument("player").validator(playerMustExist).tabs(onlinePlayerTabs)
}.argument("player").validator(playerMustExist).tabs(onlinePlayerTabs)
.permission(manipulateOtherPermission).permissionMessage(manipulateOtherPermissionMessage)
.execute { commandSender, name, key, value, player ->
setMemoryVariable(commandSender, petMustExist(player, name), key, value)
Expand Down Expand Up @@ -862,10 +863,18 @@ class PetBlocksCommandExecutor @Inject constructor(
}

private fun setRelativeVelocityToPet(
sender: CommandSender, pet: Pet, vector: Vector
sender: CommandSender, pet: Pet, vector: Vector, overrideY: String
) {
val normalized = pet.velocity.normalize()
pet.velocity = normalized.multiply(vector)
val normalized = pet.location.direction.normalize()

if (overrideY.toDoubleOrNull() != null) {
normalized.y = overrideY.toDouble()
}

normalized.x = vector.x * normalized.x
normalized.y = vector.y * normalized.y
normalized.z = vector.z * normalized.z
pet.velocity = normalized
sender.sendPluginMessage(String.format(PetBlocksLanguage.petVelocityAppliedMessage, pet.name))
}

Expand Down Expand Up @@ -1102,7 +1111,7 @@ class PetBlocksCommandExecutor @Inject constructor(
}

private fun setMemoryVariable(sender: CommandSender, pet: Pet, key: String, value: String) {
pet.javaScriptMemory[key] = value
pet.memory[key] = value
sender.sendPluginMessage(String.format(PetBlocksLanguage.variableChangedMessage, key, value))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import java.util.*
import kotlin.collections.HashMap

class PetBlocksPlaceHolderProvider(
private val petMetaRepository: CachePlayerRepository<PlayerInformation>,
private val petService: PetService
) :
PlaceHolderProvider {
private val petMetaRepository: CachePlayerRepository<PlayerInformation>, private val petService: PetService
) : PlaceHolderProvider {
private val playerPlaceHolderFunctions = HashMap<String, ((Player) -> String)>()
private val petPlaceHolderFunctions = HashMap<String, ((Pet) -> String)>()
private val selectedPetPlaceHolderFunctions = HashMap<String, ((Pet) -> String)>()
Expand All @@ -34,37 +32,27 @@ class PetBlocksPlaceHolderProvider(
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_LOCATION_WORLD) { player: Player -> player.location.world!!.name }
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_LOCATION_X) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.x
Locale.ENGLISH, "%.2f", player.location.x
)
}
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_LOCATION_Y) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.y
Locale.ENGLISH, "%.2f", player.location.y
)
}
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_LOCATION_Z) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.z
Locale.ENGLISH, "%.2f", player.location.z
)
}
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_LOCATION_YAW) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.yaw
Locale.ENGLISH, "%.2f", player.location.yaw
)
}
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_LOCATION_PITCH) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.pitch
Locale.ENGLISH, "%.2f", player.location.pitch
)
}
registerPlayerPlaceHolder(PlaceHolder.PLAYER_OWNER_ITEMMAINHAND_TYPE) { player -> "minecraft:" + player.inventory.itemInMainHand.type.name.lowercase() }
Expand All @@ -76,37 +64,27 @@ class PetBlocksPlaceHolderProvider(
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_LOCATION_WORLD) { player: Player -> player.location.world!!.name }
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_LOCATION_X) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.x
Locale.ENGLISH, "%.2f", player.location.x
)
}
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_LOCATION_Y) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.y
Locale.ENGLISH, "%.2f", player.location.y
)
}
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_LOCATION_Z) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.z
Locale.ENGLISH, "%.2f", player.location.z
)
}
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_LOCATION_YAW) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.yaw
Locale.ENGLISH, "%.2f", player.location.yaw
)
}
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_LOCATION_PITCH) { player ->
String.format(
Locale.ENGLISH,
"%.2f",
player.location.pitch
Locale.ENGLISH, "%.2f", player.location.pitch
)
}
registerPlayerPlaceHolder(PlaceHolder.EVENT_PLAYER_OWNER_ITEMMAINHAND_TYPE) { player -> "minecraft:" + player.inventory.itemInMainHand.type.name.lowercase() }
Expand All @@ -123,44 +101,32 @@ class PetBlocksPlaceHolderProvider(
registerPetPlaceHolder(PlaceHolder.PET_LOOP) { pet -> pet.loop }
registerPetPlaceHolder(PlaceHolder.PET_LOCATION_WORLD) { pet ->
String.format(
Locale.ENGLISH,
"%.2f",
pet.location.world!!.name
Locale.ENGLISH, "%.2f", pet.location.world!!.name
)
}
registerPetPlaceHolder(PlaceHolder.PET_LOCATION_X) { pet ->
String.format(
Locale.ENGLISH,
"%.2f",
pet.location.x
Locale.ENGLISH, "%.2f", pet.location.x
)
}
registerPetPlaceHolder(PlaceHolder.PET_LOCATION_Y) { pet ->
String.format(
Locale.ENGLISH,
"%.2f",
pet.location.y
Locale.ENGLISH, "%.2f", pet.location.y
)
}
registerPetPlaceHolder(PlaceHolder.PET_LOCATION_Z) { pet ->
String.format(
Locale.ENGLISH,
"%.2f",
pet.location.z
Locale.ENGLISH, "%.2f", pet.location.z
)
}
registerPetPlaceHolder(PlaceHolder.PET_LOCATION_YAW) { pet ->
String.format(
Locale.ENGLISH,
"%.2f",
pet.location.yaw
Locale.ENGLISH, "%.2f", pet.location.yaw
)
}
registerPetPlaceHolder(PlaceHolder.PET_LOCATION_PITCH) { pet ->
String.format(
Locale.ENGLISH,
"%.2f",
pet.location.pitch
Locale.ENGLISH, "%.2f", pet.location.pitch
)
}
registerPetPlaceHolder(PlaceHolder.PET_ITEM_TYPE) { pet -> pet.headItemStack.type.name }
Expand Down Expand Up @@ -220,7 +186,10 @@ class PetBlocksPlaceHolderProvider(
}
} else if (petPlaceHolderFunctions.containsKey(placeHolderText) && pet != null) {
locatedPlaceHolders[placeHolderText] = petPlaceHolderFunctions[placeHolderText]!!.invoke(pet)
} else if (selectedPetPlaceHolderFunctions.containsKey(placeHolderText)) {
} else if (selectedPetPlaceHolderFunctions.containsKey(placeHolderText) || (placeHolderText.endsWith("_selected%") && placeHolderText.startsWith(
"%petblocks_js"
))
) {
val petsOfPlayer = petService.getCache()[player]
val playerInformation = petMetaRepository.getCachedByPlayer(player)
if (petsOfPlayer != null && playerInformation != null) {
Expand All @@ -231,7 +200,7 @@ class PetBlocksPlaceHolderProvider(
pet = petsOfPlayer.firstOrNull()
}

if (pet != null) {
if (pet != null && selectedPetPlaceHolderFunctions.containsKey(placeHolderText)) {
locatedPlaceHolders[placeHolderText] =
selectedPetPlaceHolderFunctions[placeHolderText]!!.invoke(pet)
}
Expand All @@ -250,16 +219,17 @@ class PetBlocksPlaceHolderProvider(
}

if (pet != null && output.contains("%petblocks_js")) {
for (key in pet.javaScriptMemory.keys) {
val value = pet.javaScriptMemory[key]!!
for (key in pet.memory.keys) {
val value = pet.memory[key]!!
if (key.contains("json")) {
val parsedJsonObject = mapper.readValue(value, Map::class.java)
for (innerKey in parsedJsonObject.keys) {
output =
output.replace("%petblocks_js_${key}_${innerKey}%", parsedJsonObject[innerKey].toString())
}
} else {
output = output.replace("%petblocks_js_${key}%", value)
output =
output.replace("%petblocks_js_${key}%", value).replace("%petblocks_js_${key}_selected%", value)
}
}
}
Expand Down
Loading

0 comments on commit 4120826

Please sign in to comment.