Skip to content

Commit

Permalink
dyigg
Browse files Browse the repository at this point in the history
  • Loading branch information
NotIntense committed Sep 9, 2023
1 parent 4ff8765 commit 1715a09
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 23 deletions.
9 changes: 9 additions & 0 deletions RainbowTags - Nebuli/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Config : IConfiguration
{
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;
public bool GroupSpecificSequences { get; set; } = false;

[Description("Tags Configuration")]
public float ColorInterval { get; set; } = 0.5f;
Expand All @@ -28,4 +29,12 @@ public class Config : IConfiguration
"silver",
"crimson"
};

public Dictionary<string, List<string>> GroupSequences { get; set; } = new Dictionary<string, List<string>>
{
{ "owner", new List<string>() { "red", "orange", "yellow", "green", "blue_green", "magenta", "silver", "crimson" } },
{ "moderator", new List<string>() { "red", "orange", "yellow", "green", "blue_green", "magenta", "silver", "crimson" } },
{ "admin", new List<string>() { "red", "orange", "yellow", "green", "blue_green", "magenta", "silver", "crimson" } }
};

}
59 changes: 46 additions & 13 deletions RainbowTags - Nebuli/MainClass.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using InventorySystem.Items.Usables;
using Nebuli.API.Features;
using Nebuli.API.Features;
using Nebuli.API.Features.Player;
using Nebuli.Events.EventArguments.Player;
using Nebuli.Events.Handlers;
Expand All @@ -17,6 +16,7 @@ public class MainClass : Plugin<Config>
public override string Name => "RainbowTags";
public override Version Version { get; } = new(1, 0, 2);
public override Version NebuliVersion { get; } = new(0, 0, 0);
public override bool SkipVersionCheck { get; } = true;

public static List<NebuliPlayer> PlayersWithoutRTags { get; } = new();

Expand All @@ -39,6 +39,17 @@ private bool TryGetColors(string rank, out string[] availableColors)
availableColors = Config.Sequences;
return !string.IsNullOrEmpty(rank) && Config.RanksWithRTags.Contains(rank);
}

private bool TryGetCustomColors(string rank, out string[] availableColors)
{
if (Config.GroupSequences[rank] == null)
{
availableColors = null;
return false;
}
availableColors = Config.GroupSequences[rank].ToArray();
return !string.IsNullOrEmpty(rank) && Config.RanksWithRTags.Contains(rank);
}
private bool EqualsTo(UserGroup thisGroup, UserGroup otherGroup)
{
return thisGroup.BadgeColor == otherGroup.BadgeColor && thisGroup.BadgeText == otherGroup.BadgeText &&
Expand All @@ -57,19 +68,41 @@ private string GetGroupKey(UserGroup group)
}
private void OnChangingGroup(PlayerChangingUserGroupEvent ev)
{
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.Group != null && ev.Player.Group == null && TryGetColors(GetGroupKey(ev.Group), out var colors))
if (ev.Player == null || ev.Group == null) return;

if (Config.GroupSpecificSequences)
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.Group != null && ev.Player.Group == null && TryGetCustomColors(GetGroupKey(ev.Group), out var colors))
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}
if (TryGetColors(GetGroupKey(ev.Group), out colors))
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
}
if (TryGetColors(GetGroupKey(ev.Group), out colors))
else
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.Group != null && ev.Player.Group == null && TryGetColors(GetGroupKey(ev.Group), out var colors))
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}
if (TryGetColors(GetGroupKey(ev.Group), out colors))
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
}
}
}
8 changes: 8 additions & 0 deletions RainbowTags/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Config : IConfig
{
public bool IsEnabled { get; set; } = true;
public bool Debug { get; set; } = false;
public bool GroupSpecificSequences { get; set; } = false;

[Description("Tags Configuration")]
public float ColorInterval { get; set; } = 0.5f;
Expand All @@ -28,4 +29,11 @@ public class Config : IConfig
"silver",
"crimson"
};

public Dictionary<string, List<string>> GroupSequences { get; set; } = new Dictionary<string, List<string>>
{
{ "owner", new List<string>() { "red", "orange", "yellow", "green", "blue_green", "magenta", "silver", "crimson" } },
{ "moderator", new List<string>() { "red", "orange", "yellow", "green", "blue_green", "magenta", "silver", "crimson" } },
{ "admin", new List<string>() { "red", "orange", "yellow", "green", "blue_green", "magenta", "silver", "crimson" } }
};
}
51 changes: 41 additions & 10 deletions RainbowTags/MainClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ private bool TryGetColors(string rank, out string[] availableColors)
availableColors = Config.Sequences;
return !string.IsNullOrEmpty(rank) && Config.RanksWithRTags.Contains(rank);
}

private bool TryGetCustomColors(string rank, out string[] availableColors)
{
if (Config.GroupSequences[rank] == null)
{
availableColors = null;
return false;
}
availableColors = Config.GroupSequences[rank].ToArray();
return !string.IsNullOrEmpty(rank) && Config.RanksWithRTags.Contains(rank);
}
private bool EqualsTo(UserGroup thisGroup, UserGroup otherGroup)
{
return thisGroup.BadgeColor == otherGroup.BadgeColor && thisGroup.BadgeText == otherGroup.BadgeText &&
Expand All @@ -55,19 +66,39 @@ private string GetGroupKey(UserGroup group)
}
private void OnChangingGroup(ChangingGroupEventArgs ev)
{
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.NewGroup != null && ev.Player.Group == null && TryGetColors(GetGroupKey(ev.NewGroup), out var colors))
if (Config.GroupSpecificSequences)
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.NewGroup != null && ev.Player.Group == null && TryGetCustomColors(GetGroupKey(ev.NewGroup), out var colors))
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}
if (TryGetColors(GetGroupKey(ev.NewGroup), out colors))
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
}
if (TryGetColors(GetGroupKey(ev.NewGroup), out colors))
else
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
if (!PlayersWithoutRTags.Contains(ev.Player) && ev.NewGroup != null && ev.Player.Group == null && TryGetColors(GetGroupKey(ev.NewGroup), out var colors))
{
Log.Debug("RainbowTags: Added to " + ev.Player.Nickname);
var rtController = ev.Player.GameObject.AddComponent<TagController>();
rtController.Colors = colors;
rtController.Interval = Config.ColorInterval;
return;
}
if (TryGetColors(GetGroupKey(ev.NewGroup), out colors))
{
ev.Player.GameObject.GetComponent<TagController>().Colors = colors;
return;
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
}
Object.Destroy(ev.Player.GameObject.GetComponent<TagController>());
}
}

0 comments on commit 1715a09

Please sign in to comment.