C#:
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Collections;
using System.Globalization;
using System.Linq;
using ConVar;
namespace Oxide.Plugins
{
[Info("ApartmentModifier", "Khan", "1.0.0")]
[Description("Modifies the apartments monument settings")]
public class ApartmentModifier : RustPlugin
{
private static PluginConfig _config;
private class PluginConfig
{
[JsonProperty("Admin Apartment Bypass, Should admins be able to bypass apartment authorization checks")]
public bool AdminApartmentBypass = false;
[JsonProperty("Admin Apartment Noclip, Should admins be able to noclip in apartments")]
public bool AdminApartmentNoclip = true;
[JsonProperty("Enable Invisible Blocker, Should an invisible wall prevent guests from entering apartments that they don't have access to")]
public bool ApartmentInvisibleBlocker = true;
[JsonProperty("Allow combat inside apartment rooms outside of the break-in period")]
public bool AllowCombatOutsideBreakIn = true;
[JsonProperty("Break-In Duration (Seconds), How long a player needs to hold the break in interaction on an apartment door with a master key")]
public float BreakInSeconds = 30f;
[JsonProperty("Eviction Delay (Seconds), How long should we wait before evicting a player from their apartment if they don't pay rent")]
public float ApartmentEvictionDelay = 86400f;
[JsonProperty("How much scrap the apartment security NPC charges for a master key")]
public int MasterKeyPrice = 1000;
[JsonProperty("Free Rent Time (Hours) so players don't see 'Eviction' vital right after renting an apartment")]
public float ApartmentFreeRentHours = 4f;
[JsonProperty("Intruder Authorization Duration (Seconds), How long a player stays authorized on an apartment room after breaking in with a master key")]
public float IntruderAuthSeconds = 300f;
[JsonProperty("Rent Scaling Multiplier, Should the rent scale based on the items you have stored inside your apartment")]
public float RentScaling = 0.0f;
[JsonProperty("Security NPC Door Open Time (Seconds), How long should the apartment security NPC keep the door open for after being paid")]
public float ApartmentSecurityAccessTime = 300f;
public Dictionary<string, object> ToDictionary() => JsonConvert.DeserializeObject<Dictionary<string, object>>(JsonConvert.SerializeObject(this));
}
protected override void LoadDefaultConfig()
{
_config = new PluginConfig();
SaveConfig();
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<PluginConfig>();
if (_config == null)
{
LoadDefaultConfig();
PrintError("Config was NULL, restoring defaults.");
}
if (!_config.ToDictionary().Keys.SequenceEqual(Config.ToDictionary(x => x.Key, x => x.Value).Keys))
{
PrintWarning("Configuration appears to be outdated; updating and saving");
SaveConfig();
}
}
catch (Exception ex)
{
PrintError($"Config file corrupt!\n{ex}");
}
}
protected override void SaveConfig() => Config.WriteObject(_config, true);
private void OnServerInitialized()
{
bool changed =
ApartmentCommands.adminapartmentbypass != _config.AdminApartmentBypass ||
ApartmentCommands.adminapartmentnoclip != _config.AdminApartmentNoclip ||
ApartmentCommands.apartmentinvisibleblocker != _config.ApartmentInvisibleBlocker ||
ApartmentCommands.allowcombatoutsideofbreakin != _config.AllowCombatOutsideBreakIn ||
ApartmentCommands.breakinseconds != _config.BreakInSeconds ||
ApartmentCommands.apartmentevictiondelay != _config.ApartmentEvictionDelay ||
ApartmentCommands.masterkeyprice != _config.MasterKeyPrice ||
ApartmentCommands.apartmentfreerenthours != _config.ApartmentFreeRentHours ||
ApartmentCommands.intruderauthseconds != _config.IntruderAuthSeconds ||
ApartmentCommands.rentscaling != _config.RentScaling ||
ApartmentCommands.apartmentsecurityaccesstime != _config.ApartmentSecurityAccessTime;
if (!changed) return;
ApartmentCommands.adminapartmentbypass = _config.AdminApartmentBypass;
ApartmentCommands.adminapartmentnoclip = _config.AdminApartmentNoclip;
ApartmentCommands.apartmentinvisibleblocker = _config.ApartmentInvisibleBlocker;
ApartmentCommands.allowcombatoutsideofbreakin = _config.AllowCombatOutsideBreakIn;
ApartmentCommands.breakinseconds = _config.BreakInSeconds;
ApartmentCommands.apartmentevictiondelay = _config.ApartmentEvictionDelay;
ApartmentCommands.masterkeyprice = _config.MasterKeyPrice;
ApartmentCommands.apartmentfreerenthours = _config.ApartmentFreeRentHours;
ApartmentCommands.intruderauthseconds = _config.IntruderAuthSeconds;
ApartmentCommands.rentscaling = _config.RentScaling;
ApartmentCommands.apartmentsecurityaccesstime = _config.ApartmentSecurityAccessTime;
Server.Command("server.writecfg");
}
private void Unload()
{
_config = null;
}
}
}