Example #1
0
        internal static void SendLevelCustomBlocks(Player pl)
        {
            BlockDefinition[] defs = pl.level.CustomBlockDefs;
            for (int i = 1; i < defs.Length; i++)
            {
                BlockDefinition def = defs[i];
                if (def == null)
                {
                    continue;
                }
                if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && def.Shape != 0)
                {
                    SendDefineBlockExt(pl, def, true);
                }
                else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0)
                {
                    SendDefineBlockExt(pl, def, false);
                }
                else
                {
                    SendDefineBlock(pl, def);
                }

                if (pl.HasCpeExt(CpeExt.BlockPermissions))
                {
                    pl.Send(Packet.BlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete));
                }
            }
        }
Example #2
0
        public static void Add(BlockDefinition def, BlockDefinition[] defs, Level level)
        {
            byte id     = def.BlockID;
            bool global = defs == GlobalDefs;

            if (global)
            {
                Level[] loaded = LevelInfo.Loaded.Items;
                foreach (Level lvl in loaded)
                {
                    if (lvl.CustomBlockDefs[id] == null)
                    {
                        lvl.CustomBlockDefs[id] = def;
                    }
                }
            }
            defs[id] = def;
            if (global)
            {
                Block.SetDefaultNames();
            }

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!global && pl.level != level)
                {
                    continue;
                }
                if (!pl.hasBlockDefs)
                {
                    continue;
                }
                if (global && pl.level.CustomBlockDefs[id] != GlobalDefs[id])
                {
                    continue;
                }

                if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt, 2) && def.Shape != 0)
                {
                    SendDefineBlockExt(pl, def, true);
                }
                else if (pl.HasCpeExt(CpeExt.BlockDefinitionsExt) && def.Shape != 0)
                {
                    SendDefineBlockExt(pl, def, false);
                }
                else
                {
                    SendDefineBlock(pl, def);
                }

                if (pl.HasCpeExt(CpeExt.BlockPermissions))
                {
                    pl.Send(Packet.BlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete));
                }
            }
            Save(global, level);
        }
Example #3
0
        public static void ResendBlockPermissions(byte block)
        {
            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!pl.HasCpeExt(CpeExt.BlockPermissions))
                {
                    continue;
                }

                int count = pl.hasCustomBlocks ? Block.CpeCount : Block.OriginalCount;
                if (block < count)
                {
                    bool canAffect = Block.canPlace(pl, block);
                    pl.Send(Packet.BlockPermission(block, canAffect, canAffect));
                }
            }
        }
Example #4
0
        public static void Add(BlockDefinition def, BlockDefinition[] defs, Level level)
        {
            byte raw    = def.BlockID;
            bool global = defs == GlobalDefs;

            if (global)
            {
                UpdateGlobalCustom(raw, def);
            }

            defs[raw] = def;
            if (global)
            {
                Block.SetDefaultNames();
            }
            if (!global)
            {
                level.UpdateCustomBlock(raw, def);
            }

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!global && pl.level != level)
                {
                    continue;
                }
                if (!pl.hasBlockDefs)
                {
                    continue;
                }
                if (global && pl.level.CustomBlockDefs[raw] != GlobalDefs[raw])
                {
                    continue;
                }

                pl.Send(def.MakeDefinePacket(pl));
                if (pl.Supports(CpeExt.BlockPermissions))
                {
                    pl.Send(Packet.BlockPermission(def.BlockID, pl.level.CanPlace, pl.level.CanDelete));
                }
            }
            Save(global, level);
        }
Example #5
0
        public void SendCurrentBlockPermissions()
        {
            byte count = hasCustomBlocks ? Block.CpeCount : Block.OriginalCount;

            for (byte i = 0; i < count; i++)
            {
                bool canPlace  = Block.canPlace(this, i) && level.CanPlace;
                bool canDelete = Block.canPlace(this, i) && level.CanDelete;
                Send(Packet.BlockPermission(i, canPlace, canDelete));
            }

            if (!hasBlockDefs)
            {
                return;
            }
            for (int i = count; i < 256; i++)
            {
                if (level.CustomBlockDefs[i] == null)
                {
                    continue;
                }
                Send(Packet.BlockPermission((byte)i, level.CanPlace, level.CanDelete));
            }
        }