mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-11 09:51:35 +01:00
Add preventive kick instead of hard to debug timeouts
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
099397b968
commit
13a8a22546
@ -12,6 +12,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.event.HoverEvent;
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
import net.kyori.adventure.text.event.HoverEvent.ShowEntity;
|
import net.kyori.adventure.text.event.HoverEvent.ShowEntity;
|
||||||
import net.kyori.adventure.text.event.HoverEventSource;
|
import net.kyori.adventure.text.event.HoverEventSource;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||||
import net.kyori.adventure.title.Title;
|
import net.kyori.adventure.title.Title;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
@ -100,6 +101,8 @@ import java.util.function.UnaryOperator;
|
|||||||
*/
|
*/
|
||||||
public class Player extends LivingEntity implements CommandSender, Localizable, HoverEventSource<ShowEntity>, Identified, NamedAndIdentified {
|
public class Player extends LivingEntity implements CommandSender, Localizable, HoverEventSource<ShowEntity>, Identified, NamedAndIdentified {
|
||||||
|
|
||||||
|
private static final Component REMOVE_MESSAGE = Component.text("You have been removed from the server without reason.", NamedTextColor.RED);
|
||||||
|
|
||||||
private long lastKeepAlive;
|
private long lastKeepAlive;
|
||||||
private boolean answerKeepAlive;
|
private boolean answerKeepAlive;
|
||||||
|
|
||||||
@ -448,9 +451,8 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
EventDispatcher.call(new PlayerDisconnectEvent(this));
|
EventDispatcher.call(new PlayerDisconnectEvent(this));
|
||||||
super.remove();
|
super.remove();
|
||||||
this.packets.clear();
|
this.packets.clear();
|
||||||
if (getOpenInventory() != null) {
|
final Inventory currentInventory = getOpenInventory();
|
||||||
getOpenInventory().removeViewer(this);
|
if (currentInventory != null) currentInventory.removeViewer(this);
|
||||||
}
|
|
||||||
MinecraftServer.getBossBarManager().removeAllBossBars(this);
|
MinecraftServer.getBossBarManager().removeAllBossBars(this);
|
||||||
// Advancement tabs cache
|
// Advancement tabs cache
|
||||||
{
|
{
|
||||||
@ -467,6 +469,10 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
|||||||
this.viewableChunks.forEach(chunk -> chunk.removeViewer(this));
|
this.viewableChunks.forEach(chunk -> chunk.removeViewer(this));
|
||||||
// Remove from the tab-list
|
// Remove from the tab-list
|
||||||
PacketUtils.broadcastPacket(getRemovePlayerToList());
|
PacketUtils.broadcastPacket(getRemovePlayerToList());
|
||||||
|
|
||||||
|
// Prevent the player from being stuck in loading screen, or just unable to interact with the server
|
||||||
|
// This should be considered as a bug, since the player will ultimately time out anyway.
|
||||||
|
if (playerConnection.isOnline()) kick(REMOVE_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user