Skip to content

Commit

Permalink
Update Server.Events.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tides committed Apr 29, 2023
1 parent 0a3e470 commit 29980a4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions Obsidian/Server.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,19 @@ private async Task PlayerAttack(PlayerAttackEntityEventArgs e)

private async Task OnContainerClosed(ContainerClosedEventArgs e)
{
if (e.Cancel || e.Container is not IBlockEntity blockEntity)
var player = (e.Player as Player)!;

if (e.Cancel)
{
//Resend open container again.
await player.OpenInventoryAsync(e.Container);
return;
}

//Player successfully exited container
player.OpenedContainer = null;

if (e.Container is not IBlockEntity blockEntity)
return;

var position = blockEntity.BlockPosition;
Expand All @@ -31,8 +43,6 @@ private async Task OnContainerClosed(ContainerClosedEventArgs e)
if (block is null)
return;

var player = (e.Player as Player)!;

switch (block.Material)
{
case Material.Chest:
Expand Down Expand Up @@ -66,7 +76,7 @@ await player.SendSoundAsync(SoundEffectBuilder.Create(SoundId.BlockEnderChestClo
.Build());
break;
}
case Material.Barrel:
case Material.Barrel://Barrels don't have a block action
{
await player.SendSoundAsync(SoundEffectBuilder.Create(SoundId.BlockBarrelClose)
.WithSoundPosition(position.SoundPosition)
Expand All @@ -91,8 +101,6 @@ await player.SendSoundAsync(SoundEffectBuilder.Create(SoundId.BlockShulkerBoxClo
break;
}
}

player.OpenedContainer = null;
}

private async Task OnPlayerInteract(PlayerInteractEventArgs e)
Expand Down

0 comments on commit 29980a4

Please sign in to comment.