Use PermissionsEx API into a mod

Not sure if this is the right section to ask, but i have a mod made with Forge and i added the PermissionsEx API to check if the player has a permission. But for some reason it looks like the API doesn’t work (or perhaps it always say that a player hasn’t a permission while in the json file he have it). What i’m doing right now is this in Forge

public static IPermissionHandler pex = PermissionAPI.getPermissionHandler();
ForgeGuard.UTILS.sendMessage(player, ForgeGuard.pex.hasPermission(player.getGameProfile(), "region.use", null) + "");

So basically i send a message to the player saying if he has that permission, but it always return false (as he doesn’t). Am i checking it wrong or it’s just that a mod can’t communicate with a sponge plugin?

It’s all one big JVM. Forge has no say in what can ‘communicate’ with it, nor does sponge. It’s all just classes and methods. The correct answer is that you are doing it wrong. Are you sure this code is even called?

Also, just use the Sponge permission API.
player.hasPermission(String)

In sponge i can check the permission correctly. The problem is that i had to check it in Forge, not in Sponge. And yes, the code is called as the message is displayed correctly

Am confuse.

//EntityPlayerMP player;
if ((Player) player).hasPermission("region.use") {

What i’m trying to do is a mod made in Forge checking for a permission (added using PermissionsEx plugin).
I also tried doing this

Player pl = (Player)player;

But when compiling the mod this error comes up

package org.spongepowered.api.entity.living.player does not exist
import org.spongepowered.api.entity.living.player.Player;
                                                 ^

You need to have sponge added as a library. Although, if you’re already building against PEX, not sure why it wouldn’t be, unless you’re not using a build system.

Wich is what i’ve done, i’ve downloaded the sponge api jar and included into eclipse. The jar i’m using is the spongeapi-5.0.0-shaded.jar
EDIT: in fact i understand that using pex api is useless, so i’m trying to use the sponge api directly but as i said when compiling i got that errore, event if the api jar is in the referenced libraries

Also, I understood that part perfectly. What I don’t know is why you need the PEX API and not the Sponge one. PEX didn’t invent permissions, it just provides an implementation for what’s already there.

You should use a build system like Gradle. Keeps problems like this from ever happening. The shaded jar is a last resort, not a development tool

So i should follow the guidelines on this page?
https://github.com/SpongePowered/SpongeAPI

If i clone the github using Git Bash i got this

$ git clone [email protected]:SpongePowered/SpongeAPI.git
Cloning into 'SpongeAPI'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

First of all, I don’t bother with the SSH-style format. I just use https://github.com/SpongePowered/SpongeAPI.git.

Second, that’s a description of how to download, set up, and compile it yourself. That is not a description of how to use a build system for a project of your own.

Meanwhile, Eclipse is to development what McAfee is to antivirus (or what Internet Explorer 9 is to web browsing)

Since you clearly have gradle set up for a forge mod environment, just add SpongeAPI to the dependencies:
https://docs.spongepowered.org/master/en/plugin/project/gradle.html

To create a permission node in Forge to use in Sponge simply use player.canCommandSenderUseCommand(4, "some.perm.node");
My issue to add this to the docs is still open, i will have to revisit it so that the next person gets a simple link

Yes, adding sponge api to the libs actually worked :smiley: Thanks everyone for your help :slight_smile: