Skip to content

Commit

Permalink
Cleaned up code
Browse files Browse the repository at this point in the history
  • Loading branch information
NotIntense committed Aug 16, 2024
1 parent 2140f5b commit 56c42eb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 40 deletions.
11 changes: 7 additions & 4 deletions RainbowTags/Commands/ToggleRTag.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using CommandSystem;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Player;
using RemoteAdmin;

namespace RainbowTags.Commands;
Expand All @@ -18,7 +19,8 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
{
if (sender is PlayerCommandSender playerCommandSender)
{
var player = Player.Get(playerCommandSender);
Player player = Player.Get(playerCommandSender);

if (player == null)
{
response = "You must be in-game to use this command!";
Expand Down Expand Up @@ -51,9 +53,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
else
{
//I dont think this would ever happen
response = "Error, report to notintense on Discord!";
return false;
MainClass.PlayersWithoutRTags.Remove(player);
MainClass.Instance.OnChangingGroup(new ChangingGroupEventArgs(player, player.Group));
response = "Your rainbow tag has been enabled!";
return true;
}
}

Expand Down
54 changes: 20 additions & 34 deletions RainbowTags/MainClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Player;
using UnityEngine;
using Object = UnityEngine.Object;

namespace RainbowTags;
Expand All @@ -13,7 +14,7 @@ public class MainClass : Plugin<Config>
public override string Author => "NotIntense";
public override string Name => "RainbowTags";
public override string Prefix => "RainbowTags";
public override Version Version { get; } = new(2, 0, 2);
public override Version Version { get; } = new(2, 0, 5);
public override Version RequiredExiledVersion { get; } = new(8, 0, 0);
public static List<Player> PlayersWithoutRTags { get; } = new();

Expand Down Expand Up @@ -67,48 +68,33 @@ private string GetGroupKey(UserGroup group)
return ServerStatic.PermissionsHandler._groups.FirstOrDefault(g => EqualsTo(g.Value, group)).Key ?? string.Empty;
}

private void OnChangingGroup(ChangingGroupEventArgs ev)
{
AssignGroupColor(ev, Config.GroupSpecificSequences);
}

private void AssignGroupColor(ChangingGroupEventArgs ev, bool groupSequence)
public void OnChangingGroup(ChangingGroupEventArgs ev)
{
string[] colors;

if (groupSequence)
{ //Using custom try get colors
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.NewGroup != null && ev.Player.Group == null)
{
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.NewGroup != null)
{
if (Config.GroupSpecificSequences)
TryGetCustomColors(GetGroupKey(ev.NewGroup), out colors);
else
TryGetColors(GetGroupKey(ev.NewGroup), out colors);

Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
TagController rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}

//Something went wrong
Log.Error($"Failed to assign RainbowTag to {ev.Player}!\n NewGroup Null? : {ev.NewGroup == null}\n PlayerGroup Null? : {ev.Player?.Group == null}\n Could get colors? : {TryGetCustomColors(GetGroupKey(ev.NewGroup), out _)}");
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
return;
}
else
{
//Using normal try get colors
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.NewGroup != null && ev.Player.Group == null && TryGetColors(GetGroupKey(ev.NewGroup), out colors))
if (colors == null)
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
//Something went wrong
Log.Error($"Failed to assign RainbowTag to {ev.Player}!\n NewGroup Null? : {ev.NewGroup == null}\n PlayerGroup Null? : {ev.Player?.Group == null}\n Could get colors? : {(Config.GroupSpecificSequences ? TryGetCustomColors(GetGroupKey(ev.NewGroup), out _) : TryGetColors(GetGroupKey(ev.NewGroup), out _))}");
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
return;
}

//Something went wrong
Log.Error($"Failed to assign RainbowTag to {ev.Player}!\n NewGroup Null? : {ev.NewGroup == null}\n PlayerGroup Null? : {ev.Player?.Group == null}\n Could get colors? : {TryGetCustomColors(GetGroupKey(ev.NewGroup), out _)}");
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);

if (ev.Player.GameObject.TryGetComponent(out TagController controller))
Object.Destroy(controller);

TagController rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions RainbowTags/RainbowTags.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
<Compile Include="TagController.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EXILED">
<Version>8.9.5</Version>
<PackageReference Include="EXILEDOFFICIAL">
<Version>8.12.0-rc.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down

0 comments on commit 56c42eb

Please sign in to comment.