Fire PermRefreshEvent in sponge too

This commit is contained in:
Luck 2016-08-20 16:26:32 +01:00
parent 4aa753515d
commit 6fc00976a0
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B

View File

@ -23,6 +23,8 @@
package me.lucko.luckperms.users;
import me.lucko.luckperms.LPSpongePlugin;
import me.lucko.luckperms.api.event.events.UserPermissionRefreshEvent;
import me.lucko.luckperms.api.implementation.internal.UserLink;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.util.Tristate;
@ -46,18 +48,21 @@ class SpongeUser extends User {
@Override
public void refreshPermissions() {
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
if (!p.isPresent()) return;
plugin.doSync(() -> {
Optional<Player> p = plugin.getGame().getServer().getPlayer(plugin.getUuidCache().getExternalUUID(getUuid()));
if (!p.isPresent()) return;
final Player player = p.get();
final Player player = p.get();
// Clear existing permissions
player.getSubjectData().clearParents();
player.getSubjectData().clearPermissions();
// Clear existing permissions
player.getSubjectData().clearParents();
player.getSubjectData().clearPermissions();
// Re-add all defined permissions for the user
final String world = player.getWorld().getName();
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), world, null);
local.entrySet().forEach(e -> player.getSubjectData().setPermission(Collections.emptySet(), e.getKey(), Tristate.fromBoolean(e.getValue())));
// Re-add all defined permissions for the user
final String world = player.getWorld().getName();
Map<String, Boolean> local = getLocalPermissions(getPlugin().getConfiguration().getServer(), world, null);
local.entrySet().forEach(e -> player.getSubjectData().setPermission(Collections.emptySet(), e.getKey(), Tristate.fromBoolean(e.getValue())));
plugin.getApiProvider().fireEventAsync(new UserPermissionRefreshEvent(new UserLink(this)));
});
}
}