Java Code Examples for net.luckperms.api.context.ImmutableContextSet#Builder
The following examples show how to use
net.luckperms.api.context.ImmutableContextSet#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompatibilityUtil.java From LuckPerms with MIT License | 6 votes |
public static ImmutableContextSet convertContexts(Set<Context> contexts) { Objects.requireNonNull(contexts, "contexts"); if (contexts instanceof ForwardingContextSet) { return ((ForwardingContextSet) contexts).delegate().immutableCopy(); } if (contexts.isEmpty()) { return ImmutableContextSetImpl.EMPTY; } ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (Map.Entry<String, String> entry : contexts) { builder.add(new ContextImpl(entry.getKey(), entry.getValue())); } return builder.build(); }
Example 2
Source File: AbstractConfigurateStorage.java From LuckPerms with MIT License | 6 votes |
private static ImmutableContextSet readContexts(ConfigurationNode attributes) { ImmutableContextSet.Builder contextBuilder = new ImmutableContextSetImpl.BuilderImpl(); ConfigurationNode contextMap = attributes.getNode("context"); if (!contextMap.isVirtual() && contextMap.hasMapChildren()) { contextBuilder.addAll(ContextSetConfigurateSerializer.deserializeContextSet(contextMap)); } String server = attributes.getNode("server").getString("global"); if (!server.equals("global")) { contextBuilder.add(DefaultContextKeys.SERVER_KEY, server); } String world = attributes.getNode("world").getString("global"); if (!world.equals("global")) { contextBuilder.add(DefaultContextKeys.WORLD_KEY, world); } return contextBuilder.build(); }
Example 3
Source File: LuckPermsHook.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
@Override public ContextSet estimatePotentialContexts() { ImmutableContextSet.Builder builder = ImmutableContextSet.builder(); builder.add(CONTEXT_LINKED, "true"); builder.add(CONTEXT_LINKED, "false"); builder.add(CONTEXT_BOOSTING, "true"); builder.add(CONTEXT_BOOSTING, "false"); Guild mainGuild = DiscordSRV.getPlugin().getMainGuild(); if (mainGuild != null) { for (Role role : mainGuild.getRoles()) { builder.add(CONTEXT_ROLE, role.getName()); } } return builder.build(); }
Example 4
Source File: WorldCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { List<World> worlds = this.plugin.getBootstrap().getServer().getWorlds(); ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (World world : worlds) { String name = world.getName().toLowerCase(); if (Context.isValidValue(name)) { builder.add(DefaultContextKeys.WORLD_KEY, name); } } return builder.build(); }
Example 5
Source File: LuckPermsVaultChat.java From LuckPerms with MIT License | 5 votes |
private QueryOptions createQueryOptionsForWorldSet(String world) { ImmutableContextSet.Builder context = new ImmutableContextSetImpl.BuilderImpl(); if (world != null && !world.equals("") && !world.equalsIgnoreCase("global")) { context.add(DefaultContextKeys.WORLD_KEY, world.toLowerCase()); } context.add(DefaultContextKeys.SERVER_KEY, this.vaultPermission.getVaultServer()); QueryOptions.Builder builder = QueryOptionsImpl.DEFAULT_CONTEXTUAL.toBuilder(); builder.context(context.build()); builder.flag(Flag.INCLUDE_NODES_WITHOUT_SERVER_CONTEXT, this.vaultPermission.isIncludeGlobal()); return builder.build(); }
Example 6
Source File: RedisBungeeCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { RedisBungeeAPI redisBungee = RedisBungee.getApi(); if (redisBungee == null) { return ImmutableContextSetImpl.EMPTY; } ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (String server : redisBungee.getAllServers()) { builder.add(PROXY_KEY, server); } return builder.build(); }
Example 7
Source File: BackendServerCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { Collection<ServerInfo> servers = this.plugin.getBootstrap().getProxy().getServers().values(); ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (ServerInfo server : servers) { builder.add(DefaultContextKeys.WORLD_KEY, server.getName().toLowerCase()); } return builder.build(); }
Example 8
Source File: WorldCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { Game game = this.plugin.getBootstrap().getGame(); if (!game.isServerAvailable()) { return ImmutableContextSetImpl.EMPTY; } Collection<World> worlds = game.getServer().getWorlds(); ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (World world : worlds) { builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase()); } return builder.build(); }
Example 9
Source File: WorldCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { Collection<Level> worlds = this.plugin.getBootstrap().getServer().getLevels().values(); ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (Level world : worlds) { builder.add(DefaultContextKeys.WORLD_KEY, world.getName().toLowerCase()); } return builder.build(); }
Example 10
Source File: BackendServerCalculator.java From LuckPerms with MIT License | 5 votes |
@Override public ContextSet estimatePotentialContexts() { Collection<RegisteredServer> servers = this.plugin.getBootstrap().getProxy().getAllServers(); ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (RegisteredServer server : servers) { builder.add(DefaultContextKeys.WORLD_KEY, server.getServerInfo().getName().toLowerCase()); } return builder.build(); }
Example 11
Source File: ContextManager.java From LuckPerms with MIT License | 5 votes |
protected QueryOptions calculate(S subject) { ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl(); for (ContextCalculator<? super S> calculator : this.calculators) { try { calculator.calculate(subject, accumulator::add); } catch (Throwable e) { this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating the context of subject " + subject); e.printStackTrace(); } } return formQueryOptions(subject, accumulator.build()); }
Example 12
Source File: ContextManager.java From LuckPerms with MIT License | 5 votes |
private QueryOptions calculateStatic() { ImmutableContextSet.Builder accumulator = new ImmutableContextSetImpl.BuilderImpl(); for (StaticContextCalculator calculator : this.staticCalculators) { try { calculator.calculate(accumulator::add); } catch (Throwable e) { this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst calculating static contexts"); e.printStackTrace(); } } return formQueryOptions(accumulator.build()); }
Example 13
Source File: ContextManager.java From LuckPerms with MIT License | 5 votes |
public ImmutableContextSet getPotentialContexts() { ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); for (ContextCalculator<? super S> calculator : this.calculators) { ContextSet potentialContexts; try { potentialContexts = calculator.estimatePotentialContexts(); } catch (Throwable e) { this.plugin.getLogger().warn("An exception was thrown by " + getCalculatorClass(calculator) + " whilst estimating potential contexts"); e.printStackTrace(); continue; } builder.addAll(potentialContexts); } return builder.build(); }
Example 14
Source File: LPStaticContextsCalculator.java From LuckPerms with MIT License | 4 votes |
@Override public ContextSet estimatePotentialContexts() { ImmutableContextSet.Builder builder = new ImmutableContextSetImpl.BuilderImpl(); calculate(builder::add); return builder.build(); }