Skip to content

Commit

Permalink
test: add tests for Player.send_particle
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Oct 22, 2024
1 parent 85d14c9 commit bd698d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
18 changes: 17 additions & 1 deletion src/endstone_test/command_executor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

import numpy as np
from endstone import ColorFormat, Player
from endstone.command import (
Command,
Expand All @@ -9,6 +10,7 @@
)
from endstone.form import *
from endstone.lang import Translatable as tr
from endstone.util import Vector


class TestCommandExecutor(CommandExecutor):
Expand Down Expand Up @@ -115,7 +117,7 @@ def on_command(
sender.send_error_message(f"Unknown sender: {sender.__class__}")
return False

case ["player", ("toast" | "title" | "kick") as test_type]:
case ["player", ("toast" | "title" | "kick" | "particle") as test_type]:
if not isinstance(sender, Player):
sender.send_error_message(
"You must execute this command as a player"
Expand All @@ -128,6 +130,20 @@ def on_command(
sender.send_title("Welcome!", sender.name)
elif test_type == "kick":
sender.kick("kick is working!")
elif test_type == "particle":
radius = 1.0
points = 20
angles = np.linspace(0, 2 * np.pi, points, endpoint=False)
x_values = radius * np.cos(angles)
z_values = radius * np.sin(angles)
for x, z in zip(x_values, z_values):
location = sender.location + Vector(x, 1, z)
sender.spawn_particle(
"minecraft:basic_flame_particle",
location.x,
location.y,
location.z,
)

case ["block", *rest]:
sender.send_message(str(rest))
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_test/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class EndstoneTest(Plugin):
"usages": [
"/test (form)<test: FormTestAction> (message|action|modal)<type: FormTestTypes>",
"/test (sender)<test: SenderTestAction>",
"/test (player)<test: PlayerTestAction> (toast|kick)<type: PlayerTestTypes>",
"/test (player)<test: PlayerTestAction> (toast|title|kick|particle)<type: PlayerTestTypes>",
"/test (block)<test: BlockTestAction> <block: block> [blockStates: block_states]",
],
"permissions": ["endstone_test.command.test"],
Expand Down
4 changes: 3 additions & 1 deletion src/endstone_test/tests/on_player_join/test_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def test_player_add_tag(player: Player, server: Server):
assert "test_tag" in player.scoreboard_tags

assert not player.add_scoreboard_tag("test_tag")
server.dispatch_command(server.command_sender, f'tag "{player.name}" remove test_tag')
server.dispatch_command(
server.command_sender, f'tag "{player.name}" remove test_tag'
)


def test_player_remove_tag(player: Player, server: Server):
Expand Down
2 changes: 1 addition & 1 deletion src/endstone_test/tests/on_player_join/test_scoreboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def scoreboard(server: Server) -> Scoreboard:


def test_scoreboard_value(
player: Player, server: Server, scoreboard: Scoreboard
player: Player, server: Server, scoreboard: Scoreboard
) -> None:
server.dispatch_command(
server.command_sender, "scoreboard objectives add test_objective dummy"
Expand Down

0 comments on commit bd698d6

Please sign in to comment.