Skip to content

Commit

Permalink
Merge pull request #598 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 26, 2024
2 parents 637d85a + 4120826 commit c91d451
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 94 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
32 changes: 31 additions & 1 deletion docs/wiki/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> <mx> <my> <mz> [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

```
Expand Down Expand Up @@ -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 <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
24 changes: 13 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 All @@ -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. |
Expand All @@ -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
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 @@ -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."

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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."),
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 @@ -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("<mx>") }.argument("my").validator(mustBeDouble).tabs { listOf("<my>") }
.argument("mz").validator(mustBeDouble).tabs { listOf("<mz>") }
.executePlayer(senderHasToBePlayer) { player, name, x, y, z ->
setRelativeVelocityToPet(
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, 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)
Expand Down Expand Up @@ -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("<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)
.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 @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit c91d451

Please sign in to comment.