Skip to content

Commit

Permalink
feat: add /test command
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jun 14, 2024
1 parent 72d5270 commit 1d38a95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/endstone_test/event_listener.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from functools import partial
from uuid import UUID

from endstone import Server
from endstone import ColorFormat, Server
from endstone.event import event_handler, PlayerJoinEvent
from endstone.plugin import Plugin

Expand All @@ -12,14 +12,15 @@ def __init__(self, plugin: Plugin):

@event_handler
def on_player_join(self, event: PlayerJoinEvent) -> None:
def send_welcome_message(player_name: str, player_id: uuid.UUID) -> None:
self.server.broadcast_message(f"Welcome {player_name} to the server.")
def send_welcome_message(player_name: str, player_id: UUID) -> None:
self.server.broadcast_message(ColorFormat.YELLOW + f"{player_name} joined the game.")
self.server.dispatch_command(self.server.command_sender, f"say {player_name}, uuid: {player_id}")

self.server.scheduler.run_task_later(self._plugin,
partial(send_welcome_message, event.player.name, event.player.unique_id),
delay=20)
self.server.scheduler.run_task_later(
self._plugin, partial(send_welcome_message, event.player.name, event.player.unique_id), delay=20
)

assert event.player in self.server.online_players
assert self.server.get_player(event.player.name) is event.player
# assert self.server.get_player(event.player.unique_id) is event.player # TODO: this will crash

Expand Down
15 changes: 15 additions & 0 deletions src/endstone_test/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,21 @@ class TestPlugin(Plugin):
name = "EndstoneTest"
api_version = "0.4"

commands = {
"test": {
"description": "Run the test command",
"usages": ["/test"],
"permissions": ["endstone_test.command.test"],
}
}

permissions = {
"endstone_test.command.test": {
"description": "Allow users to use the /test command.",
"default": True,
}
}

def on_load(self) -> None:
self.logger.info("on_load is called!")
assert len(self.server.levels) == 0
Expand Down

0 comments on commit 1d38a95

Please sign in to comment.