Skip to content

Commit

Permalink
#575 Added /petblocks velocityrel command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Shynixn committed Jul 26, 2024
1 parent b5cc12c commit c17afff
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 3 deletions.
16 changes: 15 additions & 1 deletion docs/wiki/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,26 @@ 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> [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.
* Player: Optional player_name/player_UUID parameter targeting a player from the console or command block.


### /petblocks skintype

```
Expand Down
3 changes: 2 additions & 1 deletion docs/wiki/docs/permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -58,4 +59,4 @@ The following permissions are available in PetBlocks.
| 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.variable | Admin | Allows to use the /petblocks variable command
| petblocks.pet.variable | Admin | Allows to use the /petblocks variable command
Original file line number Diff line number Diff line change
Expand Up @@ -118,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
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 @@ -38,6 +39,7 @@ enum class Permission(val text: String) {
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 @@ -459,6 +459,25 @@ 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("player").validator(playerMustExist).tabs(onlinePlayerTabs)
.permission(manipulateOtherPermission).permissionMessage(manipulateOtherPermissionMessage)
.execute { commandSender, name, x, y, z, player ->
setRelativeVelocityToPet(
commandSender, petMustExist(player, name), Vector(x, y, z)
)
}
}
subCommand("skintype") {
permission(Permission.SKIN)
toolTip { PetBlocksLanguage.skinTypeCommandHint }
Expand Down Expand Up @@ -727,7 +746,8 @@ class PetBlocksCommandExecutor @Inject constructor(
permission(Permission.VARIABLE)
toolTip { PetBlocksLanguage.variableCommandHint }
builder().argument("name").tabs(petNamesTabs)
.argument("key").argument("value").executePlayer(senderHasToBePlayer) { player, name, key, value ->
.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)
Expand Down Expand Up @@ -841,6 +861,14 @@ class PetBlocksCommandExecutor @Inject constructor(
sender.sendPluginMessage(String.format(PetBlocksLanguage.petVelocityAppliedMessage, pet.name))
}

private fun setRelativeVelocityToPet(
sender: CommandSender, pet: Pet, vector: Vector
) {
val normalized = pet.velocity.normalize()
pet.velocity = normalized.multiply(vector)
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
1 change: 1 addition & 0 deletions src/main/resources/lang/en_us.properties
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ 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.

0 comments on commit c17afff

Please sign in to comment.