I’ve been trying to re-give permissions via SubjectData#setPermission () in RespawnPlayerEvent but the permissions disappear as soon as the event ends
Code:
I’ve been trying to re-give permissions via SubjectData#setPermission () in RespawnPlayerEvent but the permissions disappear as soon as the event ends
Code:
setPermission
Returns A CompletableFuture, check if the value is actually being added with it.
It returns false
What permissions plugin are you using? Or are you attempting to make your own?
I’m just doing the server plugin, it doesn’t provide an permission service for Sponge
It maybe that Sponge expects a permissions service to use Subject, even though you are using Transient. Add a permissions plugin and see if the value returns true
I use this way when a player join, and everything is fine
Also it’s written in the docs that it’s not necessary a permission service to use Transient, i’ll try anyway.
Okay, it worked; but will I be required to use a permission plugin just to fix this?
I couldnt find in the docs to state that it is optional for a permissions service. I did find this though
Regular (persistent) = Might be saved somewhere, and therefore be persisted and exist forever. Its recommended for PermissionServices to implement a persistent store, however it is not a requirement
To me that reads that there is a optional part of the permission service that is for storing, not that the permission service is optional for a subject data.
Anyways, as your issue is that it requires a permission plugin (as you are dealing with permissions) and most servers will have a permissions plugin anyway, it seems like a issue for those servers that somwhow exist without a permissions plugin, i wouldnt be surprised if this is 1% of the servers running Sponge
Try something like this:
@Listener(order = Order.LATE)
public void onPlayerRespawn(RespawnPlayerEvent event) {
HTIPlayer player = SpongePlugin.getPlayer(event.getOriginalPlayer().getUniqueId());
SubjectData data = event.getTargetEntity().getSubjectData();
player.roles.forEach(role -> role.getPermissions().forEach(permission -> data.setPermission(SubjectData.GLOBAL_CONTEXT, permission, Tristate.TRUE)));
}