Skip to content

Commit

Permalink
Optional force use ProtocolLib
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Jun 20, 2019
1 parent ccd75c0 commit 6862e69
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/mengcraft/playersql/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Config {
public static final boolean KICK_LOAD_FAILED;
public static final boolean TRANSFER_ORIGIN;
public static final boolean OMIT_PLAYER_DEATH;
public static final boolean FORCE_PROTOCOLLIB;

public static final boolean DEBUG;
public static final int SYN_DELAY;
Expand All @@ -33,6 +34,7 @@ public class Config {
OMIT_PLAYER_DEATH = CONF.getBoolean("plugin.omit-player-death", false);
KICK_LOAD_FAILED = CONF.getBoolean("kick-load-failed", true);
TRANSFER_ORIGIN = CONF.getBoolean("transfer-origin", false);
FORCE_PROTOCOLLIB = CONF.getBoolean("plugin.use-protocollib-default", false);
}

}
38 changes: 21 additions & 17 deletions src/main/java/com/mengcraft/playersql/DataSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@ public class DataSerializer {
private static final IPacketDataSerializer.IFactory PACKET_DATA_SERIALIZER_FACTORY;

static {
switch (Bukkit.getServer().getClass().getPackage().getName()) {
case "org.bukkit.craftbukkit.v1_8_R3":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_8_3.PacketDataSerializer(buf);
break;
case "org.bukkit.craftbukkit.v1_12_R1":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_12.PacketDataSerializer(buf);
break;
case "org.bukkit.craftbukkit.v1_13_R1":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_13.PacketDataSerializer(buf);
break;
case "org.bukkit.craftbukkit.v1_13_R2":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_13_2.PacketDataSerializer(buf);
break;
default:
PACKET_DATA_SERIALIZER_FACTORY = null;
break;
if (Config.FORCE_PROTOCOLLIB) {
PACKET_DATA_SERIALIZER_FACTORY = null;
} else {
switch (Bukkit.getServer().getClass().getPackage().getName()) {
case "org.bukkit.craftbukkit.v1_8_R3":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_8_3.PacketDataSerializer(buf);
break;
case "org.bukkit.craftbukkit.v1_12_R1":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_12.PacketDataSerializer(buf);
break;
case "org.bukkit.craftbukkit.v1_13_R1":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_13.PacketDataSerializer(buf);
break;
case "org.bukkit.craftbukkit.v1_13_R2":
PACKET_DATA_SERIALIZER_FACTORY = buf -> new com.mengcraft.playersql.internal.v1_13_2.PacketDataSerializer(buf);
break;
default:
PACKET_DATA_SERIALIZER_FACTORY = null;
break;
}
}
System.out.println(String.format("PACKET_DATA_SERIALIZER_FACTORY = %s", PACKET_DATA_SERIALIZER_FACTORY));
}
Expand All @@ -57,7 +61,7 @@ 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?
} catch (RuntimeException e) {// upgrade from below 2.9?
Preconditions.checkState(Bukkit.getPluginManager().isPluginEnabled("ProtocolLib"), "protocollib not found");
output = StreamSerializer.getDefault().deserializeItemStack(input);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugin:
omit-player-death: false
# Use this option in your own risk. It's MAY BREAK SERVER.
use-protocol-locker: false
use-protocollib-default: false

sync:
health: true
Expand Down

0 comments on commit 6862e69

Please sign in to comment.