Search in sources :

Example 1 with IColonyManagerCapability

use of com.minecolonies.coremod.colony.IColonyManagerCapability in project minecolonies by ldtteam.

the class CommandPruneWorld method tryPrune.

/**
 * Tries to prune the world, protects colony buildings in this world by the given radius(min 100)
 *
 * @param context command context
 * @param arg     progress arg
 * @return command return
 */
private int tryPrune(final CommandContext<CommandSource> context, final int arg) {
    if (arg < 3) {
        context.getSource().sendSuccess(LanguageHandler.buildChatComponent("com.minecolonies.command.prune.next", arg + 1), true);
        return 0;
    }
    final int radius = IntegerArgumentType.getInteger(context, RADIUS_ARG);
    int deleteCount = 0;
    final World world = context.getSource().getLevel();
    // Local save folder for this word
    final File saveDir = new File(DimensionType.getStorageFolder(world.dimension(), world.getServer().getWorldPath(FolderName.ROOT).toFile()), REGION_FOLDER);
    // Colony list for this world
    List<IColony> colonies = new ArrayList<>();
    final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).orElseGet(null);
    if (cap != null) {
        colonies = cap.getColonies();
    } else {
        return 0;
    }
    // Loop the region data files
    for (final File currentRegion : saveDir.listFiles()) {
        if (currentRegion != null && currentRegion.getName().contains(".mca")) {
            final String[] split = currentRegion.getName().split("\\.");
            if (split.length != 4) {
                continue;
            }
            // Current region file X/Z positions
            final int regionX = Integer.parseInt(split[1]);
            final int regionZ = Integer.parseInt(split[2]);
            if (isFarEnoughFromColonies(regionX, regionZ, radius, colonies)) {
                if (!currentRegion.delete()) {
                    context.getSource().sendSuccess(new StringTextComponent("Could not delete file:" + currentRegion.getPath()), true);
                } else {
                    deleteCount++;
                    context.getSource().sendSuccess(new StringTextComponent("Deleted file:" + currentRegion.getPath()), true);
                }
            }
        }
    }
    context.getSource().sendSuccess(new StringTextComponent("Successfully deleted " + deleteCount + " regions!"), true);
    return 0;
}
Also used : IColonyManagerCapability(com.minecolonies.coremod.colony.IColonyManagerCapability) ArrayList(java.util.ArrayList) IColony(com.minecolonies.api.colony.IColony) StringTextComponent(net.minecraft.util.text.StringTextComponent) World(net.minecraft.world.World) File(java.io.File)

Example 2 with IColonyManagerCapability

use of com.minecolonies.coremod.colony.IColonyManagerCapability in project minecolonies by Minecolonies.

the class ChunkDataHelper method loadChunk.

/**
 * Load the colony info for a certain chunk.
 *
 * @param chunk the chunk.
 * @param world the worldg to.
 */
public static void loadChunk(final Chunk chunk, final World world) {
    // If colony is farther away from a capability then this times the default colony distance it will delete the capability.
    final int distanceToDelete = MineColonies.getConfig().getServer().maxColonySize.get() * BLOCKS_PER_CHUNK * 2 * 5;
    final IChunkmanagerCapability chunkManager = world.getCapability(CHUNK_STORAGE_UPDATE_CAP, null).resolve().orElse(null);
    if (chunkManager == null) {
        Log.getLogger().error(UNABLE_TO_FIND_WORLD_CAP_TEXT, new Exception());
        return;
    }
    if (!chunkManager.getAllChunkStorages().isEmpty()) {
        final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).resolve().orElse(null);
        if (cap == null) {
            return;
        }
        final ChunkLoadStorage existingStorage = chunkManager.getChunkStorage(chunk.getPos().x, chunk.getPos().z);
        if (existingStorage != null) {
            addStorageToChunk(chunk, existingStorage);
        }
    }
    final int closeColony = chunk.getCapability(CLOSE_COLONY_CAP, null).map(IColonyTagCapability::getOwningColony).orElse(0);
    if (closeColony != 0) {
        final IColony colony = IColonyManager.getInstance().getColonyByDimension(closeColony, world.dimension());
        if (colony != null) {
            colony.addLoadedChunk(ChunkPos.asLong(chunk.getPos().x, chunk.getPos().z), chunk);
        }
    }
}
Also used : IColonyManagerCapability(com.minecolonies.coremod.colony.IColonyManagerCapability) IChunkmanagerCapability(com.minecolonies.api.colony.IChunkmanagerCapability) IColony(com.minecolonies.api.colony.IColony) ChunkLoadStorage(com.minecolonies.api.util.ChunkLoadStorage)

Example 3 with IColonyManagerCapability

use of com.minecolonies.coremod.colony.IColonyManagerCapability in project minecolonies by Minecolonies.

the class CommandPruneWorld method tryPrune.

/**
 * Tries to prune the world, protects colony buildings in this world by the given radius(min 100)
 *
 * @param context command context
 * @param arg     progress arg
 * @return command return
 */
private int tryPrune(final CommandContext<CommandSource> context, final int arg) {
    if (arg < 3) {
        context.getSource().sendSuccess(new TranslationTextComponent(COMMAND_PRUNE_WORLD_WARNING, arg + 1), true);
        return 0;
    }
    final int radius = IntegerArgumentType.getInteger(context, RADIUS_ARG);
    int deleteCount = 0;
    final World world = context.getSource().getLevel();
    // Local save folder for this word
    final File saveDir = new File(DimensionType.getStorageFolder(world.dimension(), world.getServer().getWorldPath(FolderName.ROOT).toFile()), REGION_FOLDER);
    // Colony list for this world
    List<IColony> colonies = new ArrayList<>();
    final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).orElseGet(null);
    if (cap != null) {
        colonies = cap.getColonies();
    } else {
        return 0;
    }
    // Loop the region data files
    for (final File currentRegion : saveDir.listFiles()) {
        if (currentRegion != null && currentRegion.getName().contains(".mca")) {
            final String[] split = currentRegion.getName().split("\\.");
            if (split.length != 4) {
                continue;
            }
            // Current region file X/Z positions
            final int regionX = Integer.parseInt(split[1]);
            final int regionZ = Integer.parseInt(split[2]);
            if (isFarEnoughFromColonies(regionX, regionZ, radius, colonies)) {
                if (!currentRegion.delete()) {
                    context.getSource().sendSuccess(new StringTextComponent("Could not delete file:" + currentRegion.getPath()), true);
                } else {
                    deleteCount++;
                    context.getSource().sendSuccess(new StringTextComponent("Deleted file:" + currentRegion.getPath()), true);
                }
            }
        }
    }
    context.getSource().sendSuccess(new StringTextComponent("Successfully deleted " + deleteCount + " regions!"), true);
    return 0;
}
Also used : IColonyManagerCapability(com.minecolonies.coremod.colony.IColonyManagerCapability) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) IColony(com.minecolonies.api.colony.IColony) StringTextComponent(net.minecraft.util.text.StringTextComponent) World(net.minecraft.world.World) File(java.io.File)

Example 4 with IColonyManagerCapability

use of com.minecolonies.coremod.colony.IColonyManagerCapability in project minecolonies by ldtteam.

the class ChunkDataHelper method loadChunk.

/**
 * Load the colony info for a certain chunk.
 *
 * @param chunk the chunk.
 * @param world the worldg to.
 */
public static void loadChunk(final Chunk chunk, final World world) {
    // If colony is farther away from a capability then this times the default colony distance it will delete the capability.
    final int distanceToDelete = MineColonies.getConfig().getServer().maxColonySize.get() * BLOCKS_PER_CHUNK * 2 * 5;
    final IChunkmanagerCapability chunkManager = world.getCapability(CHUNK_STORAGE_UPDATE_CAP, null).resolve().orElse(null);
    if (chunkManager == null) {
        Log.getLogger().error(UNABLE_TO_FIND_WORLD_CAP_TEXT, new Exception());
        return;
    }
    if (!chunkManager.getAllChunkStorages().isEmpty()) {
        final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).resolve().orElse(null);
        if (cap == null) {
            return;
        }
        final ChunkLoadStorage existingStorage = chunkManager.getChunkStorage(chunk.getPos().x, chunk.getPos().z);
        if (existingStorage != null) {
            addStorageToChunk(chunk, existingStorage);
        }
    }
    final int closeColony = chunk.getCapability(CLOSE_COLONY_CAP, null).map(IColonyTagCapability::getOwningColony).orElse(0);
    if (closeColony != 0) {
        final IColony colony = IColonyManager.getInstance().getColonyByDimension(closeColony, world.dimension());
        if (colony != null) {
            colony.addLoadedChunk(ChunkPos.asLong(chunk.getPos().x, chunk.getPos().z), chunk);
        }
    }
}
Also used : IColonyManagerCapability(com.minecolonies.coremod.colony.IColonyManagerCapability) IChunkmanagerCapability(com.minecolonies.api.colony.IChunkmanagerCapability) IColony(com.minecolonies.api.colony.IColony) ChunkLoadStorage(com.minecolonies.api.util.ChunkLoadStorage)

Aggregations

IColony (com.minecolonies.api.colony.IColony)4 IColonyManagerCapability (com.minecolonies.coremod.colony.IColonyManagerCapability)4 IChunkmanagerCapability (com.minecolonies.api.colony.IChunkmanagerCapability)2 ChunkLoadStorage (com.minecolonies.api.util.ChunkLoadStorage)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 World (net.minecraft.world.World)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)1