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 oven", "Julio Juajez", "1.0.3")] [Description("Lock your furnaces and refineries")] class Lockoven : RustPlugin { public static Lockoven Instance; ConfigData configData; class ConfigData { public string Command = "refresh"; public string PermAdmin = "lockoven.admin"; public bool ActivatePermUse = false; public string PermUse = "lockoven.use"; } 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); permission.RegisterPermission(configData.PermUse, 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 UnityEngine.Object.FindObjectsOfType()){ if (entity == null) { continue; } if(isPlayer(entity.OwnerID)){ var oven = entity as BaseOven; oven.isLockable = true; oven.SendNetworkUpdate(); oven.SendNetworkUpdateImmediate(true); } } Message(player, "Success"); }); } static bool isPlayer(ulong id) => id > 76560000000000000L; private void OnEntitySpawned(BaseNetworkable entity) { var oven = entity as BaseOven; if (oven == null){ var ent = entity as BaseLock; if(ent == null){ return; } else { BaseEntity par = ent.GetParentEntity(); if(par is BaseOven){ if (configData.ActivatePermUse) { if (!permission.UserHasPermission(ent.OwnerID.ToString(), configData.PermUse)) { BasePlayer player = BasePlayer.FindByID(ent.OwnerID); var PrefabName = ent.PrefabName; if (player != null) { Message(player, "NoPerm"); var shortname = ""; if(PrefabName == "assets/prefabs/locks/keylock/lock.key.prefab"){ shortname = "lock.key"; } else if(PrefabName == "assets/prefabs/locks/keypad/lock.code.prefab"){ shortname = "lock.code"; } player.inventory.GiveItem(ItemManager.CreateByName(shortname, 1)); } ent.Kill(); return; } } if(par.PrefabName == "assets/prefabs/deployable/furnace/furnace.prefab"){ ent.transform.localPosition = new Vector3(-0.02f, 0.3f, 0.5f); ent.transform.localRotation = Quaternion.Euler(0, 90, 0); } else if(par.PrefabName == "assets/prefabs/deployable/furnace.large/furnace.large.prefab"){ ent.transform.localPosition = new Vector3(0.62f, 1.0f, -0.63f); ent.transform.localRotation = Quaternion.Euler(0, 45, 0); } else if(par.PrefabName == "assets/prefabs/deployable/oil refinery/refinery_small_deployed.prefab"){ ent.transform.localPosition = new Vector3(-0.02f, 1.45f, -0.7f); ent.transform.localRotation = Quaternion.Euler(0, 90, 0); } else if(par.PrefabName == "assets/prefabs/deployable/playerioents/electricfurnace/electricfurnace.deployed.prefab"){ ent.transform.localPosition = new Vector3(0f, 0.2f, 0.3f); ent.transform.localRotation = Quaternion.Euler(0, 90, 0); } else { return; } } } return; } else { if(oven.OwnerID != 0L && isPlayer(oven.OwnerID)){ oven.isLockable = true; oven.SendNetworkUpdate(); oven.SendNetworkUpdateImmediate(true); } } } protected override void LoadDefaultMessages() { lang.RegisterMessages(new Dictionary { {"Usage", "You do not have permission to use this command"}, {"Success", "Refreshing is done"}, {"NoPerm", "You do not have permission to lock this oven"} }, 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)); } } }