BlueGit

timfa chestpreviews

Fix embedded PacketEvents load by matching ContainerPipes shading.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-08-22 · 2 months ago

Hash
94f220abd6974e8d24e5573032735288328db79e
Parent
4a06e1b8
2 files changed +31 −16
build.gradle.kts +9 −7
@@ -16,8 +16,11 @@ repositories {
16 16 dependencies {
17 17 compileOnly("io.papermc.paper:paper-api:26.2.build.+")
18 18
19 // Bundled into ChestPreview by shadowJar.
20 implementation("com.github.retrooper:packetevents-spigot:2.13.0")
19 // Bundled into ChestPreview by shadowJar. Adventure stays on Paper's classpath;
20 // relocating net.kyori is what broke embedded PacketEvents on load.
21 implementation("com.github.retrooper:packetevents-spigot:2.13.0") {
22 exclude(group = "net.kyori")
23 }
21 24 }
22 25
23 26 java {
@@ -32,11 +35,10 @@ tasks.shadowJar {
32 35 archiveClassifier.set("")
33 36 archiveFileName.set("ChestPreview-${project.version}.jar")
34 37
35 // PacketEvents' current bundling guide explicitly requires these relocations.
36 relocate("com.github.retrooper", "nl.timfalken.chestpreview.libs.packetevents")
37 relocate("io.github.retrooper", "nl.timfalken.chestpreview.libs.packetevents")
38 relocate("net.kyori", "nl.timfalken.chestpreview.libs.kyori")
39 relocate("com.google.gson", "nl.timfalken.chestpreview.libs.gson")
38 // Same relocation as ContainerPipes: only PacketEvents itself. Paper already
39 // ships Adventure and Gson; relocating those breaks PacketEvents on load.
40 relocate("com.github.retrooper.packetevents", "nl.timfalken.chestpreview.libs.packetevents.api")
41 relocate("io.github.retrooper.packetevents", "nl.timfalken.chestpreview.libs.packetevents.impl")
40 42
41 43 // PacketEvents embeds bStats in the Spigot implementation. Keep our private copy private too.
42 44 relocate("org.bstats", "nl.timfalken.chestpreview.libs.bstats")
@@ -16,8 +16,11 @@ repositories {
16dependencies {
16dependencies {
17 compileOnly("io.papermc.paper:paper-api:26.2.build.+")
17 compileOnly("io.papermc.paper:paper-api:26.2.build.+")
18
18
19 // Bundled into ChestPreview by shadowJar.
19 // Bundled into ChestPreview by shadowJar. Adventure stays on Paper's classpath;
20 implementation("com.github.retrooper:packetevents-spigot:2.13.0")
20 // relocating net.kyori is what broke embedded PacketEvents on load.
21 implementation("com.github.retrooper:packetevents-spigot:2.13.0") {
22 exclude(group = "net.kyori")
23 }
21}
24}
22
25
23java {
26java {
@@ -32,11 +35,10 @@ tasks.shadowJar {
32 archiveClassifier.set("")
35 archiveClassifier.set("")
33 archiveFileName.set("ChestPreview-${project.version}.jar")
36 archiveFileName.set("ChestPreview-${project.version}.jar")
34
37
35 // PacketEvents' current bundling guide explicitly requires these relocations.
38 // Same relocation as ContainerPipes: only PacketEvents itself. Paper already
36 relocate("com.github.retrooper", "nl.timfalken.chestpreview.libs.packetevents")
39 // ships Adventure and Gson; relocating those breaks PacketEvents on load.
37 relocate("io.github.retrooper", "nl.timfalken.chestpreview.libs.packetevents")
40 relocate("com.github.retrooper.packetevents", "nl.timfalken.chestpreview.libs.packetevents.api")
38 relocate("net.kyori", "nl.timfalken.chestpreview.libs.kyori")
41 relocate("io.github.retrooper.packetevents", "nl.timfalken.chestpreview.libs.packetevents.impl")
39 relocate("com.google.gson", "nl.timfalken.chestpreview.libs.gson")
40
42
41 // PacketEvents embeds bStats in the Spigot implementation. Keep our private copy private too.
43 // PacketEvents embeds bStats in the Spigot implementation. Keep our private copy private too.
42 relocate("org.bstats", "nl.timfalken.chestpreview.libs.bstats")
44 relocate("org.bstats", "nl.timfalken.chestpreview.libs.bstats")
src/main/java/nl/timfalken/chestpreview/ChestPreviewPlugin.java +22 −9
@@ -8,6 +8,8 @@ import org.bukkit.command.Command;
8 8 import org.bukkit.command.CommandSender;
9 9 import org.bukkit.plugin.java.JavaPlugin;
10 10
11 import java.util.logging.Level;
12
11 13 public final class ChestPreviewPlugin extends JavaPlugin {
12 14 private boolean packetEventsLoaded;
13 15 private PreviewManager manager;
@@ -16,22 +18,33 @@ public final class ChestPreviewPlugin extends JavaPlugin {
16 18
17 19 @Override
18 20 public void onLoad() {
19 // PacketEvents 2.13.0 is shaded and relocated into this plugin, so ChestPreview owns
20 // this private PacketEvents instance and must manage its lifecycle itself.
21 PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
22 PacketEvents.getAPI().getSettings().checkForUpdates(false);
23 PacketEvents.getAPI().load();
24 packetEventsLoaded = true;
21 // PacketEvents 2.13.0 is shaded into this plugin, so ChestPreview owns this
22 // private instance. Match ContainerPipes: build + load here, init in onEnable.
23 try {
24 PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
25 PacketEvents.getAPI().getSettings().checkForUpdates(false);
26 PacketEvents.getAPI().load();
27 packetEventsLoaded = true;
28 } catch (Throwable t) {
29 getLogger().log(Level.SEVERE, "Embedded PacketEvents failed during onLoad", t);
30 }
25 31 }
26 32
27 33 @Override
28 34 public void onEnable() {
29 if (!packetEventsLoaded || PacketEvents.getAPI() == null) {
30 getLogger().severe("Embedded PacketEvents failed to load; disabling ChestPreview.");
35 try {
36 if (PacketEvents.getAPI() == null) {
37 PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
38 PacketEvents.getAPI().getSettings().checkForUpdates(false);
39 PacketEvents.getAPI().load();
40 }
41 PacketEvents.getAPI().init();
42 packetEventsLoaded = true;
43 } catch (Throwable t) {
44 getLogger().log(Level.SEVERE, "Embedded PacketEvents failed to load; disabling ChestPreview.", t);
31 45 Bukkit.getPluginManager().disablePlugin(this);
32 46 return;
33 47 }
34 PacketEvents.getAPI().init();
35 48
36 49 saveDefaultConfig();
37 50 manager = new PreviewManager(this);
@@ -8,6 +8,8 @@ import org.bukkit.command.Command;
8import org.bukkit.command.CommandSender;
8import org.bukkit.command.CommandSender;
9import org.bukkit.plugin.java.JavaPlugin;
9import org.bukkit.plugin.java.JavaPlugin;
10
10
11import java.util.logging.Level;
12
11public final class ChestPreviewPlugin extends JavaPlugin {
13public final class ChestPreviewPlugin extends JavaPlugin {
12 private boolean packetEventsLoaded;
14 private boolean packetEventsLoaded;
13 private PreviewManager manager;
15 private PreviewManager manager;
@@ -16,22 +18,33 @@ public final class ChestPreviewPlugin extends JavaPlugin {
16
18
17 @Override
19 @Override
18 public void onLoad() {
20 public void onLoad() {
19 // PacketEvents 2.13.0 is shaded and relocated into this plugin, so ChestPreview owns
21 // PacketEvents 2.13.0 is shaded into this plugin, so ChestPreview owns this
20 // this private PacketEvents instance and must manage its lifecycle itself.
22 // private instance. Match ContainerPipes: build + load here, init in onEnable.
21 PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
23 try {
22 PacketEvents.getAPI().getSettings().checkForUpdates(false);
24 PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
23 PacketEvents.getAPI().load();
25 PacketEvents.getAPI().getSettings().checkForUpdates(false);
24 packetEventsLoaded = true;
26 PacketEvents.getAPI().load();
27 packetEventsLoaded = true;
28 } catch (Throwable t) {
29 getLogger().log(Level.SEVERE, "Embedded PacketEvents failed during onLoad", t);
30 }
25 }
31 }
26
32
27 @Override
33 @Override
28 public void onEnable() {
34 public void onEnable() {
29 if (!packetEventsLoaded || PacketEvents.getAPI() == null) {
35 try {
30 getLogger().severe("Embedded PacketEvents failed to load; disabling ChestPreview.");
36 if (PacketEvents.getAPI() == null) {
37 PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
38 PacketEvents.getAPI().getSettings().checkForUpdates(false);
39 PacketEvents.getAPI().load();
40 }
41 PacketEvents.getAPI().init();
42 packetEventsLoaded = true;
43 } catch (Throwable t) {
44 getLogger().log(Level.SEVERE, "Embedded PacketEvents failed to load; disabling ChestPreview.", t);
31 Bukkit.getPluginManager().disablePlugin(this);
45 Bukkit.getPluginManager().disablePlugin(this);
32 return;
46 return;
33 }
47 }
34 PacketEvents.getAPI().init();
35
48
36 saveDefaultConfig();
49 saveDefaultConfig();
37 manager = new PreviewManager(this);
50 manager = new PreviewManager(this);