plan-player-analytics / Plan

Player Analytics plugin for Minecraft Server platforms - View player activity of your server with ease. :calendar:
https://www.spigotmc.org/resources/plan-player-analytics.32536/
GNU Lesser General Public License v3.0
865 stars 170 forks source link

QueryService.getInstance() throws IllegalStateException #3061

Closed patrickdundas closed 4 months ago

patrickdundas commented 1 year ago

Describe the issue

I am following the Query API Getting Started guide and am having the following error. The below code in PlanHook.java throws the warning that Plan is not enabled (IllegalStateException):

private QueryAPIAccessor createQueryAPIAccessor() {
        try {
            return new QueryAPIAccessor(QueryService.getInstance());
        } catch (IllegalStateException planIsNotEnabled) {
            Bukkit.getLogger().warning("Warning: Plan is not enabled");
            // Plan is not enabled, handle exception
            return null;
        }
    }

In plugin.yml, I've tried making Plan both a soft and regular dependency: depend: [Plan]

In pom.xml, I have confirmed that the plan API for 5.5.2391 is loaded correctly, and I have the same Jar running on my server. I've confirmed that Plan enables before my plugin in the startup logs:

[03:13:25 INFO]: [Plan] Enabling Plan v5.5 build 2391
[03:13:26 INFO]: [Plan] 
[03:13:26 INFO]: [Plan]            ██▌
[03:13:26 INFO]: [Plan]      ██▌   ██▌
[03:13:26 INFO]: [Plan]   ██▌██▌██▌██▌  Player Analytics
[03:13:26 INFO]: [Plan]   ██▌██▌██▌██▌  v5.5 build 2391
[03:13:26 INFO]: [Plan] 
[03:13:26 INFO]: [dynmap] Loading default resource pack
[03:13:26 INFO]: [Plan] Locale: 'English' by AuroraLS3
[03:13:26 INFO]: [Plan] Downloading SQLite Driver, this may take a while...
[03:13:26 INFO]: [Plan] Database: Making sure schema is up to date..
[03:13:26 INFO]: [Plan] SQLite-database connection established.
[03:13:26 INFO]: [Plan] All database patches applied successfully.
[03:13:26 INFO]: [Plan] WebServer: Certificate KeyStore File not Found: plugins/Plan/Cert.jks
[03:13:26 INFO]: [Plan] WebServer: No Certificate -> Using HTTP-server for Visualization.
[03:13:26 INFO]: [Plan] WebServer: User Authorization Disabled! (Not secure over HTTP)
[03:13:26 INFO]: [Plan] Webserver running on PORT 8804 ( http://mc.patrickdundas.io:8804 )
[03:13:26 INFO]: [Plan] Loading server identifying information
[03:13:26 INFO]: [Plan] Server identifier loaded: bbb731c5-81d4-454f-859f-f5f00e28a059
[03:13:27 INFO]: [Plan] Registered extension: LuckPerms
[03:13:27 INFO]: [Plan] Player Analytics Enabled.
[03:13:27 INFO]: [MYPLUGIN] Enabling GUIShops v0.0.1
[03:13:27 INFO]: [MYPLUGIN] hookIntoPlan - returning createQueryAPIAccessor
[03:13:27 WARN]: [MYPLUGIN] Warning: Plan is not enabled
[03:13:27 INFO]: Hooked into Plan
[03:13:27 INFO]: [spark] Enabling spark v1.10.34
[03:13:27 INFO]: [spark] Using Paper ServerTickStartEvent for tick monitoring
[03:13:27 INFO]: [spark] Starting background profiler...
[03:13:28 INFO]: [TabTPS] Enabling TabTPS v1.3.17
[03:13:28 INFO]: [TabTPS] Successfully registered Mojang Brigadier support for commands.
[03:13:28 INFO]: [TabTPS] Successfully registered asynchronous command completion listener.
[03:13:28 INFO]: [GSit] Enabling GSit v1.4.5
[03:13:28 INFO]: [GSit] The plugin was successfully enabled.
[03:13:28 INFO]: Running delayed init tasks
[03:13:28 INFO]: [Plan] Storing sessions that were preserved before previous shutdown.
[03:13:29 INFO]: Done (12.739s)! For help, type "help"
[03:13:29 INFO]: Timings Reset
[03:13:29 INFO]: [Plan] You're using the latest version.


### Plugin versions
Plan v5.5 build 2391 running on Paper MC 1.20 Build 6
AuroraLS3 commented 1 year ago

Does your plugin include Plan code by accident by any chance?

AuroraLS3 commented 1 year ago

Could you send a copy of your plugin jar so that I can try reproduce the issue?

patrickdundas commented 1 year ago

Sure, here is a link to my jar: https://drive.google.com/file/d/1Oy84qE1ooBExAjHqawebiiAnl3D_xkdq/view?usp=sharing If you want to see the complete source code I can share that with you privately. The plugin does not accidentally contain any of Plan's code, it just imports it in the pom as described in the Plan API documentation. The only files related to plan are the files outlined in the Guide I linked above - I haven't changed any of the guide code aside from adding logs trying to track down the issue. Other than that, I have 1 line of code which uses getSessionCount from the guide's example QueryAPIAccessor class. I noticed this line of code was failing since the Optional<QueryAPIAccessor> was null, so I started adding logs to track down the issue, which led me here. Thank you for your responses so far!

patrickdundas commented 1 year ago

Are there any factors which would make the Query API inaccessible when QueryService.getInstance() is run? I know for a fact that this is the section of code which is causing the issues, so I'm attempting to look into any factors which would cause this to fail, but it's a bit of a black box. Are there any ports or Plan plugin configurations that I should be validating on my server? What are the dependencies or failure points of QueryService.getInstance() which might be incorrectly configured for this function to work on my machine (if you know them)

AuroraLS3 commented 1 year ago

The QueryService singleton is registered here https://github.com/plan-player-analytics/Plan/blob/master/Plan/common/src/main/java/com/djrapitops/plan/PlanSystem.java#L180 during the enable process - it should have registered at least according to the logs.

Only thing I can think of is that on fabric the enable order is slightly different and Plan enables during ServerLifecycleEvents.SERVER_STARTING instead of onInitializeServer

Another thing that comes to mind is that since it's using an AtomicReference that is not volatile (https://github.com/plan-player-analytics/Plan/blob/master/Plan/api/src/main/java/com/djrapitops/plan/query/QueryService.java#L153) the Thread from your plugin may not yet see changes to the singleton when your code is running.

One way to test this would be to delay registering the Plan hook with a Bukkit Runnable

AuroraLS3 commented 1 year ago

I haven't been able to reproduce this. Could you send the full exception stack trace for the IllegalStateException if this is still relevant?