Skip to content

Commit

Permalink
fix: close all containers when left the game
Browse files Browse the repository at this point in the history
  • Loading branch information
smartcmd committed Apr 4, 2024
1 parent 7deccaf commit 02c8833
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public interface ContainerViewer {

@UnmodifiableView
BiMap<FullContainerType<?>, Container> getTypeToContainer();

default void closeAllContainers() {
getIdToContainer().forEach(this::onClose);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.allaymc.api.block.registry.BlockTypeRegistry;
import org.allaymc.api.entity.component.player.EntityPlayerContainerHolderComponent;
import org.allaymc.api.utils.Identifier;
import org.allaymc.api.client.data.LoginData;
import org.allaymc.api.client.storage.PlayerData;
Expand Down Expand Up @@ -126,10 +127,15 @@ public void handleDisconnect() {
// Especially for cheater, the BedrockPacketHandler::onDisconnect() method may won't be called
// If we call server.onDisconnect() in BedrockPacketHandler::onDisconnect(),
// cheaters will be able to create a lot of fake clients and make the server OOM
onDisconnect();
server.onDisconnect(player, disconnectReason);
}
}

protected void onDisconnect() {
player.closeAllContainers();
}

@Override
public boolean shouldHandleDisconnect() {
return !disconnected && disconnectReason != null;
Expand Down

0 comments on commit 02c8833

Please sign in to comment.