generated from EndstoneMC/python-example-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9281fe
commit 72d5270
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import uuid | ||
from functools import partial | ||
|
||
from endstone import Server | ||
from endstone.event import event_handler, PlayerJoinEvent | ||
from endstone.plugin import Plugin | ||
|
||
|
||
class EventListener: | ||
def __init__(self, plugin: Plugin): | ||
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.") | ||
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) | ||
|
||
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 | ||
|
||
@property | ||
def server(self) -> Server: | ||
return self._plugin.server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
from endstone import __minecraft_version__ | ||
from endstone.plugin import Plugin | ||
|
||
from endstone_test.event_listener import EventListener | ||
|
||
|
||
class TestPlugin(Plugin): | ||
name = "EndstoneTest" | ||
api_version = "0.4" | ||
|
||
def on_load(self) -> None: | ||
self.logger.info("on_load is called!") | ||
assert len(self.server.levels) == 0 | ||
assert self.server.minecraft_version == f"v{__minecraft_version__}" | ||
|
||
def on_enable(self) -> None: | ||
self._listener = EventListener(self) | ||
self.register_events(self._listener) | ||
|
||
self.logger.info("on_enable is called!") | ||
|
||
assert len(self.server.levels) == 1 | ||
assert self.server.max_players == 10 | ||
self.server.max_players = 100 | ||
assert self.server.max_players == 100 | ||
|
||
def on_disable(self) -> None: | ||
self.logger.info("on_disable is called!") |