Skip to content

Commit

Permalink
feat: add an event handler for ServerListPingEvent to customise serve…
Browse files Browse the repository at this point in the history
…r info displayed to players
  • Loading branch information
wu-vincent committed Mar 25, 2024
1 parent 7caaea6 commit cb91767
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/endstone_example/example_listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from endstone.event import ServerListPingEvent, event_handler, EventPriority
from endstone.util import ColorFormat


class ExampleListener:
@event_handler(priority=EventPriority.HIGHEST)
def on_server_list_ping(self, event: ServerListPingEvent):
event.motd = ColorFormat.BOLD + ColorFormat.AQUA + "Example MOTD"
event.level_name = f"Your IP is {ColorFormat.YELLOW}{event.remote_host}:{event.remote_port}{ColorFormat.RESET}"
6 changes: 5 additions & 1 deletion src/endstone_example/example_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from endstone.event import EventPriority, ServerLoadEvent, event_handler
from endstone.plugin import Plugin

from endstone_example.example_listener import ExampleListener
from endstone_example.python_command import PythonCommandExecutor


Expand Down Expand Up @@ -54,7 +55,10 @@ def on_load(self) -> None:
def on_enable(self) -> None:
self.logger.info("on_enable is called!")
self.get_command("python").executor = PythonCommandExecutor()
self.register_events(self)

self.register_events(self) # register event listeners defined directly in Plugin class
self.listener = ExampleListener()
self.register_events(self.listener) # you can also register event listeners in a separate class

def on_disable(self) -> None:
self.logger.info("on_disable is called!")
Expand Down

0 comments on commit cb91767

Please sign in to comment.