Standardize PacketEvents
This commit is contained in:
1 parent
f93401ff26
commit
7197787ad3
7 files changed
+56
-14
No files matched your search
+2
-1
@@ -34,9 +34,10 @@ val fullVersion = "1.3.5"
|
||||
val snapshot = true
|
||||
val githubRepo = System.getenv("GITHUB_REPOSITORY") ?: project.findProperty("githubRepo").toString()
|
||||
|
||||
// Suite default external provider; shaded standalone via -PshadePE=true.
|
||||
extra["shadePE"] = project.findProperty("shadePE")?.toString()?.toBoolean()
|
||||
?: System.getenv("SHADE_PE")?.toBoolean()
|
||||
?: true
|
||||
?: false
|
||||
|
||||
extra["relocate"] = project.findProperty("relocate")?.toString()?.toBoolean()
|
||||
?: System.getenv("RELOCATE_JAR")?.toBoolean()
|
||||
|
||||
@@ -83,7 +83,8 @@ tasks.processResources {
|
||||
filesMatching("plugin.yml") {
|
||||
expand(
|
||||
"version" to project.version,
|
||||
"depends" to if (shadePE) "[]" else listOf("packetevents")
|
||||
// Bukkit accepts `depend` only; `depends` is silently ignored.
|
||||
"depend" to if (shadePE) "[]" else listOf("PacketEvents")
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.world.Location;
|
||||
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
|
||||
import me.caseload.knockbacksync.common.BuildConfig;
|
||||
import me.caseload.knockbacksync.event.events.ConfigReloadEvent;
|
||||
import me.caseload.knockbacksync.event.KBSyncEventHandler;
|
||||
import me.caseload.knockbacksync.listener.bukkit.*;
|
||||
@@ -103,6 +104,10 @@ public class BukkitBase extends Base {
|
||||
|
||||
@Override
|
||||
public void load() {
|
||||
// External-provider mode delegates PacketEvents lifecycle to the installed PE plugin.
|
||||
if (!BuildConfig.SHADE_PE) {
|
||||
return;
|
||||
}
|
||||
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this.plugin));
|
||||
PacketEvents.getAPI().load();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package me.caseload.knockbacksync;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import me.caseload.knockbacksync.common.BuildConfig;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public final class BukkitLoaderPlugin extends JavaPlugin {
|
||||
@@ -19,6 +20,11 @@ public final class BukkitLoaderPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
PacketEvents.getAPI().terminate();
|
||||
// Drop listener handles before any lifecycle decision; the shared API may outlive this plugin.
|
||||
core.unregisterPacketListeners();
|
||||
// Terminate only when this plugin owns the PacketEvents lifecycle (shaded build).
|
||||
if (BuildConfig.SHADE_PE) {
|
||||
PacketEvents.getAPI().terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ api-version: '1.13' # We actually support 1.12.2, api-version was added later th
|
||||
authors: [ Caseload, Axionize ]
|
||||
description: Synchronizes player knockback for smoother gameplay.
|
||||
folia-supported: true
|
||||
depends: ${depends}
|
||||
depend: ${depend}
|
||||
permissions:
|
||||
knockbacksync.update:
|
||||
default: op
|
||||
|
||||
@@ -11,11 +11,11 @@ dependencies {
|
||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||
annotationProcessor("org.projectlombok:lombok:1.18.34")
|
||||
|
||||
// Shaded in or bundled by platform-specific code
|
||||
// Upstream 2.11.2 API; runtime impl is the externally installed True-OG fork or the shaded bundle.
|
||||
if (shadePE) {
|
||||
implementation("com.github.retrooper:packetevents-api:2.11.1+60a2c34-SNAPSHOT")
|
||||
implementation("com.github.retrooper:packetevents-api:2.11.2")
|
||||
} else {
|
||||
compileOnly("com.github.retrooper:packetevents-api:2.11.1+60a2c34-SNAPSHOT")
|
||||
compileOnly("com.github.retrooper:packetevents-api:2.11.2")
|
||||
}
|
||||
|
||||
implementation("org.yaml:snakeyaml:2.0")
|
||||
@@ -30,4 +30,6 @@ dependencies {
|
||||
|
||||
buildConfig {
|
||||
buildConfigField("String", "GITHUB_REPO", "\"${project.rootProject.ext["githubRepo"]}\"")
|
||||
// Exposes shadePE to source code as a compile-time constant.
|
||||
buildConfigField("boolean", "SHADE_PE", shadePE.toString())
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
package me.caseload.knockbacksync;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.event.PacketListenerCommon;
|
||||
import lombok.Getter;
|
||||
import me.caseload.knockbacksync.command.MainCommand;
|
||||
import me.caseload.knockbacksync.common.BuildConfig;
|
||||
import me.caseload.knockbacksync.command.generic.AbstractPlayerSelectorParser;
|
||||
import me.caseload.knockbacksync.command.generic.BuilderCommand;
|
||||
import me.caseload.knockbacksync.command.subcommand.PingCommand;
|
||||
@@ -53,6 +55,9 @@ public abstract class Base {
|
||||
@Getter
|
||||
protected AbstractPlayerSelectorParser<Sender> playerSelectorParser;
|
||||
|
||||
// Tracked so onDisable can unregister exactly the listeners registered against the shared provider.
|
||||
private final java.util.List<PacketListenerCommon> peListenerHandles = new java.util.ArrayList<>();
|
||||
|
||||
protected Base() {
|
||||
this.platform = detectPlatform();
|
||||
INSTANCE = this;
|
||||
@@ -105,6 +110,10 @@ public abstract class Base {
|
||||
public abstract void initializeScheduler();
|
||||
|
||||
public void initializePacketEvents() {
|
||||
// External-provider mode skips lifecycle ownership entirely.
|
||||
if (!BuildConfig.SHADE_PE) {
|
||||
return;
|
||||
}
|
||||
PacketEvents.getAPI().getSettings()
|
||||
.checkForUpdates(false)
|
||||
.debug(false);
|
||||
@@ -113,16 +122,34 @@ public abstract class Base {
|
||||
}
|
||||
|
||||
protected void registerCommonListeners() {
|
||||
PacketEvents.getAPI().getEventManager().registerListeners(
|
||||
new AttributeChangeListener(),
|
||||
new PingSendListener(),
|
||||
new PingReceiveListener(),
|
||||
new PacketPlayerJoinQuit(),
|
||||
new ClientBrandListener()
|
||||
);
|
||||
registerTrackedPacketListener(new AttributeChangeListener());
|
||||
registerTrackedPacketListener(new PingSendListener());
|
||||
registerTrackedPacketListener(new PingReceiveListener());
|
||||
registerTrackedPacketListener(new PacketPlayerJoinQuit());
|
||||
registerTrackedPacketListener(new ClientBrandListener());
|
||||
Event.setEventBus(eventBus);
|
||||
}
|
||||
|
||||
/** Register a PacketEvents listener and remember its handle for unregister on disable. */
|
||||
protected void registerTrackedPacketListener(PacketListenerCommon listener) {
|
||||
PacketEvents.getAPI().getEventManager().registerListener(listener);
|
||||
peListenerHandles.add(listener);
|
||||
}
|
||||
|
||||
/** Unregister every tracked PacketEvents listener. */
|
||||
public void unregisterPacketListeners() {
|
||||
for (PacketListenerCommon handle : peListenerHandles) {
|
||||
try {
|
||||
PacketEvents.getAPI().getEventManager().unregisterListener(handle);
|
||||
} catch (Throwable t) {
|
||||
if (LOGGER != null) {
|
||||
LOGGER.warning("Failed to unregister PE listener: " + t.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
peListenerHandles.clear();
|
||||
}
|
||||
|
||||
protected abstract void registerPlatformListeners();
|
||||
|
||||
protected void registerCommands() {
|
||||
|
||||
Reference in new issue
Block a user