Skip to content

Commit

Permalink
feat: send current time to all online players
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed May 2, 2024
1 parent 55e33db commit f4d89d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/endstone_example/example_listener.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/endstone_example/example_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down Expand Up @@ -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)

0 comments on commit f4d89d6

Please sign in to comment.