use of org.spongepowered.api.service.permission.PermissionService in project LanternServer by LanternPowered.
the class NetworkSession method isWhitelisted.
private static boolean isWhitelisted(GameProfile gameProfile) {
if (!Lantern.getGame().getGlobalConfig().isWhitelistEnabled()) {
return true;
}
final WhitelistService whitelistService = Sponge.getServiceManager().provideUnchecked(WhitelistService.class);
if (whitelistService.isWhitelisted(gameProfile)) {
return true;
}
final PermissionService permissionService = Sponge.getServiceManager().provideUnchecked(PermissionService.class);
return permissionService.getUserSubjects().getSubject(gameProfile.getUniqueId().toString()).map(subject -> subject.hasPermission(Permissions.Login.BYPASS_WHITELIST_PERMISSION)).orElse(false);
}
use of org.spongepowered.api.service.permission.PermissionService in project LanternServer by LanternPowered.
the class ProxySubject method resolveNullableSubject.
@Nullable
default Subject resolveNullableSubject() {
SubjectReference reference = getInternalSubject();
if (reference == null) {
final Optional<PermissionService> optService = Lantern.getGame().getServiceManager().provide(PermissionService.class);
if (optService.isPresent()) {
// Try to update the internal subject
SubjectSettingCallback.apply(this, optService.get());
// Get the new subject reference, can be null if failed
reference = getInternalSubject();
}
}
return reference == null ? null : reference.resolve().join();
}
use of org.spongepowered.api.service.permission.PermissionService in project LanternServer by LanternPowered.
the class LanternGame method initialize.
public void initialize() throws IOException {
final LanternMinecraftVersion versionCacheEntry = this.minecraftVersionCache.getVersionOrUnknown(Protocol.CURRENT_VERSION, false);
if (!LanternMinecraftVersion.CURRENT.equals(versionCacheEntry)) {
throw new RuntimeException("The current version and version in the cache don't match: " + LanternMinecraftVersion.CURRENT + " != " + versionCacheEntry);
}
// Load the plugin instances
try {
// By default, use the '--scanClasspath <true|false>' option, if it can't
// be found, fall back to a environment based decision
Boolean scanClasspath = this.scanClasspath;
if (scanClasspath == null) {
scanClasspath = Environment.get() == Environment.DEVELOPMENT;
}
this.pluginManager.loadPlugins(scanClasspath);
} catch (IOException e) {
throw new RuntimeException("An error occurred while loading the plugins.", e);
}
this.gameRegistry.registerDefaults();
this.gameRegistry.earlyRegistry();
// Load the global configuration
this.globalConfig.load();
// Save missing settings
this.globalConfig.save();
// They should not be replaced by now
this.whitelistService.extended(WhitelistConfig.class).get().load();
this.banService.extended(BanConfig.class).get().load();
// Create the event manager instance
this.eventManager.registerListeners(this.implContainer, LanternServiceListeners.getInstance());
this.pluginManager.registerPluginInstances();
// Call pre registry phase.
this.gameRegistry.preRegistry();
// Register temporarily a empty rcon service
registerService(RconService.class, new EmptyRconService(this.globalConfig.getRconPassword()));
// Create the cause to post events...
final CauseStack causeStack = CauseStack.current();
causeStack.pushCause(this);
final Cause gameCause = causeStack.getCurrentCause();
// Call the construction events
postGameStateChange(SpongeEventFactory.createGameConstructionEvent(gameCause));
// Call pre init phase for registry
this.gameRegistry.preInit();
LanternServiceListeners.getInstance().registerServiceCallback(PermissionService.class, input -> {
this.server.getConsole().getContainingCollection();
input.registerContextCalculator(new LanternContextCalculator());
});
// Pre-init phase
postGameStateChange(SpongeEventFactory.createGamePreInitializationEvent(gameCause));
// Call init phase for registry
this.gameRegistry.init();
final PermissionService permissionService = this.permissionService.get();
if (permissionService instanceof LanternPermissionService) {
final LanternPermissionService service = (LanternPermissionService) permissionService;
service.getGroupForOpLevel(Permissions.SELECTOR_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.SELECTOR_PERMISSION, Tristate.TRUE);
service.getGroupForOpLevel(Permissions.COMMAND_BLOCK_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.COMMAND_BLOCK_PERMISSION, Tristate.TRUE);
service.getGroupForOpLevel(Permissions.Login.BYPASS_PLAYER_LIMIT_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.Login.BYPASS_PLAYER_LIMIT_PERMISSION, Tristate.FALSE);
service.getGroupForOpLevel(Permissions.Login.BYPASS_WHITELIST_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.Login.BYPASS_WHITELIST_PERMISSION, Tristate.TRUE);
service.getGroupForOpLevel(Permissions.Chat.FORMAT_URLS_LEVEL).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, Permissions.Chat.FORMAT_URLS, Tristate.TRUE);
}
// Load the default commands
this.injector.getInstance(DefaultCommandsCollection.class).load();
// Init phase
postGameStateChange(SpongeEventFactory.createGameInitializationEvent(gameCause));
// Call post init phase for registry
this.gameRegistry.postInit();
// Post-init phase
postGameStateChange(SpongeEventFactory.createGamePostInitializationEvent(gameCause));
// Load-complete phase
postGameStateChange(SpongeEventFactory.createGameLoadCompleteEvent(gameCause));
// Pop off the game instance
causeStack.popCause();
}
use of org.spongepowered.api.service.permission.PermissionService in project Nucleus by NucleusPowered.
the class ListPlayerCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
boolean showVanished = this.permissions.testSuffix(src, "seevanished");
Collection<Player> players = Sponge.getServer().getOnlinePlayers();
long playerCount = players.size();
long hiddenCount = players.stream().filter(x -> x.get(Keys.VANISH).orElse(false)).count();
Text header;
if (showVanished && hiddenCount > 0) {
header = plugin.getMessageProvider().getTextMessageWithFormat("command.list.playercount.hidden", String.valueOf(playerCount), String.valueOf(Sponge.getServer().getMaxPlayers()), String.valueOf(hiddenCount));
} else {
header = plugin.getMessageProvider().getTextMessageWithFormat("command.list.playercount.base", String.valueOf(playerCount - hiddenCount), String.valueOf(Sponge.getServer().getMaxPlayers()));
}
src.sendMessage(header);
Optional<PermissionService> optPermissionService = Sponge.getServiceManager().provide(PermissionService.class);
if (this.listConfig.isGroupByPermissionGroup() && optPermissionService.isPresent()) {
listByPermissionGroup(optPermissionService.get(), players, src, showVanished);
} else {
// If we have players, send them on.
getPlayerList(players, showVanished).ifPresent(src::sendMessage);
}
return CommandResult.success();
}
use of org.spongepowered.api.service.permission.PermissionService in project Nucleus by NucleusPowered.
the class NucleusPlugin method registerPermissions.
@Override
protected void registerPermissions() {
Optional<PermissionService> ops = Sponge.getServiceManager().provide(PermissionService.class);
ops.ifPresent(permissionService -> {
Map<String, PermissionInformation> m = this.getPermissionRegistry().getPermissions();
m.entrySet().stream().filter(x -> {
SuggestedLevel lvl = x.getValue().level;
return lvl == SuggestedLevel.ADMIN || lvl == SuggestedLevel.OWNER;
}).filter(x -> x.getValue().isNormal).forEach(k -> permissionService.newDescriptionBuilder(this).assign(PermissionDescription.ROLE_ADMIN, true).description(k.getValue().description).id(k.getKey()).register());
m.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.MOD).filter(x -> x.getValue().isNormal).forEach(k -> permissionService.newDescriptionBuilder(this).assign(PermissionDescription.ROLE_STAFF, true).description(k.getValue().description).id(k.getKey()).register());
m.entrySet().stream().filter(x -> x.getValue().level == SuggestedLevel.USER).filter(x -> x.getValue().isNormal).forEach(k -> permissionService.newDescriptionBuilder(this).assign(PermissionDescription.ROLE_USER, true).description(k.getValue().description).id(k.getKey()).register());
});
}
Aggregations