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);
}
}
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);
}
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()));
}
}
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();
}
Aggregations