diff --git a/build.gradle.kts b/build.gradle.kts index bf65ad465..e2c732099 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "com.github.shynixn" -version = "9.10.0" +version = "9.11.0" repositories { mavenCentral() diff --git a/docs/wiki/docs/commands.md b/docs/wiki/docs/commands.md index 7e203136d..095726757 100644 --- a/docs/wiki/docs/commands.md +++ b/docs/wiki/docs/commands.md @@ -188,12 +188,27 @@ Teleports the pet to the given location. Launches the pet into the given direction. * Name: Identifier of a pet -* World: Target world * X: X Vector * Y: Y Vector * Z: Z Vector * Player: Optional player_name/player_UUID parameter targeting a player from the console or command block. +### /petblocks velocityrel + +``` +/petblocks velocityrel [oy] [player] +``` + +Launches the pet into the current looking direction with the given multipliers. + +* Name: Identifier of a pet +* 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. + + ### /petblocks skintype ``` @@ -463,6 +478,21 @@ Changes the offset of the body of the entity to the ground. Useful when configur * Offset: A numeric comma value. e.g. 0.3, -0.3, 1.0 * Player: Optional player_name/player_UUID parameter targeting a player from the console or command block. +### /petblocks variable + +``` +/petblocks variable [player] +``` + +Sets the value of the variable with the given key. This is useful store arbitrary data into the pet. +e.g. health, selected particle, selected sound, etc. + +* Name: Identifier of a pet +* Key: A key to store and retrieve a value +* Value: Arbitrary data to store. +* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block. + + ## Command /petblocksgui **Required Permission:** diff --git a/docs/wiki/docs/permission.md b/docs/wiki/docs/permission.md index 460fea554..91a2627fe 100644 --- a/docs/wiki/docs/permission.md +++ b/docs/wiki/docs/permission.md @@ -11,15 +11,15 @@ The following permissions are available in PetBlocks. | Permission | Level | Description | |-------------------------------------------------|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| petblocks.command | User | Allows to use the /petblocks command. -| petblocks.gui.petblocks_main_menu | User | Allows to access the main GUI of PetBlocks. -| petblocks.gui.petblocks_skins_menu | User | Allows to access the skins GUI of PetBlocks. -| petblocks.gui.petblocks_skins_blockskins_menu | User | Allows to access the block skins GUI of PetBlocks. -| petblocks.gui.petblocks_skins_petskins_menu | User | Allows to access the pet skins GUI of PetBlocks. -| petblocks.gui.petblocks_skins_vehicleskins_menu | User | Allows to access the vehicle skins GUI of PetBlocks. -| petblocks.gui.petblocks_skins_plushieskins_menu | User | Allows to access the vehicle skins GUI of PetBlocks. -| petblocks.gui.[gui-name] | User | Allows to access a specific gui. -| petblocks.pet.select | User | Allows to mark a pet as selected. **Important for GUI** +| petblocks.command | User | Allows to use the /petblocks command. +| petblocks.gui.petblocks_main_menu | User | Allows to access the main GUI of PetBlocks. +| petblocks.gui.petblocks_skins_menu | User | Allows to access the skins GUI of PetBlocks. +| petblocks.gui.petblocks_skins_blockskins_menu | User | Allows to access the block skins GUI of PetBlocks. +| petblocks.gui.petblocks_skins_petskins_menu | User | Allows to access the pet skins GUI of PetBlocks. +| petblocks.gui.petblocks_skins_vehicleskins_menu | User | Allows to access the vehicle skins GUI of PetBlocks. +| petblocks.gui.petblocks_skins_plushieskins_menu | User | Allows to access the vehicle skins GUI of PetBlocks. +| petblocks.gui.[gui-name] | User | Allows to access a specific gui. +| petblocks.pet.select | User | Allows to mark a pet as selected. **Important for GUI** | petblocks.help | User | Allows to see the help messages. | | petblocks.reload | Admin | Permission to use the /petblocks reload command. | | petblocks.pet.create | Admin/User | Allows to create a new pet. This command should probably be executed by a GUI / Sign / Server Management Plugin. If you set receivePetsOnJoin in the config.yml, you do not need this permission. | @@ -41,6 +41,7 @@ The following permissions are available in PetBlocks. | petblocks.pet.movetoOwner | Admin/User | Allows to force the pet to move to the owner | | petblocks.pet.teleport | Admin/User | Allows to force the pet to teleport to a given location | | petblocks.pet.velocity | Admin/User | Allows to force the pet to fly to a given direction | +| petblocks.pet.velocityRel | Admin/User | Allows to force the pet to fly to a given direction | petblocks.pet.visibility | Admin/User | Allows to change the pet visibility. | | petblocks.pet.loop | Admin/User | Allows to change the pet loop. A loop is discussed further in the pet customization section. | | petblocks.pet.loop | Admin/User | Allows to change the pet loop. A loop is discussed further in the pet customization section. | @@ -56,5 +57,6 @@ The following permissions are available in PetBlocks. | petblocks.pet.moveRel | Admin/User | Allows to use the /petblocks moveforward command | | petblocks.pet.rotateRel | Admin/User | Allows to use the /petblocks rotaterel command | | petblocks.pet.entityType | Admin/User | Allows to use the /petblocks entitytype command | -| petblocks.pet.entityVisibility | Admin/User | Allows to use the /petblocks entityvisible command -| petblocks.pet.groundOffset | Admin/User | Allows to use the /petblocks groundOffset command +| petblocks.pet.entityVisibility | Admin/User | Allows to use the /petblocks entityvisible command +| petblocks.pet.groundOffset | Admin/User | Allows to use the /petblocks groundOffset command +| petblocks.pet.variable | Admin | Allows to use the /petblocks variable command diff --git a/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguage.kt b/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguage.kt index afcb2fccf..3a9f8b3b6 100644 --- a/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguage.kt +++ b/src/main/java/com/github/shynixn/petblocks/PetBlocksLanguage.kt @@ -64,6 +64,9 @@ object PetBlocksLanguage { /** Goes back one GUI page. **/ var backCommandHint : String = "Goes back one GUI page." + /** [&9PetBlocks&f] The pet memory variable %1$1s has been set to %2$1s. **/ + var variableChangedMessage : String = "[&9PetBlocks&f] The pet memory variable %1$1s has been set to %2$1s." + /** Closes the GUI menu. **/ var closeCommandHint : String = "Closes the GUI menu." @@ -115,6 +118,9 @@ object PetBlocksLanguage { /** [&9PetBlocks&f] &cCannot parse boolean %1$1s. **/ var cannotParseBoolean : String = "[&9PetBlocks&f] &cCannot parse boolean %1$1s." + /** Launches the pet into the current looking direction with the given multipliers. **/ + var velocityRelCommandHint : String = "Launches the pet into the current looking direction with the given multipliers." + /** Rotates the pet relative to its current rotation. **/ var rotateRelCommandHint : String = "Rotates the pet relative to its current rotation." @@ -208,6 +214,9 @@ object PetBlocksLanguage { /** No pet. **/ var placeHolderPetNotFound : String = "No pet." + /** Sets the value of the variable with the given key. This is useful store arbitrary data into the pet e.g. health. **/ + var variableCommandHint : String = "Sets the value of the variable with the given key. This is useful store arbitrary data into the pet e.g. health." + /** Opens the headDatabase inventory with a special hook, which applies the next item you select in the headdatabse gui to the pet. **/ var openHeadDatabaseCommandHint : String = "Opens the headDatabase inventory with a special hook, which applies the next item you select in the headdatabse gui to the pet." diff --git a/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt b/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt index e2232e46b..6c9d28915 100644 --- a/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt +++ b/src/main/java/com/github/shynixn/petblocks/contract/Pet.kt @@ -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 + val memory: MutableMap /** * Calls the pet to the player. Spawns the pet if it is not spawned, and places the pet diff --git a/src/main/java/com/github/shynixn/petblocks/entity/PetMeta.kt b/src/main/java/com/github/shynixn/petblocks/entity/PetMeta.kt index 21b72d84c..3be590523 100644 --- a/src/main/java/com/github/shynixn/petblocks/entity/PetMeta.kt +++ b/src/main/java/com/github/shynixn/petblocks/entity/PetMeta.kt @@ -66,6 +66,11 @@ class PetMeta { */ var physics: PhysicSettings = PhysicSettings() + /** + * Stored arbitrary data. + */ + val memory: MutableMap = HashMap() + /** * Last persisted location of the pet. */ diff --git a/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt b/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt index 2bdaa6176..a0cb394c6 100644 --- a/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt +++ b/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt @@ -23,6 +23,7 @@ enum class Permission(val text: String) { MOVETOOWNER("petblocks.pet.movetoOwner"), TELEPORT("petblocks.pet.teleport"), VELOCITY("petblocks.pet.velocity"), + VELOCITYREL("petblocks.pet.velocityRel"), VISIBILITY("petblocks.pet.visibility"), LOOP("petblocks.pet.loop"), TEMPLATE("petblocks.pet.setTemplate"), @@ -37,6 +38,8 @@ enum class Permission(val text: String) { ENTITYTYPE("petblocks.pet.entityType"), ENTITYVISIBILITY("petblocks.pet.entityVisibility"), GROUNDOFFSET("petblocks.pet.groundOffset"), + VARIABLE("petblocks.pet.variable"), + // Dynamic DYN_AMOUNT("petblocks.pet.amount."), DYN_TEMPLATE("petblocks.pet.template."), diff --git a/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt index d3c33c48d..aed5a919c 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/PetImpl.kt @@ -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 = HashMap() + override val memory: MutableMap + get() { + return petMeta.memory + } /** * Calls the pet to the player. Spawns the pet if it is not spawned, and places the pet diff --git a/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt b/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt index 94aa8ed42..7acdabf23 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt @@ -459,15 +459,37 @@ class PetBlocksCommandExecutor @Inject constructor( ) } } + subCommand("velocityrel") { + permission(Permission.VELOCITYREL) + toolTip { PetBlocksLanguage.velocityRelCommandHint } + builder().argument("name").tabs(petNamesTabs).argument("mx").validator(mustBeDouble) + .tabs { listOf("") }.argument("my").validator(mustBeDouble).tabs { listOf("") } + .argument("mz").validator(mustBeDouble).tabs { listOf("") } + .executePlayer(senderHasToBePlayer) { player, name, x, y, z -> + setRelativeVelocityToPet( + player, petMustExist(player, name), Vector(x, y, z), "-" + ) + }.argument("oy").tabs { listOf("", "-") } + .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, oy, player -> + setRelativeVelocityToPet( + commandSender, petMustExist(player, name), Vector(x, y, z), oy + ) + } + } subCommand("skintype") { permission(Permission.SKIN) toolTip { PetBlocksLanguage.skinTypeCommandHint } 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) @@ -723,6 +745,18 @@ class PetBlocksCommandExecutor @Inject constructor( snap(commandSender, petMustExist(player, name)) } } + subCommand("variable") { + permission(Permission.VARIABLE) + toolTip { PetBlocksLanguage.variableCommandHint } + builder().argument("name").tabs(petNamesTabs).argument("key").tabs { listOf("") }.argument("value") + .tabs { listOf("") }.executePlayer(senderHasToBePlayer) { player, name, key, value -> + setMemoryVariable(player, petMustExist(player, name), key, value) + }.argument("player").validator(playerMustExist).tabs(onlinePlayerTabs) + .permission(manipulateOtherPermission).permissionMessage(manipulateOtherPermissionMessage) + .execute { commandSender, name, key, value, player -> + setMemoryVariable(commandSender, petMustExist(player, name), key, value) + } + } subCommand("reload") { permission(Permission.RELOAD) toolTip { PetBlocksLanguage.reloadCommandHint } @@ -828,6 +862,22 @@ class PetBlocksCommandExecutor @Inject constructor( sender.sendPluginMessage(String.format(PetBlocksLanguage.petVelocityAppliedMessage, pet.name)) } + private fun setRelativeVelocityToPet( + sender: CommandSender, pet: Pet, vector: Vector, overrideY: String + ) { + 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)) + } + private fun setSkinType(sender: CommandSender, pet: Pet, material: String, durability: Int) { val item = pet.headItem item.typeName = material @@ -1060,6 +1110,11 @@ class PetBlocksCommandExecutor @Inject constructor( sender.sendPluginMessage(String.format(PetBlocksLanguage.groundOffsetChangedMessage, offset)) } + private fun setMemoryVariable(sender: CommandSender, pet: Pet, key: String, value: String) { + pet.memory[key] = value + sender.sendPluginMessage(String.format(PetBlocksLanguage.variableChangedMessage, key, value)) + } + private fun CommandSender.sendPluginMessage(message: String) { if (message.isBlank()) { return diff --git a/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt b/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt index 3809b907f..c1c684fe9 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/listener/PetListener.kt @@ -48,6 +48,7 @@ class PetListener @Inject constructor( plugin.logger.log(Level.FINE, "Loaded [${pets.size}] pets for player ${player.name}.") } + // Apply pets from config val petsToReceive = configurationService.findValue>>(petsToReceiveOnJoinKey) for (petToReceive in petsToReceive) { @@ -63,6 +64,24 @@ class PetListener @Inject constructor( ) } } + + // Fix references of pet to world which does not exist anymore. e.g. Cross Servers + for (pet in pets) { + var resetToOwnerPosition = false + + try { + if (pet.location.world == null) { + resetToOwnerPosition = true + } + } catch (e: Exception) { + // Exception handling is important here. + resetToOwnerPosition = true + } + + if (resetToOwnerPosition) { + pet.location = player.location + } + } } } diff --git a/src/main/java/com/github/shynixn/petblocks/impl/provider/PetBlocksPlaceHolderProvider.kt b/src/main/java/com/github/shynixn/petblocks/impl/provider/PetBlocksPlaceHolderProvider.kt index cbd8b4968..f2523f700 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/provider/PetBlocksPlaceHolderProvider.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/provider/PetBlocksPlaceHolderProvider.kt @@ -13,10 +13,8 @@ import java.util.* import kotlin.collections.HashMap class PetBlocksPlaceHolderProvider( - private val petMetaRepository: CachePlayerRepository, - private val petService: PetService -) : - PlaceHolderProvider { + private val petMetaRepository: CachePlayerRepository, private val petService: PetService +) : PlaceHolderProvider { private val playerPlaceHolderFunctions = HashMap String)>() private val petPlaceHolderFunctions = HashMap String)>() private val selectedPetPlaceHolderFunctions = HashMap String)>() @@ -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() } @@ -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() } @@ -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 } @@ -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) { @@ -231,7 +200,7 @@ class PetBlocksPlaceHolderProvider( pet = petsOfPlayer.firstOrNull() } - if (pet != null) { + if (pet != null && selectedPetPlaceHolderFunctions.containsKey(placeHolderText)) { locatedPlaceHolders[placeHolderText] = selectedPetPlaceHolderFunctions[placeHolderText]!!.invoke(pet) } @@ -250,8 +219,8 @@ 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) { @@ -259,7 +228,8 @@ class PetBlocksPlaceHolderProvider( 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) } } } diff --git a/src/main/java/com/github/shynixn/petblocks/impl/service/PetActionExecutionServiceImpl.kt b/src/main/java/com/github/shynixn/petblocks/impl/service/PetActionExecutionServiceImpl.kt index 3b894a490..a65672a71 100644 --- a/src/main/java/com/github/shynixn/petblocks/impl/service/PetActionExecutionServiceImpl.kt +++ b/src/main/java/com/github/shynixn/petblocks/impl/service/PetActionExecutionServiceImpl.kt @@ -104,7 +104,11 @@ class PetActionExecutionServiceImpl @Inject constructor( if (conditionType == PetActionConditionType.JAVASCRIPT) { val placeHolderParsedCondition = - placeHolderService.resolvePlaceHolder(eventPlayer, condition.js!!, mapOf(PetBlocksPlaceHolderProvider.petKey to pet)) + placeHolderService.resolvePlaceHolder( + eventPlayer, + condition.js!!, + mapOf(PetBlocksPlaceHolderProvider.petKey to pet) + ) val conditionResult = withContext(plugin.asyncDispatcher) { scriptService.evaluate(placeHolderParsedCondition) } as Boolean @@ -118,8 +122,16 @@ class PetActionExecutionServiceImpl @Inject constructor( return conditionResult } else { - val leftEscaped = placeHolderService.resolvePlaceHolder(eventPlayer, condition.left!!, mapOf(PetBlocksPlaceHolderProvider.petKey to pet)) - val rightEscaped = placeHolderService.resolvePlaceHolder(eventPlayer, condition.right!!, mapOf(PetBlocksPlaceHolderProvider.petKey to pet)) + val leftEscaped = placeHolderService.resolvePlaceHolder( + eventPlayer, + condition.left!!, + mapOf(PetBlocksPlaceHolderProvider.petKey to pet) + ) + val rightEscaped = placeHolderService.resolvePlaceHolder( + eventPlayer, + condition.right!!, + mapOf(PetBlocksPlaceHolderProvider.petKey to pet) + ) if (conditionType == PetActionConditionType.STRING_EQUALS) { val conditionResult = rightEscaped == leftEscaped @@ -143,9 +155,8 @@ class PetActionExecutionServiceImpl @Inject constructor( } return conditionResult - } - else if (conditionType == PetActionConditionType.STRING_EQUALS_IGNORE_CASE) { - val conditionResult = rightEscaped.equals(leftEscaped,true) + } else if (conditionType == PetActionConditionType.STRING_EQUALS_IGNORE_CASE) { + val conditionResult = rightEscaped.equals(leftEscaped, true) if (action.debug) { plugin.logger.log( @@ -156,7 +167,7 @@ class PetActionExecutionServiceImpl @Inject constructor( return conditionResult } else if (conditionType == PetActionConditionType.STRING_NOT_EQUALS_IGNORE_CASE) { - val conditionResult = !rightEscaped.equals(leftEscaped,true) + val conditionResult = !rightEscaped.equals(leftEscaped, true) if (action.debug) { plugin.logger.log( @@ -166,8 +177,7 @@ class PetActionExecutionServiceImpl @Inject constructor( } return conditionResult - } - else { + } else { val leftNumber = leftEscaped.toDoubleOrNull() if (leftNumber == null) { @@ -259,7 +269,11 @@ class PetActionExecutionServiceImpl @Inject constructor( command } - executionCommand = placeHolderService.resolvePlaceHolder(eventPlayer, executionCommand, mapOf(PetBlocksPlaceHolderProvider.petKey to pet)) + executionCommand = placeHolderService.resolvePlaceHolder( + eventPlayer, + executionCommand, + mapOf(PetBlocksPlaceHolderProvider.petKey to pet) + ) if (action.debug) { plugin.logger.log(Level.INFO, "Start executing command '${executionCommand}'.") @@ -278,12 +292,16 @@ class PetActionExecutionServiceImpl @Inject constructor( } private suspend fun executeJavaScriptAction(player: Player, pet: Pet, action: PetAction) { - if (action.initial != null && !pet.javaScriptMemory.containsKey(action.variable)) { - pet.javaScriptMemory[action.variable!!] = action.initial!! + if (action.initial != null && !pet.memory.containsKey(action.variable)) { + pet.memory[action.variable!!] = action.initial!! } val parsedJs = - placeHolderService.resolvePlaceHolder(player, action.js!!, mapOf(PetBlocksPlaceHolderProvider.petKey to pet)) + placeHolderService.resolvePlaceHolder( + player, + action.js!!, + mapOf(PetBlocksPlaceHolderProvider.petKey to pet) + ) if (action.debug) { plugin.logger.log(Level.INFO, "Start evaluating JavaScript '${parsedJs}'.") @@ -297,7 +315,7 @@ class PetActionExecutionServiceImpl @Inject constructor( plugin.logger.log(Level.INFO, "End evaluating JavaScript '${result}'.") } - val memory = pet.javaScriptMemory + val memory = pet.memory if (result == null && memory.containsKey(action.variable)) { memory.remove(action.variable) diff --git a/src/main/resources/lang/en_us.properties b/src/main/resources/lang/en_us.properties index 747c2a8e0..eee0bde3e 100644 --- a/src/main/resources/lang/en_us.properties +++ b/src/main/resources/lang/en_us.properties @@ -98,3 +98,6 @@ nextCommandHint=Opens the next GUI page. messageCommandHint=Sends a chat message. guiMenuNotFoundMessage=[&9PetBlocks&f] &cMenu %1$1s not found. guiMenuNoPermissionMessage=[&9PetBlocks&f] &cYou do not have permission for menu %1$1s. +variableCommandHint=Sets the value of the variable with the given key. This is useful store arbitrary data into the pet e.g. health. +variableChangedMessage=[&9PetBlocks&f] The pet memory variable %1$1s has been set to %2$1s. +velocityRelCommandHint=Launches the pet into the current looking direction with the given multipliers. diff --git a/src/main/resources/plugin-legacy.yml b/src/main/resources/plugin-legacy.yml index 3e748d45b..92e34a087 100644 --- a/src/main/resources/plugin-legacy.yml +++ b/src/main/resources/plugin-legacy.yml @@ -1,5 +1,5 @@ name: PetBlocks -version: 9.10.0 +version: 9.11.0 author: Shynixn main: com.github.shynixn.petblocks.PetBlocksPlugin softdepend: [ PlaceholderAPI, HeadDatabase] diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 57abdf605..02d9adec9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: PetBlocks -version: 9.10.0 +version: 9.11.0 author: Shynixn main: com.github.shynixn.petblocks.PetBlocksPlugin softdepend: [ PlaceholderAPI, HeadDatabase]