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

Support Spigot 1.8 #834

Merged
merged 48 commits into from
Apr 17, 2021
Merged

Support Spigot 1.8 #834

merged 48 commits into from
Apr 17, 2021

Conversation

cswhite2000
Copy link
Member

This still compiles against SportPaper, but I've changed enough of the references to SportPaper specific methods for it to be able to run the maps in https://github.com/PGMDev/Maps without issue. I haven't as of yet tested this on maps not in that repository.

I wasn't really sure how best to handle EventHandlers for events not in Spigot, so I've commented those out for now.
I'm also not sure about how best to handle attributes in spigot 1.8, since those weren't added to spigot until 1.9, so those are also commented out for now.

@Electroid
Copy link
Member

Wow, thanks @cswhite2000, also hello again!

I had a conversation in Discord about this a while ago, but (if it helps) we can target Paper 1.8. I won't have time to review this until the weekend, but will tag @Pablete1234 to take a look as I think he may have some opinions/ideas.

@Electroid Electroid added the refactor Code needs to be redesigned label Mar 18, 2021
@Electroid
Copy link
Member

Also, since you've dived into this: how feasible is it to no longer compile against SportPaper? What would you see as the hurdles?

@applenick
Copy link
Member

applenick commented Mar 18, 2021

@Electroid
Just wanna inject, for nicknames to be supported in Community & PGM, the FakeName & Skin API in SportPaper is of interest 👀

Also excellent job @cswhite2000 🎉

@cswhite2000
Copy link
Member Author

No longer compiling against SportPaper is feasible. You would lose a few features that require sportpaper, and that can't be replicated with reflection.

There's also probably a number of places that use SportPaper APIs that I've missed, as in things not used by the default maps, and those would have to handled too.

And then it would be fairly easy to go from checking to see if SportPaper is running before running SportPaper specific methods to just removing those method calls.

I think ideally, pgm should compile against Paper, but check before using paper specific methods, so that it still runs on spigot.

@Electroid
Copy link
Member

So, basically we need a way to listen to events that may or may not exist in the Bukkit runtime.

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

Thoughts?

@cswhite2000
Copy link
Member Author

That sounds like it would work.

@cswhite2000
Copy link
Member Author

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

@Electroid
Copy link
Member

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

What doesn't work about it? Is the package the same?

@Pablete1234
Copy link
Member

You could make a separate PGM module that is pgm-sportpaper, that compiles against sportpaper and adds listeners to sportpaper events and launches PGM events.
You can compile pgm against spigot, and that other module compiles against sportpaper, and you are able to compile pgm without that module too if you wish to run it on just spigot

@cswhite2000
Copy link
Member Author

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

What doesn't work about it? Is the package the same?

Yeah the package is the same. I copied BlockFallEvent into util but I still got
java.lang.NoClassDefFoundError: org/bukkit/event/block/BlockFallEvent
when trying to run it

Copy link
Member

@Pablete1234 Pablete1234 left a comment

Choose a reason for hiding this comment

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

I feel like every place where BukkitUtils.isSportPaper() is used should contain a comment about what happens about it.

Some features look straight-out disabled, like attribute kits or canplace/candestroy. If these do not work without sportpaper we either need alternatives for other platforms or we need to make it very clear in the documentation that these features will simply not work outside sportpaper.
It's essentially turning them into second-class features that maps could avoid because they don't work, meaning maps may try to avoid using them for being "non-compliant" with the "standard set of features that works everywhere". Should definetly try to look into alternatives.

One decent way to do this would be to move some of these into NMSHacks, and have differing implementations for NMSHacks, one that can work for spigot via NMS or reflection if needed, and another that can make those methods use directy sportpaper apis.

@Pablete1234
Copy link
Member

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

What doesn't work about it? Is the package the same?

Yeah the package is the same. I copied BlockFallEvent into util but I still got
java.lang.NoClassDefFoundError: org/bukkit/event/block/BlockFallEvent
when trying to run it

Are you adding the event in that package inside PGM?

@cswhite2000
Copy link
Member Author

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

What doesn't work about it? Is the package the same?

Yeah the package is the same. I copied BlockFallEvent into util but I still got
java.lang.NoClassDefFoundError: org/bukkit/event/block/BlockFallEvent
when trying to run it

Are you adding the event in that package inside PGM?

Yes

@cswhite2000
Copy link
Member Author

Some features look straight-out disabled, like attribute kits or canplace/candestroy. If these do not work without sportpaper we either need alternatives for other platforms or we need to make it very clear in the documentation that these features will simply not work outside sportpaper.
It's essentially turning them into second-class features that maps could avoid because they don't work, meaning maps may try to avoid using them for being "non-compliant" with the "standard set of features that works everywhere". Should definetly try to look into alternatives.

I've added more comments explaining these. Attributes and canplace/candestroy should be doable with reflection, however they would take a significant amount of code / time, so I should think they should be done in their own pull request.

One decent way to do this would be to move some of these into NMSHacks, and have differing implementations for NMSHacks, one that can work for spigot via NMS or reflection if needed, and another that can make those methods use directy sportpaper apis.

That does sound like a good way to do it

@Electroid Electroid changed the title Allow PGM to run on Spigot 1.8.8 Support Spigot 1.8 Mar 19, 2021
@cswhite2000
Copy link
Member Author

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

I believe this is why it didn't work
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/4c766c92ac4d10daeedee256e096106570d0e9b9

@Electroid
Copy link
Member

What if in util, we copy-paste the events we need from SportPaper with the same package path, same signature. We can import those events in our code. If the runtime already defines the event class, it does not get overriden. If the runtime doesn't have the class, also no problem, the event just never gets thrown.

This doesn't seem to work.

I believe this is why it didn't work
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/4c766c92ac4d10daeedee256e096106570d0e9b9

Yep, that’ll be the problem. Can we load the class outside of PluginClassLoader?

@Pablete1234
Copy link
Member

Pablete1234 commented Mar 20, 2021

I believe this is why it didn't work
https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/4c766c92ac4d10daeedee256e096106570d0e9b9

Yep, that’ll be the problem. Can we load the class outside of PluginClassLoader?

I don't think you'll ever be able to load those classes. Bukkit/spigot load plugins with its own class loader, the PluginClassLoader. Due to class loader hierarchy if you try to create your own class loader in PGM to boot those classes yourself, the parent class loader will still prevent them from going thru.

@cswhite2000
Copy link
Member Author

cswhite2000 commented Mar 23, 2021

So at this point pgm should run on sportpaper with all of the features it had before.

With spigot I haven't implemented the following:

  • - Attributes
  • - canPlaceOn / canDestroy
  • - None of the events in tc.oc.pgm.util.event.sport are called unless the server is running sportpaper

@cswhite2000
Copy link
Member Author

I can't think of any good ways to call any of the events in tc.oc.pgm.util.event.sport when the server isn't running SportPaper.
Aside from that, this should be done.

Copy link
Member

@Electroid Electroid left a comment

Choose a reason for hiding this comment

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

This is really great work, @cswhite2000. You're taking this in the right direction, but I think we need more abstractions (separate interfaces/implementations).

Right now, a lot of the pattern is:

if (BukkitUtils.isSportPaper()) {
 // SportPaper stuff
} else {
 // Fallback, sometimes invoking NMS
}

I worry about too much of that in the codebase, because we have two medium-term goals:

  1. Don't depend on SportPaper API (reflection only)
  2. Potentially support newer server versions

Obviously, we aren't going to get there 100% in this PR, but we need to keep that in mind.

For most of my comments, I suggest moving the logic into a utility method (either in BukkitUtils or NMSHacks depending on what it does). But for Attribute, I think we should try a interface/implementation approach (you can take some inspiration from ItemTag)

It would be great if we no longer import the SportPaper APIs, and just use reflection, but if you think that's too much for now, we can punt that to a v2.

core/pom.xml Outdated Show resolved Hide resolved
core/src/main/java/tc/oc/pgm/itemmeta/ItemRule.java Outdated Show resolved Hide resolved
core/src/main/java/tc/oc/pgm/kits/KitParser.java Outdated Show resolved Hide resolved
util/src/main/java/tc/oc/pgm/util/skin/Skin.java Outdated Show resolved Hide resolved
util/src/main/java/tc/oc/pgm/util/tablist/TabRender.java Outdated Show resolved Hide resolved
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
cswhite2000 and others added 4 commits April 3, 2021 13:28
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
This was previously called on PlayerResetEvent, but the method that calls that event already resets player attributes

Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
@cswhite2000
Copy link
Member Author

cswhite2000 commented Apr 6, 2021

This now depends on Electroid/SportPaper#66
With this, the tab list should be faster, with one step less of serialization/deserialization, and PGM will be using adventure Components for the tab list.

Also, this should make multi version support easier since later versions don't support BaseComponents for the tab list either

cswhite2000 and others added 3 commits April 10, 2021 16:03
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
@Electroid
Copy link
Member

Some people will try using an older version of SportPaper, does PGM handle the case where that patch isn't introduced?

…Paper

Signed-off-by: cswhite2000 <18whitechristop@gmail.com>
@cswhite2000
Copy link
Member Author

Some people will try using an older version of SportPaper, does PGM handle the case where that patch isn't introduced?

It'll fall back to the spigot compatible version if the field doesn't exist

@Electroid Electroid merged commit 89332cf into PGMDev:dev Apr 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code needs to be redesigned
Development

Successfully merging this pull request may close these issues.

Make PGM independent from SportPaper
5 participants