예제 #1
0
        /// <summary>
        /// JDeployable API
        /// <para/>Unregisters JDeployables that were registered.
        /// </summary>
        /// <param name="pluginname">plugin name/title</param>
        public static void UnregisterJDeployables(string pluginname)
        {
            HashSet <Type> types;

            if (!DeployableTypesByPlugin.TryGetValue(pluginname, out types))
            {
                return;
            }

            foreach (Type type in types)
            {
                // get info attribute
                JInfoAttribute info = (JInfoAttribute)Attribute.GetCustomAttribute(type, typeof(JInfoAttribute));

                if (DeployableTypes.Remove(type) && DeployableTypeRequirements.Remove(type) && DeployableTypeUpdates.Remove(type))
                {
                    Interface.Oxide.LogInfo($"[JtechCore] Unregistered JDeployable: [{info.PluginInfo.Title}] {info.Name}");
                }
                else
                {
                    Interface.Oxide.LogInfo($"[JtechCore] Failed to Unregistered JDeployable: [{info.PluginInfo.Title}] {info.Name}");
                }
            }

            DeployableTypesByPlugin.Remove(pluginname);
        }
예제 #2
0
        /// <summary>
        /// JDeployable API
        /// <para/>Unregisters JDeployable from the JDeployableManager.
        /// </summary>
        /// <typeparam name="T">JDeployable</typeparam>
        public static void UnregisterJDeployable <T>() where T : JDeployable
        {
            // get info attribute
            JInfoAttribute info = (JInfoAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(JInfoAttribute));

            if (DeployableTypes.Remove(typeof(T)) && DeployableTypeRequirements.Remove(typeof(T)) && DeployableTypeUpdates.Remove(typeof(T)))
            {
                Interface.Oxide.LogInfo($"[JtechCore] Unregistered JDeployable: [{info.PluginInfo.Title}] {info.Name}");
            }
            else
            {
                Interface.Oxide.LogInfo($"[JtechCore] Failed to Unregistered JDeployable: [{info.PluginInfo.Title}] {info.Name}");
            }
        }
예제 #3
0
        private static bool SaveJDeployable(int id, JDeployable d)
        {
            DeployableSaveData sd = new DeployableSaveData {
                t = d.ToString(),
                s = d.data
            };

            JInfoAttribute info = null;

            if (!DeployableTypes.TryGetValue(d.GetType(), out info))
            {
                return(false);
            }

            if (!DataManager.data.p.ContainsKey(info.PluginInfo.Title))
            {
                DataManager.data.p.Add(info.PluginInfo.Title, new Dictionary <int, DeployableSaveData>());
            }

            DataManager.data.p[info.PluginInfo.Title].Add(id, sd);

            return(true);
        }
예제 #4
0
        /// <summary>
        /// JDeployable API
        /// <para/>Registers JDeployable to the JDeployableManager
        /// </summary>
        /// <typeparam name="T">JDeployable</typeparam>
        public static void RegisterJDeployable <T>() where T : JDeployable
        {
            // get info attribute
            JInfoAttribute info = (JInfoAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(JInfoAttribute));

            if (info == null)
            {
                Interface.Oxide.LogWarning($"[JtechCore] Failed to register ({typeof(T)}) - Missing JInfoAttribute.");
                return;
            }

            if (DeployableTypes.ContainsKey(typeof(T)) || DeployableTypeRequirements.ContainsKey(typeof(T)))
            {
                Interface.Oxide.LogWarning($"[JtechCore] [{info.PluginInfo.Title}] {info.Name} has already been registered!");
                return;
            }

            // get requirements attributes
            List <JRequirementAttribute> requirements = Attribute.GetCustomAttributes(typeof(T), typeof(JRequirementAttribute)).OfType <JRequirementAttribute>().ToList();

            if (requirements == null || requirements.Count == 0)
            {
                Interface.Oxide.LogWarning($"[JtechCore] Failed to register ({typeof(T)}) - Missing JRequirementAttribute.");
                return;
            }
            else if (requirements.Count > 5)
            {
                Interface.Oxide.LogWarning($"[JtechCore] Failed to register ({typeof(T)}) - More than 5 JRequirementAttribute are not allowed.");
                return;
            }

            // get JUpdate attribute
            JUpdateAttribute jupdate = (JUpdateAttribute)Attribute.GetCustomAttribute(typeof(T), typeof(JUpdateAttribute));

            if (jupdate == null)
            {
                Interface.Oxide.LogWarning($"[JtechCore] Failed to register ({typeof(T)}) - Missing JUpdateAttribute.");
                return;
            }

            // save all the attributes

            DeployableTypes.Add(typeof(T), info);

            requirements.OrderBy(x => x.ItemId);             // order requirements by their item id (just like the rust crafting menu)
            DeployableTypeRequirements.Add(typeof(T), requirements);

            DeployableTypeUpdates.Add(typeof(T), jupdate);
            if (!spawnedDeployablesByType.ContainsKey(typeof(T)))
            {
                spawnedDeployablesByType.Add(typeof(T), new List <JDeployable>());
            }

            if (!DeployableTypesByPlugin.ContainsKey(info.PluginInfo.Title))
            {
                DeployableTypesByPlugin.Add(info.PluginInfo.Title, new HashSet <Type>());
            }
            DeployableTypesByPlugin[info.PluginInfo.Title].Add(typeof(T));

            Interface.Oxide.LogInfo($"[JtechCore] Registered JDeployable: [{info.PluginInfo.Title}] {info.Name}");
        }