Skip to content

Commit

Permalink
Yo it's working
Browse files Browse the repository at this point in the history
  • Loading branch information
Misaka-ZeroTwo committed Nov 15, 2021
1 parent d55e0db commit 4cd5663
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 67 deletions.
11 changes: 5 additions & 6 deletions TestingPlugin.csproj → BetterMute.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{B3E18056-A283-4430-96CE-696D878C7BAC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestingPlugin</RootNamespace>
<AssemblyName>TestingPlugin</AssemblyName>
<RootNamespace>BetterMute</RootNamespace>
<AssemblyName>BetterMute</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
Expand All @@ -33,10 +33,10 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\Downloads\Dev\Assembly-CSharp-firstpass.dll</HintPath>
<HintPath>..\..\..\Downloads\Dev\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-Publicized">
<HintPath>..\..\..\..\Downloads\Dev\Assembly-CSharp-Publicized.dll</HintPath>
<HintPath>..\..\..\Downloads\Dev\Assembly-CSharp-Publicized.dll</HintPath>
</Reference>
<Reference Include="CommandSystem.Core">
<HintPath>..\..\..\Downloads\Dev\CommandSystem.Core.dll</HintPath>
Expand Down Expand Up @@ -81,9 +81,8 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Commands\Test.cs" />
<Compile Include="Commands\MuteCommand.cs" />
<Compile Include="Config.cs" />
<Compile Include="EventHandlers\PlayerHandlers.cs" />
<Compile Include="EventHandlers\ServerHandlers.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
2 changes: 1 addition & 1 deletion TestingPlugin.sln → BetterMute.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30907.101
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestingPlugin", "TestingPlugin.csproj", "{B3E18056-A283-4430-96CE-696D878C7BAC}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BetterMute", "BetterMute.csproj", "{B3E18056-A283-4430-96CE-696D878C7BAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
42 changes: 42 additions & 0 deletions Commands/MuteCommand.cs
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;
}
}
}
25 changes: 0 additions & 25 deletions Commands/Test.cs

This file was deleted.

9 changes: 7 additions & 2 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
using System.Text;
using System.Threading.Tasks;
using Exiled.API.Interfaces;
using System.IO;
using Exiled.API.Features;

namespace TestingPlugin

namespace BetterMute
{
public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;
public bool IsEnabled { get; set; } = true;

public string DataDir = Path.Combine(Paths.Plugins, "BetterMute");
}
}
16 changes: 0 additions & 16 deletions EventHandlers/PlayerHandlers.cs

This file was deleted.

88 changes: 83 additions & 5 deletions EventHandlers/ServerHandlers.cs
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;
}

}
35 changes: 23 additions & 12 deletions Plugin.cs
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();

}
}
}

0 comments on commit 4cd5663

Please sign in to comment.