Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

Commit

Permalink
Fix being able to place down in claims
Browse files Browse the repository at this point in the history
  • Loading branch information
copygirl committed Nov 16, 2019
1 parent ec83f73 commit 0041cc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/CarriedBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ public static IEnumerable<CarriedBlock> GetCarried(this Entity entity)
public static bool Carry(this Entity entity, BlockPos pos,
CarrySlot slot, bool checkIsCarryable = true)
{
if ((entity is EntityPlayer playerEntity) && !entity.World.Claims.TryAccess(
playerEntity.Player, pos, EnumBlockAccessFlags.BuildOrBreak)) return false;
if (CarriedBlock.Get(entity, slot) != null) return false;
var carried = CarriedBlock.PickUp(entity.World, pos, slot, checkIsCarryable);
if (carried == null) return false;
Expand All @@ -294,6 +296,8 @@ public static bool PlaceCarried(this IPlayer player, BlockSelection selection, C
if (player == null) throw new ArgumentNullException(nameof(player));
if (selection == null) throw new ArgumentNullException(nameof(selection));

if (!player.Entity.World.Claims.TryAccess(
player, selection.Position, EnumBlockAccessFlags.BuildOrBreak)) return false;
var carried = CarriedBlock.Get(player.Entity, slot);
if (carried == null) return false;

Expand Down
5 changes: 2 additions & 3 deletions src/Common/CarryHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ public void OnPickUpMessage(IServerPlayer player, PickUpMessage message)
var carried = player.Entity.GetCarried(message.Slot);
if ((message.Slot == CarrySlot.Back) || (carried != null) ||
!CanInteract(player.Entity, true) ||
!player.Entity.World.Claims.TryAccess(player, message.Position, EnumBlockAccessFlags.BuildOrBreak) ||
!player.Entity.Carry(message.Position, message.Slot))
InvalidCarry(player, message.Position);
}
Expand All @@ -280,9 +279,9 @@ public void OnPlaceDownMessage(IServerPlayer player, PlaceDownMessage message)
// FIXME: Do at least some validation of this data.

var carried = player.Entity.GetCarried(message.Slot);
if ((message.Slot == CarrySlot.Back) ||
if ((message.Slot == CarrySlot.Back) || (carried == null) ||
!CanInteract(player.Entity, (message.Slot != CarrySlot.Hands)) ||
(carried == null) || !PlaceDown(player, carried, message.Selection, out var placedAt))
!PlaceDown(player, carried, message.Selection, out var placedAt))
InvalidCarry(player, message.PlacedAt);
// If succeeded, but by chance the client's projected placement isn't
// the same as the server's, re-sync the block at the client's position.
Expand Down

0 comments on commit 0041cc1

Please sign in to comment.