#Создание плагина
#1. Создайте проект
groovy
plugins {
id 'java'
}
repositories {
maven { url 'https://repo.alexec0de.pro' }
}
dependencies {
compileOnly 'dev.ovrex:api:26.0-snapshot-1'
}
java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}#2. Создайте главный класс
java
package com.example.myplugin;
import com.proxy.api.plugin.Plugin;
public class MyPlugin extends Plugin {
@Override
public void onEnable() {
System.out.println("Мой плагин включен!");
getProxy().getEventBus().register(this, new MyListener());
getProxy().getCommandManager().register(new MyCommand());
}
@Override
public void onDisable() {
getProxy().getScheduler().cancelAll(this);
getProxy().getEventBus().unregisterAll(this);
System.out.println("Мой плагин выключен!");
}
}#3. Создайте plugin.yml
Файл src/main/resources/plugin.yml:
yaml
name: MyPlugin
version: 1.0.0
author: YourName
main: com.example.myplugin.MyPlugin
description: Мой первый плагин для Ovrex#4. Соберите и установите
bash
./gradlew buildСкопируйте JAR из build/libs/ в папку plugins/ Ovrex.
#Жизненный цикл
JAR загружен -> plugin.yml прочитан -> ClassLoader создан -> конструктор -> onEnable() -> ... -> onDisable() -> ClassLoader закрыт
⚠️ WARNING: Не выполняйте тяжёлые операции в onEnable(). Используйте Scheduler.runAsync().