using System.Collections.Generic; using Newtonsoft.Json; namespace Oxide.Plugins { [Info("Block Item Backpack", "YaMang -w-", "1.0.3")] [Description("YaMang-w-")] internal class BlockItemBackpack : RustPlugin { #region Hook private void OnItemAddedToContainer(ItemContainer container, Item item) { if(container == null || container.parent == null || !container.parent.info.shortname.Contains("backpack") || item == null) return; var player = container.parent.parent.playerOwner; if (player == null) return; if (_config.blockSettings.blockcategory.Contains(item.info.category.ToString())) { PrintToChat(player, $"{Lang("BlockItem", item.info.category.ToString())}"); player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp); return; } if (!_config.blockSettings.blockItems.ContainsKey(item.info.shortname)) return; var find = false; if (_config.blockSettings.blockItems.Count == 0) find = true; else if (_config.blockSettings.blockItems.Count == 1 && _config.blockSettings.blockItems[item.info.shortname][0] == 0) find = true; else find = _config.blockSettings.blockItems[item.info.shortname].Contains(item.skin); if (find) { player.GiveItem(item, BaseEntity.GiveItemReason.PickedUp); string itemname = ""; if (string.IsNullOrEmpty(item.name)) itemname = item.info.displayName.english; else itemname = item.name; PrintToChat(player, $"{Lang("BlockItem", itemname)}"); } } #endregion #region Config private ConfigData _config; private class ConfigData { [JsonProperty(PropertyName = "Block Items Settings")] public BlockSettings blockSettings { get; set; } public Core.VersionNumber Version { get; set; } } protected override void LoadConfig() { base.LoadConfig(); _config = Config.ReadObject(); if (_config.Version < Version) UpdateConfigValues(); Config.WriteObject(_config, true); } protected override void LoadDefaultConfig() => _config = GetBaseConfig(); private ConfigData GetBaseConfig() { return new ConfigData { blockSettings = new BlockSettings() { blockItems = new Dictionary>() { { "wood", new List() { 0 } } }, blockcategory = new List { "Weapon" } }, Version = Version }; } public class BlockSettings { [JsonProperty(PropertyName = "Disallowed item shortname,skin (0 - block all shortname)")] public Dictionary> blockItems { get; set; } [JsonProperty(PropertyName = "Disallowed item categories")] public List blockcategory { get; set; } } protected override void SaveConfig() => Config.WriteObject(_config, true); private void UpdateConfigValues() { PrintWarning("Config update detected! Updating config values..."); _config.Version = Version; PrintWarning("Config update completed!"); } #endregion #region Lang protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { { "BlockItem", "{0} items cannot be placed in the bag." } }, this); } private string Lang(string key, params object[] args) { return string.Format(lang.GetMessage(key, this), args); } #endregion } }