How can I get Player mod list when player join ?
e.g. Player Mods:
- Biomes O’ Plenty
- Custom NPCs
Please help me.
How can I get Player mod list when player join ?
e.g. Player Mods:
Please help me.
There is no way to do this in just sponge api (not unless you reimplement the forge packet for requesting mods)
So assuming that the implementation of sponge that your plugin is running on is spongeforge (if its a public plugin then dont assume that unless it relies on it) then you can use forge code to get the mod list.
Be warned. The mod list the client has can and will eventually be modified to report cheating mods as other mods or just hidden from the mod list you see on the server. So if your making a anti-cheat plugin. Do not rely on this (its more like a table that blocks your path - east to get around but some still fall for it)
Anyway its been a long time since I touched forge code. But last I checked. You need to get the NetworkDispatch
of the player. From there it has a method called getModList
You can get the forge player from the sponge player by simply casting it
EntityPlayerMP forgePlayer = (EntityPlayerMP)spongePlayer
Thank for you care! in 1.12.2 I can find the way. but In Forge 1.16.5. I couldn’t find the way to get player mod list. How can I get player mod in 1.16.5 ?
Like i said. I havent touched forge in a long time.
Just creating a 1.16 forge so I can have a play and report my findings
Got it
ServerPlayerEntity forgePlayer;
NetworkHooks.getConnectionData(forgePlayer.connection.netManager).getModList();
Thank you so much!
It shows this error
java.lang.NoSuchFieldError: connection
code
ServerPlayer p;
ServerPlayerEntity forgePlayer = (ServerPlayerEntity) p;
ImmutableList list = NetworkHooks.getConnectionData(forgePlayer.connection.netManager).getModList(); <— Error this line
How can I fix it ?
So thats a issue with mods in general. You need to build your plugin against the same mappings (typically mcp of some kind). This will convert the english name to the deopforcated (however you spell it) field name that is in the Minecraft code.
Or you can use reflection and work out the mapping names.
Last time i wrote a plugin that hooked into forge, i had already setup the whole project for sponge api and only needed forge for slight correction. So i did the reflection way.
However it is much easier (im told) to do it the gradle remapping way (i believe sponge gradle/forge gradle does this)
Thank you so much!
Now I can get Player Mod List name. but I can’t get the version of mod.
How can I get Player mod name & version ?
Please help me.
Not sure if this is possible without the help of client mods.
I knew the mod ids got sent to the server as its the servers job to check if a player has the required mods.
Your best bet is to ask on the forge forums as they know forge better then the sponge community.
As a sponge plugin you have access to all sponge and forge methods (casting maybe required)
Thank for you care!