public bool DoBlockchange(Player p, ushort x, ushort y, ushort z, byte block, byte extBlock = 0, bool drawn = false) { string errorLocation = "start"; retry: try { //if (x < 0 || y < 0 || z < 0) return; if (x >= Width || y >= Height || z >= Length) { return(false); } byte old = GetTile(x, y, z), extOld = 0; if (old == Block.custom_block) { extOld = GetExtTile(x, y, z); } errorLocation = "Permission checking"; if (!CheckAffectPermissions(p, x, y, z, old, block, extBlock)) { p.RevertBlock(x, y, z); return(false); } if (old == Block.sponge && physics > 0 && block != Block.sponge) { OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z)); } if (old == Block.lava_sponge && physics > 0 && block != Block.lava_sponge) { OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true); } errorLocation = "Undo buffer filling"; Player.UndoPos Pos; Pos.x = x; Pos.y = y; Pos.z = z; Pos.mapName = name; Pos.type = old; Pos.extType = extOld; Pos.newtype = block; Pos.newExtType = extBlock; Pos.timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; p.UndoBuffer.Add(this, Pos); errorLocation = "Setting tile"; p.IncrementBlockStats(block, drawn); SetTile(x, y, z, block); if (old == Block.custom_block && block != Block.custom_block) { RevertExtTileNoCheck(x, y, z); } if (block == Block.custom_block) { SetExtTileNoCheck(x, y, z, extBlock); } errorLocation = "Adding physics"; if (p.PlayingTntWars && block == Block.smalltnt) { AddTntCheck(PosToInt(x, y, z), p); } if (physics > 0 && ActivatesPhysics(block, extBlock)) { AddCheck(PosToInt(x, y, z)); } changed = true; backedup = false; bool diffBlock = old == Block.custom_block ? extOld != extBlock : Block.Convert(old) != Block.Convert(block); return(diffBlock); } catch (OutOfMemoryException) { Player.Message(p, "Undo buffer too big! Cleared!"); p.UndoBuffer.Clear(); p.RemoveInvalidUndos(); goto retry; } catch (Exception e) { Server.ErrorLog(e); Chat.MessageOps(p.name + " triggered a non-fatal error on " + ColoredName); Chat.MessageOps("Error location: " + errorLocation); Server.s.Log(p.name + " triggered a non-fatal error on " + ColoredName); Server.s.Log("Error location: " + errorLocation); return(false); } }
internal bool DoBlockchange(Player p, ushort x, ushort y, ushort z, byte type, byte extType = 0) { string errorLocation = "start"; retry: try { //if (x < 0 || y < 0 || z < 0) return; if (x >= Width || y >= Height || z >= Length) { return(false); } byte b = GetTile(x, y, z), extB = 0; if (b == Block.custom_block) { extB = GetExtTile(x, y, z); } errorLocation = "Permission checking"; if (!CheckAffectPermissions(p, x, y, z, b, type, extType)) { p.RevertBlock(x, y, z); return(false); } if (b == Block.sponge && physics > 0 && type != Block.sponge) { OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z)); } if (b == Block.lava_sponge && physics > 0 && type != Block.lava_sponge) { OtherPhysics.DoSpongeRemoved(this, PosToInt(x, y, z), true); } errorLocation = "Undo buffer filling"; Player.UndoPos Pos; Pos.x = x; Pos.y = y; Pos.z = z; Pos.mapName = name; Pos.type = b; Pos.extType = extB; Pos.newtype = type; Pos.newExtType = extType; Pos.timeDelta = (int)DateTime.UtcNow.Subtract(Server.StartTime).TotalSeconds; p.UndoBuffer.Add(this, Pos); errorLocation = "Setting tile"; p.loginBlocks++; p.overallBlocks++; SetTile(x, y, z, type); if (b == Block.custom_block && type != Block.custom_block) { RevertExtTileNoCheck(x, y, z); } if (type == Block.custom_block) { SetExtTileNoCheck(x, y, z, extType); } errorLocation = "Adding physics"; if (p.PlayingTntWars && type == Block.smalltnt) { AddTntCheck(PosToInt(x, y, z), p); } if (physics > 0 && Block.Physics(type)) { AddCheck(PosToInt(x, y, z)); } changed = true; backedup = false; bool diffBlock = b == Block.custom_block ? extB != extType : Block.Convert(b) != Block.Convert(type); return(diffBlock); } catch (OutOfMemoryException) { Player.SendMessage(p, "Undo buffer too big! Cleared!"); p.UndoBuffer.Clear(); p.RemoveInvalidUndos(); goto retry; } catch (Exception e) { Server.ErrorLog(e); Chat.GlobalMessageOps(p.name + " triggered a non-fatal error on " + name); Chat.GlobalMessageOps("Error location: " + errorLocation); Server.s.Log(p.name + " triggered a non-fatal error on " + name); Server.s.Log("Error location: " + errorLocation); return(false); } }