Skip to content

Commit

Permalink
Merge branch 'mcMMO-Dev:master' into update
Browse files Browse the repository at this point in the history
  • Loading branch information
SrBedrock authored Nov 8, 2024
2 parents e5a8b18 + c54a758 commit 865115b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 2.2.026
Fixed NPE on ChunkUnloadEvent

Version 2.2.025
Fixed NullPointerException spam when processing XP for child skills

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>2.2.025</version>
<version>2.2.026</version>
<name>mcMMO</name>
<url>https://github.com/mcMMO-Dev/mcMMO</url>
<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ public synchronized void closeAll() {
}

private synchronized @Nullable ChunkStore readChunkStore(@NotNull World world, int cx, int cz) throws IOException {
McMMOSimpleRegionFile rf = getReadableSimpleRegionFile(world, cx, cz);
if (rf == null)
return null; // If there is no region file, there can't be a chunk
final McMMOSimpleRegionFile rf = getWriteableSimpleRegionFile(world, cx, cz);
try (DataInputStream in = rf.getInputStream(cx, cz)) { // Get input stream for chunk
if (in == null)
return null; // No chunk
Expand Down Expand Up @@ -74,17 +72,6 @@ private synchronized void writeChunkStore(@NotNull World world, @NotNull ChunkSt
});
}

private synchronized @Nullable McMMOSimpleRegionFile getReadableSimpleRegionFile(@NotNull World world, int cx, int cz) {
CoordinateKey regionKey = toRegionKey(world.getUID(), cx, cz);

return regionMap.computeIfAbsent(regionKey, k -> {
File regionFile = getRegionFile(world, regionKey);
if (!regionFile.exists())
return null; // Don't create the file on read-only operations
return new McMMOSimpleRegionFile(regionFile, regionKey.x, regionKey.z);
});
}

private @NotNull File getRegionFile(@NotNull World world, @NotNull CoordinateKey regionKey) {
if (world.getUID() != regionKey.worldID)
throw new IllegalArgumentException();
Expand Down Expand Up @@ -112,7 +99,7 @@ private void unloadChunk(int cx, int cz, @NotNull World world) {
CoordinateKey regionKey = toRegionKey(world.getUID(), cx, cz);
HashSet<CoordinateKey> chunkKeys = chunkUsageMap.get(regionKey);
chunkKeys.remove(chunkKey); // remove from region file in-use set
// If it was last chunk in region, close the region file and remove it from memory
// If it was last chunk in the region, close the region file and remove it from memory
if (chunkKeys.isEmpty()) {
chunkUsageMap.remove(regionKey);
regionMap.remove(regionKey).close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,27 @@ void testRegressionChunkMirrorBug() {
assertTrue(chunkManager.isIneligible(mockBlockA));
}

@Test
void testUnload() {
final ChunkManager chunkManager = new HashChunkManager();
Block mockBlockA = Mockito.mock(Block.class);
when(mockBlockA.getX()).thenReturn(15);
when(mockBlockA.getZ()).thenReturn(15);
when(mockBlockA.getY()).thenReturn(0);
when(mockBlockA.getWorld()).thenReturn(mockWorld);
Block mockBlockB = Mockito.mock(Block.class);
when(mockBlockB.getX()).thenReturn(-15);
when(mockBlockB.getZ()).thenReturn(-15);
when(mockBlockB.getY()).thenReturn(0);
when(mockBlockB.getWorld()).thenReturn(mockWorld);

chunkManager.setIneligible(mockBlockA);
chunkManager.setEligible(mockBlockB);
assertTrue(chunkManager.isIneligible(mockBlockA));

chunkManager.chunkUnloaded(0, 0, mockWorld);
}

@NotNull
private Block initMockBlock(int x, int y, int z) {
final Block mockBlock = Mockito.mock(Block.class);
Expand Down

0 comments on commit 865115b

Please sign in to comment.