generated from Misaka-SL-Project/TemplatePlugin
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d55e0db
commit 4cd5663
Showing
8 changed files
with
161 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using CommandSystem; | ||
using Exiled.API.Features; | ||
using static BetterMute.EventHandlers.ServerHandlers; | ||
|
||
namespace BetterMute | ||
{ | ||
[CommandHandler(typeof(RemoteAdminCommandHandler))] | ||
public class MuteCommand : ICommand | ||
{ | ||
public string[] Aliases { get; } = { }; | ||
public string Command => "bmute"; | ||
public string Description => "Mute player with configurable duration"; | ||
|
||
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response) | ||
{ | ||
Log.Info(1); | ||
if (Int32.TryParse(arguments.At(0), out int result)) | ||
{ | ||
Log.Info(2); | ||
Player player = Player.Get(result); | ||
Log.Info(3); | ||
player.IsMuted = true; | ||
player.IsIntercomMuted = true; | ||
string userid = player.UserId; | ||
int duration = 1; | ||
if (Int32.TryParse(arguments.At(1), out int result2)) | ||
{ | ||
duration = result2; | ||
} | ||
Log.Info(4); | ||
AddingMuteStatus(userid, duration); | ||
response = $"{player.Nickname} will be muted for {duration} rounds"; | ||
} | ||
else | ||
{ | ||
response = "Please enter player id"; | ||
} | ||
return true; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Exiled.Events.EventArgs; | ||
using Exiled.API.Features; | ||
using System.IO; | ||
|
||
namespace TestingPlugin.EventHandlers | ||
namespace BetterMute.EventHandlers | ||
{ | ||
public class ServerHandlers | ||
{ | ||
private readonly Plugin plugin; | ||
public ServerHandlers(Plugin plugin) => this.plugin = plugin; | ||
private readonly Plugin _plugin; | ||
public ServerHandlers(Plugin plugin) => this._plugin = plugin; | ||
static Dictionary<Player, int> MutedPlayers = new Dictionary<Player, int>(); | ||
public static string path; | ||
|
||
public void OnRoundEnded(RoundEndedEventArgs ev) | ||
{ | ||
foreach (Player player in MutedPlayers.Keys) | ||
{ | ||
if (Player.List.Contains(player)) | ||
{ | ||
if (MutedPlayers[player] > 1) | ||
{ | ||
UpdateMuteStatus(player.UserId, MutedPlayers[player] - 1); | ||
} | ||
else | ||
{ | ||
player.IsMuted = false; | ||
player.IsIntercomMuted = false; | ||
RemoveMuteStatus(player.UserId); | ||
} | ||
} | ||
} | ||
} | ||
public void OnVerified(VerifiedEventArgs ev) | ||
{ | ||
MuteList = GetMuteList(); | ||
Log.Info(ev.Player.UserId); | ||
Log.Info(MuteList[0].Split(' ').ElementAt(0)); | ||
Log.Info(MuteList[1].Split(' ').ElementAt(0)); | ||
if (ev.Player.IsMuted || ev.Player.IsIntercomMuted) | ||
{ | ||
for (int i = 0; i < MuteList.Count(); i++) | ||
{ | ||
if (MuteList[i].Split(' ').First() == ev.Player.UserId) | ||
{ | ||
MutedPlayers.Add(ev.Player, Convert.ToInt32(MuteList[i].Split(' ').ElementAt(1))); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
public static void UpdateMuteStatus(string userid, int duration) | ||
{ | ||
MuteList = GetMuteList(); | ||
for (int i = 0; i < MuteList.Count(); i++) | ||
{ | ||
if (MuteList[i].Split(' ').First() == userid) | ||
{ | ||
MuteList[i] = MuteList[i].Split(' ').First() + " " + duration; | ||
break; | ||
} | ||
} | ||
File.WriteAllLines(path, MuteList); | ||
} | ||
public static void RemoveMuteStatus(string userid) | ||
{ | ||
MuteList = GetMuteList(); | ||
for (int i = 0; i < MuteList.Count(); i++) | ||
{ | ||
if (MuteList[i].Split(' ').First() == userid) | ||
{ | ||
MuteList[i] = ""; | ||
break; | ||
} | ||
} | ||
File.WriteAllLines(path, MuteList); | ||
} | ||
public static void AddingMuteStatus(string userid, int duration) | ||
{ | ||
File.AppendAllText(path, $"\r\n{userid} {duration}"); | ||
MutedPlayers.Add(Player.Get(userid), duration); | ||
} | ||
public static string[] GetMuteList() | ||
{ | ||
return File.ReadAllLines(path); | ||
} | ||
public static string[] MuteList; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Exiled.API.Features; | ||
using System.IO; | ||
using static BetterMute.EventHandlers.ServerHandlers; | ||
|
||
namespace TestingPlugin | ||
namespace BetterMute | ||
{ | ||
using EventHandlers; | ||
public class Plugin : Plugin<Config> | ||
{ | ||
public override string Author { get; } = "Killla"; | ||
public override string Name { get; } = "Template Plugin"; | ||
public override string Prefix { get; } = "TP"; | ||
public override Version RequiredExiledVersion { get; } = new Version(3, 0, 0); | ||
public override string Name { get; } = "Better Mute"; | ||
public override string Prefix { get; } = "BetterMute"; | ||
public override Version RequiredExiledVersion { get; } = new Version(3, 0, 0); | ||
|
||
public PlayerHandlers PlayerHandlers; | ||
public ServerHandlers ServerHandlers; | ||
|
||
|
||
public override void OnEnabled() | ||
{ | ||
PlayerHandlers = new PlayerHandlers(this); | ||
ServerHandlers = new ServerHandlers(this); | ||
Exiled.Events.Handlers.Server.RoundEnded += ServerHandlers.OnRoundEnded; | ||
Exiled.Events.Handlers.Player.Verified += ServerHandlers.OnVerified; | ||
path = Config.DataDir; | ||
if (!Directory.Exists(path)) | ||
{ | ||
Directory.CreateDirectory(path); | ||
} | ||
path = Path.Combine(path, "MuteList.txt"); | ||
if (!File.Exists(path)) | ||
{ | ||
File.Create(path).Close(); | ||
} | ||
MuteList = GetMuteList(); | ||
base.OnEnabled(); | ||
} | ||
public override void OnDisabled() | ||
{ | ||
|
||
Exiled.Events.Handlers.Server.RoundEnded -= ServerHandlers.OnRoundEnded; | ||
Exiled.Events.Handlers.Player.Verified -= ServerHandlers.OnVerified; | ||
base.OnDisabled(); | ||
|
||
} | ||
} | ||
} |