C#:
using System;
using System.Collections.Generic;
using Oxide.Core;
using Newtonsoft.Json;
using System.Text;
using System.Text.RegularExpressions;
namespace Oxide.Plugins {
[Info("SimpleRules", "P4R4NORM4L", "1.0.1")]
[Description("This is a simple rules plugin!")]
public class SimpleRules : RustPlugin {
#region Permissions
const string usePerm = "simplerules.use";
readonly StringBuilder _sb = new StringBuilder();
#endregion
#region Initialization
private void Init() {
permission.RegisterPermission(usePerm, this);
}
#endregion
#region Config
Configuration config;
class Configuration {
[JsonProperty(PropertyName = "Chat Icon (SteamID64)")]
public ulong ChatIcon = 0;
[JsonProperty(PropertyName = "Use Chat Prefix")]
public bool UsePrefix = true;
}
protected override void LoadConfig() {
base.LoadConfig();
try {
config = Config.ReadObject<Configuration>();
if (config == null) throw new Exception();
}
catch {
Config.WriteObject(config, false, $"{Interface.Oxide.ConfigDirectory}/{Name}.jsonError");
PrintError("The configuration file contains an error and has been replaced with a default config.\nThe error configuration file was saved in the .jsonError extension");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => config = new Configuration();
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages() {
var compiledLangs = new Dictionary<string, Dictionary<string, string>>();
foreach (var line in GetMessages()) {
foreach (var translate in line.Value) {
if (!compiledLangs.ContainsKey(translate.Key)) {
compiledLangs[translate.Key] = new Dictionary<string, string>();
}
compiledLangs[translate.Key][line.Key] = translate.Value;
}
}
foreach (var cLangs in compiledLangs) {
lang.RegisterMessages(cLangs.Value, this, cLangs.Key);
}
}
Dictionary<string, Dictionary<string, string>> GetMessages() {
return new Dictionary<string, Dictionary<string, string>> {
{
"No Permission", new Dictionary<string, string>() {
{
"en", "You do not have permission to run this command!"
}
,
}
}
, {
"Rules", new Dictionary<string, string>() {
{
"en", "#1 No slurs, racism or excessive toxicity! \n#2 No cheating or exploiting! \n#3 Respect the staff! \n#4 No doxing! \n#5 No griefing bases (read description for more details) \n#6 Zerging is prohibited under the following guidelines: \n- Only 6 players allowed on a team! \n- Only 6 owners of bags/beds allowed in a base/compound (same owners as on the TC). \n- Max raiding, roaming, and PVP groups of up to 6 players! \n\n*We have a strict 6 player group limit! No exceptions are made for allies, hotels, friends, other smaller groups. *Building next to your ally and helping defend is not allowed. We suggest building away from your ally to avoid any issues."
}
,
}
}
, {
"Prefix", new Dictionary<string, string>() {
{
"en", "<color=#55aaff>[Server Rules]</color> \n"
}
,
}
}
,
}
;
}
string _(string source) => source.Contains(">") ? Regex.Replace(source, "<.*?>", string.Empty) : source;
string msg(string key, string id = null, params object[] args) {
_sb.Length = 0;
if (config.UsePrefix && id != "server_console" && id != null) {
_sb.Append(lang.GetMessage("Prefix", this, id));
}
_sb.Append(id == "server_console" || id == null ? _(lang.GetMessage(key, this, id)) : lang.GetMessage(key, this, id));
return args.Length > 0 ? string.Format(_sb.ToString(), args) : _sb.ToString();
}
#endregion
#region Commands
[ChatCommand("rules")]
void RulesCommand(BasePlayer player) {
if (!permission.UserHasPermission(player.UserIDString, usePerm)) {
Player.Message(player, msg("No Permission", player.UserIDString), config.ChatIcon);
}
else Player.Message(player, msg("Rules", player.UserIDString), config.ChatIcon);
}
#endregion
}
}