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

FREE BetterPaintballOveralls : 1.2.5 1.2.5

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

namespace Oxide.Plugins 

{
    [Info("BetterPaintballOveralls", "Kaehmper", "1.2.5")]
    [Description("Allows equipping specific items while wearing a paintball overall.")]
    public class BetterPaintballOveralls : RustPlugin
    { 
        #region Fields

        private ConfigData _config;
        
        private const string PERMISSION_ADMIN = "betterpaintballoveralls.admin"; 
        private const string PAINTBALL_SUIT_SHORTNAME = "paintballoveralls.suit";

        #endregion

        #region Configuration

        private class ConfigData
        {
            [JsonProperty(PropertyName = "Allowed Items (Shortnames)")]
            public List<string> AllowedItemsWhileWearingPaintballOveralls { get; set; } = new List<string> { "mask.bandana" };
        }

        protected override void LoadConfig()
        {
            base.LoadConfig();
            try
            {
                _config = Config.ReadObject<ConfigData>();
                if (_config == null) throw new JsonException();
            }
            catch
            {
                Puts("Config File not found. Loading default config.");
                LoadDefaultConfig();
            }
        }  

        protected override void LoadDefaultConfig()
        {
            _config = new ConfigData();
        }

        protected override void SaveConfig()
        {
            Config.WriteObject(_config, true);
        }

        #endregion

        #region Localization

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["NoPermission"] = "You do not have permission to use this command.",
                ["SyntaxError"] = "Invalid syntax. Use: /pb <add|remove> <itemshortname>",
                ["ItemAdded"] = "Item '{0}' has been added to the allowed list.",
                ["ItemAlreadyExists"] = "Item '{0}' is already in the list.",
                ["ItemRemoved"] = "Item '{0}' has been removed from the allowed list.",
                ["ItemNotFound"] = "Item '{0}' was not found in the list.",
				["InvalidItem"] = "Item '{0}' does not exist. Please check the shortname."
            }, this);

            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["NoPermission"] = "Du hast keine Berechtigung, diesen Befehl zu verwenden.",
                ["SyntaxError"] = "Ungültige Syntax. Benutze: /pb <add|remove> <itemshortname>",
                ["ItemAdded"] = "Item '{0}' wurde zur Konfiguration hinzugefügt.",
                ["ItemAlreadyExists"] = "Item '{0}' ist bereits in der Konfiguration vorhanden.",
                ["ItemRemoved"] = "Item '{0}' wurde aus der Konfiguration entfernt.",
				["ItemNotFound"] = "Item '{0}' wurde in Konfiguration nicht gefunden.",
                ["InvalidItem"] = "Der Gegenstand '{0}' existiert nicht. Bitte prüfe den Shortname."
            }, this, "de");
        }

        #endregion

        #region Plugin Hooks

        private void Init()
        {
            permission.RegisterPermission(PERMISSION_ADMIN, this);
        }
        
        private object CanWearItem(PlayerInventory inventory, Item item, int targetSlot)
        {
            if (inventory?.baseEntity == null || item?.info?.ItemModWearable == null) 
                return null;

            ItemModWearable targetWearable = item.info.ItemModWearable;
            bool allowedOverrideFound = false;

            foreach (Item wornItem in inventory.containerWear.itemList)
            {
                if (wornItem == item) continue;

                ItemModWearable wornWearable = wornItem.info.ItemModWearable;
                if (wornWearable == null) continue;
                
                bool vanillaConflicts = !targetWearable.CanExistWith(wornWearable);

                if (vanillaConflicts)
                {
                    
                    bool isTargetOveralls = IsOveralls(item.info.shortname);
                    bool isWornOveralls = IsOveralls(wornItem.info.shortname);

                    if (isTargetOveralls || isWornOveralls)
                    {
                        string otherItemShortname = isTargetOveralls ? wornItem.info.shortname : item.info.shortname;
                        
                        if (IsAllowed(otherItemShortname))
                        {
                            allowedOverrideFound = true;
                            continue;
                        }
                    }
                    
                    return null; 
                }
            }
            
            if (allowedOverrideFound)
            {
                return true;
            }
            
            return null;
        }

        #endregion

        #region Commands
        
        [Command("pb")]
        private void ChatCmdPb(IPlayer player, string command, string[] args)
        {
            if (!player.HasPermission(PERMISSION_ADMIN))
            {
                player.Reply(Lang("NoPermission", player.Id));
                return;
            }

            if (args == null || args.Length < 2)
            {
                player.Reply(Lang("SyntaxError", player.Id));
                return;
            }

            string subCommand = args[0].ToLower();
            string itemShortname = args[1].ToLower();

            switch (subCommand)
            {
                case "add":
                    
                    if (ItemManager.FindItemDefinition(itemShortname) == null)
                    {
                        player.Reply(Lang("InvalidItem", player.Id, itemShortname));
                        return;
                    }

                    if (_config.AllowedItemsWhileWearingPaintballOveralls.Contains(itemShortname))
                    {
                        player.Reply(Lang("ItemAlreadyExists", player.Id, itemShortname));
                    }
					
                    else
                    {
                        _config.AllowedItemsWhileWearingPaintballOveralls.Add(itemShortname);
                        SaveConfig();
                        player.Reply(Lang("ItemAdded", player.Id, itemShortname));
                    }
                    break;

                case "remove":
					
					if (ItemManager.FindItemDefinition(itemShortname) == null)
                    {
                        player.Reply(Lang("InvalidItem", player.Id, itemShortname));
                        return;
                    }
					
                    if (_config.AllowedItemsWhileWearingPaintballOveralls.Remove(itemShortname))
                    {
                        SaveConfig();
                        player.Reply(Lang("ItemRemoved", player.Id, itemShortname));
                    }
					
                    else
                    {
                        player.Reply(Lang("ItemNotFound", player.Id, itemShortname));
                    }
                    break;

                default:
                    player.Reply(Lang("SyntaxError", player.Id));
                    break;
            }
        }

        #endregion

        #region Helpers

        private bool IsOveralls(string shortname)
        {
            return string.Equals(shortname, PAINTBALL_SUIT_SHORTNAME, StringComparison.OrdinalIgnoreCase);
        }

        private bool IsAllowed(string shortname)
        {
            return _config.AllowedItemsWhileWearingPaintballOveralls.Exists(x => x.Equals(shortname, StringComparison.OrdinalIgnoreCase));
        }

        private string Lang(string key, string userId = null, params object[] args)
        {
            return string.Format(lang.GetMessage(key, this, userId), args);
        }

        #endregion
    }
}

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