Search in sources :

Example 51 with CauseStack

use of org.lanternpowered.server.event.CauseStack in project LanternServer by LanternPowered.

the class LanternChunkManager method shutdown.

/**
 * Shuts the chunk manager down, all the chunks will
 * be saved in the process.
 */
public void shutdown() {
    try {
        LanternLoadingTicketIO.save(this.worldFolder, this.tickets);
    } catch (IOException e) {
        this.game.getLogger().warn("An error occurred while saving the chunk loading tickets", e);
    }
    final CauseStack causeStack = CauseStack.current();
    final Cause cause = causeStack.getCurrentCause();
    for (Entry<Vector2i, LanternChunk> entry : this.loadedChunks.entrySet()) {
        final LanternChunk chunk = entry.getValue();
        // Post the chunk unload event
        this.game.getEventManager().post(SpongeEventFactory.createUnloadChunkEvent(cause, chunk));
        // Save the chunk
        save(chunk);
    }
    // Cleanup
    this.loadedChunks.clear();
    this.reusableChunks.clear();
    this.chunkTaskExecutor.shutdown();
    try {
        this.chunkIOService.unload();
    } catch (IOException e) {
        this.game.getLogger().warn("An error occurred while unloading the chunk io service", e);
    }
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) Cause(org.spongepowered.api.event.cause.Cause) IOException(java.io.IOException) Vector2i(com.flowpowered.math.vector.Vector2i)

Example 52 with CauseStack

use of org.lanternpowered.server.event.CauseStack in project LanternServer by LanternPowered.

the class HandlerPlayInRegisterChannels method handle.

@Override
public void handle(NetworkContext context, MessagePlayInOutRegisterChannels message) {
    final Set<String> channels = message.getChannels();
    final Set<String> registeredChannels = context.getSession().getRegisteredChannels();
    final CauseStack causeStack = CauseStack.current();
    causeStack.pushCause(context.getSession());
    causeStack.pushCause(context.getSession().getPlayer());
    final Cause cause = causeStack.getCurrentCause();
    for (String channel : channels) {
        if (registeredChannels.add(channel)) {
            Sponge.getEventManager().post(SpongeEventFactory.createChannelRegistrationEventRegister(cause, channel));
        }
    }
    causeStack.popCauses(2);
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) Cause(org.spongepowered.api.event.cause.Cause)

Example 53 with CauseStack

use of org.lanternpowered.server.event.CauseStack in project LanternServer by LanternPowered.

the class HandlerPlayInResourcePackStatus method handle.

@Override
public void handle(NetworkContext context, MessagePlayInResourcePackStatus message) {
    final Optional<ResourcePack> resourcePack = context.getSession().getPlayer().getResourcePackSendQueue().poll(message.getStatus());
    final LanternPlayer player = context.getSession().getPlayer();
    if (!resourcePack.isPresent()) {
        Lantern.getLogger().warn("{} received a unexpected resource pack status message ({}), no resource pack was pending", player.getName(), message.getStatus());
        return;
    }
    final CauseStack causeStack = CauseStack.current();
    try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
        frame.addContext(EventContextKeys.PLAYER, player);
        Sponge.getEventManager().post(SpongeEventFactory.createResourcePackStatusEvent(frame.getCurrentCause(), resourcePack.get(), player, message.getStatus()));
    }
}
Also used : CauseStack(org.lanternpowered.server.event.CauseStack) ResourcePack(org.spongepowered.api.resourcepack.ResourcePack) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer)

Example 54 with CauseStack

use of org.lanternpowered.server.event.CauseStack 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

CauseStack (org.lanternpowered.server.event.CauseStack)54 ItemStack (org.spongepowered.api.item.inventory.ItemStack)18 Entity (org.spongepowered.api.entity.Entity)16 ArrayList (java.util.ArrayList)15 Nullable (javax.annotation.Nullable)15 World (org.spongepowered.api.world.World)15 Optional (java.util.Optional)14 Lantern (org.lanternpowered.server.game.Lantern)13 AbstractSlot (org.lanternpowered.server.inventory.AbstractSlot)13 LanternWorld (org.lanternpowered.server.world.LanternWorld)13 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)13 Vector3i (com.flowpowered.math.vector.Vector3i)12 List (java.util.List)12 LanternPlayer (org.lanternpowered.server.entity.living.player.LanternPlayer)12 Keys (org.spongepowered.api.data.key.Keys)12 EventContextKeys (org.spongepowered.api.event.cause.EventContextKeys)12 Sponge (org.spongepowered.api.Sponge)11 Transform (org.spongepowered.api.entity.Transform)11 Player (org.spongepowered.api.entity.living.player.Player)11 SpongeEventFactory (org.spongepowered.api.event.SpongeEventFactory)11