using System; using UnityEngine; using System.Collections.Generic; using Oxide.Core; using Oxide.Core.Plugins; using Convert = System.Convert; using System.Linq; using Oxide.Game.Rust.Cui; using Rust; namespace Oxide.Plugins { [Info("Lock Barrels", "Julio Juajez", "1.0.2")] [Description("Lock your Barels")] class LockBarrels : RustPlugin { public static LockBarrels Instance; ConfigData configData; class ConfigData { public string Command = "refreshbarrels"; public string PermAdmin = "lockbarrels.admin"; } protected override void LoadDefaultConfig() { configData = new ConfigData(){}; SaveConfig(configData); PrintWarning("New configuration file created."); } private void Init(){ Instance = this; configData = Config.ReadObject(); SaveConfig(configData); permission.RegisterPermission(configData.PermAdmin, this); cmd.AddChatCommand(configData.Command, this, "CmdRefresh"); } private void SaveConfig(ConfigData config) => Config.WriteObject(config, true); private void CmdRefresh(BasePlayer player, string command, string[] args) { if(!permission.UserHasPermission(player.UserIDString, configData.PermAdmin)){ Message(player, "Usage"); return; } NextTick(() => { foreach (var entity in BaseNetworkable.serverEntities.OfType()){ if (entity == null) { continue; } if(isPlayer(entity.OwnerID)){ var barrel = entity as BoxStorage; if(barrel.PrefabName == "assets/prefabs/misc/decor_dlc/storagebarrel/storage_barrel_b.prefab" || barrel.PrefabName == "assets/prefabs/misc/decor_dlc/storagebarrel/storage_barrel_c.prefab"){ barrel.isLockable = true; barrel.SendNetworkUpdate(); barrel.SendNetworkUpdateImmediate(true); } } } Message(player, "Success"); }); } static bool isPlayer(ulong id) => id > 76560000000000000L; private void OnEntitySpawned(BaseNetworkable entity) { if (entity is BoxStorage) { var barrel = entity as BoxStorage; if(barrel.PrefabName == "assets/prefabs/misc/decor_dlc/storagebarrel/storage_barrel_b.prefab" || barrel.PrefabName == "assets/prefabs/misc/decor_dlc/storagebarrel/storage_barrel_c.prefab"){ barrel.isLockable = true; barrel.SendNetworkUpdate(); barrel.SendNetworkUpdateImmediate(true); } return; } } protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { {"Usage", "You do not have permission to use this command"}, {"Success", "Refreshing is done"} }, this); } private string Lang(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args); private void Message(BasePlayer player, string key, params object[] args) { SendReply(player, Lang(key, player.UserIDString, args)); } } }