Skip to content

Commit

Permalink
Fix issue with ByteBuffer when compiling on Java 9+ (#9)
Browse files Browse the repository at this point in the history
Java 9+ has ABI breakage on ByteBuffer's clear method, which then causes an error for anyone attempting to run the plugin on Java 8. This change addresses that by changing the way the buffer is read in, avoiding that method call entirely.
  • Loading branch information
pop4959 committed Jul 1, 2021
1 parent 3fdf13a commit 839f3da
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/main/java/com/wimbli/WorldBorder/WorldFileData.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,11 @@ private List<Boolean> getRegionData(CoordXZ region)
if ( ! coord.equals(region))
continue;

try
try (final RandomAccessFile regionData = new RandomAccessFile(this.regionFile(i), "r"))
{
RandomAccessFile regionData = new RandomAccessFile(this.regionFile(i), "r");

// Use of ByteBuffer+IntBuffer for reading file headers to improve performance, as suggested by aikar, reference:
// https://github.com/PaperMC/Paper/blob/b62dfa0bf95ac27ba0fbb3fae18c064e4bb61d50/Spigot-Server-Patches/0086-Reduce-IO-ops-opening-a-new-region-file.patch
ByteBuffer header = ByteBuffer.allocate(8192);
while (header.hasRemaining())
{
if (regionData.getChannel().read(header) == -1)
throw new EOFException();
}
header.clear();
IntBuffer headerAsInts = header.asIntBuffer();
final byte[] header = new byte[8192];
regionData.readFully(header);
IntBuffer headerAsInts = ByteBuffer.wrap(header).asIntBuffer();

// first 4096 bytes of region file consists of 4-byte int pointers to chunk data in the file (32*32 chunks = 1024; 1024 chunks * 4 bytes each = 4096)
for (int j = 0; j < 1024; j++)
Expand All @@ -221,7 +212,6 @@ private List<Boolean> getRegionData(CoordXZ region)
if ((headerAsInts.get() == 0) && data.get(j))
data.set(j, false);
}
regionData.close();
}
catch (FileNotFoundException ex)
{
Expand Down

0 comments on commit 839f3da

Please sign in to comment.