C#:
//#define Debug
using ConVar;
using System.Collections.Generic;
namespace Oxide.Plugins
{
[Info("MuteChat", "kaucsenta", "1.0.0")]
[Description("Mute server and voice chat")]
internal class MuteChat : RustPlugin
{
public PluginConfig config;
public List<string> VoiceMuteFilter = new List<string>();
private object OnPlayerChat(BasePlayer player, string message, Chat.ChatChannel channel)
{
if(permission.UserHasPermission(player.UserIDString, "mutechat.mutechat") && !message.StartsWith("/"))
{
if(config.EnableMutedChatNotification)
{
SendReply(player, LangFormatter("ChatMuted", player.UserIDString));
}
#if Debug
Puts("OnPlayerChat works! - Muted");
#endif
return false;
}
#if Debug
Puts("OnPlayerChat works! - Notmuted");
#endif
return null;
}
private object OnPlayerVoice(BasePlayer player, System.Byte[] data)
{
if (permission.UserHasPermission(player.UserIDString, "mutechat.mutevoice"))
{
if (config.EnableMutedVoiceNotification && !VoiceMuteFilter.Contains(player.UserIDString))
{
SendReply(player, LangFormatter("VoiceMuted", player.UserIDString));
VoiceMuteFilter.Add(player.UserIDString);
timer.Once(30f, () => { VoiceMuteFilter.Remove(player.UserIDString); });
}
#if Debug
Puts("OnPlayerVoice works! - Muted");
#endif
return false;
}
else
{
#if Debug
Puts("OnPlayerVoice works! - Notmuted");
#endif
return null;
}
}
private void Init()
{
LoadVariables();
permission.RegisterPermission("mutechat.mutechat", this);
permission.RegisterPermission("mutechat.mutevoice", this);
}
private void LoadVariables()
{
LoadConfigVariables();
SaveConfig(config);
}
private void LoadConfigVariables()
{
config = Config.ReadObject<PluginConfig>();
}
public class PluginConfig
{
public bool EnableMutedVoiceNotification = false;
public bool EnableMutedChatNotification = false;
}
protected override void LoadDefaultConfig()
{
Puts("Creating a new config file");
config = new PluginConfig
{
EnableMutedVoiceNotification = false,
EnableMutedChatNotification = false,
};
SaveConfig(config);
}
void SaveConfig(PluginConfig config, string filename = null) => Config.WriteObject(config, true, filename);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["ChatMuted"] = "Chat is muted, you have no permission to use the chat, only for commands",
["VoiceMuted"] = "Voice chat is muted, you have no permission to use it."
}, this);
}
private string LangFormatter(string key, string id = null, params object[] args) => string.Format(lang.GetMessage(key, this, id), args);
}
}