LuckPerms

LuckPerms

41.4k Downloads

Can't save!

mcoo opened this issue · 12 comments

commented
public void addPermission(Player player, String permission,int timer) {
        // assert that the player is online
        if (!player.isOnline()) {
            throw new IllegalStateException("Player is offline");
        }
        User user =  LuckPermsProvider.get().getUserManager().getUser(player.getUniqueId());
        long time1 = new Date().getTime();
        time1 +=timer * 3600;
        user.getNodes().add(Node.builder(permission).value(true).expiry(time1).build());
        // TODO add the permission
        // Now we need to save changes.
        player.sendMessage("Success");
        LuckPermsProvider.get().getUserManager().saveUser(user);
    }

When I use it, I can't see it in Web Permissions Editor or anywhere. Why? : (

addPermission(player,"essentials.fly",3);
commented

But I have LuckPermsProvider.get().getUserManager().saveUser(user); It's can't work?
And in game,I get the Permission, but it's nothing in Web Permissions Editor.

commented

Sorry. I missed that.

Make sure to open a new editor session after you added the node.

commented

I am sure I open a new editor session after the node.
QQ截图20200331155954
QQ截图20200331160015
QQ截图20200331160204

    public void addPermission(Player player, String permission,int timer) {
        // assert that the player is online
        if (!player.isOnline()) {
            throw new IllegalStateException("Player is offline");
        }
        User user =  LuckPermsProvider.get().getUserManager().getUser(player.getUniqueId());
        long time1 = new Date().getTime();
        time1 += timer * 3600;
        assert user != null;
        user.getNodes().add(Node.builder(permission).value(true).expiry(time1).build());
        player.sendMessage("Success");
        LuckPermsProvider.get().getUserManager().saveUser(user);
    }

addPermission(player,"essentials.fly",timer);

commented

What LP version are you using?

commented

[LP] Running LuckPerms v5.0.102.

[16:06:13 INFO]: [LP] Running LuckPerms v5.0.102 by Luck.
[16:06:13 INFO]: [LP] -  Platform: Bukkit
[16:06:13 INFO]: [LP] -  Server Brand: Paper
[16:06:13 INFO]: [LP] -  Server Version:
[16:06:13 INFO]: [LP] -  git-Paper-143 (MC: 1.15.2) - 1.15.2-R0.1-SNAPSHOT
[16:06:13 INFO]: [LP] -  Storage:
[16:06:13 INFO]: [LP] -     Type: H2
[16:06:13 INFO]: [LP] -     File Size: 0.05MB
[16:06:13 INFO]: [LP] -  Messaging: None
[16:06:13 INFO]: [LP] -  Instance:
[16:06:13 INFO]: [LP] -     Static contexts: None
[16:06:13 INFO]: [LP] -     Online Players: 4 (4 unique)
[16:06:13 INFO]: [LP] -     Uptime: 20m 21s
[16:06:13 INFO]: [LP] -     Local Data: 4 users, 3 groups, 0 tracks
commented

Hm. Then I don't know. Luck will need to help.

commented

I see.
Thank you for your good work and look forward to early solving

commented

I'm guessing your duration calculation is wrong - so the the node is expiring straight away.

Assuming timer is how long you want the permission to last in hours (I assume that due to your * 3600 call), then this will work.

Node.builder(permission).value(true).expiry(Duration.ofHours(timer)).build()
commented

image
It can't work,so I use it to replace:

user.getNodes().add(Node.builder(permission).value(true).expiry(Duration.ofHours(timer).getSeconds()).build());

But, it is same. Can't save.

commented

When I use the api to add Permission, I get the Permission in game, but when I reload my plugin I lost the Permission. I am sure when I can use the Permission, I can't see it in Web Permissions Editor. So...I can't save it, and I think duration calculation is ok because I can use the Permission in game. What's more, is the expiry a time stamp?

commented

Could you give me a example?