diff --git a/docs/.vitepress/de.ts b/docs/.vitepress/de.ts index 0aea999..fd91857 100644 --- a/docs/.vitepress/de.ts +++ b/docs/.vitepress/de.ts @@ -102,7 +102,21 @@ export const de = defineConfig({ }, { text: "Python", - link: "/de/plugin-dev/python", + collapsed: false, + items: [ + { + text: "Quick Start", + link: "/de/plugin-dev/python/quick-start", + }, + { + text: "Basic Logic", + link: "/de/plugin-dev/python/basic-logic", + }, + { + text: "Events", + link: "/de/plugin-dev/python/events", + }, + ], }, ], }, diff --git a/docs/.vitepress/en.ts b/docs/.vitepress/en.ts index 9f7c28a..eeb4796 100644 --- a/docs/.vitepress/en.ts +++ b/docs/.vitepress/en.ts @@ -100,7 +100,21 @@ export const en = defineConfig({ }, { text: "Python", - link: "/plugin-dev/python", + collapsed: false, + items: [ + { + text: "Quick Start", + link: "/plugin-dev/python/quick-start", + }, + { + text: "Basic Logic", + link: "/plugin-dev/python/basic-logic", + }, + { + text: "Events", + link: "/plugin-dev/python/events", + }, + ], }, ], }, diff --git a/docs/.vitepress/nl.ts b/docs/.vitepress/nl.ts index 9cf3b05..9fc3edd 100644 --- a/docs/.vitepress/nl.ts +++ b/docs/.vitepress/nl.ts @@ -83,7 +83,21 @@ export const nl = defineConfig({ }, { text: "Python", - link: "/nl/plugin-dev/python", + collapsed: false, + items: [ + { + text: "Quick Start", + link: "/nl/plugin-dev/python/quick-start", + }, + { + text: "Basic Logic", + link: "/nl/plugin-dev/python/basic-logic", + }, + { + text: "Events", + link: "/nl/plugin-dev/python/events", + }, + ], }, ], }, diff --git a/docs/.vitepress/pt.ts b/docs/.vitepress/pt.ts index 1b39470..0afc025 100644 --- a/docs/.vitepress/pt.ts +++ b/docs/.vitepress/pt.ts @@ -83,7 +83,21 @@ export const pt = defineConfig({ }, { text: "Python", - link: "/pt/plugin-dev/python", + collapsed: false, + items: [ + { + text: "Quick Start", + link: "/pt/plugin-dev/python/quick-start", + }, + { + text: "Basic Logic", + link: "/pt/plugin-dev/python/basic-logic", + }, + { + text: "Events", + link: "/pt/plugin-dev/python/events", + }, + ], }, ], }, diff --git a/docs/.vitepress/tr_tr.ts b/docs/.vitepress/tr_tr.ts index 28b0ca0..2acb28b 100644 --- a/docs/.vitepress/tr_tr.ts +++ b/docs/.vitepress/tr_tr.ts @@ -102,7 +102,21 @@ export const trTR = defineConfig({ }, { text: "Python", - link: "/tr_TR/plugin-dev/python", + collapsed: false, + items: [ + { + text: "Quick Start", + link: "/tr_TR/plugin-dev/python/quick-start", + }, + { + text: "Basic Logic", + link: "/tr_TR/plugin-dev/python/basic-logic", + }, + { + text: "Events", + link: "/tr_TR/plugin-dev/python/events", + }, + ], }, ], }, diff --git a/docs/.vitepress/zh_cn.ts b/docs/.vitepress/zh_cn.ts index 7ccdf8f..74cc0bc 100644 --- a/docs/.vitepress/zh_cn.ts +++ b/docs/.vitepress/zh_cn.ts @@ -108,7 +108,21 @@ export const zhCN = defineConfig({ }, { text: "Python", - link: "/zh_cn/plugin-dev/python", + collapsed: false, + items: [ + { + text: "Quick Start", + link: "/zh_cn/plugin-dev/python/quick-start", + }, + { + text: "Basic Logic", + link: "/zh_cn/plugin-dev/python/basic-logic", + }, + { + text: "Events", + link: "/zh_cn/plugin-dev/python/events", + }, + ], }, ], }, diff --git a/docs/de/plugin-dev/python/basic-logic.md b/docs/de/plugin-dev/python/basic-logic.md new file mode 100644 index 0000000..94d1d6e --- /dev/null +++ b/docs/de/plugin-dev/python/basic-logic.md @@ -0,0 +1,38 @@ +# Basic Logic + +This section covers the basic structure of a Pumpkin plugin in Python. + +## Plugin Class + +Every Python plugin must inherit from the `Plugin` class. This class provides the base structure and methods needed for the server to interact with your plugin. + +```python +from pumpkin_api import Plugin, PluginMetadata, context + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + # Define plugin metadata here + pass + + def on_load(self, ctx: context.Context) -> None: + # Code to run when the plugin is loaded + pass + + def on_unload(self, ctx: context.Context) -> None: + # Code to run when the plugin is unloaded + pass +``` + +## Plugin Metadata + +The `metadata` method must return a `PluginMetadata` object, which contains information about your plugin. + +- `name`: The name of your plugin. +- `version`: The version of your plugin. +- `authors`: A list of authors. +- `description`: A short description of what your plugin does. + +## Loading and Unloading + +- `on_load`: This method is called when the server loads your plugin. You should use this to register events, commands, and perform any initialization. +- `on_unload`: This method is called when the server unloads your plugin. Use this for cleanup if necessary. diff --git a/docs/de/plugin-dev/python/events.md b/docs/de/plugin-dev/python/events.md new file mode 100644 index 0000000..135b08e --- /dev/null +++ b/docs/de/plugin-dev/python/events.md @@ -0,0 +1,30 @@ +# Events + +Events allow your plugin to respond to actions occurring on the server, such as players joining or messages being sent. + +## Registering an Event + +You can register an event handler in the `on_load` method of your plugin using `self.register_event`. + +```python +def on_load(self, ctx: context.Context) -> None: + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) +``` + +## Event Handlers + +An event handler is a method that receives the server instance and the event data. It should return the (possibly modified) event data. + +```python +def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt +``` + +## Event Types + +The `event.EventType` enum contains all available events. Some common events include: + +- `PLAYER_JOIN_EVENT` +- `PLAYER_QUIT_EVENT` +- `PLAYER_CHAT_EVENT` diff --git a/docs/de/plugin-dev/python.md b/docs/de/plugin-dev/python/quick-start.md similarity index 58% rename from docs/de/plugin-dev/python.md rename to docs/de/plugin-dev/python/quick-start.md index 6204515..282df4c 100644 --- a/docs/de/plugin-dev/python.md +++ b/docs/de/plugin-dev/python/quick-start.md @@ -1,6 +1,18 @@ -# Python Plugin Development +# Quick Start -Pumpkin supports writing plugins in Python. Below is a basic example of a Python plugin. +This guide will help you get started with writing Pumpkin server plugins using Python. + +## Installation + +First, you need to install the `pumpkin-api-py` library: + +```bash +pip install pumpkin-api-py +``` + +## Creating your first plugin + +Create a file named `main.py` and add the following content: ```python from pumpkin_api import ( @@ -29,3 +41,13 @@ class MyPlugin(Plugin): register_plugin(MyPlugin) ``` + +## Building the plugin + +Build your plugin into a WebAssembly component using the provided build tool: + +```bash +pumpkin-api-build main -o my_plugin.wasm +``` + +This will generate a `my_plugin.wasm` file that you can place in the `plugins` folder of your Pumpkin server. diff --git a/docs/en/plugin-dev/python/basic-logic.md b/docs/en/plugin-dev/python/basic-logic.md new file mode 100644 index 0000000..94d1d6e --- /dev/null +++ b/docs/en/plugin-dev/python/basic-logic.md @@ -0,0 +1,38 @@ +# Basic Logic + +This section covers the basic structure of a Pumpkin plugin in Python. + +## Plugin Class + +Every Python plugin must inherit from the `Plugin` class. This class provides the base structure and methods needed for the server to interact with your plugin. + +```python +from pumpkin_api import Plugin, PluginMetadata, context + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + # Define plugin metadata here + pass + + def on_load(self, ctx: context.Context) -> None: + # Code to run when the plugin is loaded + pass + + def on_unload(self, ctx: context.Context) -> None: + # Code to run when the plugin is unloaded + pass +``` + +## Plugin Metadata + +The `metadata` method must return a `PluginMetadata` object, which contains information about your plugin. + +- `name`: The name of your plugin. +- `version`: The version of your plugin. +- `authors`: A list of authors. +- `description`: A short description of what your plugin does. + +## Loading and Unloading + +- `on_load`: This method is called when the server loads your plugin. You should use this to register events, commands, and perform any initialization. +- `on_unload`: This method is called when the server unloads your plugin. Use this for cleanup if necessary. diff --git a/docs/en/plugin-dev/python/events.md b/docs/en/plugin-dev/python/events.md new file mode 100644 index 0000000..135b08e --- /dev/null +++ b/docs/en/plugin-dev/python/events.md @@ -0,0 +1,30 @@ +# Events + +Events allow your plugin to respond to actions occurring on the server, such as players joining or messages being sent. + +## Registering an Event + +You can register an event handler in the `on_load` method of your plugin using `self.register_event`. + +```python +def on_load(self, ctx: context.Context) -> None: + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) +``` + +## Event Handlers + +An event handler is a method that receives the server instance and the event data. It should return the (possibly modified) event data. + +```python +def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt +``` + +## Event Types + +The `event.EventType` enum contains all available events. Some common events include: + +- `PLAYER_JOIN_EVENT` +- `PLAYER_QUIT_EVENT` +- `PLAYER_CHAT_EVENT` diff --git a/docs/en/plugin-dev/python.md b/docs/en/plugin-dev/python/quick-start.md similarity index 58% rename from docs/en/plugin-dev/python.md rename to docs/en/plugin-dev/python/quick-start.md index 6204515..282df4c 100644 --- a/docs/en/plugin-dev/python.md +++ b/docs/en/plugin-dev/python/quick-start.md @@ -1,6 +1,18 @@ -# Python Plugin Development +# Quick Start -Pumpkin supports writing plugins in Python. Below is a basic example of a Python plugin. +This guide will help you get started with writing Pumpkin server plugins using Python. + +## Installation + +First, you need to install the `pumpkin-api-py` library: + +```bash +pip install pumpkin-api-py +``` + +## Creating your first plugin + +Create a file named `main.py` and add the following content: ```python from pumpkin_api import ( @@ -29,3 +41,13 @@ class MyPlugin(Plugin): register_plugin(MyPlugin) ``` + +## Building the plugin + +Build your plugin into a WebAssembly component using the provided build tool: + +```bash +pumpkin-api-build main -o my_plugin.wasm +``` + +This will generate a `my_plugin.wasm` file that you can place in the `plugins` folder of your Pumpkin server. diff --git a/docs/nl/plugin-dev/python/basic-logic.md b/docs/nl/plugin-dev/python/basic-logic.md new file mode 100644 index 0000000..94d1d6e --- /dev/null +++ b/docs/nl/plugin-dev/python/basic-logic.md @@ -0,0 +1,38 @@ +# Basic Logic + +This section covers the basic structure of a Pumpkin plugin in Python. + +## Plugin Class + +Every Python plugin must inherit from the `Plugin` class. This class provides the base structure and methods needed for the server to interact with your plugin. + +```python +from pumpkin_api import Plugin, PluginMetadata, context + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + # Define plugin metadata here + pass + + def on_load(self, ctx: context.Context) -> None: + # Code to run when the plugin is loaded + pass + + def on_unload(self, ctx: context.Context) -> None: + # Code to run when the plugin is unloaded + pass +``` + +## Plugin Metadata + +The `metadata` method must return a `PluginMetadata` object, which contains information about your plugin. + +- `name`: The name of your plugin. +- `version`: The version of your plugin. +- `authors`: A list of authors. +- `description`: A short description of what your plugin does. + +## Loading and Unloading + +- `on_load`: This method is called when the server loads your plugin. You should use this to register events, commands, and perform any initialization. +- `on_unload`: This method is called when the server unloads your plugin. Use this for cleanup if necessary. diff --git a/docs/nl/plugin-dev/python/events.md b/docs/nl/plugin-dev/python/events.md new file mode 100644 index 0000000..135b08e --- /dev/null +++ b/docs/nl/plugin-dev/python/events.md @@ -0,0 +1,30 @@ +# Events + +Events allow your plugin to respond to actions occurring on the server, such as players joining or messages being sent. + +## Registering an Event + +You can register an event handler in the `on_load` method of your plugin using `self.register_event`. + +```python +def on_load(self, ctx: context.Context) -> None: + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) +``` + +## Event Handlers + +An event handler is a method that receives the server instance and the event data. It should return the (possibly modified) event data. + +```python +def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt +``` + +## Event Types + +The `event.EventType` enum contains all available events. Some common events include: + +- `PLAYER_JOIN_EVENT` +- `PLAYER_QUIT_EVENT` +- `PLAYER_CHAT_EVENT` diff --git a/docs/nl/plugin-dev/python.md b/docs/nl/plugin-dev/python/quick-start.md similarity index 58% rename from docs/nl/plugin-dev/python.md rename to docs/nl/plugin-dev/python/quick-start.md index 6204515..282df4c 100644 --- a/docs/nl/plugin-dev/python.md +++ b/docs/nl/plugin-dev/python/quick-start.md @@ -1,6 +1,18 @@ -# Python Plugin Development +# Quick Start -Pumpkin supports writing plugins in Python. Below is a basic example of a Python plugin. +This guide will help you get started with writing Pumpkin server plugins using Python. + +## Installation + +First, you need to install the `pumpkin-api-py` library: + +```bash +pip install pumpkin-api-py +``` + +## Creating your first plugin + +Create a file named `main.py` and add the following content: ```python from pumpkin_api import ( @@ -29,3 +41,13 @@ class MyPlugin(Plugin): register_plugin(MyPlugin) ``` + +## Building the plugin + +Build your plugin into a WebAssembly component using the provided build tool: + +```bash +pumpkin-api-build main -o my_plugin.wasm +``` + +This will generate a `my_plugin.wasm` file that you can place in the `plugins` folder of your Pumpkin server. diff --git a/docs/pt/plugin-dev/python/basic-logic.md b/docs/pt/plugin-dev/python/basic-logic.md new file mode 100644 index 0000000..94d1d6e --- /dev/null +++ b/docs/pt/plugin-dev/python/basic-logic.md @@ -0,0 +1,38 @@ +# Basic Logic + +This section covers the basic structure of a Pumpkin plugin in Python. + +## Plugin Class + +Every Python plugin must inherit from the `Plugin` class. This class provides the base structure and methods needed for the server to interact with your plugin. + +```python +from pumpkin_api import Plugin, PluginMetadata, context + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + # Define plugin metadata here + pass + + def on_load(self, ctx: context.Context) -> None: + # Code to run when the plugin is loaded + pass + + def on_unload(self, ctx: context.Context) -> None: + # Code to run when the plugin is unloaded + pass +``` + +## Plugin Metadata + +The `metadata` method must return a `PluginMetadata` object, which contains information about your plugin. + +- `name`: The name of your plugin. +- `version`: The version of your plugin. +- `authors`: A list of authors. +- `description`: A short description of what your plugin does. + +## Loading and Unloading + +- `on_load`: This method is called when the server loads your plugin. You should use this to register events, commands, and perform any initialization. +- `on_unload`: This method is called when the server unloads your plugin. Use this for cleanup if necessary. diff --git a/docs/pt/plugin-dev/python/events.md b/docs/pt/plugin-dev/python/events.md new file mode 100644 index 0000000..135b08e --- /dev/null +++ b/docs/pt/plugin-dev/python/events.md @@ -0,0 +1,30 @@ +# Events + +Events allow your plugin to respond to actions occurring on the server, such as players joining or messages being sent. + +## Registering an Event + +You can register an event handler in the `on_load` method of your plugin using `self.register_event`. + +```python +def on_load(self, ctx: context.Context) -> None: + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) +``` + +## Event Handlers + +An event handler is a method that receives the server instance and the event data. It should return the (possibly modified) event data. + +```python +def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt +``` + +## Event Types + +The `event.EventType` enum contains all available events. Some common events include: + +- `PLAYER_JOIN_EVENT` +- `PLAYER_QUIT_EVENT` +- `PLAYER_CHAT_EVENT` diff --git a/docs/pt/plugin-dev/python.md b/docs/pt/plugin-dev/python/quick-start.md similarity index 58% rename from docs/pt/plugin-dev/python.md rename to docs/pt/plugin-dev/python/quick-start.md index 6204515..282df4c 100644 --- a/docs/pt/plugin-dev/python.md +++ b/docs/pt/plugin-dev/python/quick-start.md @@ -1,6 +1,18 @@ -# Python Plugin Development +# Quick Start -Pumpkin supports writing plugins in Python. Below is a basic example of a Python plugin. +This guide will help you get started with writing Pumpkin server plugins using Python. + +## Installation + +First, you need to install the `pumpkin-api-py` library: + +```bash +pip install pumpkin-api-py +``` + +## Creating your first plugin + +Create a file named `main.py` and add the following content: ```python from pumpkin_api import ( @@ -29,3 +41,13 @@ class MyPlugin(Plugin): register_plugin(MyPlugin) ``` + +## Building the plugin + +Build your plugin into a WebAssembly component using the provided build tool: + +```bash +pumpkin-api-build main -o my_plugin.wasm +``` + +This will generate a `my_plugin.wasm` file that you can place in the `plugins` folder of your Pumpkin server. diff --git a/docs/tr_TR/plugin-dev/python/basic-logic.md b/docs/tr_TR/plugin-dev/python/basic-logic.md new file mode 100644 index 0000000..94d1d6e --- /dev/null +++ b/docs/tr_TR/plugin-dev/python/basic-logic.md @@ -0,0 +1,38 @@ +# Basic Logic + +This section covers the basic structure of a Pumpkin plugin in Python. + +## Plugin Class + +Every Python plugin must inherit from the `Plugin` class. This class provides the base structure and methods needed for the server to interact with your plugin. + +```python +from pumpkin_api import Plugin, PluginMetadata, context + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + # Define plugin metadata here + pass + + def on_load(self, ctx: context.Context) -> None: + # Code to run when the plugin is loaded + pass + + def on_unload(self, ctx: context.Context) -> None: + # Code to run when the plugin is unloaded + pass +``` + +## Plugin Metadata + +The `metadata` method must return a `PluginMetadata` object, which contains information about your plugin. + +- `name`: The name of your plugin. +- `version`: The version of your plugin. +- `authors`: A list of authors. +- `description`: A short description of what your plugin does. + +## Loading and Unloading + +- `on_load`: This method is called when the server loads your plugin. You should use this to register events, commands, and perform any initialization. +- `on_unload`: This method is called when the server unloads your plugin. Use this for cleanup if necessary. diff --git a/docs/tr_TR/plugin-dev/python/events.md b/docs/tr_TR/plugin-dev/python/events.md new file mode 100644 index 0000000..135b08e --- /dev/null +++ b/docs/tr_TR/plugin-dev/python/events.md @@ -0,0 +1,30 @@ +# Events + +Events allow your plugin to respond to actions occurring on the server, such as players joining or messages being sent. + +## Registering an Event + +You can register an event handler in the `on_load` method of your plugin using `self.register_event`. + +```python +def on_load(self, ctx: context.Context) -> None: + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) +``` + +## Event Handlers + +An event handler is a method that receives the server instance and the event data. It should return the (possibly modified) event data. + +```python +def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt +``` + +## Event Types + +The `event.EventType` enum contains all available events. Some common events include: + +- `PLAYER_JOIN_EVENT` +- `PLAYER_QUIT_EVENT` +- `PLAYER_CHAT_EVENT` diff --git a/docs/tr_TR/plugin-dev/python/quick-start.md b/docs/tr_TR/plugin-dev/python/quick-start.md new file mode 100644 index 0000000..282df4c --- /dev/null +++ b/docs/tr_TR/plugin-dev/python/quick-start.md @@ -0,0 +1,53 @@ +# Quick Start + +This guide will help you get started with writing Pumpkin server plugins using Python. + +## Installation + +First, you need to install the `pumpkin-api-py` library: + +```bash +pip install pumpkin-api-py +``` + +## Creating your first plugin + +Create a file named `main.py` and add the following content: + +```python +from pumpkin_api import ( + Plugin, PluginMetadata, register_plugin, + server, event, command, text, context +) + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + return PluginMetadata( + name="my-plugin", + version="0.1.0", + authors=["you"], + description="An example plugin." + ) + + def on_load(self, ctx: context.Context) -> None: + print("Python plugin loaded!") + + # Register an event handler + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) + + def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt + +register_plugin(MyPlugin) +``` + +## Building the plugin + +Build your plugin into a WebAssembly component using the provided build tool: + +```bash +pumpkin-api-build main -o my_plugin.wasm +``` + +This will generate a `my_plugin.wasm` file that you can place in the `plugins` folder of your Pumpkin server. diff --git a/docs/tr_tr/plugin-dev/python.md b/docs/tr_tr/plugin-dev/python.md deleted file mode 100644 index 6204515..0000000 --- a/docs/tr_tr/plugin-dev/python.md +++ /dev/null @@ -1,31 +0,0 @@ -# Python Plugin Development - -Pumpkin supports writing plugins in Python. Below is a basic example of a Python plugin. - -```python -from pumpkin_api import ( - Plugin, PluginMetadata, register_plugin, - server, event, command, text, context -) - -class MyPlugin(Plugin): - def metadata(self) -> PluginMetadata: - return PluginMetadata( - name="my-plugin", - version="0.1.0", - authors=["you"], - description="An example plugin." - ) - - def on_load(self, ctx: context.Context) -> None: - print("Python plugin loaded!") - - # Register an event handler - self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) - - def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: - print(f"Player {evt.player.get_name()} joined!") - return evt - -register_plugin(MyPlugin) -``` diff --git a/docs/zh_cn/plugin-dev/python.md b/docs/zh_cn/plugin-dev/python.md deleted file mode 100644 index 6204515..0000000 --- a/docs/zh_cn/plugin-dev/python.md +++ /dev/null @@ -1,31 +0,0 @@ -# Python Plugin Development - -Pumpkin supports writing plugins in Python. Below is a basic example of a Python plugin. - -```python -from pumpkin_api import ( - Plugin, PluginMetadata, register_plugin, - server, event, command, text, context -) - -class MyPlugin(Plugin): - def metadata(self) -> PluginMetadata: - return PluginMetadata( - name="my-plugin", - version="0.1.0", - authors=["you"], - description="An example plugin." - ) - - def on_load(self, ctx: context.Context) -> None: - print("Python plugin loaded!") - - # Register an event handler - self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) - - def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: - print(f"Player {evt.player.get_name()} joined!") - return evt - -register_plugin(MyPlugin) -``` diff --git a/docs/zh_cn/plugin-dev/python/basic-logic.md b/docs/zh_cn/plugin-dev/python/basic-logic.md new file mode 100644 index 0000000..94d1d6e --- /dev/null +++ b/docs/zh_cn/plugin-dev/python/basic-logic.md @@ -0,0 +1,38 @@ +# Basic Logic + +This section covers the basic structure of a Pumpkin plugin in Python. + +## Plugin Class + +Every Python plugin must inherit from the `Plugin` class. This class provides the base structure and methods needed for the server to interact with your plugin. + +```python +from pumpkin_api import Plugin, PluginMetadata, context + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + # Define plugin metadata here + pass + + def on_load(self, ctx: context.Context) -> None: + # Code to run when the plugin is loaded + pass + + def on_unload(self, ctx: context.Context) -> None: + # Code to run when the plugin is unloaded + pass +``` + +## Plugin Metadata + +The `metadata` method must return a `PluginMetadata` object, which contains information about your plugin. + +- `name`: The name of your plugin. +- `version`: The version of your plugin. +- `authors`: A list of authors. +- `description`: A short description of what your plugin does. + +## Loading and Unloading + +- `on_load`: This method is called when the server loads your plugin. You should use this to register events, commands, and perform any initialization. +- `on_unload`: This method is called when the server unloads your plugin. Use this for cleanup if necessary. diff --git a/docs/zh_cn/plugin-dev/python/events.md b/docs/zh_cn/plugin-dev/python/events.md new file mode 100644 index 0000000..135b08e --- /dev/null +++ b/docs/zh_cn/plugin-dev/python/events.md @@ -0,0 +1,30 @@ +# Events + +Events allow your plugin to respond to actions occurring on the server, such as players joining or messages being sent. + +## Registering an Event + +You can register an event handler in the `on_load` method of your plugin using `self.register_event`. + +```python +def on_load(self, ctx: context.Context) -> None: + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) +``` + +## Event Handlers + +An event handler is a method that receives the server instance and the event data. It should return the (possibly modified) event data. + +```python +def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt +``` + +## Event Types + +The `event.EventType` enum contains all available events. Some common events include: + +- `PLAYER_JOIN_EVENT` +- `PLAYER_QUIT_EVENT` +- `PLAYER_CHAT_EVENT` diff --git a/docs/zh_cn/plugin-dev/python/quick-start.md b/docs/zh_cn/plugin-dev/python/quick-start.md new file mode 100644 index 0000000..282df4c --- /dev/null +++ b/docs/zh_cn/plugin-dev/python/quick-start.md @@ -0,0 +1,53 @@ +# Quick Start + +This guide will help you get started with writing Pumpkin server plugins using Python. + +## Installation + +First, you need to install the `pumpkin-api-py` library: + +```bash +pip install pumpkin-api-py +``` + +## Creating your first plugin + +Create a file named `main.py` and add the following content: + +```python +from pumpkin_api import ( + Plugin, PluginMetadata, register_plugin, + server, event, command, text, context +) + +class MyPlugin(Plugin): + def metadata(self) -> PluginMetadata: + return PluginMetadata( + name="my-plugin", + version="0.1.0", + authors=["you"], + description="An example plugin." + ) + + def on_load(self, ctx: context.Context) -> None: + print("Python plugin loaded!") + + # Register an event handler + self.register_event(ctx, event.EventType.PLAYER_JOIN_EVENT, self.on_player_join) + + def on_player_join(self, srv: server.Server, evt: event.PlayerJoinEventData) -> event.PlayerJoinEventData: + print(f"Player {evt.player.get_name()} joined!") + return evt + +register_plugin(MyPlugin) +``` + +## Building the plugin + +Build your plugin into a WebAssembly component using the provided build tool: + +```bash +pumpkin-api-build main -o my_plugin.wasm +``` + +This will generate a `my_plugin.wasm` file that you can place in the `plugins` folder of your Pumpkin server.