use of org.spongepowered.api.service.context.Context in project LanternServer by LanternPowered.
the class LanternContextCalculator method buildAddressCache.
private LoadingCache<RemoteSource, Set<Context>> buildAddressCache(final String contextKey, final Function<RemoteSource, InetAddress> function) {
return Caffeine.newBuilder().weakKeys().build(key -> {
final ImmutableSet.Builder<Context> builder = ImmutableSet.builder();
final InetAddress address = checkNotNull(function.apply(key), "address");
builder.add(new Context(contextKey, address.getHostAddress()));
for (String set : Maps.filterValues(Lantern.getGame().getGlobalConfig().getIpSets(), input -> input.test(address)).keySet()) {
builder.add(new Context(contextKey, set));
}
return builder.build();
});
}
use of org.spongepowered.api.service.context.Context in project LanternServer by LanternPowered.
the class LanternContextCalculator method accumulateContexts.
@Override
public void accumulateContexts(Subject subject, Set<Context> accumulator) {
final Optional<CommandSource> subjSource = subject.getCommandSource();
if (subjSource.isPresent()) {
final CommandSource source = subjSource.get();
if (source instanceof Locatable) {
final World currentExt = ((Locatable) source).getWorld();
accumulator.add(currentExt.getContext());
accumulator.add((currentExt.getDimension().getContext()));
}
if (source instanceof RemoteSource) {
final RemoteSource rem = (RemoteSource) source;
accumulator.addAll(this.remoteIpCache.get(rem));
accumulator.addAll(this.localIpCache.get(rem));
accumulator.add(new Context(Context.LOCAL_PORT_KEY, String.valueOf(rem.getConnection().getVirtualHost().getPort())));
accumulator.add(new Context(Context.LOCAL_HOST_KEY, rem.getConnection().getVirtualHost().getHostName()));
}
}
}
use of org.spongepowered.api.service.context.Context in project Nucleus by NucleusPowered.
the class EnforceGamemodeListener method enforce.
private void enforce(Player player, World world) {
if (world.getProperties().getGameMode() == GameModes.NOT_SET) {
return;
}
Set<Context> contextSet = Sets.newHashSet(player.getActiveContexts());
contextSet.removeIf(x -> x.getKey().equals(Context.WORLD_KEY));
contextSet.add(new Context(Context.WORLD_KEY, world.getName()));
if (!player.hasPermission(contextSet, this.perm)) {
// set their gamemode accordingly.
player.offer(Keys.GAME_MODE, world.getProperties().getGameMode());
}
}
use of org.spongepowered.api.service.context.Context in project Nucleus by NucleusPowered.
the class SetupPermissionsCommand method setupPerms.
private void setupPerms(CommandSource src, Subject group, SuggestedLevel level, boolean reset, boolean inherit) throws Exception {
if (inherit && level.getLowerLevel() != null) {
setupPerms(src, group, level.getLowerLevel(), reset, inherit);
}
Set<Context> globalContext = Sets.newHashSet();
SubjectData data = group.getSubjectData();
Set<String> definedPermissions = data.getPermissions(ImmutableSet.of()).keySet();
Logger logger = Nucleus.getNucleus().getLogger();
MessageProvider messageProvider = Nucleus.getNucleus().getMessageProvider();
// Register all the permissions, but only those that have yet to be assigned.
permissionRegistry.getPermissions().entrySet().stream().filter(x -> x.getValue().level == level).filter(x -> reset || !definedPermissions.contains(x.getKey())).forEach(x -> {
logger.info(messageProvider.getMessageWithFormat("command.nucleus.permission.added", x.getKey(), group.getIdentifier()));
data.setPermission(globalContext, x.getKey(), Tristate.TRUE);
});
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.nucleus.permission.complete", level.toString().toLowerCase(), group.getIdentifier()));
}
use of org.spongepowered.api.service.context.Context in project SpongeCommon by SpongePowered.
the class MixinDimensionType method onConstruct.
@Inject(method = "<init>", at = @At("RETURN"))
public void onConstruct(String enumName, int ordinal, int idIn, String nameIn, String suffixIn, Class<? extends WorldProvider> clazzIn, CallbackInfo ci) {
String dimName = enumName.toLowerCase().replace(" ", "_").replaceAll("[^A-Za-z0-9_]", "");
this.enumName = dimName;
this.modId = SpongeImplHooks.getModIdFromClass(clazzIn);
this.configPath = SpongeImpl.getSpongeConfigDir().resolve("worlds").resolve(this.modId).resolve(this.enumName);
this.config = new SpongeConfig<>(SpongeConfig.Type.DIMENSION, this.configPath.resolve("dimension.conf"), SpongeImpl.ECOSYSTEM_ID);
this.generateSpawnOnLoad = idIn == 0;
this.loadSpawn = this.generateSpawnOnLoad;
this.config.getConfig().getWorld().setGenerateSpawnOnLoad(this.generateSpawnOnLoad);
this.sanitizedId = this.modId + ":" + dimName;
String contextId = this.sanitizedId.replace(":", ".");
this.context = new Context(Context.DIMENSION_KEY, contextId);
if (!WorldManager.isDimensionRegistered(idIn)) {
DimensionTypeRegistryModule.getInstance().registerAdditionalCatalog((org.spongepowered.api.world.DimensionType) this);
}
}
Aggregations