Skip to content

Commit

Permalink
Use ProtocolLib if built-in serializer fail
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Feb 28, 2019
1 parent fef2507 commit e2ea5b8
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/mengcraft/playersql/DataSerializer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mengcraft.playersql;

import com.comphenix.protocol.utility.StreamSerializer;
import com.google.common.base.Preconditions;
import com.mengcraft.playersql.internal.IPacketDataSerializer;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.buffer.Unpooled;
Expand Down Expand Up @@ -52,6 +53,9 @@ public static ItemStack deserialize(String input) {
ItemStack output;
try (IPacketDataSerializer serializer = PACKET_DATA_SERIALIZER_FACTORY.create(Unpooled.wrappedBuffer(Base64.getDecoder().decode(input)))) {
output = serializer.readItemStack();
} catch (io.netty.handler.codec.EncoderException e) {// upgrade from below 2.9?
Preconditions.checkState(Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"), "protocollib not found");
output = StreamSerializer.getDefault().deserializeItemStack(input);
}
return output;
}
Expand Down

0 comments on commit e2ea5b8

Please sign in to comment.