Permission not applied through the API
magrigry opened this issue · 1 comments
Description
I am using the API to give a few permissions when players join. Sometimes, permission arn't given for some unknown reason. See example in "Logs and Configs" and "Extra Details".
Reproduction Steps
I am not able to reproduce the issue or to find any pattern. The issue randomly happen.
I tried desperately to switch to another fresh and clean database installation (but same engine, still MariaDB), same thing happen.
Expected Behaviour
Player should have the given permission.
Server Details
git-Pufferfish-20 (MC: 1.17.1) (Implementing API version 1.17.1-R0.1-SNAPSHOT) (Git: b9556fd on HEAD)
LuckPerms Version
5.3.98 (I tried updating many times)
Logs and Configs
[11:43:39] [User Authenticator #40/INFO]: [LuckPerms] Processing pre-login for 84af41c1-99b5-42ab-b25e-ef2995858056 - Boonix
[11:43:39] [User Authenticator #40/INFO]: UUID of player Boonix is 84af41c1-99b5-42ab-b25e-ef2995858056
[11:43:39] [Server thread/INFO]: [LuckPerms] Processing login for 84af41c1-99b5-42ab-b25e-ef2995858056 - Boonix
[11:43:39] [Server thread/INFO]: [ExcellentShop] Created new user data for: '84af41c1-99b5-42ab-b25e-ef2995858056'
[11:43:39] [Server thread/INFO]: Boonix à rejoint le serveur pour la première fois.
[11:43:39] [Server thread/INFO]: Loading user boonix
[11:43:39] [Server thread/INFO]: Adding permission historya.jobs.nojob
[11:43:39] [Server thread/INFO]: Adding permission historya.jobs.branch1.notstarted
[11:43:39] [Server thread/INFO]: Adding permission historya.jobs.branch2.notstarted
[11:43:39] [Server thread/INFO]: Adding permission historya.jobs.branch3.notstarted
[11:43:39] [Server thread/INFO]: Adding permission historya.jobs.branch4.notstarted
[11:43:39] [ForkJoinPool-1-worker-144/INFO]: boonix has been saved.
As we can see below, permission arn't added:
Extra Details
Here is the code I am using that generated a few logs above
@EventHandler
public void onPlayerFirstJoin(PlayerJoinEvent event) {
if(!event.getPlayer().hasPlayedBefore()) {
Bukkit.getLogger().info(event.getPlayer().getName() + " joined for the first time.");
Player player = event.getPlayer();
List<String> permissions = new ArrayList<>();
permissions.add("historya.jobs.nojob");
permissions.add("historya.jobs.branch1.notstarted");
permissions.add("historya.jobs.branch2.notstarted");
permissions.add("historya.jobs.branch3.notstarted");
permissions.add("historya.jobs.branch4.notstarted");
LuckPermsUtils.addPlayerPermissions(player, permissions);
}
}
}
public static void addPlayerPermissions(Player player, List<String> permissions) {
User user = luckPermsAPI.getPlayerAdapter(Player.class).getUser(player);
Bukkit.getLogger().info("Loading user " + user.getUsername());
permissions.forEach(permission -> {
Bukkit.getLogger().info("Adding permission " + permission);
DataMutateResult result = user.data().add(Node.builder(permission).build());
if (!result.wasSuccessful()) {
Bukkit.getLogger().log(Level.WARNING, user.getUsername() + " already has permission: " + permission);
}
});
luckPermsAPI.getUserManager().saveUser(user)
.whenComplete((unused, throwable) -> {
Bukkit.getLogger().info(user.getUsername() + " has been saved.");
});
}
Let me know if there is any extra details I can give to improve debugging. I am pretty confused with this issue and tried mlostly everything I though about
Looks ok to me!
Please try updating again to the latest development build: https://luckperms.net/download
If it's still an issue, try making a call to luckperms.getStorage().loadUser()
before making your changes (although a recent-ish change means this shouldn't be necessary anymore)