use of org.spongepowered.common.config.SpongeConfig in project SpongeCommon by SpongePowered.
the class SpongeCommandFactory method createSpongeChunksCommand.
// Flag children
private static CommandSpec createSpongeChunksCommand() {
return CommandSpec.builder().description(Text.of("Print chunk information, optionally dump")).arguments(optional(seq(literal(Text.of("dump"), "dump"), optional(literal(Text.of("dump-all"), "all"))))).permission("sponge.command.chunks").executor(new ConfigUsingExecutor(true) {
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
CommandResult res = super.execute(src, args);
if (args.hasAny("dump")) {
File file = new File(new File(new File("."), "chunk-dumps"), "chunk-info-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(Instant.now()) + "-server.txt");
src.sendMessage(Text.of("Writing chunk info to: ", file));
ChunkSaveHelper.writeChunks(file, args.hasAny("dump-all"));
src.sendMessage(Text.of("Chunk info complete"));
}
return res;
}
@Override
protected Text processGlobal(SpongeConfig<GlobalConfig> config, CommandSource source, CommandContext args) throws CommandException {
for (World world : SpongeImpl.getGame().getServer().getWorlds()) {
source.sendMessage(Text.of("World ", Text.of(TextStyles.BOLD, world.getName()), getChunksInfo(((WorldServer) world))));
}
return Text.of("Printed chunk info for all worlds ");
}
@Override
protected Text processDimension(SpongeConfig<DimensionConfig> config, DimensionType dim, CommandSource source, CommandContext args) throws CommandException {
SpongeImpl.getGame().getServer().getWorlds().stream().filter(world -> world.getDimension().getType().equals(dim)).forEach(world -> source.sendMessage(Text.of("World ", Text.of(TextStyles.BOLD, world.getName()), getChunksInfo(((WorldServer) world)))));
return Text.of("Printed chunk info for all worlds in dimension ", dim.getName());
}
@Override
protected Text processWorld(SpongeConfig<WorldConfig> config, World world, CommandSource source, CommandContext args) throws CommandException {
return getChunksInfo((WorldServer) world);
}
protected Text key(Object text) {
return Text.of(TextColors.GOLD, text);
}
protected Text value(Object text) {
return Text.of(TextColors.GRAY, text);
}
protected Text getChunksInfo(WorldServer worldserver) {
return Text.of(NEWLINE_TEXT, key("DimensionId: "), value(WorldManager.getDimensionId(worldserver)), NEWLINE_TEXT, key("Loaded chunks: "), value(worldserver.getChunkProvider().getLoadedChunkCount()), NEWLINE_TEXT, key("Active chunks: "), value(worldserver.getChunkProvider().getLoadedChunks().size()), NEWLINE_TEXT, key("Entities: "), value(worldserver.loadedEntityList.size()), NEWLINE_TEXT, key("Tile Entities: "), value(worldserver.loadedTileEntityList.size()), NEWLINE_TEXT, key("Removed Entities:"), value(worldserver.unloadedEntityList.size()), NEWLINE_TEXT, key("Removed Tile Entities: "), value(worldserver.tileEntitiesToBeRemoved), NEWLINE_TEXT);
}
}).build();
}
use of org.spongepowered.common.config.SpongeConfig in project SpongeCommon by SpongePowered.
the class SpongeHooks method getActiveConfig.
public static SpongeConfig<? extends GeneralConfigBase> getActiveConfig(Path dimensionPath, String worldFolder) {
if (dimensionPath == null) {
// If no dimension type, go global
return SpongeImpl.getGlobalConfig();
}
if (worldFolder != null) {
final Optional<org.spongepowered.api.world.World> optWorld = SpongeImpl.getGame().getServer().getWorld(worldFolder);
// If this is a loaded world then we only return configs on the loaded objects. Don't go to disk.
if (optWorld.isPresent()) {
return ((IMixinWorldServer) optWorld.get()).getActiveConfig();
}
}
// No in-memory config objects, lookup from disk.
final Path dimConfPath = dimensionPath.resolve("dimension.conf");
if (worldFolder != null) {
final Path worldConfPath = dimensionPath.resolve(worldFolder).resolve("world.conf");
final SpongeConfig<WorldConfig> worldConfig = new SpongeConfig<>(SpongeConfig.Type.WORLD, worldConfPath, SpongeImpl.ECOSYSTEM_ID);
if (worldConfig.getConfig().isConfigEnabled()) {
return worldConfig;
}
}
final SpongeConfig<DimensionConfig> dimConfig = new SpongeConfig<>(SpongeConfig.Type.DIMENSION, dimConfPath, SpongeImpl.ECOSYSTEM_ID);
if (dimConfig.getConfig().isConfigEnabled()) {
return dimConfig;
}
// Neither in-memory or on-disk enabled configs. Go global.
return SpongeImpl.getGlobalConfig();
}
Aggregations