From 34727a3b41c209749e257146890ad8b0123a39ce Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 17 Jun 2024 02:13:37 +0100 Subject: [PATCH] feat: add more tests --- src/endstone_test/event_listener.py | 19 ++++++++++++++----- src/endstone_test/plugin.py | 3 ++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/endstone_test/event_listener.py b/src/endstone_test/event_listener.py index 7b3e1b4..0c74bfb 100644 --- a/src/endstone_test/event_listener.py +++ b/src/endstone_test/event_listener.py @@ -2,7 +2,7 @@ from functools import partial from endstone import ColorFormat, Server -from endstone.event import event_handler, PlayerLoginEvent, PlayerJoinEvent +from endstone.event import * from endstone.plugin import Plugin @@ -23,9 +23,7 @@ def on_player_join(self, event: PlayerJoinEvent) -> 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), delay=20 - ) + self.server.scheduler.run_task_later(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 @@ -39,7 +37,7 @@ def send_welcome_message(player_name: str) -> None: 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"Op status: {event.player.is_op}") self._plugin.logger.info(f"Ping: {event.player.ping / datetime.timedelta(milliseconds=1)}") self._plugin.logger.info("===========================") @@ -51,6 +49,17 @@ def send_welcome_message(player_name: str) -> None: assert event.player.has_permission("minecraft.command.me") is False event.player.update_commands() + event.player.allow_flight = True + assert event.player.allow_flight is True + + @event_handler + def on_player_death(self, event: PlayerDeathEvent): + self._plugin.logger.info(f"{event.player.name} dies.") + + @event_handler + def on_actor_death(self, event: ActorDeathEvent): + self._plugin.logger.info(f"{event.actor.name} dies.") + @property def server(self) -> Server: return self._plugin.server diff --git a/src/endstone_test/plugin.py b/src/endstone_test/plugin.py index 0a4fc49..430a424 100644 --- a/src/endstone_test/plugin.py +++ b/src/endstone_test/plugin.py @@ -3,6 +3,7 @@ from endstone import __minecraft_version__ from endstone.plugin import Plugin + from endstone_test.event_listener import EventListener @@ -69,5 +70,5 @@ def send_debug_message(self): 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}" + f"OnGround: {player.is_on_ground}, MayFly: {player.allow_flight}, Flying: {player.is_flying}" )