Skip to content

Commit

Permalink
#576 Added /petblocks variable command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Jul 26, 2024
1 parent 4756944 commit b5cc12c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 11 deletions.
15 changes: 15 additions & 0 deletions docs/wiki/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> <key> <value> [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:**
Expand Down
23 changes: 12 additions & 11 deletions docs/wiki/docs/permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/lang/en_us.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit b5cc12c

Please sign in to comment.