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