use of org.spongepowered.common.config.type.GlobalConfig 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();
}
Aggregations