Skip to content

Commit

Permalink
chore(db): add precheck for item serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Oct 24, 2024
1 parent ab17dc5 commit 78328f1
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.xzavier0722.mc.plugin.slimefun4.storage.util;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.StorageType;
import io.github.thebusybiscuit.slimefun4.core.debug.Debug;
import io.github.thebusybiscuit.slimefun4.core.debug.TestCase;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
Expand All @@ -21,7 +22,14 @@ public static String itemStack2String(ItemStack itemStack) {
var stream = new ByteArrayOutputStream();
try (var bs = new BukkitObjectOutputStream(stream)) {
bs.writeObject(itemStack);
return Base64Coder.encodeLines(stream.toByteArray());
var itemStr = Base64Coder.encodeLines(stream.toByteArray());

if (Slimefun.getDatabaseManager().getBlockDataStorageType() != StorageType.SQLITE
&& itemStr.length() > 65535) {
throw new IllegalArgumentException("ItemStack too large");
}

return itemStr;
} catch (IOException e) {
e.printStackTrace();
return "";
Expand Down

0 comments on commit 78328f1

Please sign in to comment.