Exemplo n.º 1
0
        public static void Remove(BlockDefinition def, BlockDefinition[] defs, Level level)
        {
            BlockID block  = def.GetBlock();
            bool    global = defs == GlobalDefs;

            if (global)
            {
                UpdateGlobalCustom(block, null);
            }

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

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

                pl.Session.SendUndefineBlock(def);
            }
        }
Exemplo n.º 2
0
        public static BlockDefinition[] Load(string path)
        {
            BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount];
            if (!File.Exists(path))
            {
                return(defs);
            }
            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BlockDefinition));
            }

            try {
                JsonContext ctx = new JsonContext();
                ctx.Val = File.ReadAllText(path);
                JsonArray array = (JsonArray)Json.ParseStream(ctx);
                if (array == null)
                {
                    return(defs);
                }

                foreach (object raw in array)
                {
                    JsonObject obj = (JsonObject)raw;
                    if (obj == null)
                    {
                        continue;
                    }

                    BlockDefinition def = new BlockDefinition();
                    obj.Deserialise(elems, def);
                    if (String.IsNullOrEmpty(def.Name))
                    {
                        continue;
                    }

                    BlockID block = def.GetBlock();
                    if (block >= defs.Length)
                    {
                        Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID);
                    }
                    else
                    {
                        defs[block] = def;
                    }

                    // In case user manually edited fallback in the json file
                    def.FallBack = Math.Min(def.FallBack, Block.CpeMaxBlock);
                }
            } catch (Exception ex) {
                Logger.LogError("Error Loading block defs from " + path, ex);
            }
            return(defs);
        }
Exemplo n.º 3
0
        public static BlockDefinition[] Load(bool global, string mapName)
        {
            BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount];
            string            path = global ? GlobalPath : "blockdefs/lvl_" + mapName + ".json";

            if (!File.Exists(path))
            {
                return(defs);
            }
            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BlockDefinition));
            }

            try {
                JsonContext ctx = new JsonContext();
                ctx.Val = File.ReadAllText(path);
                JsonArray array = (JsonArray)Json.ParseStream(ctx);
                if (array == null)
                {
                    return(defs);
                }

                foreach (object raw in array)
                {
                    JsonObject obj = (JsonObject)raw;
                    if (obj == null)
                    {
                        continue;
                    }

                    BlockDefinition def = new BlockDefinition();
                    obj.Deserialise(elems, def);
                    if (String.IsNullOrEmpty(def.Name))
                    {
                        continue;
                    }

                    BlockID block = def.GetBlock();
                    if (block >= defs.Length)
                    {
                        Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID);
                    }
                    else
                    {
                        defs[block] = def;
                    }
                }
            } catch (Exception ex) {
                Logger.LogError("Error Loading block defs from " + path, ex);
            }
            return(defs);
        }
Exemplo n.º 4
0
 static BlockID GetBlockByName(string msg, BlockDefinition[] defs)
 {
     for (int i = 1; i < defs.Length; i++)
     {
         BlockDefinition def = defs[i];
         if (def == null)
         {
             continue;
         }
         if (def.Name.Replace(" ", "").CaselessEq(msg))
         {
             return(def.GetBlock());
         }
     }
     return(Block.Invalid);
 }
Exemplo n.º 5
0
        public static void Add(BlockDefinition def, BlockDefinition[] defs, Level level)
        {
            BlockID block  = def.GetBlock();
            bool    global = defs == GlobalDefs;

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

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

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!global && pl.level != level)
                {
                    continue;
                }
                if (!pl.hasBlockDefs || def.RawID > pl.MaxRawBlock)
                {
                    continue;
                }
                if (global && pl.level.CustomBlockDefs[block] != GlobalDefs[block])
                {
                    continue;
                }

                pl.Send(def.MakeDefinePacket(pl));
                pl.SendCurrentBlockPermissions();
            }
            Save(global, level);
        }
Exemplo n.º 6
0
        public static void Remove(BlockDefinition def, BlockDefinition[] defs, Level level)
        {
            BlockID block  = def.GetBlock();
            bool    global = defs == GlobalDefs;

            if (global)
            {
                UpdateGlobalCustom(block, null);
            }

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

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (!global && pl.level != level)
                {
                    continue;
                }
                if (!pl.hasBlockDefs || def.RawID > pl.MaxRawBlock)
                {
                    continue;
                }
                if (global && pl.level.CustomBlockDefs[block] != null)
                {
                    continue;
                }

                pl.Send(Packet.UndefineBlock(def, pl.hasExtBlocks));
            }
            Save(global, level);
        }
Exemplo n.º 7
0
        public static BlockDefinition[] Load(string path)
        {
            BlockDefinition[] defs = new BlockDefinition[Block.ExtendedCount];
            if (!File.Exists(path))
            {
                return(defs);
            }
            if (elems == null)
            {
                elems = ConfigElement.GetAll(typeof(BlockDefinition));
            }

            try {
                string json = File.ReadAllText(path);

                JsonReader reader = new JsonReader(json);
                reader.OnMember = (obj, key, value) => {
                    if (obj.Meta == null)
                    {
                        obj.Meta = new BlockDefinition();
                    }
                    ConfigElement.Parse(elems, obj.Meta, key, (string)value);
                };

                JsonArray array = (JsonArray)reader.Parse();
                if (array == null)
                {
                    return(defs);
                }

                foreach (object raw in array)
                {
                    JsonObject obj = (JsonObject)raw;
                    if (obj == null || obj.Meta == null)
                    {
                        continue;
                    }

                    BlockDefinition def = (BlockDefinition)obj.Meta;
                    if (String.IsNullOrEmpty(def.Name))
                    {
                        continue;
                    }

                    BlockID block = def.GetBlock();
                    if (block >= defs.Length)
                    {
                        Logger.Log(LogType.Warning, "Invalid block ID: " + def.RawID);
                    }
                    else
                    {
                        defs[block] = def;
                    }

                    // In case user manually edited fallback in the json file
                    def.FallBack = Math.Min(def.FallBack, Block.CpeMaxBlock);
                }
            } catch (Exception ex) {
                Logger.LogError("Error Loading block defs from " + path, ex);
            }
            return(defs);
        }