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 17, 2024
1 parent 1f7f167 commit 34727a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 14 additions & 5 deletions src/endstone_test/event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
Expand All @@ -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("===========================")

Expand All @@ -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
3 changes: 2 additions & 1 deletion src/endstone_test/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from endstone import __minecraft_version__
from endstone.plugin import Plugin

from endstone_test.event_listener import EventListener


Expand Down Expand Up @@ -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}"
)

0 comments on commit 34727a3

Please sign in to comment.