Check if a player is OP?

Sorry about posting all of these stupid questions, but I don’t see any methods in the Player class to check if a Player is OP. Anyone know how to check?

There is no concept of op in Sponge. Take a look at the hasPermission method and use that instead.

The /op commands are still there so I feel like the methods should be there too

3 Likes

I think that @zml means, that sponge doesn’t want to endorse the idea of OP. Meaning that having op won’t give you full permissions with sponge plugins. What actually makes sense. For example:

player.hasPermission("flyplugin.fly"){
   player.setFly(true)
}

Will work if the player has one the following perms:

  • flyplugin.fly
  • flyplugin.*

Lets say you add the concept of OP in it.

player.hasPermission("flyplugin.fly") && player.isOp(){
   player.setFly(true)
}

Meaning that you need to write extra code for a very simplistic form of permissions.

Also tell me if you are op on a bukkit server. Don’t you have both things, * and op? This won’t give any problems.

On a bukkit server hasPermission returned true when you were op.

The /op command provides full permissions unless a server runs a permissions plugin like PEX, which entirely replaces the limited builtin system. Nothing checks op status. There is no way to check op status in the API. You check permissions instead. Just forget that there is anything called op pretty much.

2 Likes

Edited, I want to try to use PEX.

Everything is working well, thanks for adding the extra information on the github post. However, I can’t seem to replicate op for myself. Can you tell me what I’m doing wrong? My username is soccer66 and I want a group called Owner to have all permissions. My permissions file is below. I am trying to run the commands /time set 0 and /weather clear as a test commands, and it is denying them.
@zml

{
    "systems": {
        "default": [ {
            "contexts": {
                "srcip": "127.0.0.1"
            },
            "permissions-default": 1
        } ]
    },
    "schema-version": 2,
    "groups": {
        "Trainer": [ {
            "permissions": {
                "test.perm": 1
            }
        } ],
        "Owner": [ {
            "permissions": {
                "*": 1
            }
        } ]
    },
    "users": {
        "cae9634c-f2df-4a41-b4a3-15d48b319b7f": [ {
            "parents": [ "group:Owner" ]
        } ]
    }
}

This view may make sense when it comes to checking permissions, but there are multiple plugins that need to check whether someone is OP for different reasons. Also, over all that “OP isn’t a thing” and hiding it, one mustn’t forget that OP still exists and grants permissions.

1 Like

The permission ‘*’ no longer exists. Instead, you set the default permission to true, like so:

/pex group Owner def true

This allows plugins to explicitly set permissions to false and not have the admins override them unless specifically desired, which was an issue on Bukkit PEX.

No there aren’t. Anything that does an op check can do a permissions check instead. And op does not grant permissions unless the server is running fallback permissions, in which case the op levels are exposed as permissions groups.

And how would a plugin go about oping / deoping someone?

I think what @zml is saying is there is again no concept of OP.

Basically from what I’ve interpreted OP is basically gone forever. There are only permissions.
So instead of having “OP”, or the “*” permission, you only have the default permission.
So by giving/revoking the default permission you are removing/giving all permissions to a player. (From what I understand)

Why would you need to op or deop someone? What does/should OP even mean for sponge?

So, assume a user /ops another user and there is a plugin that should check against a list of ops allowed and deop them again (as if an op ran /deop SomeIGN) if they aren’t on that list (this is actually a thing for various reasons). How’d that work?

Register my own command to use the /op command and remove the permission for the default minecraft op command using whichever permission manager I use?

Edit: but seriously I see some use cases being valid, I was just curious.

Since op gets all permissions,

player.hasPermission(“LETS.CHECK.IF.THIS.PERSON.HAS.OP.FAKE.PERM”); would return true, and you would know they were op.

no. no. no. that is a bad idea. never do that.

2 Likes

I’ve gotta implement this in Pore at some point. Am I stuck with checking the filesystem or developing some sort of implementation-dependent under-the-hood check?

well do any real plugins people care about even check isOp in Bukkit? but realistically, in that case your best bet is probably pore.op or something – you don’t have the choice for good design there.

So assuming no permissions plugin is installed, how do I make a permission that defaults to the op status?