Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adde Folia support #3617

Merged
merged 14 commits into from
May 18, 2024

Conversation

ColdeZhang
Copy link
Contributor

Your checklist for this pull request

🚨 Please review the guidelines for contributing to this repository.

  • Make sure your name is added to Contributors file /Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/html/Contributors.java
  • If PR:ing locale changes also add a LangCode with your name /Plan/common/src/main/java/com/djrapitops/plan/settings/locale/LangCode.java

Description

Add support for folia!

Noted: It needs to merge mu update for Platform-abstraction-layer it add an new abstract layer for folia.

@ColdeZhang ColdeZhang mentioned this pull request May 14, 2024
@ColdeZhang ColdeZhang changed the title Folia support adde Folia support May 14, 2024
@AuroraLS3
Copy link
Collaborator

This is an interesting surprise, thanks!

Looks like there are ~100-200 bukkit based servers running Java version <17 which this PR drops support for.

If there is some way to retain support for them I'd like to consider it - one option could be placing the folia code in new gradle module and using reflection to create the FoliaPlatformLayer instance in the bukkit module - I'm not 100% sure if gradle allows that sort of thing

I'll review these two PRs when I have the time, thanks!

@ColdeZhang
Copy link
Contributor Author

one option could be placing the folia code in new gradle module and using reflection to create the FoliaPlatformLayer instance in the bukkit module

That's a good idea. I will try this method later!

@ColdeZhang
Copy link
Contributor Author

After consulting the relevant information and making some attempts...

Yes, maybe it could be compatible both 11 and 17 with different libs, but it's too complicateed to done. In contrast, the effort made is much higher than the harvest, and the cost performance is too low.

I choose to give up on this attemption, it's more than I can handle. :(

If Plan insist on looking back to under java17 servers, mybe this merge should be postponed, until the number of servers using older versions of Java is negligible.

@AuroraLS3
Copy link
Collaborator

Thanks for trying it out! Could you tell me what you attempted so that I can avoid repeating those attempts? :)

@ColdeZhang
Copy link
Contributor Author

Thanks for trying it out! Could you tell me what you attempted so that I can avoid repeating those attempts? :)

Sure, I'll get back to you when I'm tidying it up。

@ColdeZhang
Copy link
Contributor Author

ColdeZhang commented May 14, 2024

  1. do not compile shadow "net.playeranalytics:platform-abstraction-layer-folia:$palVersion", but package it in to jar.
  2. change codes into below, use reflection to load this class when java version is 17 and running on folia server.
    public void onLoad() {
        if (isJava17OrLater() && isFolia()) {
            try {
                // Attempt to load and use the Folia library for Java 17
                Class<?> foliaPlatformLayer = Class.forName("net.playeranalytics.plugin.FoliaPlatformLayer");
                abstractionLayer = (PlatformAbstractionLayer) foliaPlatformLayer.getConstructor(PlanPlugin.class).newInstance(this);
            } catch (Exception e) {
                this.getLogger().log(Level.SEVERE, "Failed to load FoliaPlatformLayer", e);
                abstractionLayer = new BukkitPlatformLayer(this);
            }
        } else {
            abstractionLayer = new BukkitPlatformLayer(this);
        }
        pluginLogger = abstractionLayer.getPluginLogger();
        runnableFactory = abstractionLayer.getRunnableFactory();
    }
  1. Theoretically, this is possible.

Howerver, here is the problem I encountered......

  1. I didnt figure out how to controll gradle just 'package' lib instead of 'compile' it. Whatever I tried, gradle still check the java versions and then throw errs.
  2. I tried to put lib into servers 'libriries' folder directly, I assume mc should load libs in that folder. But it still doesnt work.

:(

Here is my trial.

@AuroraLS3
Copy link
Collaborator

AuroraLS3 commented May 14, 2024

Alright, I think trying this option in the folia module might do something, not sure https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api.plugins/-java-plugin-convention/disable-auto-target-jvm.html

It might also be possible to try include the folia module in the plugin module instead of bukkit module

(This whole comment assumes a new folia module is added to Plan project)

@ColdeZhang
Copy link
Contributor Author

ColdeZhang commented May 15, 2024

Alright, I think trying this option in the folia module might do something, not sure https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api.plugins/-java-plugin-convention/disable-auto-target-jvm.html

It might also be possible to try include the folia module in the plugin module instead of bukkit module

(This whole comment assumes a new folia module is added to Plan project)

wow, thanks for this information. it works now. I tested it on paper 1.16.5(java11) and folia 1.20.4(java21), both of them can loaded Plan proply.

image
image

@ColdeZhang
Copy link
Contributor Author

I did some test about CI-CD, it failed on 'aggregateJavadocs' step.
The problem is still about the jvm versions,

* What went wrong:
Execution failed for task ':aggregateJavadocs'.
> Could not resolve all files for configuration ':plugin:compileClasspath'.
   > Could not resolve net.playeranalytics:platform-abstraction-layer-folia:5.2.0.
     Required by:
         project :plugin > project :bukkit
      > No matching variant of net.playeranalytics:platform-abstraction-layer-folia:5.2.0 was found. The consumer was configured to find a library for use during compile-time, compatible with Java 11, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally but:
          - Variant 'apiElements' declares a library for use during compile-time, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
          - Variant 'runtimeElements' declares a library for use during runtime, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares a component, compatible with Java 17 and the consumer needed a component, compatible with Java 11
              - Other compatible attribute:
                  - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)

@AuroraLS3
Copy link
Collaborator

AuroraLS3 commented May 16, 2024

Javadoc building fails, folia needs it's own gradle module, with pal-folia as dependency, and then that module would be shadowed in :plugin module, so that :bukkit module doesn't have Java 17 dependencies

The folia module doesn't need any Java files inside it as far as I'm aware

This should work at runtime since plugin module outputs the jar and bukkit module can still access the class via reflection at that point

@AnttiMK
Copy link
Contributor

AnttiMK commented May 16, 2024

Do we want to move Folia's PAL into this repository as was done with Fabric, or keep it as is?

@AuroraLS3
Copy link
Collaborator

It's fine to keep as is, just the dependency needs to be moved :)

I think fabric was more involved since it included all sorts of other things on top of PAL that would make it seem disingenuous if PAL contained fabric, while it seems to work fine for Folia

Copy link
Contributor

@AnttiMK AnttiMK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some little things, also have to make sure all scheduled stuff works correctly but code-wise lgtm

Plan/build.gradle Outdated Show resolved Hide resolved
Plan/build.gradle Outdated Show resolved Hide resolved
Plan/build.gradle Outdated Show resolved Hide resolved

dependencies {
shadow "net.playeranalytics:platform-abstraction-layer-folia:$palVersion"
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Plan/bukkit/src/main/java/com/djrapitops/plan/Plan.java Outdated Show resolved Hide resolved
Plan/bukkit/src/main/java/com/djrapitops/plan/Plan.java Outdated Show resolved Hide resolved
@ColdeZhang
Copy link
Contributor Author

Some little things, also have to make sure all scheduled stuff works correctly but code-wise lgtm

There still have javadoc problem, folia module can't pass 'aggregateJavadocs' step.

@ColdeZhang

This comment was marked as resolved.

@AuroraLS3
Copy link
Collaborator

Alright, Looks like the folia module is redundant (and can be removed).

All the funky dependency business can be done in the plugin module

dependencies {
    ...
    shadow "net.playeranalytics:platform-abstraction-layer-folia:$palVersion"
}

java {
    // This is required to prevent the shadow plugin from
    // adding the folia platform abstraction layer to the runtime classpath
    disableAutoTargetJvm()
}

I didn't have Folia installed so I couldn't test if that starts up, but at least Plan starts with Java 11 with this setup, and aggregateJavadocs works too.

@ColdeZhang
Copy link
Contributor Author

ColdeZhang commented May 18, 2024

Alright, Looks like the folia module is redundant (and can be removed).

All the funky dependency business can be done in the plugin module

dependencies {
    ...
    shadow "net.playeranalytics:platform-abstraction-layer-folia:$palVersion"
}

java {
    // This is required to prevent the shadow plugin from
    // adding the folia platform abstraction layer to the runtime classpath
    disableAutoTargetJvm()
}

I didn't have Folia installed so I couldn't test if that starts up, but at least Plan starts with Java 11 with this setup, and aggregateJavadocs works too.

1

This will also work. But I think disabling jvm inspections directly in the plugin is too aggressive and potentially dangerous.

With specificed jvm version, now we don't need to disable jvm check in folia module too.

2

To pass javadocs aggregate, I changed shadow to runtimeOnly:

dependencies {
    shadow "net.playeranalytics:platform-abstraction-layer-folia:$palVersion"
}

⬇️

dependencies {
    runtimeOnly "net.playeranalytics:platform-abstraction-layer-folia:$palVersion"
}

So this pal won't be involved in to aggregateJavadocs progress.

@AuroraLS3

This comment was marked as outdated.

@ColdeZhang

This comment was marked as outdated.

@ColdeZhang
Copy link
Contributor Author

It looks like chrome driver got updated to be more shit, I'll try to sort out the problems with the AccessControlVisibilityTest

I think that's the real problem I encountered.

https://pastes.dev/oobEreU7Lv

@AuroraLS3

This comment was marked as outdated.

@AuroraLS3

This comment was marked as outdated.

@AuroraLS3
Copy link
Collaborator

You can merge master to this branch and that should sort out the issue

@ColdeZhang
Copy link
Contributor Author

You can merge master to this branch and that should sort out the issue

Great, it works now.

Copy link
Collaborator

@AuroraLS3 AuroraLS3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! :) I'll merge this after testing that it works one more time.

Building folia itself seems to be an hour job so feel free to test it as well 😅

I'd be interested in error free behavior of:

  • Plugin enable on Folia
  • Plugin reload /plan reload
  • Plugin disable
  • Player join + Player leave adding a Session to the website
  • Player join + Gamemode change + Nether portal + Player leave adding a Session with overworld time data in Survival and Creative, and nether data in creative
  • Player join + Server shutdown + Server start adding a Session
  • Server running for few minutes adding Player online count, TPS and other performance data to Performance tab

@ColdeZhang
Copy link
Contributor Author

ColdeZhang commented May 18, 2024

Great work! :) I'll merge this after testing that it works one more time.

Building folia itself seems to be an hour job so feel free to test it as well 😅

I'd be interested in error free behavior of:

  • Plugin enable on Folia
  • Plugin reload /plan reload
  • Plugin disable
  • Player join + Player leave adding a Session to the website
  • Player join + Gamemode change + Nether portal + Player leave adding a Session with overworld time data in Survival and Creative, and nether data in creative
  • Player join + Server shutdown + Server start adding a Session
  • Server running for few minutes adding Player online count, TPS and other performance data to Performance tab

Here is the folia I built my self, if you want you can use this for test.

Three of begining I have tested:

  • Plugin enable on Folia
  • Plugin reload /plan reload
  • Plugin disable

rest of those you can check on my own server. I am using it for several days. Eveything looks great fine,

@AnttiMK
Copy link
Contributor

AnttiMK commented May 18, 2024

Folia is well available from official sources through PaperMC's downloads API, see for example https://api.papermc.io/v2/projects/folia/versions/1.20.4/builds/31/downloads/folia-1.20.4-31.jar

Per PaperMC, the downloads are intentionally API-only since the platform is still very experimental.

@AuroraLS3
Copy link
Collaborator

AuroraLS3 commented May 18, 2024

Tested:

  • Plugin enable on Folia
  • Plugin reload /plan reload
  • Plugin disable
  • Player join + Player leave adding a Session to the website
  • Player join + Gamemode change + Nether portal + Player leave adding a Session with overworld time data in Survival and Creative, and nether data in creative
    • ⚠️ world change event doesn't seem to trigger, leaving behind a Session with only one world, I don't know if this is due to Folia related changes
  • Player join + Server shutdown + Server start adding a Session
  • Server running for few minutes adding Player online count, TPS and other performance data to Performance tab
  • Plugin enabled with Java 11

@ColdeZhang
Copy link
Contributor Author

Tested:

  • Plugin enable on Folia

  • Plugin reload /plan reload

  • Plugin disable

  • Player join + Player leave adding a Session to the website

  • Player join + Gamemode change + Nether portal + Player leave adding a Session with overworld time data in Survival and Creative, and nether data in creative

    • ⚠️ world change event doesn't seem to trigger, leaving behind a Session with only one world, I don't know if this is due to Folia related changes
  • Player join + Server shutdown + Server start adding a Session

  • Server running for few minutes adding Player online count, TPS and other performance data to Performance tab

⚠️ world change event doesn't seem to trigger, leaving behind a Session with only one world, I don't know if this is due to Folia related changes

Yes, this event is disabled on folia currently.

@AuroraLS3
Copy link
Collaborator

Alright then everything seems to be working as intended :)

@AuroraLS3 AuroraLS3 merged commit fefbd9a into plan-player-analytics:master May 18, 2024
1 check passed
@AuroraLS3
Copy link
Collaborator

Thank you for all the correspondence and quick changes, it has made it easy to get this PR to the finish line & Thanks to @AnttiMK for PR review :)

@ColdeZhang
Copy link
Contributor Author

ColdeZhang commented May 18, 2024

image

The whole changeDimension was rewrited by folia. So PlayerChangedWorldEvent will not be called.

@AuroraLS3
Copy link
Collaborator

Hopefully they will eventually sort that out, until then I'll just put a disclaimer to the change log and wiki for Folia about this data being wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants