From b5cc12c61cf6fd421127346d87cd64c0882e4414 Mon Sep 17 00:00:00 2001 From: Shynixn Date: Fri, 26 Jul 2024 14:39:52 +0200 Subject: [PATCH] #576 Added /petblocks variable command. --- docs/wiki/docs/commands.md | 15 ++++++++++++ docs/wiki/docs/permission.md | 23 ++++++++++--------- .../shynixn/petblocks/PetBlocksLanguage.kt | 6 +++++ .../petblocks/enumeration/Permission.kt | 1 + .../PetBlocksCommandExecutor.kt | 18 +++++++++++++++ src/main/resources/lang/en_us.properties | 2 ++ 6 files changed, 54 insertions(+), 11 deletions(-) diff --git a/docs/wiki/docs/commands.md b/docs/wiki/docs/commands.md index 7e203136d..a536e126e 100644 --- a/docs/wiki/docs/commands.md +++ b/docs/wiki/docs/commands.md @@ -463,6 +463,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..d2f44b4aa 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. | @@ -56,5 +56,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..8305210c1 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." @@ -208,6 +211,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/enumeration/Permission.kt b/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt index 2bdaa6176..9ec775e08 100644 --- a/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt +++ b/src/main/java/com/github/shynixn/petblocks/enumeration/Permission.kt @@ -37,6 +37,7 @@ 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/commandexecutor/PetBlocksCommandExecutor.kt b/src/main/java/com/github/shynixn/petblocks/impl/commandexecutor/PetBlocksCommandExecutor.kt index 94aa8ed42..687d47678 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 @@ -723,6 +723,19 @@ class PetBlocksCommandExecutor @Inject constructor( snap(commandSender, petMustExist(player, name)) } } + subCommand("variable") { + permission(Permission.VARIABLE) + toolTip { PetBlocksLanguage.variableCommandHint } + builder().argument("name").tabs(petNamesTabs) + .argument("key").argument("value").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 } @@ -1060,6 +1073,11 @@ class PetBlocksCommandExecutor @Inject constructor( sender.sendPluginMessage(String.format(PetBlocksLanguage.groundOffsetChangedMessage, offset)) } + private fun setMemoryVariable(sender: CommandSender, pet: Pet, key: String, value: String) { + pet.javaScriptMemory[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/resources/lang/en_us.properties b/src/main/resources/lang/en_us.properties index 747c2a8e0..8ee93790b 100644 --- a/src/main/resources/lang/en_us.properties +++ b/src/main/resources/lang/en_us.properties @@ -98,3 +98,5 @@ 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.