Skip to content

Commit

Permalink
New World constructor with ability to set max region quantity. New te…
Browse files Browse the repository at this point in the history
…st to check autosave works
  • Loading branch information
Pavel Fedin committed Dec 4, 2016
1 parent d0c53ff commit c79994f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/mregioneer/mcaliases/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ public World(File world_dir) throws IOException {
}
}
}

public World(File world_dir, int region_limit) throws IOException {
this(world_dir);

this.regions = new ConcurrentLinkedHashMap.Builder<Point2d, Region>()
.maximumWeightedCapacity(region_limit)
.listener(listener)
.build();
}

/**
* Save all cashed regions to their files
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/TestRegionAutoRemove.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import mregioneer.mcaliases.World;
import mregioneer.utils.Point3d;
import org.ini4j.Ini;
import org.junit.Test;

import java.io.File;
import java.util.Random;

import static org.junit.Assert.assertTrue;

public class TestRegionAutoRemove {
@Test
public void testAdd() {
World world;
try {
//initializing path to region folder
String presets_url = TestReadWrite.class.getClassLoader().getResource("local_presets.ini").getPath();
Ini ini = new Ini(new File(presets_url));
String path_to_mca_folder = ini.get("paths", "world_path", String.class);

world = new World(new File(path_to_mca_folder), 1);

Random rand = new Random(1);
byte id = (byte) rand.nextInt(24);

Point3d point1 = new Point3d(1, 1, 64);
Point3d point2 = new Point3d(-2,-2,64);

world.changeBlockID(point1, id);
world.changeBlockID(point2, id);

world.save();

assertTrue(world.getBlockId(point1) == world.getBlockId(point2));

} catch (Exception e) {
e.printStackTrace();
}
}
}

0 comments on commit c79994f

Please sign in to comment.