Search in sources :

Example 1 with LanternPermissionService

use of org.lanternpowered.server.service.permission.LanternPermissionService in project LanternServer by LanternPowered.

the class SubjectSettingCallback method apply.

static boolean apply(@Nullable ProxySubject ref, @Nullable PermissionService input) {
    if (ref == null) {
        // as a listener, and will not be tested again.
        return false;
    }
    // if PS has just been unregistered, ignore the change.
    if (input == null) {
        return true;
    }
    final SubjectReference subject;
    // we can skip some unnecessary instance creation this way.
    if (input instanceof LanternPermissionService) {
        final LanternPermissionService service = (LanternPermissionService) input;
        final LanternSubjectCollection collection = service.get(ref.getSubjectCollectionIdentifier());
        subject = collection.get(ref.getIdentifier()).asSubjectReference();
    } else {
        // build a new subject reference using the permission service
        // this doesn't actually load the subject, so it will be lazily init'd when needed.
        subject = input.newSubjectReference(ref.getSubjectCollectionIdentifier(), ref.getIdentifier());
    }
    ref.setInternalSubject(subject);
    return true;
}
Also used : LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) SubjectReference(org.spongepowered.api.service.permission.SubjectReference) LanternSubjectCollection(org.lanternpowered.server.service.permission.base.LanternSubjectCollection)

Example 2 with LanternPermissionService

use of org.lanternpowered.server.service.permission.LanternPermissionService in project LanternServer by LanternPowered.

the class DefaultCommandsCollection method load.

public void load() {
    final Multimap<PluginContainer, CommandProvider> commandProviders = HashMultimap.create();
    // Minecraft Commands
    commandProviders.put(this.minecraft, new CommandBan());
    commandProviders.put(this.minecraft, new CommandBanIp());
    commandProviders.put(this.minecraft, new CommandBorder());
    commandProviders.put(this.minecraft, new CommandDeop());
    commandProviders.put(this.minecraft, new CommandDifficulty());
    commandProviders.put(this.minecraft, new CommandGameMode());
    commandProviders.put(this.minecraft, new CommandGameRule());
    commandProviders.put(this.minecraft, new CommandHelp());
    commandProviders.put(this.minecraft, new CommandKick());
    commandProviders.put(this.minecraft, new CommandListBans());
    commandProviders.put(this.minecraft, new CommandListPlayers());
    commandProviders.put(this.minecraft, new CommandMe());
    commandProviders.put(this.minecraft, new CommandOp());
    commandProviders.put(this.minecraft, new CommandPardon());
    commandProviders.put(this.minecraft, new CommandPardonIp());
    commandProviders.put(this.minecraft, new CommandParticle());
    commandProviders.put(this.implementation, new CommandParticleEffect());
    commandProviders.put(this.minecraft, new CommandPlaySound());
    commandProviders.put(this.minecraft, new CommandSay());
    commandProviders.put(this.minecraft, new CommandScoreboard());
    commandProviders.put(this.implementation, new CommandSetData());
    commandProviders.put(this.minecraft, new CommandSetIdleTimeout());
    commandProviders.put(this.minecraft, new CommandSetSpawn());
    commandProviders.put(this.minecraft, new CommandStop());
    commandProviders.put(this.minecraft, new CommandStopSound());
    commandProviders.put(this.minecraft, new CommandTeleport());
    commandProviders.put(this.minecraft, new CommandTell());
    commandProviders.put(this.minecraft, new CommandTime());
    commandProviders.put(this.minecraft, new CommandTitle());
    commandProviders.put(this.minecraft, new CommandToggleDownfall());
    commandProviders.put(this.minecraft, new CommandTp());
    commandProviders.put(this.implementation, new CommandVersion());
    commandProviders.put(this.minecraft, new CommandWeather());
    commandProviders.put(this.minecraft, new CommandWhitelist());
    // Testing Commands
    commandProviders.put(this.implementation, new CommandOpenTestContainer());
    for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
        final PluginContainer plugin = entry.getKey();
        this.commandManager.register(plugin, entry.getValue().buildSpecFor(plugin), entry.getValue().getAliases());
    }
    final PermissionService permissionService = this.permissionService.get();
    if (permissionService instanceof LanternPermissionService) {
        final LanternPermissionService lanternPermissionService = (LanternPermissionService) permissionService;
        // noinspection Convert2streamapi
        for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
            entry.getValue().getOpPermissionLevel().ifPresent(level -> lanternPermissionService.getGroupForOpLevel(level).getSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE));
        }
    } else {
        // noinspection Convert2streamapi
        for (Map.Entry<PluginContainer, CommandProvider> entry : commandProviders.entries()) {
            if (entry.getValue().getOpPermissionLevel().orElse(0) == 0) {
                permissionService.getDefaults().getTransientSubjectData().setPermission(SubjectData.GLOBAL_CONTEXT, entry.getValue().getPermissionFor(entry.getKey()), Tristate.TRUE);
            }
        }
    }
}
Also used : LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) PermissionService(org.spongepowered.api.service.permission.PermissionService) CommandOpenTestContainer(org.lanternpowered.server.command.test.CommandOpenTestContainer) PluginContainer(org.spongepowered.api.plugin.PluginContainer) LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) Map(java.util.Map)

Example 3 with LanternPermissionService

use of org.lanternpowered.server.service.permission.LanternPermissionService 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();
}
Also used : PermissionService(org.spongepowered.api.service.permission.PermissionService) LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) LanternCauseStack(org.lanternpowered.server.event.LanternCauseStack) CauseStack(org.lanternpowered.server.event.CauseStack) LanternMinecraftVersion(org.lanternpowered.server.game.version.LanternMinecraftVersion) EmptyRconService(org.lanternpowered.server.network.rcon.EmptyRconService) LanternPermissionService(org.lanternpowered.server.service.permission.LanternPermissionService) Cause(org.spongepowered.api.event.cause.Cause) DefaultCommandsCollection(org.lanternpowered.server.command.DefaultCommandsCollection) IOException(java.io.IOException) LanternContextCalculator(org.lanternpowered.server.service.permission.LanternContextCalculator)

Aggregations

LanternPermissionService (org.lanternpowered.server.service.permission.LanternPermissionService)3 PermissionService (org.spongepowered.api.service.permission.PermissionService)2 IOException (java.io.IOException)1 Map (java.util.Map)1 DefaultCommandsCollection (org.lanternpowered.server.command.DefaultCommandsCollection)1 CommandOpenTestContainer (org.lanternpowered.server.command.test.CommandOpenTestContainer)1 CauseStack (org.lanternpowered.server.event.CauseStack)1 LanternCauseStack (org.lanternpowered.server.event.LanternCauseStack)1 LanternMinecraftVersion (org.lanternpowered.server.game.version.LanternMinecraftVersion)1 EmptyRconService (org.lanternpowered.server.network.rcon.EmptyRconService)1 LanternContextCalculator (org.lanternpowered.server.service.permission.LanternContextCalculator)1 LanternSubjectCollection (org.lanternpowered.server.service.permission.base.LanternSubjectCollection)1 Cause (org.spongepowered.api.event.cause.Cause)1 PluginContainer (org.spongepowered.api.plugin.PluginContainer)1 SubjectReference (org.spongepowered.api.service.permission.SubjectReference)1