Skip to content

Commit

Permalink
feat: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jun 14, 2024
1 parent 1d38a95 commit 213630f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/endstone_test/event_listener.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import datetime
from functools import partial
from uuid import UUID

Expand All @@ -14,15 +15,29 @@ def __init__(self, plugin: Plugin):
def on_player_join(self, event: PlayerJoinEvent) -> None:
def send_welcome_message(player_name: str, player_id: UUID) -> None:
self.server.broadcast_message(ColorFormat.YELLOW + f"{player_name} joined the game.")
self.server.dispatch_command(self.server.command_sender, f"say {player_name}, uuid: {player_id}")

self.server.scheduler.run_task_later(
self._plugin, partial(send_welcome_message, event.player.name, event.player.unique_id), delay=20
)

assert event.player in self.server.online_players
assert self.server.get_player(event.player.name) is event.player
# assert self.server.get_player(event.player.unique_id) is event.player # TODO: this will crash
# assert self.server.get_player(event.player.unique_id) is event.player # TODO(fixme): this will crash

self._plugin.logger.info("===========================")
self._plugin.logger.info(f"Name: {event.player.name}")
self._plugin.logger.info(f"UUID: {event.player.unique_id}")
self._plugin.logger.info(f"Entity Id: {event.player.runtime_id}")
self._plugin.logger.info(f"Address: {event.player.address}")
self._plugin.logger.info(f"Game mode: {event.player.game_mode}")
self._plugin.logger.info(f"Location: {event.player.location}")
self._plugin.logger.info(f"Velocity: {event.player.velocity}")
self._plugin.logger.info(f"Op status: {event.player.op}")
self._plugin.logger.info(f"Ping: {event.player.ping / datetime.timedelta(milliseconds=1)}")
self._plugin.logger.info("===========================")

assert event.player.inventory.size == 36
assert event.player.inventory.max_stack_size == 254

@property
def server(self) -> Server:
Expand Down
18 changes: 18 additions & 0 deletions src/endstone_test/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,30 @@ def on_enable(self) -> None:
self._listener = EventListener(self)
self.register_events(self._listener)

assert self.get_command("test") is not None
assert self.get_command("test").plugin is self

self.logger.info("on_enable is called!")

assert len(self.server.levels) == 1
assert self.server.max_players == 10
self.server.max_players = 100
assert self.server.max_players == 100

self.server.broadcast_message("Hello!")

self.server.scheduler.run_task_timer(self, self.send_debug_message, delay=0, period=10)

def on_disable(self) -> None:
self.logger.info("on_disable is called!")

def send_debug_message(self):
for player in self.server.online_players:
player.send_tip(
f"Level: {player.level.name}, Time: {player.level.time}\n"
f"Location: {player.location}\n"
f"Velocity: {player.velocity}\n"
f"Dimension: {player.location.dimension.name}\n"
f"InWater: {player.is_in_water}, InLava: {player.is_in_lava}\n"
f"OnGround: {player.is_on_ground}, Flying: {player.is_flying}"
)

0 comments on commit 213630f

Please sign in to comment.