Server Switch Prompt
The ServerSwitchPromptPacket
is a client-bound packet that allows you to open a prompt for the player that
recommends switching to another server. The player can then confirm or cancel the server switch.
The client will then respond with a ServerSwitchPromptResponsePacket
that contains the player's decision.
Creating an Input Prompt
The packet uses the ServerSwitchPrompt
model, which can be created with ServerSwitchPrompt.create
.
The ServerSwitchPrompt model uses the Server API's own Component model.
ServerSwitchPrompt serverSwitchPrompt = ServerSwitchPrompt.create(
ServerAPIComponent.text("Example Server Switch Prompt")
.color(ServerAPITextColor.GOLD)
.decorate(ServerAPITextDecoration.BOLD),
"hypixel.net"
);
Sending the Packet
The packet can either be sent via the LabyModPlayer
object of the player, or directly via the LabyModProtocol
.
If you're not sending the packet with an integrated handler, you need to register a handler for the ServerSwitchPromptResponsePacket
yourself. The process is explained here.
Via LabyModPlayer (Recommended)
// Get the LabyModPlayer
LabyModPlayer labyModPlayer = LabyModProtocolService.get().getPlayer(uniqueId);
// Open the server switch prompt and handle the response
labyModPlayer.openServerSwitchPrompt(serverSwitchPrompt, response -> {
boolean accepted = response.wasAccepted(); // Whether the player accepted the server switch
// Directly handle the response
});
// Get the LabyModPlayer
LabyModPlayer labyModPlayer = LabyModProtocolService.get().getPlayer(uniqueId);
// Open the server switch prompt
labyModPlayer.openServerSwitchPrompt(serverSwitchPrompt);
// To handle the response, you need to register a PacketHandler for the
// ServerSwitchPromptResponsePacket yourself!
Via the LabyModProtocol
// Get the LabyModProtocol
LabyModProtocol labyModProtocol = LabyModProtocolService.get().labyModProtocol();
// Send the packet
labyModProtocol.sendPacket(uniqueId, new ServerSwitchPromptPacket(inputPrompt));
// To handle the response, you need to register a PacketHandler for the
// ServerSwitchPromptResponsePacket yourself!
// Get the LabyModProtocol
LabyModProtocol labyModProtocol = LabyModProtocolService.get().labyModProtocol();
// Send the packet and handle the response
labyModProtocol.sendPacket(
uniqueId,
new ServerSwitchPromptPacket(inputPrompt),
ServerSwitchPromptResponsePacket.class,
response -> {
boolean accepted = response.wasAccepted(); // Whether the player accepted the server switch
// Handle the response packet
return false; // Return false, as only one response is expected
}
);