C#:
using Newtonsoft.Json;
using System;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Faster Composters", "Tacman", "1.0.0")]
[Description("Control composters speed with permission")]
internal class FasterComposters : RustPlugin
{
private string permName = "fastercomposters.use";
#region Config
static Configuration config;
public class Configuration
{
[JsonProperty(PropertyName = "This is the speed controller, it may take some fine tuning to get the right speed for your server.")]
public int smeltSpeed;
public static Configuration DefaultConfig()
{
return new Configuration
{
smeltSpeed = 10
};
}
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<Configuration>();
if (config == null) LoadDefaultConfig();
SaveConfig();
}
catch (Exception ex)
{
Debug.LogException(ex);
PrintWarning("Creating new configuration file.");
LoadDefaultConfig();
}
}
protected override void LoadDefaultConfig() => config = Configuration.DefaultConfig();
protected override void SaveConfig() => Config.WriteObject(config);
#endregion
#region Hooks
void Init()
{
permission.RegisterPermission(permName, this);
}
void OnEntitySpawned(Composter c)
{
if (c == null) return;
if (config == null) return;
if (c.OwnerID == 0) return;
if (!permission.UserHasPermission(c.OwnerID.ToString(), permName)) return;
c.smeltSpeed = config.smeltSpeed;
}
void OnServerInitialized(bool initial)
{
foreach (var c in BaseNetworkable.serverEntities.OfType<Composter>())
{
if (permission.UserHasPermission(c.OwnerID.ToString(), permName))
c.smeltSpeed = config.smeltSpeed;
}
}
#endregion
}
}