Skip to content

Commit

Permalink
awa
Browse files Browse the repository at this point in the history
  • Loading branch information
FTS427 committed Aug 30, 2024
1 parent 3a44ce1 commit fdfa792
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 214 deletions.
76 changes: 2 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,75 +1,3 @@
# Endstone Python Example Plugin
# Better Sever

Welcome to the example Python plugin for Endstone servers.

## Prerequisites

- Python 3.9 or higher.
- Endstone installed and set up in your Python environment.

## Structure Overview

```
python-example-plugin/
├── src/ # Main source directory
│ └── endstone_example/ # Directory for the plugin package
│ ├── __init__.py # Initializer for the package, importing ExamplePlugin class from example_plugin.py
│ ├── example_plugin.py # Implementation of ExamplePlugin class
│ └── python_command.py # Custom command executor for /python
├── .gitignore # Git ignore rules
├── LICENSE # License details
├── README.md # This file
└── pyproject.toml # Plugin configuration file which specifies the entrypoint
```

## Getting Started

1. **Clone this Repository**

```bash
git clone https://github.com/EndstoneMC/python-example-plugin.git
```

2. **Navigate to the Cloned Directory**

```bash
cd python-example-plugin
```

3. **Install Your Plugin**

When developing the plugin, you may want to install an editable package to your Python environment, this allows you
to update the codes without having to reinstall the package everytime:
```bash
pip install -e .
```
**NOTE: It is strongly recommended to create a virtual environment for your Endstone server and plugins. When
installing your plugin using `pip install`, please ensure the virtual environment is activated.**

Ensure your plugin is loaded correctly by checking the server logs or console for the log messages.

4. **Package and Distribute Your Plugin**

When everything is good to go, you can package your plugin into a `.whl` (Wheel) file for easier distribution:

```bash
pip install pipx
pipx run build --wheel
```

This command will produce a `.whl` file in the `dist` directory. Copy the `.whl` file to the `plugins` directory
of your Endstone server. Start the Endstone server and check the logs to ensure your plugin loads and operates
as expected.

To publish your plugin to a package index such as PyPI, please refer to:
- [Using TestPyPI](https://packaging.python.org/en/latest/guides/using-testpypi/)
- [Publishing package distribution releases using GitHub Actions CI/CD workflows](https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/)

## Documentation

For a deeper dive into the Endstone API and its functionalities, refer to the main
Endstone [documentation](https://endstone.readthedocs.io) (WIP).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Add some useless function
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "endstone-example"
version = "0.4.0"
name = "endstone-better-server"
version = "0.0.1"
dependencies = []
authors = [
{ name = "Endstone Developers", email = "[email protected]" },
{ name = "Huang FTS427", email = "[email protected]" },
]
description = "Python example plugin for Endstone servers"
description = "ZH-Server's plugin"
readme = "README.md"
license = { file = "LICENSE" }
keywords = ["endstone", "plugin"]

[project.urls]
Homepage = "https://github.com/EndstoneMC/python-example-plugin"
Homepage = "https://github.com/https://github.com/ZH-Server/endstone_better_server"

[project.entry-points."endstone"]
example = "endstone_example:ExamplePlugin"
example = "endstone_better_server:BetterServer"
3 changes: 3 additions & 0 deletions src/better_server/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from better_server.better_server import BetterServer

__all__ = ["BetterServer"]
20 changes: 20 additions & 0 deletions src/better_server/better_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from endstone.plugin import Plugin

from better_server.listener import PLayerListener

class BetterServer(Plugin):
api_version = "0.5"

def on_load(self) -> None:
self.logger.info("BetterServer has been loaded!")

def on_enable(self) -> None:
self.logger.info("BetterServer has been enabled!")

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

self.server.scheduler.run_task(self, self.log_time, delay=0, period=20 * 1) # every second

def on_disable(self) -> None:
self.logger.info("BetterServer has been disabled!")
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import datetime
import endstone

from endstone import ColorFormat
from endstone.event import event_handler, EventPriority, PlayerJoinEvent, PlayerQuitEvent, ServerListPingEvent
from endstone.plugin import Plugin


class ExampleListener:
class PLayerListener:
def __init__(self, plugin: Plugin):
self._plugin = plugin

@event_handler(priority=EventPriority.HIGHEST)
def on_server_list_ping(self, event: ServerListPingEvent):
event.motd = ColorFormat.BOLD + ColorFormat.AQUA + datetime.datetime.now().strftime("%c")
event.level_name = f"Your IP is {ColorFormat.YELLOW}{event.remote_host}:{event.remote_port}{ColorFormat.RESET}"
event.motd = ColorFormat.BOLD + ColorFormat.AQUA + "Welcome to ZH-Server!"

@event_handler
def on_player_join(self, event: PlayerJoinEvent):
Expand All @@ -21,10 +19,6 @@ def on_player_join(self, event: PlayerJoinEvent):
ColorFormat.YELLOW + f"{player.name}[/{player.address}] joined the game with UUID {player.unique_id}"
)

# example of explicitly removing one's permission of using /me command
player.add_attachment(self._plugin, "minecraft.command.me", False)
player.update_commands() # don't forget to resend the commands

@event_handler
def on_player_quit(self, event: PlayerQuitEvent):
player = event.player
Expand Down
3 changes: 0 additions & 3 deletions src/endstone_example/__init__.py

This file was deleted.

92 changes: 0 additions & 92 deletions src/endstone_example/example_plugin.py

This file was deleted.

30 changes: 0 additions & 30 deletions src/endstone_example/python_command.py

This file was deleted.

0 comments on commit fdfa792

Please sign in to comment.