Beispiel #1
0
        /// <summary>
        /// Causes a block change for the level
        /// </summary>
        /// <param name="x">Location of x</param>
        /// <param name="z">Location of z</param>
        /// <param name="y">Location of y</param>
        /// <param name="block">Block to set</param>
        /// <param name="p">A player who doesn't need the update.</param>
        /// <param name="blockqueue">Should this blockchange be queued by BlockQueue?</param>
        public void BlockChange(ushort x, ushort z, ushort y, byte block, Player p = null, bool blockqueue = false)
        {
            if (blockqueue)
            {
                BlockQueue.Addblock(p, x, y, z, block);
            }
            if (!IsInBounds(x, z, y) || y == CWMap.Size.z)
            {
                Logger.Log("Blockchange((ushort) " + x + ", (ushort)" + z + ", (ushort) " + y + ", (byte) " + block + ", (Player) " + p + ") is outside of level");
                return;
            }
            byte currentType = GetBlock(x, z, y);

            if (block == 0)
            {
                pblocks.ForEach(pb =>
                {
                    if (pb.X == x && pb.Y == y && pb.Z == z)
                    {
                        pblocks.Remove(pb);
                        return;
                    }
                });
            }
            if (block == currentType)
            {
                return;
            }
            if (p != null)
            {
                byte blockFrom = GetBlock(x, z, y);
                BlockChangeHistory.Add(p.Level.Name, (uint)p.UID, x, z, y, block);
            }

            SetBlock(x, z, y, block);
            if (p == null)
            {
                Player.GlobalBlockchange(this, x, z, y, block);
            }
            else
            {
                p.SendBlockchangeToOthers(this, x, z, y, block);
                p.SendBlockChange(x, z, y, block);
            }

            if ((Block)block is PhysicsBlock)
            {
                PhysicsBlock pb = (PhysicsBlock)((PhysicsBlock)block).Clone();
                pb.X = x;
                pb.Y = y;
                pb.Z = z;
                pblocks.Add(pb);
            }

            //TODO Special stuff for block changing
        }
 void OnAllLevelsLoadUnload_Normal(Level sender, API.Events.LevelLoadEventArgs args)
 {
     if (args.Loaded)
     {
         if (!BlockChangeHistory.Load(sender.Name))
         {
             BlockChangeHistory.SetLevel(sender.Name, (ushort)sender.CWMap.Size.x, (ushort)sender.CWMap.Size.z, (ushort)sender.CWMap.Size.y, sender.CWMap.BlockData);
         }
     }
     else
     {
         BlockChangeHistory.WriteOut(sender.Name, true);
     }
 }
Beispiel #3
0
        public void Use(Entity.Player p, string[] args)
        {
            long since = 0;
            long uid   = -1;

            if (args.Length == 0)
            {
                uid = p.UID;
            }
            else
            {
                uid = Player.GetUID(args[0]);
            }
            if (uid == -1)
            {
                p.SendMessage("Player not found");
                return;
            }
            if (args.Length > 1)
            {
                try {
                    since = DateTime.Now.AddSeconds(-int.Parse(args[1])).Ticks;
                }
                catch (Exception e) {
                    if (e.GetType() == typeof(FormatException))
                    {
                        p.SendMessage("Not supported number format");
                    }
                    else if (e.GetType() == typeof(OverflowException))
                    {
                        p.SendMessage("Your number was out of range");
                    }
                }
            }
            foreach (var block in BlockChangeHistory.GetCurrentIfUID(p.Level.Name, (uint)uid, since))
            {
                if (block.Item4 == 0)
                {
                    p.SendBlockChange(block.Item1, block.Item2, block.Item3, MCForge.World.Block.NameToBlock("red"));
                }
                else
                {
                    p.SendBlockChange(block.Item1, block.Item2, block.Item3, MCForge.World.Block.NameToBlock("green"));
                }
            }
            p.SendMessage("Highlighting " + ((uid == p.UID) ? p.DisplayName : args[0]));
        }
        void Undo(long UID, int time, Level l, Player online)
        {
            long since = DateTime.Now.AddSeconds(-time).Ticks;
            int  count = 0;

            foreach (var ch in BlockChangeHistory.GetCurrentIfUID(l.Name, (uint)UID, since))
            {
                RedoHistory.Add((uint)UID, l.Name, ch.Item1, ch.Item2, ch.Item3, ch.Item4);
                count++;
            }
            foreach (var ch in BlockChangeHistory.Undo(l.Name, (uint)UID, since))
            {
                l.BlockChange(ch.Item1, ch.Item2, ch.Item3, ch.Item4);
            }
            online.SendMessage("&e" + count + Server.DefaultColor + " Blocks changed");
            return;
        }
Beispiel #5
0
        void OnBlockChange(Player sender, BlockChangeEventArgs e)
        {
            sender.OnPlayerBlockChange.Normal -= OnBlockChange;
            e.Cancel();
            int count = 0;

            foreach (var info in BlockChangeHistory.About(sender.Level.Name, e.X, e.Z, e.Y))
            {
                string name  = Player.GetName(info.Item2);
                string color = Player.GetColor(info.Item2);
                sender.SendMessage(((name == null) ? "nobody" : ((color == null) ? "" : color) + name) + " changed to " + ((info.Item1 == 0) ? "&4" : "&3") + ((Block)info.Item1).Name + " " + Server.DefaultColor + "at " + new DateTime(info.Item3).ToString("dd/MM/yy HH:mm:ss"));
                count++;
            }
            sender.SendMessage(count + Server.DefaultColor + " changes listed.");
            if (sender.StaticCommandsEnabled)
            {
                sender.SendMessage("Break block to get info");
                sender.OnPlayerBlockChange.Normal += OnBlockChange;
            }
        }