diff --git a/src/endstone_test/event_listener.py b/src/endstone_test/event_listener.py index c2b3ba8..61b4e5d 100644 --- a/src/endstone_test/event_listener.py +++ b/src/endstone_test/event_listener.py @@ -1,6 +1,5 @@ import datetime from functools import partial -from uuid import UUID from endstone import ColorFormat, Server from endstone.event import event_handler, PlayerJoinEvent @@ -13,16 +12,16 @@ def __init__(self, plugin: Plugin): @event_handler def on_player_join(self, event: PlayerJoinEvent) -> None: - def send_welcome_message(player_name: str, player_id: UUID) -> None: + def send_welcome_message(player_name: str) -> None: self.server.broadcast_message(ColorFormat.YELLOW + f"{player_name} joined the game.") self.server.scheduler.run_task_later( - self._plugin, partial(send_welcome_message, event.player.name, event.player.unique_id), delay=20 + self._plugin, partial(send_welcome_message, event.player.name), 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(fixme): this will crash + assert self.server.get_player(event.player.unique_id) is event.player self._plugin.logger.info("===========================") self._plugin.logger.info(f"Name: {event.player.name}") diff --git a/src/endstone_test/plugin.py b/src/endstone_test/plugin.py index cdf21ca..dd836ae 100644 --- a/src/endstone_test/plugin.py +++ b/src/endstone_test/plugin.py @@ -1,3 +1,6 @@ +import datetime +import uuid + from endstone import __minecraft_version__ from endstone.plugin import Plugin @@ -42,8 +45,10 @@ def on_enable(self) -> None: self.server.max_players = 100 assert self.server.max_players == 100 - self.server.broadcast_message("Hello!") + assert self.server.get_player("non-existent") is None + assert self.server.get_player(uuid.uuid4()) is None + 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: @@ -52,7 +57,7 @@ def on_disable(self) -> None: 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"Level: {player.level.name}, Time: {player.level.time}, Ping: {player.ping / datetime.timedelta(milliseconds=1)}\n" f"Location: {player.location}\n" f"Velocity: {player.velocity}\n" f"Dimension: {player.location.dimension.name}\n"