retrooper / packetevents

Precision meets performance—a powerful tool for mastering Minecraft packet manipulation with speed and finesse.
GNU General Public License v3.0
549 stars 151 forks source link

my plugin cannot `init` - docs issue #976

Open svaningelgem opened 2 months ago

svaningelgem commented 2 months ago

Describe the bug

org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register io.github.retrooper.packetevents.bukkit.InternalBukkitListener@3270aabd while not enabled

Software brand

[14:27:38 INFO]: This server is running Paper version git-Paper-22 (MC: 1.20.5) (Implementing API version 1.20.5-R0.1-SNAPSHOT) (Git: 8f7ac62)

Log Cut down to the only relevant parts

[14:27:38 INFO]: Starting minecraft server version 1.20.5
[14:27:38 INFO]: Loading properties
[14:27:38 INFO]: This server is running Paper version git-Paper-22 (MC: 1.20.5) (Implementing API version 1.20.5-R0.1-SNAPSHOT) (Git: 8f7ac62)
[14:27:39 INFO]: Server Ping Player Sample Count: 12
[14:27:39 INFO]: [ChunkTaskScheduler] Chunk system is using 1 I/O threads, 8 worker threads, and gen parallelism of 8 threads
[14:27:39 INFO]: Default game type: SURVIVAL
[14:27:39 INFO]: Generating keypair
[14:27:39 INFO]: Starting Minecraft server on *:25565
[14:27:39 INFO]: Using default channel type
[14:27:39 INFO]: Paper: Using Java compression from Velocity.
[14:27:39 INFO]: Paper: Using Java cipher from Velocity.
[14:27:40 INFO]: [ProtocolLib] Loading server plugin ProtocolLib v5.3.0-SNAPSHOT-726
[14:27:40 WARN]: [ProtocolLib] Version (MC: 1.20.5) has not yet been tested! Proceed with caution.
[14:27:40 INFO]: [packetevents] Loading server plugin packetevents v2.4.0
[14:27:42 INFO]: [pluginhider] Loading server plugin pluginhider v1.0.0
[14:27:42 INFO]: [Graves] Loading server plugin Graves v0.0.0-SNAPSHOT
[14:27:42 INFO]: Server permissions file permissions.yml is empty, ignoring it
[14:27:42 INFO]: [ProtocolLib] Enabling ProtocolLib v5.3.0-SNAPSHOT-726
[14:27:43 INFO]: [pluginhider] Enabling pluginhider v1.0.0
[14:27:43 ERROR]: Error occurred while enabling pluginhider v1.0.0 (Is it up to date?)
org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register io.github.retrooper.packetevents.bukkit.InternalBukkitListener@3270aabd while not enabled
    at io.papermc.paper.plugin.manager.PaperEventManager.registerEvents(PaperEventManager.java:80) ~[paper-1.20.5.jar:git-Paper-22]
    at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.registerEvents(PaperPluginManagerImpl.java:136) ~[paper-1.20.5.jar:git-Paper-22]
    at org.bukkit.plugin.SimplePluginManager.registerEvents(SimplePluginManager.java:682) ~[paper-api-1.20.5-R0.1-SNAPSHOT.jar:?]
    at packetevents-spigot-2.4.0.jar/io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder$1.init(SpigotPacketEventsBuilder.java:147) ~[packetevents-spigot-2.4.0.jar:?]
    at PluginHider-1.0.0.jar/org.avarion.pluginhider.PluginHider.setupPacketEvents(PluginHider.java:76) ~[PluginHider-1.0.0.jar:?]
    at PluginHider-1.0.0.jar/org.avarion.pluginhider.PluginHider.onEnable(PluginHider.java:39) ~[PluginHider-1.0.0.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:287) ~[paper-api-1.20.5-R0.1-SNAPSHOT.jar:?]
    at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:202) ~[paper-1.20.5.jar:git-Paper-22]
    at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:109) ~[paper-1.20.5.jar:git-Paper-22]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:519) ~[paper-api-1.20.5-R0.1-SNAPSHOT.jar:?]
    at org.bukkit.craftbukkit.CraftServer.enablePlugin(CraftServer.java:639) ~[paper-1.20.5.jar:git-Paper-22]
    at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:551) ~[paper-1.20.5.jar:git-Paper-22]
    at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:288) ~[paper-1.20.5.jar:git-Paper-22]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1140) ~[paper-1.20.5.jar:git-Paper-22]
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:326) ~[paper-1.20.5.jar:git-Paper-22]
    at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
[14:27:43 INFO]: [pluginhider] Disabling pluginhider v1.0.0
[14:27:45 INFO]: [packetevents] Enabling packetevents v2.4.0
[14:27:45 INFO]: [packetevents] Checking for updates, please wait...
[14:27:45 INFO]: [Graves] Enabling Graves v0.0.0-SNAPSHOT
[14:27:45 INFO]: [Graves] Integration: Hooked into ProtocolLib 5.3.0-SNAPSHOT-726.
[14:27:45 INFO]: [Graves] Integration: Hooked into MiniMessage.
[14:27:45 INFO]: [packetevents] You are running the latest release of PacketEvents. Your build: (2.4.0)
[14:27:45 INFO]: Running delayed init tasks
[14:27:46 INFO]: [Graves] Update: Outdated version detected 0.0.0, latest version is 4.9.5, https://www.spigotmc.org/resources/116202/
[14:27:46 INFO]: Done (7.363s)! For help, type "help"
[14:27:46 INFO]: Timings Reset

How To Reproduce I don't know exactly how to reproduce, but what I can glance from the logs is that it looks like packetevents is still in the process of enabling itself, and my plugin is enabling in parallel. But it's faster (due to being smaller). And so PE hasn't done its full startup routine yet I guess...

Maybe there should be a similar event as in ItemsAdder that triggers "onLoad"?

svaningelgem commented 2 months ago

I do this: onEnable:

    private void setupPacketEvents() {
        var plugin = getServer().getPluginManager().getPlugin("packetevents");
        var isEnabled = plugin != null && plugin.isEnabled();

... rest of the init

==> plugin != null ==> isEnabled = false

amnoah commented 2 months ago

Add packetevents as a dependency in your plugin.yml

svaningelgem commented 2 months ago

Already did that:

depend:
  - packetevents
svaningelgem commented 2 months ago

FYI: if I relocate PE into my own plugin, it's working fine...

booky10 commented 2 months ago

If you dont shade, dont call the packetevents init methods Also make sure that packetevents is part of your plugin.yml dependencies

svaningelgem commented 2 months ago

If you dont shade, dont call the packetevents init methods

I just followed this here: https://packetevents.gitbook.io/docs/creating-your-packetevents-instance

But it doesn't mention shading anywhere? (well, there is a FAQ TODO about it). But looking at the docs, I would say I have to init()?

svaningelgem commented 2 months ago

I can confirm that everything works fine as long as I don't use init. So I'm guessing this "bug" becomes a documentation issue?

booky10 commented 2 months ago

Yes. @retrooper this should be added to the docs. The whole "Creating Your PacketEvents Instace" page only applies when shading.