internal static void RaisePlayerPlacedBlockEvent(Player player, Map map, Vector3I coords, Block oldBlock, Block newBlock, BlockChangeContext context) { var e = new PlayerPlacedBlockEventArgs(player, map, coords, oldBlock, newBlock, context); PlacedBlockEvent.Raise(e); }
internal static void RaisePlayerPlacedBlockEvent(PlayerPlacedBlockEventArgs args) { var handler = PlacedBlock; if (handler != null) { handler(null, args); } }
protected bool DrawOneBlock() { BlocksProcessed++; if (!Map.InBounds(Coords)) { BlocksSkipped++; return false; } #if DEBUG_CHECK_DUPLICATE_COORDS TestForDuplicateModification(); #endif Block newBlock = Brush.NextBlock(this); if (newBlock == Block.None) return false; int blockIndex = Map.Index(Coords); Block oldBlock = (Block)Map.Blocks[blockIndex]; if (oldBlock == newBlock) { BlocksSkipped++; return false; } if (Player.CanPlace(Map, Coords, newBlock, Context) != CanPlaceResult.Allowed) { BlocksDenied++; return false; } Map.SetBlock(blockIndex, newBlock); World world = Map.World; if (world != null && !world.IsFlushing) { // cannot reuse packet as each player may require different modifications to block field Player[] players = world.Players; for (int i = 0; i < players.Length; i++) players[i].SendBlock(Coords, newBlock); } // Reuse instance to avoid memory allocations if (placeArgs == null) placeArgs = new PlayerPlacedBlockEventArgs(Player, Map, Vector3I.Zero, Block.Air, Block.Air, Context); placeArgs.Coords = Coords; placeArgs.OldBlock = oldBlock; placeArgs.NewBlock = newBlock; Player.RaisePlayerPlacedBlockEvent(placeArgs); if (!UndoState.IsTooLargeToUndo) { if (!UndoState.Add(Coords, Map, oldBlock)) { Player.LastDrawOp = null; Player.Message("{0}: Too many blocks to undo.", Description); } } BlocksUpdated++; return true; }
public static void OnPlayerPlacedBlock(Object sender, PlayerPlacedBlockEventArgs e) { if (e.Context != BlockChangeContext.Manual && e.Context != BlockChangeContext.Replaced) { return; } try { SetHistory(e.Player.World, e.Coords.X, e.Coords.Y, e.Coords.Z, e.Player, e.OldBlock); } catch (Exception) { } }
static void OnPlayerPlacedBlock(object sender, [NotNull] PlayerPlacedBlockEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } World world = e.Map.World; if (world != null && world.BlockDB.IsEnabled) { BlockDBEntry newEntry = new BlockDBEntry((int)DateTime.UtcNow.ToUnixTime(), e.Player.Info.ID, e.Coords, e.OldBlock, e.NewBlock, e.Context); world.BlockDB.AddEntry(newEntry); } }
protected bool DrawOneBlock() { BlocksProcessed++; if (!Map.InBounds(Coords)) { BlocksSkipped++; return(false); } #if DEBUG_CHECK_DUPLICATE_COORDS TestForDuplicateModification(); #endif Block newBlock = Brush.NextBlock(this); if (newBlock == Block.Undefined) { return(false); } int blockIndex = Map.Index(Coords); Block oldBlock = (Block)Map.Blocks[blockIndex]; if (oldBlock == newBlock) { BlocksSkipped++; return(false); } if (Player.CanPlace(Map, Coords, newBlock, Context) != CanPlaceResult.Allowed) { BlocksDenied++; return(false); } Map.Blocks[blockIndex] = (byte)newBlock; World world = Map.World; if (world != null && !world.IsFlushing) { world.Players.SendLowPriority(PacketWriter.MakeSetBlock(Coords, newBlock)); } // Reuse instance to avoid memory allocations if (placeArgs == null) { placeArgs = new PlayerPlacedBlockEventArgs(Player, Map, Vector3I.Zero, Block.Air, Block.Air, Context); } placeArgs.Coords = Coords; placeArgs.OldBlock = oldBlock; placeArgs.NewBlock = newBlock; Player.RaisePlayerPlacedBlockEvent(placeArgs); if (!UndoState.IsTooLargeToUndo) { if (!UndoState.Add(Coords, oldBlock)) { Player.LastDrawOp = null; Player.Message("{0}: Too many blocks to undo.", Description); } } BlocksUpdated++; return(true); }