Иконка ресурса

FREE AutoHeal : 1.0.0 1.0.0

Нет прав для скачивания
C#:
using Oxide.Core.Libraries.Covalence;
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using Oxide.Core;
using Oxide.Core.Plugins;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Facepunch;
using Rust;
using Rust.Ai;

namespace Oxide.Plugins
{
    [Info("AutoHeal", "Sashon", "1.0.0")]
    [Description("Heals the player with permission on command with the specified amount of HP.")]

    class AutoHeal : CovalencePlugin
    {
       // static AutoHeal ins;
        private AutoHealConfig _config ;
        private HashSet<string> cooldowns = new HashSet<string>();

        class AutoHealConfig
        {
            [JsonProperty(PropertyName = "PluginConfiguration")]
            public PluginConfiguration pluginConfiguration { get; set; }

            [JsonProperty(PropertyName = "PermissionsConfiguration")]
            public PermissionsConfiguration permissionsConfiguration { get; set; }
        }

        class PluginConfiguration 
        {
            [JsonProperty(PropertyName = "Healing command")]
            public string healingCommand { get; set; }

            [JsonProperty(PropertyName = "Cooldown time per player in seconds (0 = no cooldown)")]
            public int cooldownPerPlayer { get; set; }

            [JsonProperty(PropertyName = "Show healing message to player")]
            public bool showHealingMessageToPlayer { get; set; }

            [JsonProperty(PropertyName = "Show no-permission message to player")]
            public bool showNoPermissionMessageToPlayer { get; set; }
            
        }

        class PermissionsConfiguration
        {
            [JsonProperty(PropertyName = "Default permission name")]
            public string defaultPermissionName { get; set; }
        }

        #region Config
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                _config = Config.ReadObject<AutoHealConfig>();
                if (_config == null) throw new Exception();
                    SaveConfig();
            }
            catch
            {
                PrintError("[AutoHeal] : Your configuration file contains an error. Loading default configuration values.");
                LoadDefaultConfig();
            }
        }

        
        protected override void LoadDefaultConfig() {
            Puts("Loading default config ...");
            _config = new AutoHealConfig()
            {
                pluginConfiguration = new PluginConfiguration()
                {
                    healingCommand = "h",
                    cooldownPerPlayer = 10,
                    showHealingMessageToPlayer = true,
                    showNoPermissionMessageToPlayer = true
                },
                permissionsConfiguration = new PermissionsConfiguration()
                {
                    defaultPermissionName = "use"
                }
            };
        }
        
        protected override void SaveConfig() => Config.WriteObject(_config);
        #endregion

        #region Hooks
        private void Init()
        {
            permission.RegisterPermission("autoheal."+_config.permissionsConfiguration.defaultPermissionName, this);
            AddCovalenceCommand(_config.pluginConfiguration.healingCommand, nameof(HealingCommand));

            Puts("Healing command (config): "+_config.pluginConfiguration.healingCommand);
            Puts("Healing permission (config): "+_config.permissionsConfiguration.defaultPermissionName);
        }
        #endregion

        #region LanguageAPI
        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["PlayerDontHavePermission"] = "You don't have the permission to use this command",
                ["WrongCommandSyntax"] = "Wrong command syntax.\nPlease use like so : /{0} <amout of HP> between 1 and 100",
                ["PlayerOnCooldown"] = "You can't be healed now, wait a bit",
                ["PlayerWasHealed"] = "You were healed of {0} HP"
            }, this);

            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["PlayerDontHavePermission"] = "Vous n'avez pas la permission d'utiliser cette commande",
                ["WrongCommandSyntax"] = "Syntaxe de commande incorrecte. Veuillez utiliser comme ceci : /{0} <quantité de HP> entre 1 et 100",
                ["PlayerOnCooldown"] = "Tu ne peux pas être soigné pour l'instant, attends un peu",
                ["PlayerWasHealed"] = "Vous avez été soigné de {0} HP"
            }, this, "fr");
        }
        #endregion

        #region Functions
        internal void SendMessageToPlayer(IPlayer player, string message, params object [] args)
        {
            string playerMessage = lang.GetMessage(message, this, player.Id);

            if (args.Length == 0)
            {
                player.Message(playerMessage);
            }
            else 
            {
                player.Message(string.Format(playerMessage, args));
            }
        }
        #endregion

        #region Commands
        // Command that heals the player of the amout specified in arg
        private void HealingCommand(IPlayer player, string command, string[] args)
        {
            if (player.IsServer) return;

            if(!player.HasPermission("autoheal."+_config.permissionsConfiguration.defaultPermissionName))
            {
                // Sending or not no-perm message
                if (_config.pluginConfiguration.showNoPermissionMessageToPlayer)
                {
                    SendMessageToPlayer(player, "PlayerDontHavePermission");
                }
                return;
            }
            if (args.Length == 1 && int.TryParse(args[0], out int value) && value > 0 && value <= 100)
            {
                // Checking players cooldown
                if(cooldowns.Contains(player.Id) && _config.pluginConfiguration.cooldownPerPlayer != 0) 
                {
                    SendMessageToPlayer(player, "PlayerOnCooldown");
                    return;
                }
                else
                {
                    // Healing player
                    player.Heal(int.Parse(args[0]));

                    // Setting players cooldown
                    if(_config.pluginConfiguration.cooldownPerPlayer != 0)
                    {
                        cooldowns.Add(player.Id);
                        timer.Once(_config.pluginConfiguration.cooldownPerPlayer, () => cooldowns.Remove(player.Id));
                    }

                    // Sending or not healed message
                    if (_config.pluginConfiguration.showHealingMessageToPlayer)
                    {
                        SendMessageToPlayer(player, "PlayerWasHealed", args[0]);
                    }
                }
            }
            else 
            {
                // Sending wrong syntax message
                SendMessageToPlayer(player, "WrongCommandSyntax", _config.pluginConfiguration.healingCommand);
            }
        }
        #endregion
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху