Skip to content

Commit

Permalink
Added persistant mute options
Browse files Browse the repository at this point in the history
removed unused class

Change some config
  • Loading branch information
Antoniofo committed Jul 31, 2024
1 parent 8fae8ea commit 53fc026
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 94 deletions.
8 changes: 7 additions & 1 deletion AudioPlayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,9 +35,9 @@
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Compile Include="FakeConnection.cs" />
<Compile Include="Config.cs" />
<Compile Include="Mute.cs" />
<Compile Include="PlayerRepository.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="PlaySound.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down Expand Up @@ -78,6 +80,9 @@
<Reference Include="Exiled.Permissions, Version=8.11.0.0, Culture=neutral, processorArchitecture=AMD64">
<HintPath>packages\EXILEDOFFICIAL.8.11.0\lib\net48\Exiled.Permissions.dll</HintPath>
</Reference>
<Reference Include="LiteDB, Version=5.0.21.0, Culture=neutral, PublicKeyToken=4ee40123013c9f27, processorArchitecture=MSIL">
<HintPath>packages\LiteDB.5.0.21\lib\net45\LiteDB.dll</HintPath>
</Reference>
<Reference Include="Mirror">
<HintPath>$(EXILED_REFERENCES)\Mirror.dll</HintPath>
</Reference>
Expand All @@ -92,6 +97,7 @@
<HintPath>.\lib\SCPSLAudioApi.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Numerics" />
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(EXILED_REFERENCES)\UnityEngine.dll</HintPath>
Expand Down
16 changes: 7 additions & 9 deletions Config.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using Exiled.API.Interfaces;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Exiled.API.Interfaces;
using System.IO;

namespace AudioPlayer
{
Expand All @@ -13,17 +9,19 @@ public class Config : IConfig
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;

public string AudioFilePath { get; set; } = "/home/container/.config/EXILED/Configs/audio";
public string AudioFilePath { get; set; } = Path.Combine(Exiled.API.Features.Paths.Configs, "audio");

public bool PlayMtfSound { get; set; } = true;
public bool PlayMtfSound { get; set; } = false;

public string MtfSoundFilePath {get; set;} = "mtf.ogg";

public bool PlayChaosSound { get; set; } = true;
public bool PlayChaosSound { get; set; } = false;

public string ChaosSoundFilePath {get; set;} = "chaos.ogg";

[Description("Do not put over 100 because it could break the VoiceChat for everyplayer and they'll have to restart SL")]
public float Volume {get; set;} = 20f;

public string DatabaseFilePath { get; set; } = Path.Combine(Exiled.API.Features.Paths.Configs, "audio/audioplayers.db");
}
}
30 changes: 0 additions & 30 deletions FakeConnection.cs

This file was deleted.

35 changes: 27 additions & 8 deletions Mute.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using CommandSystem;
using CommandSystem;
using Exiled.API.Features;
using System;

Expand Down Expand Up @@ -28,16 +28,35 @@ protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSe
return false;
}
string plyID = ply.UserId;
if (Plugin.instance.MutedAnnounce.Contains(plyID))
using (var playerRepo = new PlayerRepository(Plugin.instance.Config.DatabaseFilePath))
{
Plugin.instance.MutedAnnounce.Remove(plyID);
PlayerDB playerdb = playerRepo.GetPlayerByUserId(plyID);
if (playerdb != null)
{
if (playerdb.Mute == 2)
{
Log.Info(playerdb.Mute);
playerdb.Mute = 1;
playerRepo.UpdatePlayer(playerdb);
Plugin.instance.MutedAnnounce.Remove(plyID);

}
else
{
playerdb.Mute = 2;
playerRepo.UpdatePlayer(playerdb);
Plugin.instance.MutedAnnounce.Add(plyID);
}
}
else
{
playerRepo.InsertPlayer(new PlayerDB() { UserId = plyID, Mute = 2 });
Plugin.instance.MutedAnnounce.Add(plyID);
}
playerdb = playerRepo.GetPlayerByUserId(plyID);
response = playerdb.Mute == 2 ? "You have muted the Facility Announce" : "You have unmuted the Facility Announce";

}
else
{
Plugin.instance.MutedAnnounce.Add(plyID);
}
response = Plugin.instance.MutedAnnounce.Contains(plyID) ? "You have muted the Facility Announce": "You have unmuted the Facility Announce";
return true;
}
}
Expand Down
14 changes: 4 additions & 10 deletions PlaySound.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
using System;
using System.IO;
using CommandSystem;
using Exiled.API.Features;
using CommandSystem;
using Exiled.Permissions.Extensions;
using SCPSLAudioApi.AudioCore;
using UnityEngine;
using MapGeneration;
using PlayerRoles;
using RemoteAdmin;
using System.Linq;
using System;
using System.Collections.Generic;
using Mirror;
using System.IO;
using System.Linq;

namespace AudioPlayer

Expand Down
59 changes: 59 additions & 0 deletions PlayerRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using LiteDB;
using System;
using System.IO;


namespace AudioPlayer
{
public class PlayerRepository : IDisposable
{
private readonly LiteDatabase _db;

public PlayerRepository(string databasePath)
{
var directory = Path.GetDirectoryName(databasePath);
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}

_db = new LiteDatabase(databasePath);

var players = _db.GetCollection<PlayerDB>("t_players");
players.EnsureIndex(x => x.UserId, true);

}

public PlayerDB GetPlayerByUserId(string userId)
{
var players = _db.GetCollection<PlayerDB>("t_players");
var player = players.FindOne(x => x.UserId == userId);
return player;
}

public void InsertPlayer(PlayerDB player)
{
var players = _db.GetCollection<PlayerDB>("t_players");
players.Insert(player);
}

public void UpdatePlayer(PlayerDB player)
{
var players = _db.GetCollection<PlayerDB>("t_players");
players.Update(player);
}

public void Dispose()
{
_db.Dispose();
}
}

public class PlayerDB
{
public int Id { get; set; }
public string UserId { get; set; }
public int Mute { get; set; }
}

}
Loading

0 comments on commit 53fc026

Please sign in to comment.