Skip to content

Commit

Permalink
5.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco authored and Francesco committed Jan 14, 2023
1 parent bdc53fd commit c43e1bc
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 29 deletions.
140 changes: 115 additions & 25 deletions SCPUtils/Commands/SwapRequest.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using CommandSystem;
using System;
using Exiled.API.Features;
using System.Linq;
using Eplayer = Exiled.API.Features.Player;

namespace SCPUtils.Commands
{
Expand All @@ -17,21 +17,21 @@ internal class SwapRequest : ICommand

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{

if (ScpUtils.StaticInstance.Functions.CheckCommandCooldown(sender) == true)
{
response = ScpUtils.StaticInstance.Config.CooldownMessage;
return false;
}

Exiled.API.Features.Player player = Exiled.API.Features.Player.Get(((CommandSender)sender).SenderId);

if (!ScpUtils.StaticInstance.Config.AllowSCPSwap)
{
response = $"<color=yellow>SCP swap module is disabled on this server!</color>";
return false;
}

if (!player.IsScp)
{
response = $"<color=yellow>Only SCPs are allowed to use this command!</color>";
Expand All @@ -40,10 +40,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s

else
{

if (arguments.Count < 1)
{
response = $"<color=yellow>Usage: {Command} <player></color>";
response = $"<color=yellow>Usage: {Command} <player id/nickname or SCP-NUMBER (example: swap SCP-939)></color>";
return false;
}
else if (Exiled.API.Features.Round.ElapsedTime.TotalSeconds >= ScpUtils.StaticInstance.Config.MaxAllowedTimeScpSwapRequest)
Expand All @@ -58,47 +58,137 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
else
{

var target = Exiled.API.Features.Player.Get(arguments.Array[1].ToString());

Eplayer target;
switch (arguments.Array[1].ToString().ToUpper())
{
case "SCP-939":
case "SCP939":
case "939":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp939);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

case "SCP-049":
case "SCP049":
case "049":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp049);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

case "SCP-0492":
case "SCP0492":
case "0492":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp0492);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

case "SCP-106":
case "SCP106":
case "106":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp106);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

case "SCP-096":
case "SCP096":
case "096":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp096);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

case "SCP-079":
case "SCP079":
case "079":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp079);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

case "SCP-173":
case "SCP173":
case "173":

target = Eplayer.List.FirstOrDefault(x => x.Role.Type == PlayerRoles.RoleTypeId.Scp173);
if (target == null)
{
response = $"<color=red>{arguments.Array[1].ToString().ToUpper() } didn't spawned!</color>";
return false;
}
break;

default:
target = Eplayer.Get(arguments.Array[1].ToString());
break;

}

var seconds = Math.Round(ScpUtils.StaticInstance.Config.MaxAllowedTimeScpSwapRequestAccept - Exiled.API.Features.Round.ElapsedTime.TotalSeconds);

if (target == null)
{
response = $"<color=red>Invalid player!</color>";
response = $"<color=red>Invalid player nickname/id or invalid SCP name!</color>";
return false;
}

if (ScpUtils.StaticInstance.Config.AllowSCPSwapOnlyFullHealth && target.Health < target.MaxHealth)
{
response = $"<color=red>Target has not full health!</color>";
return false;
}

if (ScpUtils.StaticInstance.EventHandlers.SwapRequest.ContainsKey(target) || ScpUtils.StaticInstance.EventHandlers.SwapRequest.ContainsValue(target))
{
response = $"<color=red>Target already sent a request or has a pending request</color>";
return false;
}

if (ScpUtils.StaticInstance.EventHandlers.SwapRequest.ContainsKey(player) || ScpUtils.StaticInstance.EventHandlers.SwapRequest.ContainsValue(player))
{
response = $"<color=red>You already sent or received a swap request, verify that</color>";
return false;
}

if (target == player)
{
response = $"<color=red>You can't send swap request to yourself!</color>";
return false;
}

if (!target.IsScp)
{
response = $"<color=red>Target is not SCP!</color>";
return false;
}

if (target.Role == player.Role)
{
response = $"<color=red>You have the same role of another player!</color>";
Expand All @@ -121,18 +211,18 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}
}

ScpUtils.StaticInstance.EventHandlers.SwapRequest.Add(player, target);

target.ClearBroadcasts();

var message = ScpUtils.StaticInstance.Config.SwapRequestBroadcast.Content;

message = message.Replace("%player%", player.DisplayNickname).Replace("%scp%", player.Role.Name).Replace("%seconds%", seconds.ToString());
target.Broadcast(ScpUtils.StaticInstance.Config.SwapRequestBroadcast.Duration, message, ScpUtils.StaticInstance.Config.SwapRequestBroadcast.Type, false);
response = $"<color=green>Request has been sent successfully, player has {seconds} seconds to accept the request. Use .cancel to cancel the request</color>";

response = $"<color=green>Request has been sent successfully to {target.DisplayNickname}, player has {seconds} seconds to accept the request. Use .cancel to cancel the request</color>";

return true;
}
}
Expand Down
6 changes: 6 additions & 0 deletions SCPUtils/Commands/SwapRequestAccept.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if(!target.IsScp)
{
response = $"<color=red>Target is not an SCP</color>";
return false;
}

if (target.CustomInfo != null && ScpUtils.StaticInstance.Config.DeniedSwapCustomInfo?.Any() == true)
{
if (ScpUtils.StaticInstance.Config.DeniedSwapCustomInfo.Contains(target.CustomInfo.ToString()))
Expand Down
2 changes: 1 addition & 1 deletion SCPUtils/Configs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public class Configs : IConfig

[Description("Command cooldown text")]
public string CooldownMessage { get; private set; } = "<color=red>Command execution failed! You are under cooldown or command banned, wait 5 seconds and try again, if the error persist you might have been banned from using commands, to see the reason and duration open the console after joining the server, this abusive action has been reported to the staff for futher punishments</color>";
// public string CooldownMessage { get; private set; } = "<color=red>Esecuzione del comando fallita! Attualmente sei sotto cooldown oppure bannato, attendi 5 secondi e riprova, se l'errore è persistente significa che sei bannato, per vedere durata e motivazione apri la console appena entri nel server, questa azione illecita è stata segnalata allo staff.</color>";
// public string CooldownMessage { get; private set; } = "<color=red>Esecuzione del comando fallita! Attualmente sei sotto cooldown oppure bannato, attendi 5 secondi e riprova, se l'errore è persistente significa che sei bannato, per vedere durata e motivazione apri la console appena entri nel server, questa azione illecita è stata segnalata allo staff.</color>";

[Description("From which groups plugin should ignore DNT flag?")]
public List<string> DntIgnoreList { get; private set; } = new List<string>() { "testusergroup1", "testusergroup2" };
Expand Down
4 changes: 2 additions & 2 deletions SCPUtils/Functions/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public void CheckIp(Exiled.API.Features.Player player)
}

public bool CheckCommandCooldown(ICommandSender sender)
{
{
if (((CommandSender)sender).Nickname.Equals("SERVER CONSOLE"))
{
return false;
Expand All @@ -672,7 +672,7 @@ public bool CheckCommandCooldown(ICommandSender sender)
else
{
pluginInstance.EventHandlers.LastCommand[player] = DateTime.Now.AddSeconds(pluginInstance.Config.CommandCooldownSeconds);
return false;
return false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion SCPUtils/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ScpUtils : Features.Plugin<Configs>
{
public override string Author { get; } = "Terminator_97#0507";
public override string Name { get; } = "SCPUtils";
public override Version Version { get; } = new Version(5, 1, 1);
public override Version Version { get; } = new Version(5, 1, 2);
public override Version RequiredExiledVersion { get; } = new Version(6, 0, 0);
public EventHandlers EventHandlers { get; private set; }
public Functions Functions { get; private set; }
Expand Down

0 comments on commit c43e1bc

Please sign in to comment.