use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class LPPermissionAttachment method setPermissionInternal.
private void setPermissionInternal(String name, boolean value) {
if (!this.permissible.getPlugin().getConfiguration().get(ConfigKeys.APPLY_NUKKIT_ATTACHMENT_PERMISSIONS)) {
return;
}
// construct a node for the permission being set
// we use the servers static context to *try* to ensure that the node will apply
Node node = NodeFactory.builder(name).setValue(value).withExtraContext(this.permissible.getPlugin().getContextManager().getStaticContext()).build();
// convert the constructed node to a transient node instance to refer back to this attachment
ImmutableTransientNode<LPPermissionAttachment> transientNode = ImmutableTransientNode.of(node, this);
// set the transient node
User user = this.permissible.getUser();
if (user.setTransientPermission(transientNode).asBoolean()) {
user.reloadCachedData();
}
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class LPNukkitPlugin method performFinalSetup.
@Override
protected void performFinalSetup() {
// register permissions
try {
PluginManager pm = this.bootstrap.getServer().getPluginManager();
PermissionDefault permDefault = getConfiguration().get(ConfigKeys.COMMANDS_ALLOW_OP) ? PermissionDefault.OP : PermissionDefault.FALSE;
for (CommandPermission p : CommandPermission.values()) {
pm.addPermission(new Permission(p.getPermission(), null, permDefault.toString()));
}
} catch (Exception e) {
// this throws an exception if the plugin is /reloaded, grr
}
if (!getConfiguration().get(ConfigKeys.OPS_ENABLED)) {
Config ops = this.bootstrap.getServer().getOps();
ops.getKeys(false).forEach(ops::remove);
}
// replace the temporary executor when the Nukkit one starts
this.bootstrap.getServer().getScheduler().scheduleTask(this.bootstrap, () -> this.bootstrap.getScheduler().setUseFallback(false), true);
// Load any online users (in the case of a reload)
for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
this.bootstrap.getScheduler().doAsync(() -> {
try {
User user = this.connectionListener.loadUser(player.getUniqueId(), player.getName());
if (user != null) {
this.bootstrap.getScheduler().doSync(() -> {
try {
LPPermissible lpPermissible = new LPPermissible(player, user, this);
PermissibleInjector.inject(player, lpPermissible);
} catch (Throwable t) {
t.printStackTrace();
}
});
}
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class LPNukkitPlugin method removePlatformHooks.
@Override
protected void removePlatformHooks() {
// uninject from players
for (Player player : this.bootstrap.getServer().getOnlinePlayers().values()) {
try {
PermissibleInjector.unInject(player, false);
} catch (Exception e) {
e.printStackTrace();
}
if (getConfiguration().get(ConfigKeys.AUTO_OP)) {
player.setOp(false);
}
final User user = getUserManager().getIfLoaded(player.getUniqueId());
if (user != null) {
user.getCachedData().invalidateCaches();
getUserManager().unload(user);
}
}
// uninject custom maps
InjectorSubscriptionMap.uninject();
InjectorPermissionMap.uninject();
InjectorDefaultsMap.uninject();
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class HolderSubjectData method setOption.
@Override
public CompletableFuture<Boolean> setOption(ImmutableContextSet contexts, String key, String value) {
Objects.requireNonNull(contexts, "contexts");
Objects.requireNonNull(key, "key");
Objects.requireNonNull(value, "value");
Node node;
if (key.equalsIgnoreCase(NodeFactory.PREFIX_KEY) || key.equalsIgnoreCase(NodeFactory.SUFFIX_KEY)) {
// special handling.
ChatMetaType type = ChatMetaType.valueOf(key.toUpperCase());
// remove all prefixes/suffixes from the user
List<Node> toRemove = streamNodes().filter(type::matches).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
MetaAccumulator metaAccumulator = this.holder.accumulateMeta(null, this.service.getPlugin().getContextManager().formContexts(contexts));
int priority = metaAccumulator.getChatMeta(type).keySet().stream().mapToInt(e -> e).max().orElse(0);
priority += 10;
node = NodeFactory.buildChatMetaNode(type, priority, value).withExtraContext(contexts).build();
} else {
// standard remove
List<Node> toRemove = streamNodes().filter(n -> n.isMeta() && n.getMeta().getKey().equals(key)).filter(n -> n.getFullContexts().equals(contexts)).collect(Collectors.toList());
toRemove.forEach(n -> this.type.run(() -> this.holder.unsetPermission(n), () -> this.holder.unsetTransientPermission(n)));
node = NodeFactory.buildMetaNode(key, value).withExtraContext(contexts).build();
}
this.type.run(() -> this.holder.setPermission(node), () -> this.holder.setTransientPermission(node));
return objectSave(this.holder).thenApply(v -> true);
}
use of me.lucko.luckperms.common.model.User in project LuckPerms by lucko.
the class HolderSubjectData method objectSave.
private CompletableFuture<Void> objectSave(PermissionHolder t) {
// handle transient first
if (this.type == NodeMapType.TRANSIENT) {
// don't bother saving to primary storage. just refresh
if (t.getType().isUser()) {
User user = ((User) t);
return user.getRefreshBuffer().request();
} else {
return this.service.getPlugin().getUpdateTaskBuffer().request();
}
}
// handle enduring
if (t.getType().isUser()) {
User user = ((User) t);
CompletableFuture<Void> fut = new CompletableFuture<>();
this.service.getPlugin().getStorage().saveUser(user).whenCompleteAsync((v, ex) -> {
if (ex != null) {
fut.complete(null);
}
user.getRefreshBuffer().request().thenAccept(fut::complete);
}, this.service.getPlugin().getBootstrap().getScheduler().async());
return fut;
} else {
Group group = ((Group) t);
CompletableFuture<Void> fut = new CompletableFuture<>();
this.service.getPlugin().getStorage().saveGroup(group).whenCompleteAsync((v, ex) -> {
if (ex != null) {
fut.complete(null);
}
this.service.getPlugin().getUpdateTaskBuffer().request().thenAccept(fut::complete);
}, this.service.getPlugin().getBootstrap().getScheduler().async());
return fut;
}
}
Aggregations