Rapha149 / SignGUI

An api to get input text via a sign in Minecraft.
MIT License
35 stars 12 forks source link

[Bug] Could not pass event InventoryClickEvent #15

Closed Jakubk15 closed 6 days ago

Jakubk15 commented 6 days ago

API version

2.3.5

Server software and version

Paper 1.20.6

Steps to reproduce

1. Declare the dependency in `build.gradle.kts` file, as well as relocate it using goooler/shadow Gradle Plugin

implementation("de.rapha149.signgui:signgui:2.3.5")

shadowJar {
        archiveFileName.set("ParcelLockers v${project.version} (MC 1.8.8-1.20.x).jar")

        exclude(
            ...
        )

        mergeServiceFiles()
        minimize()

        val prefix = "com.eternalcode.parcellockers.libs"
        listOf(
            ...
            "de.rapha149"
        ).forEach { relocate(it, prefix) }
    }

2. Call the SignGUI using TriumphGUI library:
https://pastes.dev/wx5AD6FX94

3.Click on the button, that is supposed to open the SignGUI.
4. Observe the error.

Expected behaviour

The SignGUI should open normally, and should be able to capture input.

What is actually happening?

An exception is thrown, that SignGUI does not support 1_20_R4, despite the author claims it does: https://pastes.dev/vKeRJ0nFIz

Code snippets

My full plugin code is available on GitHub, the class where the problem persists is ParcelSendingGUI Make sure to use the finish-sending-gui branch. https://github.com/EternalCodeTeam/ParcelLockers/tree/finish-sending-logic

Any additional comments?

No response

Rapha149 commented 6 days ago

The problem is with your minimize() statement. I should really put that in to the readme 😅 My API loads the version wrapper classes via Reflection - I don't think there's another way to load them because the imports for the version wrappers that do not correspond to the current version would trigger an error.

I compiled your plugin and opened the jar file with an unzipper, as you can see, only the abstract class VersionWrapper is compiled, not the actual version wrappers themselves: screenshot

That is because the version wrappers are loaded via Reflection, the minimize() statement doesn't recognize the version wrapper classes as needed and therefore doesn't compile them. In #12 we fixed that by initializing the correct wrapper class (e.g. new Wrapper1_20_R4()), you could also do something like Wrapper1_20_R4.class.getName() so that you don't have to initialize a class unnecessarily. The only important thing was that the wrapper class was explicitly used in the code and therefore didn't get thrown out by minimize().

However, I don't know if that solution is suitable for you as I saw that your plugin is supposed to function across multiple versions. Because of that, I don't know if there is a solution for you besides getting rid of the minimize() statement or configuring it to ignore the SignGUI dependency, but I don't know if that's possible, I don't often use Gradle.

Rapha149 commented 6 days ago

I now looked into the minimize method a little bit (also because I want to put that in my readme) and found that you can exclude a dependency from being minimized like this:

minimize() {
    exclude(dependency("de\\.rapha149\\.signgui:signgui:.*")) // Regex
}

Using this, all version wrapper classes are compiled into the jar. This also compiles the classes for the versions up to 1.16 which you don't need for your plugin, but it's not that much code and I think that's the best solution for your use case. I also compared the file sizes before and after and the jar file with the whole SignGUI dependency was 0.13MB larger (133721 bytes) which I think is acceptable.

Jakubk15 commented 6 days ago

Thank you ❤️

I managed to get the library working on Paper 1.20.6! Thank you for your commitment and researching Gradle docs to help me exclude the library from minimize() method. Have a good day 😅