Fabric API

Fabric API

108M Downloads

How do I disconnect player from server (client side)

semenishchev opened this issue ยท 6 comments

commented

I want to make mod, that disconnects player from server when certain message appears in chat (I've done listening with mixin) and after all checks i need to disconnect player with message something like bad message was found blah blah and after and then I can return to multiplayer menu (all this must be clientside)

commented

This is not a fabric bug report.
Use discord or the discussions tab to ask for help.

commented

@warjort Imo such questions are fine for issues.

@SashaSemenishchev You can look into how the /kick command is implemented.

commented

gh discussions should be used for questions imo

commented

@warjort Imo such questions are fine for issues.

You should make a template for it then, instead of pointing people to the discord/discussions when you "create new issue".

commented

@SashaSemenishchev You can look into how the /kick command is implemented.

Kick is server side. You need to look at net.minecraft.client.gui.screen.GameMenuScreen.

It's basically:

MinecraftClient client = MinecraftClient.getInstance();
client.world.disconnect(); // tell the server you are disconnecting
client.disconnect(screenToShowWhenDisconnecting);
client.openScreen(screenToShowAfterwards);

Never done it myself. But I bet it only works properly if you are on the render thread?

commented

If you still need support, please ask in one of the dev channels of our official discord server.