Skip to content

Commit

Permalink
Added a check for invalid rows contents for island chests from database
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Feb 25, 2022
1 parent 5bc8b38 commit e1b4b1d
Showing 1 changed file with 23 additions and 2 deletions.
Expand Up @@ -638,16 +638,37 @@ public static void deserializeIslandChest(DatabaseBridge databaseBridge, Databas
return;
}

int contentsLength = contents.get().length;
ItemStack[] chestContents;

if(contentsLength % 9 != 0) {
int amountOfRows = Math.min(1, Math.max(6, (contentsLength / 9) + 1));
chestContents = new ItemStack[amountOfRows * 9];
int amountOfContentsToCopy = Math.min(contentsLength, chestContents.length);
System.arraycopy(contents.get(), 0, chestContents, 0, amountOfContentsToCopy);
}
else if(contentsLength > 54) {
chestContents = new ItemStack[54];
System.arraycopy(contents.get(), 0, chestContents, 0, 54);
}
else if(contentsLength < 9) {
chestContents = new ItemStack[9];
System.arraycopy(contents.get(), 0, chestContents, 0, contentsLength);
}
else {
chestContents = contents.get();
}

CachedIslandInfo cachedIslandInfo = databaseCache.computeIfAbsentInfo(uuid.get(), CachedIslandInfo::new);

if (index.get() >= cachedIslandInfo.islandChests.size()) {
while (index.get() > cachedIslandInfo.islandChests.size()) {
cachedIslandInfo.islandChests.add(new ItemStack[plugin.getSettings().getIslandChests().getDefaultSize() * 9]);
}

cachedIslandInfo.islandChests.add(contents.get());
cachedIslandInfo.islandChests.add(chestContents);
} else {
cachedIslandInfo.islandChests.set(index.get(), contents.get());
cachedIslandInfo.islandChests.set(index.get(), chestContents);
}
});
}
Expand Down

0 comments on commit e1b4b1d

Please sign in to comment.