Пример #1
0
 /// <summary>
 /// Initializes a new instance of the WebRequest class
 /// </summary>
 /// <param name="url"></param>
 /// <param name="callback"></param>
 /// <param name="owner"></param>
 public WebRequest(string url, Action <int, string> callback, Plugin owner)
 {
     Url                = url;
     Callback           = callback;
     Owner              = owner;
     removedFromManager = Owner?.OnRemovedFromManager.Add(owner_OnRemovedFromManager);
 }
Пример #2
0
 public void Reset(float delay = -1f, int repetitions = 1)
 {
     lock (Timer.Lock)
     {
         if (delay >= 0f)
         {
             this.Delay = delay;
         }
         else
         {
             delay = this.Delay;
         }
         this.Repetitions = repetitions;
         this.ExpiresAt   = Timer.Oxide.Now + delay;
         if (!this.Destroyed)
         {
             this.Remove();
         }
         else
         {
             this.Destroyed = false;
             Plugin owner = this.Owner;
             if (owner != null)
             {
                 this.removedFromManager = owner.OnRemovedFromManager.Add(new Action <Plugin, PluginManager>(this.OnRemovedFromManager));
             }
         }
         this.timer.InsertTimer(this, false);
     }
 }
Пример #3
0
            /// <summary>
            /// Resets the timer optionally changing the delay setting a number of repetitions
            /// </summary>
            /// <param name="delay">The new delay between repetitions</param>
            /// <param name="repetitions">Number of repetitions before being destroyed</param>
            public void Reset(float delay = -1, int repetitions = 1)
            {
                lock (Lock)
                {
                    if (delay < 0)
                    {
                        delay = Delay;
                    }
                    else
                    {
                        Delay = delay;
                    }

                    Repetitions = repetitions;
                    ExpiresAt   = Oxide.Now + delay;
                    if (Destroyed)
                    {
                        Destroyed = false;
                        Plugin owner = Owner;
                        if (owner != null)
                        {
                            removedFromManager = owner.OnRemovedFromManager.Add(OnRemovedFromManager);
                        }
                    }
                    else
                    {
                        Remove();
                    }
                    timer.InsertTimer(this);
                }
            }
Пример #4
0
        public void AddConsoleCommand(string name, Plugin plugin, string callback_name)
        {
            // Hook the unload event
            if (removedFromManager == null)
            {
                removedFromManager = plugin?.OnRemovedFromManager.Add(plugin_OnRemovedFromManager);
            }

            var            full_name = name.Trim();
            ConsoleCommand cmd;

            if (consoleCommands.TryGetValue(full_name, out cmd))
            {
                // This is a custom command which was already registered by another plugin
                var previous_plugin_name = cmd.PluginCallbacks[0].Plugin?.Name ?? "An unknown plugin";
                var new_plugin_name      = plugin?.Name ?? "An unknown plugin";
                var msg = $"{new_plugin_name} has replaced the '{name}' console command previously registered by {previous_plugin_name}";
                Interface.Oxide.LogWarning(msg);
                consoleCommands.Remove(full_name);
            }

            // The command either does not already exist or is replacing a previously registered command
            cmd = new ConsoleCommand(full_name);
            cmd.AddCallback(plugin, callback_name);

            // Add the new command to collections
            consoleCommands[full_name] = cmd;
        }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the TimerInstance class
 /// </summary>
 /// <param name="repetitions"></param>
 /// <param name="delay"></param>
 /// <param name="callback"></param>
 /// <param name="owner"></param>
 public TimerInstance(int repetitions, float delay, Action callback, Plugin owner)
 {
     Repetitions        = repetitions;
     Delay              = delay;
     Callback           = callback;
     nextrep            = Interface.Oxide.Now + delay;
     Owner              = owner;
     removedFromManager = owner?.OnRemovedFromManager.Add(OnRemovedFromManager);
 }
Пример #6
0
 internal void Load(Timer timer, int repetitions, float delay, Action callback, Plugin owner)
 {
     this.timer  = timer;
     Repetitions = repetitions;
     Delay       = delay;
     Callback    = callback;
     ExpiresAt   = Oxide.Now + delay;
     Owner       = owner;
     Destroyed   = false;
     if (owner != null)
     {
         removedFromManager = owner.OnRemovedFromManager.Add(OnRemovedFromManager);
     }
 }
Пример #7
0
 internal void Load(Timer timer, int repetitions, float delay, Action callback, Plugin owner)
 {
     this.timer       = timer;
     this.Repetitions = repetitions;
     this.Delay       = delay;
     this.Callback    = callback;
     this.ExpiresAt   = Timer.Oxide.Now + delay;
     this.Owner       = owner;
     this.Destroyed   = false;
     if (owner != null)
     {
         this.removedFromManager = owner.OnRemovedFromManager.Add(new Action <Plugin, PluginManager>(this.OnRemovedFromManager));
     }
 }
Пример #8
0
            public WebRequest(string url, Action <int, string> callback, Plugin owner)
            {
                Event.Callback <Plugin, PluginManager> callback1;
                this.Url      = url;
                this.Callback = callback;
                this.Owner    = owner;
                Plugin plugin = this.Owner;

                if (plugin != null)
                {
                    callback1 = plugin.OnRemovedFromManager.Add(new Action <Plugin, PluginManager>(this.owner_OnRemovedFromManager));
                }
                else
                {
                    callback1 = null;
                }
                this.removedFromManager = callback1;
            }
Пример #9
0
        public void AddChatCommand(string name, Plugin plugin, string callback_name)
        {
            var         command_name = name.ToLowerInvariant();
            ChatCommand cmd;

            if (chatCommands.TryGetValue(command_name, out cmd))
            {
                var previous_plugin_name = cmd.Plugin?.Name ?? "an unknown plugin";
                var new_plugin_name      = plugin?.Name ?? "An unknown plugin";
                var msg = $"{new_plugin_name} has replaced the '{command_name}' chat command previously registered by {previous_plugin_name}";
                Interface.Oxide.LogWarning(msg);
            }
            cmd = new ChatCommand(command_name, plugin, callback_name);

            // Add the new command to collections
            chatCommands[command_name] = cmd;

            // Hook the unload event
            if (removedFromManager == null)
            {
                removedFromManager = plugin?.OnRemovedFromManager.Add(plugin_OnRemovedFromManager);
            }
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the WebRequest class
 /// </summary>
 /// <param name="url"></param>
 /// <param name="callback"></param>
 /// <param name="owner"></param>
 public WebRequest(string url, Action<int, string> callback, Plugin owner)
 {
     URL = url;
     Callback = callback;
     Owner = owner;
     removedFromManager = Owner?.OnRemovedFromManager.Add(owner_OnRemovedFromManager);
 }