Esempio n. 1
0
        public CSharpPlugin()
        {
            int i;

            this.timer = new PluginTimers(this);
            Type type = base.GetType();

            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic);
            for (i = 0; i < (int)fields.Length; i++)
            {
                FieldInfo fieldInfo        = fields[i];
                object[]  customAttributes = fieldInfo.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
                if (customAttributes.Length != 0)
                {
                    PluginReferenceAttribute pluginReferenceAttribute = customAttributes[0] as PluginReferenceAttribute;
                    this.pluginReferenceFields[pluginReferenceAttribute.Name ?? fieldInfo.Name] = fieldInfo;
                }
            }
            MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic);
            for (i = 0; i < (int)methods.Length; i++)
            {
                MethodInfo methodInfo = methods[i];
                if (methodInfo.GetCustomAttributes(typeof(HookMethodAttribute), true).Length == 0)
                {
                    if (methodInfo.Name.Equals("OnFrame"))
                    {
                        this.HookedOnFrame = true;
                    }
                    if (methodInfo.DeclaringType.Name == type.Name)
                    {
                        base.AddHookMethod(methodInfo.Name, methodInfo);
                    }
                }
            }
        }
Esempio n. 2
0
        public CSharpPlugin()
        {
            timer = new PluginTimers(this);

            var type = GetType();

            foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                var reference_attributes = field.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
                if (reference_attributes.Length > 0)
                {
                    var pluginReference = reference_attributes[0] as PluginReferenceAttribute;
                    pluginReferenceFields[pluginReference.Name ?? field.Name] = field;
                }
            }
            foreach (var method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                var info_attributes = method.GetCustomAttributes(typeof(HookMethodAttribute), true);
                if (info_attributes.Length > 0)
                {
                    continue;
                }
                if (method.Name.Equals("OnFrame"))
                {
                    HookedOnFrame = true;
                }
                // Assume all private instance methods which are not explicitly hooked could be hooks
                if (method.DeclaringType.Name == type.Name)
                {
                    AddHookMethod(method.Name, method);
                }
            }
        }
            public EntityTracker(BaseEntity entity, byte updateIntervalSeconds, PluginTimers timerPlugin, string tag, Action <EntityTracker> onDeactivate)
            {
                if (entity == null)
                {
                    throw new ArgumentNullException(nameof(entity));
                }
                if (onDeactivate == null)
                {
                    throw new ArgumentNullException(nameof(onDeactivate));
                }
                if (timerPlugin == null)
                {
                    throw new ArgumentNullException(nameof(timerPlugin));
                }
                if (updateIntervalSeconds == 0)
                {
                    throw new ArgumentNullException(nameof(updateIntervalSeconds));
                }
                if (tag == null)
                {
                    throw new ArgumentNullException(nameof(tag));
                }

                Entity = entity;
                Tag    = tag;

                _updateIntervalSeconds = updateIntervalSeconds;
                _timerPlugin           = timerPlugin;
                _onDeactivate          = onDeactivate;

                CheckActive();
            }
Esempio n. 4
0
        private void OnPlayerDisconnected(BasePlayer player)
        {
            PluginTimers timer = new PluginTimers(this);

            timer.Once(10, () =>
            {
                player.SetFlag(BaseEntity.Flags.Locked, true);
            });
        }
Esempio n. 5
0
 /// <summary>
 /// Responsible for preventing spam to the user by setting a timer to prevent messages from Handyman for a set duration.
 /// </summary>
 private void ConfigureMessageTimer()
 {
     //checks if our timer exists
     if (RepairMessageTimer == null)
     {
         //no - create it
         RepairMessageTimer = new PluginTimers(this);
         //set it to fire every xx seconds based on configuration
         RepairMessageTimer.Every(configData.HandyManChatInterval, RepairMessageTimer_Elapsed);
     }
 }
Esempio n. 6
0
        private void Loaded()
        {
            permission.RegisterPermission("handyman.use", this);
            LoadVariables();

            try
            {
                playerData = dataFile.ReadObject <Dictionary <ulong, bool> >();
            }
            catch { }

            if (playerData == null)
            {
                playerData = new Dictionary <ulong, bool>();
            }

            //Set message timer to prevent user spam
            RepairMessageTimer = new PluginTimers(this);
            RepairMessageTimer.Every(HandyManChatInterval, () => _allowHandyManFixMessage = true);
        }
Esempio n. 7
0
        public CSharpPlugin()
            : base()
        {
            timer = new PluginTimers(this);

            var type = GetType();
            foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                var reference_attributes = field.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
                if (reference_attributes.Length > 0)
                {
                    var plugin_reference = reference_attributes[0] as PluginReferenceAttribute;
                    pluginReferenceFields[plugin_reference.Name ?? field.Name] = field;
                }
            }
            foreach (var method in type.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance))
            {
                var info_attributes = method.GetCustomAttributes(typeof(HookMethod), true);
                if (info_attributes.Length > 0) continue;
                if (method.Name == "OnFrame") HookedOnFrame = true;
                // Assume all private instance methods which are not explicitly hooked could be hooks
                if (method.DeclaringType.Name == type.Name) AddHookMethod(method.Name, method);
            }
        }
        private void Init()
        {
            _timer = this.timer;
            JsonConvert.DefaultSettings = () => new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };

            WorldShopsSettings.Loaded = this.Config.ReadObject <WorldShopsSettings.General>();

            WorldShopsData.Loaded = Interface.Oxide.DataFileSystem.ReadObject <WorldShopsData.General>(nameof(WorldShops));
            if (WorldShopsData.Loaded.Shops == null)
            {
                WorldShopsData.Loaded.Shops = new Dictionary <string, string>();
            }

            for (int i = 0; i < WorldShopsSettings.Loaded.Shops.Count; i++)
            {
                WorldShopsSettings.Shop shop = WorldShopsSettings.Loaded.Shops[i];

                if (shop.CommandName == null)
                {
                    this.PrintError($"Unable to load WorldShops. The {nameof(WorldShopsSettings.Shop.CommandName)} of {nameof(WorldShopsSettings.Shop)} #{i + 1} is null. Please set a value.");
                    this.Manager.RemovePlugin(this);
                    return;
                }

                if (shop.SellOrders == null)
                {
                    shop.SellOrders = new WorldShopsSettings.SellOrder[0];
                    this.PrintWarning($"The {nameof(WorldShopsSettings.Shop.SellOrders)} of {nameof(WorldShopsSettings.Shop)} \"{shop.CommandName}\" is null. The value has been set to an empty array.");
                }

                if (shop.WorldName == null)
                {
                    shop.WorldName = "A Shop";
                    this.PrintWarning($"The {nameof(WorldShopsSettings.Shop.WorldName)} of {nameof(WorldShopsSettings.Shop)} \"{shop.CommandName}\" is null. The value has been set \"A Shop\".");
                }

                for (int j = 0; j < shop.SellOrders.Length; j++)
                {
                    if (shop.SellOrders[j].BuyItem.Definition == null)
                    {
                        this.RaiseError($"Unable to load WorldShops. The {nameof(WorldShopsSettings.SellOrder.BuyItem)} of {nameof(WorldShopsSettings.SellOrder)} #{j + 1} in {nameof(WorldShopsSettings.Shop)} \"{shop.CommandName}\" has an invalid item shortname.");
                        this.Manager.RemovePlugin(this);
                        return;
                    }
                    if (shop.SellOrders[j].SellItem.Definition == null)
                    {
                        this.RaiseError($"Unable to load WorldShops. The {nameof(WorldShopsSettings.SellOrder.SellItem)} of {nameof(WorldShopsSettings.SellOrder)} #{j + 1} in {nameof(WorldShopsSettings.Shop)} \"{shop.CommandName}\" has an invalid item shortname.");
                        this.Manager.RemovePlugin(this);
                        return;
                    }
                }
            }

            string[] names           = WorldShopsSettings.Loaded.Shops.Select(x => x.CommandName).ToArray();
            string   conflictingName = names.FirstOrDefault(x => names.Length - names.Except(new string[] { x }).Count() > 1);

            if (conflictingName != null)
            {
                this.RaiseError($"Unable to load WorldShops. Two or more shops have a conflicting command name: {conflictingName}");
                this.Manager.RemovePlugin(this);
                return;
            }

            this.queuedShops    = new Dictionary <BasePlayer, WorldShopsSettings.Shop>();
            this.queuedWipes    = new List <BasePlayer>();
            this.queuedSaves    = new Dictionary <BasePlayer, WorldShopsSettings.Shop>();
            this.queuedDisables = new List <BasePlayer>();
            this.queuedSpawns   = new List <BasePlayer>();

            _activeShops = new Dictionary <VendingMachine, WorldShopsSettings.Shop>();

            this.permission.RegisterPermission("worldshops.build", this);
            this.permission.RegisterPermission("worldshops.spawn", this);
            this.permission.RegisterPermission("worldshops.apply", this);
            this.permission.RegisterPermission("worldshops.disable", this);
            this.permission.RegisterPermission("worldshops.wipe", this);
            this.permission.RegisterPermission("worldshops.save", this);
            this.permission.RegisterPermission("worldshops.delete", this);
            foreach (string name in names)
            {
                this.permission.RegisterPermission($"worldshops.remote.{name}", this);
            }

            this.Config.WriteObject(WorldShopsSettings.Loaded);

            if (WorldShopsSettings.Loaded.Notification.Enabled)
            {
                BasePlayer.activePlayerList.ForEach(x => x.gameObject.AddComponent <ShopBlock>());
            }
        }