-
Notifications
You must be signed in to change notification settings - Fork 2
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
9f7def6
commit ae233b4
Showing
1 changed file
with
4 additions
and
23 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 |
---|---|---|
|
@@ -9,12 +9,8 @@ | |
|
||
|
||
class ExamplePlugin(Plugin): | ||
name = "PythonExamplePlugin" | ||
version = "0.4.0" | ||
prefix = "PythonExamplePlugin" | ||
api_version = "0.4" | ||
description = "Python example plugin for Endstone servers" | ||
authors = ["Endstone Developers <[email protected]>"] | ||
website = "https://github.com/EndstoneMC/python-example-plugin" | ||
load = "POSTWORLD" | ||
|
||
commands = { | ||
|
@@ -24,15 +20,6 @@ class ExamplePlugin(Plugin): | |
"aliases": ["py"], | ||
"permissions": ["python_example.command.python"], | ||
}, | ||
"test": { | ||
"description": "This is a test command from python", | ||
"usages": [ | ||
"/test", | ||
"/test [value: int]", | ||
"/test [value: float]", | ||
], | ||
"permissions": ["python_example.command.test"], | ||
}, | ||
"kickme": { | ||
"description": "Ask the server to kick you with a custom message", | ||
"usages": ["/kickme [reason: message]"], | ||
|
@@ -72,22 +59,16 @@ def on_enable(self) -> None: | |
self.get_command("python").executor = PythonCommandExecutor() | ||
|
||
self.register_events(self) # register event listeners defined directly in Plugin class | ||
self._listener = ExampleListener(self) | ||
self.register_events(self._listener) # you can also register event listeners in a separate class | ||
self.register_events(ExampleListener(self)) # you can also register event listeners in a separate class | ||
|
||
self.server.scheduler.run_task_timer(self, self.log_time, 0, 20 * 1) # every second | ||
self.server.scheduler.run_task(self, self.log_time, delay=0, period=20 * 1) # every second | ||
|
||
def on_disable(self) -> None: | ||
self.logger.info("on_disable is called!") | ||
|
||
def on_command(self, sender: CommandSender, command: Command, args: list[str]) -> bool: | ||
# You can also handle commands here instead of setting an executor in on_enable if you prefer | ||
match command.name: | ||
case "test": | ||
if len(args) > 0: | ||
sender.send_message(f"Test with number: {args[0]}!") | ||
else: | ||
sender.send_message("Test!!") | ||
case "kickme": | ||
player = sender.as_player() | ||
if player is None: | ||
|
@@ -108,7 +89,7 @@ def on_server_load(self, event: ServerLoadEvent): | |
@event_handler(priority=EventPriority.HIGH) | ||
def on_server_load_2(self, event: ServerLoadEvent): | ||
# this will be called after on_server_load because of a higher priority | ||
self.server.dispatch_command(self.server.command_sender, "say Hello world!") | ||
self.logger.info(f"{event.event_name} is passed to on_server_load2") | ||
|
||
def log_time(self): | ||
now = datetime.datetime.now().strftime("%c") | ||
|