Skip to content

Commit

Permalink
fix: Revert "Modify KryoUtils to handle IOExceptions"
Browse files Browse the repository at this point in the history
This reverts commit 78e1d8e.
  • Loading branch information
GeorgeV220 committed Nov 11, 2023
1 parent fb36753 commit 0c146a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,7 @@ public ItemBuilder skull(String owner) {
public ItemBuilder colors(@NotNull List<String> colors, boolean kryo) {
if (colors.size() >= 2) {
if (kryo) {
try {
this.nbtItem.setByteArray("colors", KryoUtils.serialize(colors));
} catch (IOException e) {
throw new RuntimeException(e);
}
this.nbtItem.setByteArray("colors", KryoUtils.serialize(colors));
} else {
try {
this.nbtItem.setString("colors", Utils.serializeObjectToString(colors));
Expand All @@ -463,11 +459,7 @@ public ItemBuilder commands(boolean kryo, ItemCommand... itemCommands) {

public ItemBuilder commands(List<ItemCommand> itemCommands, boolean kryo) {
if (kryo) {
try {
this.nbtItem.setByteArray("commands", KryoUtils.serialize(itemCommands));
} catch (IOException e) {
throw new RuntimeException(e);
}
this.nbtItem.setByteArray("commands", KryoUtils.serialize(itemCommands));
} else {
try {
this.nbtItem.setString("commands", Utils.serializeObjectToString(itemCommands));
Expand All @@ -494,11 +486,7 @@ public ItemBuilder frames(List<ItemStack> frames) {

public ItemBuilder customNBT(String key, Object value, boolean kryo) {
if (kryo) {
try {
this.nbtItem.setByteArray(key, KryoUtils.serialize(value));
} catch (IOException e) {
throw new RuntimeException(e);
}
this.nbtItem.setByteArray(key, KryoUtils.serialize(value));
} else {
try {
this.nbtItem.setString(key, Utils.serializeObjectToString(value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,7 @@ public boolean open(Player player, int index, boolean animated) {

List<String> color;
if (registrar.kryo()) {
try {
color = KryoUtils.deserialize(nbtItem.getByteArray("colors"));
} catch (IOException e) {
registrar.getPlugin().getLogger().log(Level.SEVERE, "Error: ", e);
color = Lists.newArrayList();
}
color = KryoUtils.deserialize(nbtItem.getByteArray("colors"));
} else {
try {
color = (List<String>) Utils.deserializeObjectFromString(nbtItem.getString("colors"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
Expand All @@ -20,21 +19,22 @@
public class KryoUtils {
private static final Kryo kryo = createKryoInstance();

public static byte[] serialize(Object object) throws IOException {
public static byte[] serialize(Object object) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
Output output = new Output(byteArrayOutputStream);
output.close();
kryo.writeClassAndObject(output, object);
output.close();

return byteArrayOutputStream.toByteArray();
}

public static <T> T deserialize(byte[] bytes) throws IOException {
public static <T> T deserialize(byte[] bytes) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Input input = new Input(byteArrayInputStream);
T object = (T) kryo.readClassAndObject(input);
input.close();

return (T) kryo.readClassAndObject(input);
return object;
}

public static void registerClass(Class<?> clazz) {
Expand Down

0 comments on commit 0c146a7

Please sign in to comment.