C#:
//Requires: Clans
using System.Collections.Generic;
using System.Globalization;
using Oxide.Game.Rust.Cui;
using UnityEngine;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("ClansUI", "k1lly0u", "0.2.0")]
class ClansUI : RustPlugin
{
#region Fields
[PluginReference] Clans Clans;
private int memberLimit;
private int inviteLimit;
private bool alliancesEnabled;
private int allianceLimit;
private int allianceInviteLimit;
private bool canToggleAFF;
private bool canToggleMFF;
private bool ownerOnlyMFF;
private bool ownerOnlyAFF;
#endregion
#region Oxide Hooks
private void OnServerInitialized()
{
cmd.AddChatCommand(Configuration.Command, this, CommandClanUI);
cmd.AddConsoleCommand(Configuration.Command, this, "cmdClanUI");
memberLimit = Clans.configData.Clans.MemberLimit;
inviteLimit = Clans.configData.Clans.Invites.MemberInviteLimit;
alliancesEnabled = Clans.configData.Clans.Alliance.Enabled;
allianceLimit = Clans.configData.Clans.Alliance.AllianceLimit;
allianceInviteLimit = Clans.configData.Clans.Invites.AllianceInviteLimit;
canToggleMFF = Clans.configData.Clans.MemberFF;
canToggleAFF = Clans.configData.Clans.Alliance.AllyFF;
ownerOnlyMFF = Clans.configData.Clans.OwnerFF;
ownerOnlyAFF = Clans.configData.Clans.Alliance.OwnerFF;
}
protected override void LoadDefaultMessages() => lang.RegisterMessages(Messages, this);
private void OnPlayerDisconnected(BasePlayer player) => DestroyUI(player);
private void Unload()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
DestroyUI(player);
Configuration = null;
}
#endregion
#region Functions
private void DestroyUI(BasePlayer player) => CuiHelper.DestroyUi(player, UI_MENU);
#endregion
#region UI
private class UI
{
public static CuiElementContainer Container(string panelName, string color, UI4 dimensions, bool cursor = false, string parent = "Hud")
{
CuiElementContainer container = new CuiElementContainer()
{
{
new CuiPanel
{
Image = {Color = color},
RectTransform = {AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()},
CursorEnabled = cursor
},
new CuiElement().Parent = parent,
panelName
}
};
return container;
}
public static CuiElementContainer Container(string panelName, UI4 dimensions, string color = "0 0 0 0.9")
{
CuiElementContainer container = new CuiElementContainer()
{
{
new CuiPanel
{
Image = {Color = color, Material = "assets/content/ui/uibackgroundblur-ingamemenu.mat"},
RectTransform = {AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax()},
CursorEnabled = true
},
new CuiElement().Parent = "Hud",
panelName.ToString()
}
};
return container;
}
public static void Panel(CuiElementContainer container, string panel, string color, UI4 dimensions)
{
container.Add(new CuiPanel
{
Image = { Color = color },
RectTransform = { AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax() }
},
panel);
}
public static void Label(CuiElementContainer container, string panel, string text, int size, UI4 dimensions, TextAnchor align = TextAnchor.MiddleCenter)
{
container.Add(new CuiLabel
{
Text = { FontSize = size, Align = align, Text = text },
RectTransform = { AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax() }
},
panel);
}
public static void Label(CuiElementContainer container, string panel, string color, string text, int size, UI4 dimensions, TextAnchor align = TextAnchor.MiddleCenter)
{
container.Add(new CuiPanel
{
Image = { Color = color },
RectTransform = { AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax() }
},
panel);
dimensions.xMin += 0.005f;
dimensions.xMax -= 0.005f;
container.Add(new CuiLabel
{
Text = { FontSize = size, Align = align, Text = text },
RectTransform = { AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax() }
},
panel);
}
public static void Button(CuiElementContainer container, string panel, string color, string text, int size, UI4 dimensions, string command, TextAnchor align = TextAnchor.MiddleCenter)
{
container.Add(new CuiButton
{
Button = { Color = color, Command = command, FadeIn = 0f },
RectTransform = { AnchorMin = dimensions.GetMin(), AnchorMax = dimensions.GetMax() },
Text = { Text = text, FontSize = size, Align = align }
},
panel);
}
public static void Toggle(CuiElementContainer container, string panel, string boxColor, int fontSize, UI4 dimensions, string command, bool isOn)
{
UI.Panel(container, panel, boxColor, dimensions);
if (isOn)
UI.Label(container, panel, "✔", fontSize, dimensions);
UI.Button(container, panel, "0 0 0 0", string.Empty, 0, dimensions, command);
}
public static string Color(string hexColor, float alpha)
{
if (hexColor.StartsWith("#"))
hexColor = hexColor.TrimStart('#');
int red = int.Parse(hexColor.Substring(0, 2), NumberStyles.AllowHexSpecifier);
int green = int.Parse(hexColor.Substring(2, 2), NumberStyles.AllowHexSpecifier);
int blue = int.Parse(hexColor.Substring(4, 2), NumberStyles.AllowHexSpecifier);
return $"{(double)red / 255} {(double)green / 255} {(double)blue / 255} {alpha}";
}
}
public class UI4
{
public float xMin, yMin, xMax, yMax;
public UI4(float xMin, float yMin, float xMax, float yMax)
{
this.xMin = xMin;
this.yMin = yMin;
this.xMax = xMax;
this.yMax = yMax;
}
public string GetMin() => $"{xMin} {yMin}";
public string GetMax() => $"{xMax} {yMax}";
private static UI4 _full;
public static UI4 Full
{
get
{
if (_full == null)
_full = new UI4(0, 0, 1, 1);
return _full;
}
}
}
#endregion
#region UI
private const string UI_MENU = "ClanMenu";
private const string FIELD_COLOR = "1 1 1 0.15";
private const float ELEMENT_HEIGHT = 0.04f;
private enum Menu { Members, Alliances }
private void CreateClanMenu(BasePlayer player, Clans.Clan clan, Menu menu = Menu.Members, int page = 0)
{
CuiElementContainer container = UI.Container(UI_MENU, new UI4(0.35f, 0.15f, 0.95f, 0.85f));
UI.Panel(container, UI_MENU, Configuration.Menu.Panel.Get, new UI4(0.005f, 0.93f, 0.995f, 0.99f));
UI.Label(container, UI_MENU, Message("UI.Title", player.userID), 20, new UI4(0.015f, 0.93f, 0.99f, 0.99f), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, "<b>×</b>", 20, new UI4(0.9575f, 0.9375f, 0.99f, 0.9825f), "clansui.close");
// Clan Info
UI.Label(container, UI_MENU, Configuration.Menu.Color2.Get, Message("UI.Clan", player.userID), 14, new UI4(0.005f, 0.88f, 0.105f, 0.92f), TextAnchor.MiddleLeft);
UI.Label(container, UI_MENU, FIELD_COLOR, clan.Tag, 14, new UI4(0.1f, 0.88f, 0.25f, 0.92f), TextAnchor.MiddleRight);
UI.Label(container, UI_MENU, Configuration.Menu.Color2.Get, Message("UI.Leader", player.userID), 14, new UI4(0.005f, 0.835f, 0.105f, 0.875f), TextAnchor.MiddleLeft);
UI.Label(container, UI_MENU, FIELD_COLOR, clan.GetOwner().DisplayName, 14, new UI4(0.1f, 0.835f, 0.25f, 0.875f), TextAnchor.MiddleRight);
if (alliancesEnabled)
{
if (menu == Menu.Members)
UI.Button(container, UI_MENU, Configuration.Menu.Color4.Get, Message("UI.ViewAlliances", player.userID), 14, new UI4(0.255f, 0.88f, 0.395f, 0.92f), $"clansui.openmenu {(int)Menu.Alliances}");
else UI.Button(container, UI_MENU, Configuration.Menu.Color4.Get, Message("UI.ViewMembers", player.userID), 14, new UI4(0.255f, 0.88f, 0.395f, 0.92f), $"clansui.openmenu {(int)Menu.Members}");
}
Clans.Clan.Member member = Clans.storedData.FindMemberByID(player.userID);
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, Message("UI.Leave", player.userID), 14, new UI4(0.885f, 0.835f, 0.995f, 0.875f), "clansui.leaveclan");
if (member.Role == Clans.Clan.Member.MemberRole.Owner)
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, Message("UI.Disband", player.userID), 14, new UI4(0.77f, 0.835f, 0.88f, 0.875f), "clansui.disbandclan");
if (canToggleMFF)
{
if (!ownerOnlyMFF || (ownerOnlyMFF && (clan.IsOwner(player.userID) || clan.IsCouncil(player.userID))))
{
UI.Label(container, UI_MENU, FIELD_COLOR, Message("UI.MemberFF", player.userID), 14, new UI4(0.255f, 0.835f, 0.365f, 0.875f), TextAnchor.MiddleLeft);
UI.Toggle(container, UI_MENU, Configuration.Menu.Color1.Get, 14, new UI4(0.365f, 0.835f, 0.395f, 0.875f), "clansui.togglememberff", member.MemberFFEnabled);
}
}
if (canToggleAFF && alliancesEnabled)
{
if (!ownerOnlyAFF || (ownerOnlyAFF && (clan.IsOwner(player.userID) || clan.IsCouncil(player.userID))))
{
UI.Label(container, UI_MENU, FIELD_COLOR, Message("UI.AllyFF", player.userID), 14, new UI4(0.4f, 0.835f, 0.51f, 0.875f), TextAnchor.MiddleLeft);
UI.Toggle(container, UI_MENU, Configuration.Menu.Color1.Get, 14, new UI4(0.51f, 0.835f, 0.54f, 0.875f), "clansui.toggleallyff", member.AllyFFEnabled);
}
}
if (menu == Menu.Members)
CreateMemberInfo(player, clan, container, page);
else CreateAllianceInfo(player, clan, container, page);
DestroyUI(player);
CuiHelper.AddUi(player, container);
}
#region Members
private void CreateMemberInfo(BasePlayer player, Clans.Clan clan, CuiElementContainer container, int page = 0)
{
// Member List
UI.Label(container, UI_MENU, Configuration.Menu.Color4.Get, string.Format(Message("UI.Members", player.userID), clan.MemberCount, memberLimit), 14, new UI4(0.005f, 0.79f, 0.75f, 0.83f), TextAnchor.MiddleLeft);
int i = -1;
foreach (var kvp in clan.ClanMembers)
AddClanMemberEntry(player, container, clan, kvp.Key.ToString(), kvp.Value, i += 1);
// Member Invites
UI.Label(container, UI_MENU, Configuration.Menu.Color4.Get, string.Format(Message("UI.MemberInvites", player.userID), clan.MemberInviteCount, inviteLimit), 14, new UI4(0.755f, 0.79f, 0.995f, 0.83f), TextAnchor.MiddleLeft);
i = -1;
foreach (var kvp in clan.MemberInvites)
AddClanInviteEntry(container, kvp.Key.ToString(), kvp.Value, i += 1);
float yMin = GetVerticalPos(i += 1, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Button(container, UI_MENU, Configuration.Menu.Color2.Get, Message("UI.InviteMember", player.userID), 14, new UI4(0.755f, yMin, 0.995f, yMax), "clansui.invitemember");
}
private void AddClanMemberEntry(BasePlayer player, CuiElementContainer container, Clans.Clan clan, string targetId, Clans.Clan.Member member, int index)
{
float yMin = GetVerticalPos(index, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Label(container, UI_MENU, UI.Color(clan.GetRoleColor(member.Role), 0.25f), member.DisplayName, 14, new UI4(0.005f, yMin, 0.2f, yMax), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, Message("UI.Kick", player.userID), 14, new UI4(0.205f, yMin, 0.27f, yMax), $"clansui.kick {targetId}");
for (int i = 0; i < Configuration.MemberCommands.Count; i++)
{
ConfigData.ClanCommand cmd = Configuration.MemberCommands[i];
float xMin = 0.275f + (i * 0.07f);
float xMax = xMin + 0.065f;
if (xMax > 0.75f)
continue;
UI.Button(container, UI_MENU, Configuration.Menu.Color2.Get, cmd.Name, 14, new UI4(xMin, yMin, xMax, yMax),
$"clansui.runcommand {CommandSafe(cmd.Command.Replace("{playerName}", member.DisplayName).Replace("{playerId}", targetId))}");
}
}
private void AddClanInviteEntry(CuiElementContainer container, string targetId, Clans.Clan.MemberInvite member, int index)
{
float yMin = GetVerticalPos(index, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Panel(container, UI_MENU, FIELD_COLOR, new UI4(0.755f, yMin, 0.995f, yMax));
UI.Label(container, UI_MENU, member.DisplayName, 14, new UI4(0.76f, yMin, 0.995f, yMax), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, "<b>×</b>", 14, new UI4(0.755f, yMin, 0.995f, yMax), $"clansui.revokeinvite {targetId}");
}
#endregion
#region Alliances
private void CreateAllianceInfo(BasePlayer player, Clans.Clan clan, CuiElementContainer container, int page = 0)
{
// Current Alliances
UI.Label(container, UI_MENU, Configuration.Menu.Color4.Get, string.Format(Message("UI.Alliances", player.userID), clan.AllianceCount, allianceLimit), 14, new UI4(0.005f, 0.79f, 0.3316f, 0.83f), TextAnchor.MiddleLeft);
int i = -1;
foreach (string tag in clan.Alliances)
AddAllianceEntry(container, tag, i += 1);
// Alliance Invites
UI.Label(container, UI_MENU, Configuration.Menu.Color4.Get, string.Format(Message("UI.AllyInvites", player.userID), clan.AllianceInviteCount, allianceInviteLimit), 14, new UI4(0.3366f, 0.79f, 0.6632f, 0.83f), TextAnchor.MiddleLeft);
i = -1;
foreach (var kvp in clan.AllianceInvites)
AddAllianceInviteEntry(container, kvp.Key.ToString(), i += 1);
float yMin = GetVerticalPos(i += 1, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Button(container, UI_MENU, Configuration.Menu.Color2.Get, Message("UI.RequestAlliance", player.userID), 14, new UI4(0.3366f, yMin, 0.6632f, yMax), "clansui.requestalliance");
// Alliance Requests
UI.Label(container, UI_MENU, Configuration.Menu.Color4.Get, Message("UI.AllianceRequests", player.userID), 14, new UI4(0.6682f, 0.79f, 0.995f, 0.83f), TextAnchor.MiddleLeft);
i = -1;
foreach (string tag in clan.IncomingAlliances)
AddAllianceOfferEntry(container, tag, i += 1);
}
private void AddAllianceEntry(CuiElementContainer container, string tag, int index)
{
float yMin = GetVerticalPos(index, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Label(container, UI_MENU, FIELD_COLOR, tag, 14, new UI4(0.005f, yMin, 0.3316f, yMax), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, "0 0 0 0", string.Empty, 0, new UI4(0.005f, yMin, 0.3316f, yMax), $"clansui.viewalliance {CommandSafe(tag)}");
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, "<b>×</b>", 14, new UI4(0.3016f, yMin, 0.3316f, yMax), $"clansui.revokealliance {CommandSafe(tag)}");
}
private void AddAllianceInviteEntry(CuiElementContainer container, string tag, int index)
{
float yMin = GetVerticalPos(index, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Label(container, UI_MENU, FIELD_COLOR, tag, 14, new UI4(0.3366f, yMin, 0.6632f, yMax), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, "0 0 0 0", string.Empty, 0, new UI4(0.3366f, yMin, 0.6632f, yMax), $"clansui.viewalliance {CommandSafe(tag)}");
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, "<b>×</b>", 14, new UI4(0.6332f, yMin, 0.6632f, yMax), $"clansui.withdrawalliance {CommandSafe(tag)}");
}
private void AddAllianceOfferEntry(CuiElementContainer container, string tag, int index)
{
float yMin = GetVerticalPos(index, 0.745f);
float yMax = yMin + ELEMENT_HEIGHT;
UI.Label(container, UI_MENU, FIELD_COLOR, tag, 14, new UI4(0.6682f, yMin, 0.995f, yMax), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, "0 0 0 0", string.Empty, 0, new UI4(0.6682f, yMin, 0.995f, yMax), $"clansui.viewalliance {CommandSafe(tag)}");
UI.Button(container, UI_MENU, Configuration.Menu.Color2.Get, "<b>✔</b>", 14, new UI4(0.93f, yMin, 0.96f, yMax), $"clansui.acceptalliance {CommandSafe(tag)}");
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, "<b>×</b>", 14, new UI4(0.965f, yMin, 0.995f, yMax), $"clansui.rejectalliance {CommandSafe(tag)}");
}
#endregion
#region Invitations
private void CreateInvitationMenu(BasePlayer player, Menu menu, int page = 0)
{
CuiElementContainer container = UI.Container(UI_MENU, new UI4(0.35f, 0.15f, 0.95f, 0.85f));
UI.Panel(container, UI_MENU, Configuration.Menu.Panel.Get, new UI4(0.005f, 0.93f, 0.995f, 0.99f));
UI.Label(container, UI_MENU, menu == Menu.Members ? Message("UI.MemberInvite", player.userID) : Message("UI.AllianceInvite", player.userID), 20, new UI4(0.015f, 0.93f, 0.99f, 0.99f), TextAnchor.MiddleLeft);
UI.Button(container, UI_MENU, Configuration.Menu.Color3.Get, "<b>×</b>", 20, new UI4(0.9575f, 0.9375f, 0.99f, 0.9825f), $"clansui.openmenu {(int)menu}");
bool hasNextPage = false;
if (menu == Menu.Alliances)
{
Clans.Clan clan = Clans.Instance.storedData.FindClanByID(player.userID);
List<string> clans = Clans.storedData.clans.Keys.ToList();
hasNextPage = clans.Count > (ELEMENTS_PER_PAGE * page) + ELEMENTS_PER_PAGE;
for (int i = ELEMENTS_PER_PAGE * page; i < Mathf.Min(clans.Count, (ELEMENTS_PER_PAGE * page) + ELEMENTS_PER_PAGE); i++)
{
string tag = clans[i];
AddGridElement(container, tag, tag == clan?.Tag ? "" : $"clansui.requestalliance {CommandSafe(tag)}", i - (ELEMENTS_PER_PAGE * page));
}
}
else
{
//List<Core.Libraries.Covalence.IPlayer> players = covalence.Players.All.ToList();
//hasNextPage = players.Count > (ELEMENTS_PER_PAGE * page) + ELEMENTS_PER_PAGE;
//for (int i = ELEMENTS_PER_PAGE * page; i < Mathf.Min(players.Count, (ELEMENTS_PER_PAGE * page) + ELEMENTS_PER_PAGE); i++)
//{
// Core.Libraries.Covalence.IPlayer target = players[i];
// AddGridElement(container, target.Name, target.Id == player.UserIDString ? "" : $"clansui.invitemember {target.Id}", i - (ELEMENTS_PER_PAGE * page));
//}
List<BasePlayer> players = BasePlayer.allPlayerList.ToList();
hasNextPage = players.Count > (ELEMENTS_PER_PAGE * page) + ELEMENTS_PER_PAGE;
for (int i = ELEMENTS_PER_PAGE * page; i < Mathf.Min(players.Count, (ELEMENTS_PER_PAGE * page) + ELEMENTS_PER_PAGE); i++)
{
BasePlayer target = players[i];
AddGridElement(container, target.displayName, target == player ? "" : $"clansui.invitemember {target.UserIDString}", i - (ELEMENTS_PER_PAGE * page));
}
}
if (hasNextPage)
UI.Button(container, UI_MENU, Configuration.Menu.Color4.Get, "> > >", 14, new UI4(0.8342f, 0.005f, 0.995f, 0.045f), $"clansui.invitepage {(int)menu} {page + 1}");
if (page > 0)
UI.Button(container, UI_MENU, Configuration.Menu.Color4.Get, "< < <", 14, new UI4(0.005f, 0.005f, 0.1658f, 0.045f), $"clansui.invitepage {(int)menu} {page - 1}");
DestroyUI(player);
CuiHelper.AddUi(player, container);
}
private void AddGridElement(CuiElementContainer container, string key, string command, int index)
{
UI4 position = InviteAlign.Get(index);
UI.Button(container, UI_MENU, Configuration.Menu.Color2.Get, key, 14, position, command);
}
#region UI Grid Helper
private const int ELEMENTS_PER_PAGE = 114;
private readonly GridAlignment InviteAlign = new GridAlignment(6, 0.005f, 0.1608f, 0.005f, 0.92f, 0.04f, 0.005f);
private class GridAlignment
{
internal int Columns { get; set; }
internal float XOffset { get; set; }
internal float Width { get; set; }
internal float XSpacing { get; set; }
internal float YOffset { get; set; }
internal float Height { get; set; }
internal float YSpacing { get; set; }
internal GridAlignment(int columns, float xOffset, float width, float xSpacing, float yOffset, float height, float ySpacing)
{
Columns = columns;
XOffset = xOffset;
Width = width;
XSpacing = xSpacing;
YOffset = yOffset;
Height = height;
YSpacing = ySpacing;
}
internal UI4 Get(int index)
{
int rowNumber = index == 0 ? 0 : Mathf.FloorToInt(index / Columns);
int columnNumber = index - (rowNumber * Columns);
float offsetX = XOffset + (Width * columnNumber) + (XSpacing * columnNumber);
float offsetY = (YOffset - (rowNumber * Height) - (YSpacing * rowNumber));
return new UI4(offsetX, offsetY - Height, offsetX + Width, offsetY);
}
}
#endregion
#endregion
private float GetVerticalPos(int i, float start = 0.9f) => start - (i * (ELEMENT_HEIGHT + 0.005f));
#endregion
#region UI Commands
private static string CommandSafe(string text, bool unpack = false) => unpack ? text.Replace("▊▊", " ") : text.Replace(" ", "▊▊");
[ConsoleCommand("clansui.openmenu")]
private void ccmdOpenMenu(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Menu menu = (Menu)(arg.GetInt(0));
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID), menu);
}
[ConsoleCommand("clansui.close")]
private void ccmdUIClose(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
DestroyUI(player);
}
[ConsoleCommand("clansui.invitepage")]
private void ccmdInvitePageCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
CreateInvitationMenu(player, (Menu)arg.GetInt(0), arg.GetInt(1));
}
#region Member Commands
[ConsoleCommand("clansui.kick")]
private void ccmdKickCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.KickPlayer(player.IPlayer, arg.GetULong(0).ToString());
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID));
}
[ConsoleCommand("clansui.runcommand")]
private void ccmdRunCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
rust.RunClientCommand(player, "chat.say", CommandSafe(arg.Args[0], true));
}
[ConsoleCommand("clansui.invitemember")]
private void ccmdInviteMemberCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
if (arg.Args == null || arg.Args.Length == 0)
CreateInvitationMenu(player, Menu.Members, 0);
else
{
Clans.InvitePlayer(player.IPlayer, arg.GetULong(0).ToString());
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID));
}
}
[ConsoleCommand("clansui.revokeinvite")]
private void ccmdRevokeCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.WithdrawInvite(player.IPlayer, arg.Args[0]);
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID));
}
[ConsoleCommand("clansui.togglememberff")]
private void ccmdToggleMemberFFCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.Clan.Member member = Clans.storedData.FindMemberByID(player.userID);
member.MemberFFEnabled = !member.MemberFFEnabled;
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID));
}
[ConsoleCommand("clansui.toggleallyff")]
private void ccmdToggleAllyFFCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.Clan.Member member = Clans.storedData.FindMemberByID(player.userID);
member.AllyFFEnabled = !member.AllyFFEnabled;
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID));
}
[ConsoleCommand("clansui.leaveclan")]
private void ccmdLeaveCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.LeaveClan(player.IPlayer);
DestroyUI(player);
}
[ConsoleCommand("clansui.disbandclan")]
private void ccmdDisbandCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.DisbandClan(player.IPlayer);
DestroyUI(player);
}
#endregion
#region Alliance Commands
[ConsoleCommand("clansui.viewalliance")]
private void ccmdViewAllianceCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.Clan clan = Clans.storedData.FindClan(CommandSafe(arg.GetString(0), true));
if (clan != null)
clan.PrintClanInfo(player.IPlayer);
}
[ConsoleCommand("clansui.requestalliance")]
private void ccmdRequestAllianceCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
if (arg.Args == null || arg.Args.Length == 0)
CreateInvitationMenu(player, Menu.Alliances, 0);
else
{
Clans.OfferAlliance(player.IPlayer, CommandSafe(arg.GetString(0), true));
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID), Menu.Alliances);
}
}
[ConsoleCommand("clansui.revokealliance")]
private void ccmdRevokeAllianceCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.RevokeAlliance(player.IPlayer, CommandSafe(arg.GetString(0), true));
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID), Menu.Alliances);
}
[ConsoleCommand("clansui.withdrawalliance")]
private void ccmdWithdrawAllianceCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.WithdrawAlliance(player.IPlayer, CommandSafe(arg.GetString(0), true));
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID), Menu.Alliances);
}
[ConsoleCommand("clansui.acceptalliance")]
private void ccmdAcceptAllianceCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.AcceptAlliance(player.IPlayer, CommandSafe(arg.GetString(0), true));
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID), Menu.Alliances);
}
[ConsoleCommand("clansui.rejectalliance")]
private void ccmdRejectAllianceCommand(ConsoleSystem.Arg arg)
{
BasePlayer player = arg.Connection.player as BasePlayer;
if (player == null)
return;
Clans.RejectAlliance(player.IPlayer, CommandSafe(arg.GetString(0), true));
CreateClanMenu(player, Clans.Instance.storedData.FindClanByID(player.userID), Menu.Alliances);
}
#endregion
#endregion
#region Commands
private void CommandClanUI(BasePlayer player, string command, string[] args)
{
Clans.Clan clan = Clans.Instance.storedData.FindClanByID(player.userID);
if (clan == null)
player.ChatMessage(Message("You are not in a clan", player.userID));
else CreateClanMenu(player, clan);
}
#endregion
#region Config
private static ConfigData Configuration;
private class ConfigData
{
[JsonProperty(PropertyName = "Menu chat command")]
public string Command { get; set; }
[JsonProperty(PropertyName = "Clan member commands")]
public List<ClanCommand> MemberCommands { get; set; }
[JsonProperty(PropertyName = "UI Options")]
public MenuOptions Menu { get; set; }
public class ClanCommand
{
public string Name { get; set; }
public string Command { get; set; }
}
public class MenuOptions
{
[JsonProperty(PropertyName = "Panel Color")]
public UIColor Panel { get; set; }
[JsonProperty(PropertyName = "Disabled Color")]
public UIColor Disabled { get; set; }
[JsonProperty(PropertyName = "Color 1")]
public UIColor Color1 { get; set; }
[JsonProperty(PropertyName = "Color 2")]
public UIColor Color2 { get; set; }
[JsonProperty(PropertyName = "Color 3")]
public UIColor Color3 { get; set; }
[JsonProperty(PropertyName = "Color 4")]
public UIColor Color4 { get; set; }
}
public class UIColor
{
public string Hex { get; set; }
public float Alpha { get; set; }
[JsonIgnore]
private string _color;
[JsonIgnore]
public string Get
{
get
{
if (string.IsNullOrEmpty(_color))
_color = UI.Color(Hex, Alpha);
return _color;
}
}
}
public VersionNumber Version { get; set; }
}
protected override void LoadConfig()
{
base.LoadConfig();
Configuration = Config.ReadObject<ConfigData>();
if (Configuration.Version < Version)
UpdateConfigValues();
Config.WriteObject(Configuration, true);
}
protected override void LoadDefaultConfig() => Configuration = GetBaseConfig();
private ConfigData GetBaseConfig()
{
return new ConfigData
{
Command = "cmenu",
MemberCommands = new List<ConfigData.ClanCommand>
{
new ConfigData.ClanCommand
{
Command = "/tpr {playerName}",
Name = "TPR"
},
new ConfigData.ClanCommand
{
Command = "/trade {playerId}",
Name = "TRADE"
}
},
Menu = new ConfigData.MenuOptions
{
Panel = new ConfigData.UIColor { Hex = "#232323", Alpha = 1f },
Disabled = new ConfigData.UIColor { Hex = "#3e3e42", Alpha = 1f },
Color1 = new ConfigData.UIColor { Hex = "#007acc", Alpha = 1f },
Color2 = new ConfigData.UIColor { Hex = "#6a8b38", Alpha = 1f },
Color3 = new ConfigData.UIColor { Hex = "#d85540", Alpha = 1f },
Color4 = new ConfigData.UIColor { Hex = "#d08822", Alpha = 1f }
},
Version = Version
};
}
protected override void SaveConfig() => Config.WriteObject(Configuration, true);
private void UpdateConfigValues()
{
PrintWarning("Config update detected! Updating config values...");
ConfigData baseConfig = GetBaseConfig();
if (Configuration.Version < new VersionNumber(0, 2, 0))
Configuration = baseConfig;
Configuration.Version = Version;
PrintWarning("Config update completed!");
}
#endregion
#region Localization
private string Message(string key, ulong playerId = 0U) => lang.GetMessage(key, this, playerId != 0U ? playerId.ToString() : null);
private readonly Dictionary<string, string> Messages = new Dictionary<string, string>
{
["UI.Title"] = "Clan Administration",
["UI.Clan"] = "Clan",
["UI.Leader"] = "Leader",
["UI.ViewAlliances"] = "View Alliances",
["UI.ViewMembers"] = "View Members",
["UI.Leave"] = "Leave Clan",
["UI.Disband"] = "Disband Clan",
["UI.MemberFF"] = "Member FF",
["UI.AllyFF"] = "Ally FF",
["UI.Members"] = "Members ({0} / {1})",
["UI.MemberInvites"] = "Invites ({0} / {1})",
["UI.InviteMember"] = "Invite Member",
["UI.Kick"] = "KICK",
["UI.Alliances"] = "Alliances ({0} / {1})",
["UI.AllyInvites"] = "Alliance Invites ({0} / {1})",
["UI.RequestAlliance"] = "Request Alliance",
["UI.AllianceRequests"] = "Alliance Requests",
["UI.MemberInvite"] = "Select a player to invite",
["UI.AllianceInvite"] = "Select a clan to offer an alliance"
};
#endregion
}
}