From f4d89d64c4b23031dd2fd673742166319a2dbc24 Mon Sep 17 00:00:00 2001 From: Vincent Date: Thu, 2 May 2024 16:13:11 +0100 Subject: [PATCH] feat: send current time to all online players --- src/endstone_example/example_listener.py | 4 +++- src/endstone_example/example_plugin.py | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/endstone_example/example_listener.py b/src/endstone_example/example_listener.py index 7e99e22..8379850 100644 --- a/src/endstone_example/example_listener.py +++ b/src/endstone_example/example_listener.py @@ -1,3 +1,5 @@ +from datetime import datetime + from endstone import ColorFormat from endstone.event import event_handler, EventPriority, PlayerJoinEvent, PlayerQuitEvent, ServerListPingEvent from endstone.plugin import Plugin @@ -9,7 +11,7 @@ def __init__(self, plugin: Plugin): @event_handler(priority=EventPriority.HIGHEST) def on_server_list_ping(self, event: ServerListPingEvent): - event.motd = ColorFormat.BOLD + ColorFormat.AQUA + "Example MOTD" + event.motd = ColorFormat.BOLD + ColorFormat.AQUA + datetime.now().strftime("%c") event.level_name = f"Your IP is {ColorFormat.YELLOW}{event.remote_host}:{event.remote_port}{ColorFormat.RESET}" @event_handler diff --git a/src/endstone_example/example_plugin.py b/src/endstone_example/example_plugin.py index 3535a16..83e11ae 100644 --- a/src/endstone_example/example_plugin.py +++ b/src/endstone_example/example_plugin.py @@ -62,7 +62,7 @@ def on_enable(self) -> None: self._listener = ExampleListener(self) self.register_events(self._listener) # you can also register event listeners in a separate class - self.server.scheduler.run_task_timer(self, self.log_time, 0, 20 * 10) # every 10 seconds + self.server.scheduler.run_task_timer(self, self.log_time, 0, 20 * 1) # every second def on_disable(self) -> None: self.logger.info("on_disable is called!") @@ -94,5 +94,6 @@ def on_server_load_2(self, event: ServerLoadEvent): self.logger.info(f"{event.event_name} is passed to on_server_load_2. This will be called after on_server_load.") def log_time(self): - now = datetime.datetime.now() - self.logger.info(now.strftime("%c")) + now = datetime.datetime.now().strftime("%c") + for player in self.server.online_players: + player.send_popup(now)