Search in sources :

Example 1 with WorldConfig

use of org.spongepowered.common.config.type.WorldConfig 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();
}
Also used : IMixinMinecraftServer(org.spongepowered.common.interfaces.IMixinMinecraftServer) ClickAction(org.spongepowered.api.text.action.ClickAction) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) DimensionType(org.spongepowered.api.world.DimensionType) URL(java.net.URL) CommandCallable(org.spongepowered.api.command.CommandCallable) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) GenericArguments(org.spongepowered.api.command.args.GenericArguments) GenericArguments.choices(org.spongepowered.api.command.args.GenericArguments.choices) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) GenericArguments.plugin(org.spongepowered.api.command.args.GenericArguments.plugin) WorldConfig(org.spongepowered.common.config.type.WorldConfig) SpongeTimingsFactory(co.aikar.timings.SpongeTimingsFactory) TextActions(org.spongepowered.api.text.action.TextActions) User(org.spongepowered.api.entity.living.player.User) GenericArguments.dimension(org.spongepowered.api.command.args.GenericArguments.dimension) CommandSource(org.spongepowered.api.command.CommandSource) TextStyles(org.spongepowered.api.text.format.TextStyles) Collection(java.util.Collection) GenericArguments.optional(org.spongepowered.api.command.args.GenericArguments.optional) Sponge(org.spongepowered.api.Sponge) Instant(java.time.Instant) CommandElement(org.spongepowered.api.command.args.CommandElement) Collectors(java.util.stream.Collectors) MixinEnvironment(org.spongepowered.asm.mixin.MixinEnvironment) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) EntityUtil(org.spongepowered.common.entity.EntityUtil) BlockState(org.spongepowered.api.block.BlockState) List(java.util.List) SpongeApiTranslationHelper(org.spongepowered.api.util.SpongeApiTranslationHelper) World(org.spongepowered.api.world.World) DimensionConfig(org.spongepowered.common.config.type.DimensionConfig) CommandManager(org.spongepowered.api.command.CommandManager) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) SpongeConfig(org.spongepowered.common.config.SpongeConfig) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) SpongeImpl(org.spongepowered.common.SpongeImpl) Timings(co.aikar.timings.Timings) GenericArguments.firstParsing(org.spongepowered.api.command.args.GenericArguments.firstParsing) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) LocalDateTime(java.time.LocalDateTime) CommandMapping(org.spongepowered.api.command.CommandMapping) ArgumentParseException(org.spongepowered.api.command.args.ArgumentParseException) CommandArgs(org.spongepowered.api.command.args.CommandArgs) Function(java.util.function.Function) TreeSet(java.util.TreeSet) IMPLEMENTATION(org.spongepowered.api.Platform.Component.IMPLEMENTATION) ArrayList(java.util.ArrayList) PaginationList(org.spongepowered.api.service.pagination.PaginationList) RayTraceResult(net.minecraft.util.math.RayTraceResult) GenericArguments.seq(org.spongepowered.api.command.args.GenericArguments.seq) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) StartsWithPredicate(org.spongepowered.api.util.StartsWithPredicate) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Chunk(net.minecraft.world.chunk.Chunk) WorldServer(net.minecraft.world.WorldServer) PluginContainer(org.spongepowered.api.plugin.PluginContainer) TextColors(org.spongepowered.api.text.format.TextColors) Nullable(javax.annotation.Nullable) GenericArguments.literal(org.spongepowered.api.command.args.GenericArguments.literal) IMixinWorldInfo(org.spongepowered.common.interfaces.world.IMixinWorldInfo) GenericArguments.world(org.spongepowered.api.command.args.GenericArguments.world) Entity(net.minecraft.entity.Entity) CommandResult(org.spongepowered.api.command.CommandResult) MalformedURLException(java.net.MalformedURLException) SpongeHooks(org.spongepowered.common.util.SpongeHooks) WorldManager(org.spongepowered.common.world.WorldManager) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) GenericArguments.string(org.spongepowered.api.command.args.GenericArguments.string) DecimalFormat(java.text.DecimalFormat) BlockUtil(org.spongepowered.common.block.BlockUtil) GeneralConfigBase(org.spongepowered.common.config.type.GeneralConfigBase) File(java.io.File) CommandException(org.spongepowered.api.command.CommandException) IBlockState(net.minecraft.block.state.IBlockState) ChildCommandElementExecutor(org.spongepowered.api.command.args.ChildCommandElementExecutor) DateTimeFormatter(java.time.format.DateTimeFormatter) GenericArguments.flags(org.spongepowered.api.command.args.GenericArguments.flags) GenericArguments.optionalWeak(org.spongepowered.api.command.args.GenericArguments.optionalWeak) GlobalConfig(org.spongepowered.common.config.type.GlobalConfig) Comparator(java.util.Comparator) DimensionType(org.spongepowered.api.world.DimensionType) IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) CommandContext(org.spongepowered.api.command.args.CommandContext) SpongeConfig(org.spongepowered.common.config.SpongeConfig) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) CommandSource(org.spongepowered.api.command.CommandSource) World(org.spongepowered.api.world.World) File(java.io.File) CommandResult(org.spongepowered.api.command.CommandResult)

Example 2 with WorldConfig

use of org.spongepowered.common.config.type.WorldConfig 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();
}
Also used : Path(java.nio.file.Path) DimensionConfig(org.spongepowered.common.config.type.DimensionConfig) SpongeConfig(org.spongepowered.common.config.SpongeConfig) WorldConfig(org.spongepowered.common.config.type.WorldConfig) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) World(net.minecraft.world.World)

Example 3 with WorldConfig

use of org.spongepowered.common.config.type.WorldConfig in project SpongeCommon by SpongePowered.

the class SpongeHooks method getActiveConfig.

public static SpongeConfig<? extends GeneralConfigBase> getActiveConfig(WorldServer world, boolean refresh) {
    final IMixinWorldServer mixinWorldServer = (IMixinWorldServer) world;
    SpongeConfig<? extends GeneralConfigBase> activeConfig = mixinWorldServer.getActiveConfig();
    if (activeConfig == null || refresh) {
        final SpongeConfig<WorldConfig> worldConfig = mixinWorldServer.getWorldConfig();
        final SpongeConfig<DimensionConfig> dimensionConfig = ((IMixinDimensionType) ((Dimension) world.provider).getType()).getDimensionConfig();
        if (worldConfig != null && worldConfig.getConfig().isConfigEnabled()) {
            activeConfig = worldConfig;
        } else if (dimensionConfig != null && dimensionConfig.getConfig().isConfigEnabled()) {
            activeConfig = dimensionConfig;
        } else {
            activeConfig = SpongeImpl.getGlobalConfig();
        }
        mixinWorldServer.setActiveConfig(activeConfig);
    }
    return activeConfig;
}
Also used : DimensionConfig(org.spongepowered.common.config.type.DimensionConfig) IMixinDimensionType(org.spongepowered.common.interfaces.world.IMixinDimensionType) WorldConfig(org.spongepowered.common.config.type.WorldConfig) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer)

Aggregations

DimensionConfig (org.spongepowered.common.config.type.DimensionConfig)2 WorldConfig (org.spongepowered.common.config.type.WorldConfig)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 SpongeTimingsFactory (co.aikar.timings.SpongeTimingsFactory)1 Timings (co.aikar.timings.Timings)1 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 DecimalFormat (java.text.DecimalFormat)1 Instant (java.time.Instant)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1