Skip to content

Commit

Permalink
Update ProtocolLib for 1.19 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Jun 12, 2022
1 parent 9ec5135 commit 516066a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions bungeeguard-spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.destroystokyo.paper</groupId>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>${paper.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
<version>5.0.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.injector.server.TemporaryPlayerFactory;
import com.comphenix.protocol.injector.temporary.MinimalInjector;
import com.comphenix.protocol.injector.temporary.TemporaryPlayerFactory;
import com.comphenix.protocol.wrappers.WrappedChatComponent;

import me.lucko.bungeeguard.backend.BungeeGuardBackend;
Expand Down Expand Up @@ -120,14 +121,18 @@ public void onPacketReceiving(PacketEvent event) {
}

private static void closeConnection(Player player, String kickMessage) throws Exception {
WrappedChatComponent component = WrappedChatComponent.fromJson(ComponentSerializer.toString(TextComponent.fromLegacyText(kickMessage)));

PacketContainer packet = new PacketContainer(PacketType.Login.Server.DISCONNECT);
packet.getModifier().writeDefaults();

WrappedChatComponent component = WrappedChatComponent.fromJson(ComponentSerializer.toString(TextComponent.fromLegacyText(kickMessage)));
packet.getChatComponents().write(0, component);

// send custom disconnect message to client
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
TemporaryPlayerFactory.getInjectorFromPlayer(player).getSocket().close();

// call PlayerConnection#disconnect to ensure the underlying socket is closed
MinimalInjector injector = TemporaryPlayerFactory.getInjectorFromPlayer(player);
injector.disconnect("");
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<paper.version>1.15.2-R0.1-SNAPSHOT</paper.version>
<paper.version>1.19-R0.1-SNAPSHOT</paper.version>
<bungee.version>1.19-R0.1-SNAPSHOT</bungee.version>
</properties>

Expand Down

0 comments on commit 516066a

Please sign in to comment.