Skip to content

Commit

Permalink
3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
terminator-97 committed Sep 4, 2021
1 parent 6a9c4b5 commit ac042a2
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 61 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ This is the list of SCPUtils features with a brief description, i recomend to re
- **Team protection:** Editing configs you can set protection to the teams you want against the teams you want on specific zones or entire map.
- **SCP-096 Target:** Players gets notified via hint when they become a SCP-096 Target.
- **Last Player:** Players gets notified via hint when they are the last player of the Team.
- **Custom Hints / Broadcast:** You can save hints / broadcasts in the database and use them easily by the ID.

**Database will get created inside Exiled/SCPUtils folder.**<br /><br />
**Each server must have it's own database, you cannot use one database on multiple servers!**<br /><br />
**You must add LiteDB.dll into Plugins/dependencies folder or plugin won't work**<br /><br />
**Minimum requirements: Exiled version: 3.0.0.alpha77 and LiteDB 5.0.9**
**Minimum requirements: Exiled version: 3.0.0.alpha80 and LiteDB 5.0.9**


### Configs:
Expand Down Expand Up @@ -65,10 +66,13 @@ You can see settings and edit them inside Exiled/port-config.yml file(example Ex
| scputils_player_warnings | <userid / id> | scputils.showwarns | Show all scputils warnings of a specific player |
| scputils_player_warning | <userid / id> | scputils.showwarns | Show last scputils warning of a specific player |
| scputils_player_unwarn | <userid / id> <warn id> | scputils.unwarn | Removes a specific warning from a user |
| scputils_player_broadcast | <userid / id> <broadcast/hint> <text> | scputils.broadcast | Send an hint or broadcast to a specific player |
| scputils_broadcast | <broadcast/hint> <text> | scputils.broadcast | Send an hint or broadcast to all players |
| scputils_player_broadcast | <userid / id> <broadcast/hint> <id> <duration (optional> | scputils.broadcast | Send an hint or broadcast to a specific player |
| scputils_broadcast | <broadcast/hint> <id> <duration (optional> | scputils.broadcast | Send an hint or broadcast to all players |
| scputils_set_round_ban | <id / userid> <amount> | scputils.roundban | Sets the number of round ban to one player |
| scputils_dupeip | < id / userid > | scputils.dupeip | Check if player has another account on same IP |
| scputils_broadcast_create | <id> <duration> <text> | scputils.broadcastcreate | Create a custom broadcast |
| scputils_broadcast_delete | <id> | scputils.broadcastdelete | Delete a custom broadcast |
| scputils_broadcast_list | none | scputils.broadcastlist | List all created broadcast |

**Console commands**

Expand Down
27 changes: 21 additions & 6 deletions SCPUtils/Commands/Broadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ internal class Broadcast : ICommand
{
public string Command { get; } = "scputils_broadcast";

public string[] Aliases { get; } = new[] { "sbc", "gbc", "su_bc", "scpu_bc" };
public string[] Aliases { get; } = new[] { "sbc", "su_bc", "scpu_bc" };

public string Description { get; } = "Allows to send custom broadcastes";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
string broadcast;
if (!sender.CheckPermission("scputils.broadcast"))
{
response = "<color=red> You need a higher administration level to use this command!</color>";
Expand All @@ -26,23 +25,39 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

else if (arguments.Count < 2)
{
response = $"<color=yellow>Usage: {Command} <hint/broadcast> <text></color>";
response = $"<color=yellow>Usage: {Command} <hint(h)/broadcast(bc)> <id> <duration (optional, if empty will be used the default one set for this broadcast)></color>";
return false;
}
else
{
broadcast = string.Join(" ", arguments.Array, 2, arguments.Array.Length - 2);
var databaseBroadcast = GetBroadcast.FindBroadcast(arguments.Array[2]);

if (databaseBroadcast == null)
{
response = "Invalid broadcast ID!";
return false;
}
int duration = databaseBroadcast.Seconds;
if (arguments.Count == 3)
{
if (int.TryParse(arguments.Array[3].ToString(), out duration)) { }
else
{
response = "Broadcast duration must be an integer";
return false;
}
}

switch (arguments.Array[1].ToString())
{
case "broadcast":
case "bc":
Map.Broadcast(ScpUtils.StaticInstance.Config.BroadcastDuration, broadcast);
Map.Broadcast((ushort)duration, databaseBroadcast.Text);
response = "Sending broadcast to all the players!";
break;
case "hint":
case "h":
Map.ShowHint(broadcast, ScpUtils.StaticInstance.Config.BroadcastDuration);
Map.ShowHint(databaseBroadcast.Text, duration);
response = "Sending hint to all the players!";
break;
default:
Expand Down
39 changes: 39 additions & 0 deletions SCPUtils/Commands/BroadcastList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using CommandSystem;
using Exiled.Permissions.Extensions;
using System;
using System.Text;

namespace SCPUtils.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class BroadcastList : ICommand
{
public string Command { get; } = "scputils_broadcast_list";

public string[] Aliases { get; } = new[] { "sbcl", "bcl", "su_bcl", "scpu_bcl" };

public string Description { get; } = "List of all registred broadcast";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("scputils.broadcastlist"))
{
response = "<color=red> You need a higher administration level to use this command!</color>";
return false;
}
StringBuilder broadcastList = new StringBuilder("[Broadcast List]");
broadcastList.AppendLine();
foreach (BroadcastDb databaseBroadcast in Database.LiteDatabase.GetCollection<BroadcastDb>().FindAll())
{
broadcastList.AppendLine($"ID: {databaseBroadcast.Id}");
broadcastList.AppendLine($"Created by: {databaseBroadcast.CreatedBy}");
broadcastList.AppendLine($"Default duration: {databaseBroadcast.Seconds}");
broadcastList.AppendLine($"Text: {databaseBroadcast.Text}");
broadcastList.AppendLine("---------");
}
response = $"{broadcastList}";
return true;
}
}
}
57 changes: 57 additions & 0 deletions SCPUtils/Commands/CreateBroadcast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using CommandSystem;
using Exiled.Permissions.Extensions;
using System;

namespace SCPUtils.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class CreateBroadcast : ICommand
{
public string Command { get; } = "scputils_broadcast_create";

public string[] Aliases { get; } = new[] { "cbc", "su_cbc", "scpu_cbc" };

public string Description { get; } = "Allows to create custom broadcasts";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("scputils.broadcastcreate"))
{
response = "<color=red> You need a higher administration level to use this command!</color>";
return false;
}

else if (arguments.Count < 3)
{
response = $"<color=yellow>Usage: {Command} <id> <duration> <text>";
return false;
}
else
{
if (int.TryParse(arguments.Array[2].ToString(), out int duration))
{
if (Database.LiteDatabase.GetCollection<BroadcastDb>().Exists(broadcast => broadcast.Id == arguments.Array[1].ToString()))
{
response = "Id already exist!";
return false;
}
else
{
var broadcast = string.Join(" ", arguments.Array, 3, arguments.Array.Length - 3);
ScpUtils.StaticInstance.DatabasePlayerData.AddBroadcast(arguments.Array[1].ToString(), sender.LogName, duration, broadcast.ToString());
response = "Success!";
return true;
}
}
else
{
response = "Broadcast duration must be an integer";
return false;
}
}


}
}
}
47 changes: 47 additions & 0 deletions SCPUtils/Commands/DeleteBroadcast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CommandSystem;
using Exiled.Permissions.Extensions;
using System;

namespace SCPUtils.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class DeleteBroadcast : ICommand
{
public string Command { get; } = "scputils_broadcast_delete";

public string[] Aliases { get; } = new[] { "dbc", "su_dbc", "scpu_dbc" };

public string Description { get; } = "Allows to delete custom broadcastes";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("scputils.broadcastdelete"))
{
response = "<color=red> You need a higher administration level to use this command!</color>";
return false;
}

else if (arguments.Count < 1)
{
response = $"<color=yellow>Usage: {Command} <id>";
return false;
}
else
{

if (Database.LiteDatabase.GetCollection<BroadcastDb>().Exists(broadcast => broadcast.Id == arguments.Array[1].ToString()))
{
Database.LiteDatabase.GetCollection<BroadcastDb>().Delete(arguments.Array[1].ToString());
response = "Success!";
return true;
}
else
{
response = "Id does not exist!";
return false;
}
}
}
}
}
30 changes: 24 additions & 6 deletions SCPUtils/Commands/PlayerBroadcast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ internal class PlayerBroadcast : ICommand
public string Description { get; } = "Allows to send custom broadcaste";

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
string broadcast;
{
if (!sender.CheckPermission("scputils.broadcast"))
{
response = "<color=red> You need a higher administration level to use this command!</color>";
Expand All @@ -25,28 +24,47 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

else if (arguments.Count < 3)
{
response = $"<color=yellow>Usage: {Command} <player> <hint/broadcast> <text></color>";
response = $"<color=yellow>Usage: {Command} <player> <hint(h)/broadcast(bc)> <id> <duration (optional, if empty will be used the default one set for this broadcast)></color>";
return false;
}
else
{
broadcast = string.Join(" ", arguments.Array, 3, arguments.Array.Length - 3);
var databaseBroadcast = GetBroadcast.FindBroadcast(arguments.Array[3]);

if (databaseBroadcast == null)
{
response = "Invalid broadcast ID!";
return false;
}

Exiled.API.Features.Player player = Exiled.API.Features.Player.Get(arguments.Array[1].ToString());
if (player == null)
{
response = "Invalid player!";
return false;
}

int duration = databaseBroadcast.Seconds;
if (arguments.Count == 4)
{
if (int.TryParse(arguments.Array[4].ToString(), out duration)) { }
else
{
response = "Broadcast duration must be an integer";
return false;
}
}

switch (arguments.Array[2].ToString())
{
case "broadcast":
case "bc":
player.Broadcast(ScpUtils.StaticInstance.Config.BroadcastDuration, broadcast, global::Broadcast.BroadcastFlags.Normal, false);
player.Broadcast((ushort)duration, databaseBroadcast.Text, global::Broadcast.BroadcastFlags.Normal, false);
response = "Success!";
break;
case "hint":
case "h":
player.ShowHint(broadcast, ScpUtils.StaticInstance.Config.BroadcastDuration);
player.ShowHint(databaseBroadcast.Text, duration);
response = "Success!";
break;
default:
Expand Down
11 changes: 5 additions & 6 deletions SCPUtils/Commands/SetRoundBan.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using CommandSystem;
using Exiled.Permissions.Extensions;
using System;
using System.Collections.Generic;

namespace SCPUtils.Commands
{
[CommandHandler(typeof(RemoteAdminCommandHandler))]
[CommandHandler(typeof(GameConsoleCommandHandler))]
internal class SetRoundBan : ICommand
{
{
public string Command { get; } = "scputils_set_round_ban";

public string[] Aliases { get; } = new[] { "srb", "roundban", "su_srb", "su_roundban" };
Expand All @@ -18,22 +17,22 @@ internal class SetRoundBan : ICommand
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
string target;

if (!sender.CheckPermission("scputils.roundban"))
{
response = "<color=red> You need a higher administration level to use this command!</color>";
return false;


}

if (arguments.Count < 2)
{
response = $"<color=yellow>Usage: {Command} <player name/id> <Round bans to set> </color>";
return false;
}
else target = arguments.Array[1].ToString();
else target = arguments.Array[1].ToString();


Player databasePlayer = target.GetDatabasePlayer();

Expand Down
6 changes: 3 additions & 3 deletions SCPUtils/Commands/Unwarn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
BanHandler.RemoveBan(databasePlayer.Ip, BanHandler.BanType.IP);
}
break;
case "Round-Ban":
case "Round-Ban":
databasePlayer.ScpSuicideCount--;
databasePlayer.TotalScpSuicideBans--;
databasePlayer.SuicidePunishment[id] = "REMOVED";
Expand All @@ -95,10 +95,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

databasePlayer.RoundBanLeft -= databasePlayer.RoundsBan[id];
if (databasePlayer.RoundBanLeft < 0) databasePlayer.RoundBanLeft = 0;


Database.LiteDatabase.GetCollection<Player>().Update(databasePlayer);

break;
case "REMOVED":
message = "This sanction has already been removed!";
Expand Down
10 changes: 10 additions & 0 deletions SCPUtils/Database/BroadcastDb.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SCPUtils
{
public class BroadcastDb
{
public string Id { get; set; }
public string CreatedBy { get; set; }
public int Seconds { get; set; }
public string Text { get; set; }
}
}
Loading

0 comments on commit ac042a2

Please sign in to comment.