Plugin isn't working despite lack of compiler errorsSolved
GeniusPlayUnique
Plugin Developer
I have coded a plugin specialized for my server but despite a total lack of (compiler-)errors it is not working and I have absolutely no idea why and sadly not even any indications.

(Because I have no clue what nor where the problem is I have to put the hole code in here but I insist that this is not an illegitimate plugin release because this plugin is specialized for something we want to do on our server. Maybe I will modify it later so make it more universally usable but at this point it is solely made for our server so it has little use for anyone else.)

I hope that someone that knows more about coding plugins with Oxide can find the problem and tell me how to solve it.

using System.Collections.Generic;
using CodeHatch.Common;
using CodeHatch.Engine.Core.Consoles;
using CodeHatch.Engine.Modules.SocialSystem;
using CodeHatch.Engine.Networking;
using CodeHatch.Networking.Events.Entities;
using CodeHatch.Thrones.SocialSystem;
using CodeHatch.UserInterface.Dialogues;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;

namespace Oxide.Plugins
{
    [Info("Kingdoms", "GPU", "0.0.1")]
    public class Kingdoms : ReignOfKingsPlugin
    {

        static List<Player> AClaims = new List<Player>();
        static List<Player> BClaims = new List<Player>();
        static List<Player> CClaims = new List<Player>();
        static List<Player> DClaims = new List<Player>();
        static List<Player> EClaims = new List<Player>();
        static List<Player> FClaims = new List<Player>();
        static bool AFirstClaim = true;
        static bool BFirstClaim = true;
        static bool CFirstClaim = true;
        static bool DFirstClaim = true;
        static bool EFirstClaim = true;
        static bool FFirstClaim = true;

        #region Inherited Classes

        private class Kingdom
        {
            public string Name { get; set; }
            public ulong Ruler { get; set; }
            public double Taxrate { get; set; }
            public List<uint> MemberGuildsCrests { get; set; }

            public Kingdom() { }

            public Kingdom(string name, ulong ruler, double taxrate, List<uint> memberGuildsCrests)
            {
                Name = name;
                Ruler = ruler;
                Taxrate = taxrate;
                MemberGuildsCrests = memberGuildsCrests;
            }
        }

/*
        private class PlayerData
        {
            public string Id;
            public string Name;
            public Dictionary<string, int> Tax;

            public PlayerData()
            {
            }

            public PlayerData(Player player)
            {
                Id = player.Id.ToString();
                Name = player.DisplayName;
                Tax = new Dictionary<string, int>();
            }
        }
*/

        #endregion

        static List<Kingdom> KingdomsList = new List<Kingdom>();
        //static Dictionary<Player, PlayerData> PlayersDataList = new Dictionary<Player, PlayerData>();

        #region List loading and saving

        void Loaded()
        {
            LoadLists();
        }

        void Unload()
        {
            SaveLists();
        }

        void OnServerSave()
        {
            SaveLists();
        }

        void OnServerShutdown()
        {
            SaveLists();
        }

        void LoadLists()
        {
            KingdomsList = Interface.GetMod().DataFileSystem.ReadObject<List<Kingdom>>("KingdomsList");
            //PlayersDataList = Interface.GetMod().DataFileSystem.ReadObject<Dictionary<Player, PlayerData>>("PlayersDataList");
        }

        void SaveLists()
        {
            Interface.GetMod().DataFileSystem.WriteObject("KingdomsList", KingdomsList);
            //Interface.GetMod().DataFileSystem.WriteObject("PlayersDataList", PlayersDataList);
        }

        #endregion

        #region Commands

        [ChatCommand("kingdoms")]
        void ShowKingdoms(Player player)
        {
            LoadLists();
            string ShowKingdomsList = "";
            for (int i = 0; i <= 5; i++)
            {
                if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom A"))
                {
                    ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[000000]A[FFFFFF]]:" + "\n";
                    ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" +"\n";
                }
                if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom B"))
                {
                    ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[FF0000]B[FFFFFF]]:" + "\n";
                    ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
                }
                if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom C"))
                {
                    ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[FFFF00]C[FFFFFF]]:" + "\n";
                    ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
                }
                if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom D"))
                {
                    ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[0000FF]D[FFFFFF]]:" + "\n";
                    ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
                }
                if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom E"))
                {
                    ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[FF00FF]E[FFFFFF]]:" + "\n";
                    ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
                }
                if (KingdomsList.GetAt<Kingdom>(i).Name.Equals("Kingdom F"))
                {
                    ShowKingdomsList = ShowKingdomsList + "[b][i]" + "[008080]" + KingdomsList.GetAt<Kingdom>(i).Name + "[FFFFFF]" + "[/b][/i]" + " [[00FF00]F[FFFFFF]]:" + "\n";
                    ShowKingdomsList = ShowKingdomsList + " (Ruler: " + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).DisplayName + ")" + "\n";
                }

                List<string> KingdomMemberGuildnames = new List<string>();

                for (int ii = 0; ii < KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Count; ii++)
                {
                    uint crestId = KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.GetAt<uint>(ii);
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (!KingdomMemberGuildnames.Contains("  ∙ " + crestGuildname))
                    {
                        KingdomMemberGuildnames.Add("  ∙ " + crestGuildname);
                    }
                }

                ShowKingdomsList = ShowKingdomsList + KingdomMemberGuildnames.JoinToString("\n") + "\n";
            }

            player.ShowPopup("Kingdoms:", ShowKingdomsList);
        }

        [ChatCommand("crests")]
        void GetAllCrests(Player player, string command, string[] args)
        {
            if (!player.HasPermission("admin"))
            {
                return;
            }
            string unknownCrests = "";
            foreach (Player p in Server.AllPlayers)
            {
                Crest crest = SocialAPI.Get<CrestScheme>().GetCrest(p.Id);
                if (crest != null)
                {
                    for (int i = 0; i <= 5; i++)
                    {
                        if (!KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Contains(crest.ObjectGUID))
                        {
                            unknownCrests = unknownCrests + "∙ " + crest.GuildName + "'s Crest [" + crest.ObjectGUID.ToString() + "] at " + crest.Position.ToString() + "\n";
                        }
                    }
                }
            }

            player.ShowPopup("Unknown Crests:", unknownCrests);
            SendReply(player, "Unknown Crests:" + "\n" + unknownCrests);
        }
        
        [ChatCommand("initialize")]
        void GetCrest(Player player, string command, string[] args)
        {
            if (!player.HasPermission("admin"))
            {
                return;
            }

            Options selection1 = new Options();

            if (KingdomsList.Count != 0)
            {
                player.ShowConfirmPopup("WARNING: Reinitializing Kingdoms?", "You are about to reinitialize the Kingdoms. \n All Data will be lost. \n\n Do you want to precede?", "Confirm", "Cancel", (selection, dialogue, contextData) => selection1 = selection);
            }
            if (selection1 == Options.Cancel)
            {
                return;
            }
            Kingdom A = new Kingdom();
            Kingdom B = new Kingdom();
            Kingdom C = new Kingdom();
            Kingdom D = new Kingdom();
            Kingdom E = new Kingdom();
            Kingdom F = new Kingdom();
            KingdomsList.Add(A);
            KingdomsList.Add(B);
            KingdomsList.Add(C);
            KingdomsList.Add(D);
            KingdomsList.Add(E);
            KingdomsList.Add(F);
        }

        [ChatCommand("claim")]
        void ClaimKingdom(Player player, string command, string[] args)
        {
            int bonuses = 0;
            var kingdom = args[0].ToLower();
            if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
            {
                if (KingdomsList.GetAt<Kingdom>(0).Ruler != 0)
                {
                    player.SendError("The Kingdom A already has a Ruler.");
                    return;
                }
                if (AClaims.Contains(player))
                {
                    player.SendError("You have already submitted your claim to the Kingdom A");
                    return;
                }

                bool hasClaim = false;
                
                foreach (uint crestId in KingdomsList.GetAt<Kingdom>(0).MemberGuildsCrests)
                {
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (crestGuildname == player.GetGuild().Name.ToString())
                    {
                        hasClaim = true;
                    }
                }

                if (hasClaim == false)
                {
                    player.SendError("You have no claim to the Kingdom A.");
                    return;
                }

                bonuses = bonuses + player.GetGuild().Members().MemberCount();

                if (player.GetGuild().OwnerId == player.Id)
                {
                    bonuses = bonuses + 3;
                }

                for (int i = 0; i <= bonuses; i++)
                {
                    AClaims.Add(player);
                }

                if (AFirstClaim == true)
                {
                    AFirstClaim = false;
                    timer.In(600, () => KingdomsList.GetAt<Kingdom>(0).Ruler = DetermineRuler(AClaims));
                    timer.Once(605, () => AClaims.Clear());
                    timer.Once(610, () => AFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).SendNews("You are now the Ruler of the Kingdom A. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).DisplayName + " is the new Ruler of A.", Server.ClientPlayers, Severity.Urgent));
                }
                
            }
            if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
            {
                if (KingdomsList.GetAt<Kingdom>(1).Ruler != 0)
                {
                    player.SendError("The Kingdom B already has a Ruler.");
                    return;
                }
                if (BClaims.Contains(player))
                {
                    player.SendError("You have already submitted your claim to the Kingdom B");
                    return;
                }

                bool hasClaim = false;

                foreach (uint crestId in KingdomsList.GetAt<Kingdom>(1).MemberGuildsCrests)
                {
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (crestGuildname == player.GetGuild().Name)
                    {
                        hasClaim = true;
                    }
                }

                if (hasClaim == false)
                {
                    player.SendError("You have no claim to the Kingdom B.");
                    return;
                }

                bonuses = bonuses + player.GetGuild().Members().MemberCount();

                if (player.GetGuild().OwnerId == player.Id)
                {
                    bonuses = bonuses + 3;
                }

                for (int i = 0; i <= bonuses; i++)
                {
                    BClaims.Add(player);
                }

                if (BFirstClaim == true)
                {
                    BFirstClaim = false;
                    timer.In(600, () => KingdomsList.GetAt<Kingdom>(1).Ruler = DetermineRuler(BClaims));
                    timer.Once(605, () => BClaims.Clear());
                    timer.Once(610, () => BFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(1).Ruler).SendNews("You are now the Ruler of the Kingdom B. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(1).Ruler).DisplayName + " is the new Ruler of B.", Server.ClientPlayers, Severity.Urgent));
                }
            }
            if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
            {
                if (KingdomsList.GetAt<Kingdom>(2).Ruler != 0)
                {
                    player.SendError("The Kingdom C already has a Ruler.");
                    return;
                }
                if (CClaims.Contains(player))
                {
                    player.SendError("You have already submitted your claim to the Kingdom C");
                    return;
                }

                bool hasClaim = false;

                foreach (uint crestId in KingdomsList.GetAt<Kingdom>(2).MemberGuildsCrests)
                {
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (crestGuildname == player.GetGuild().Name)
                    {
                        hasClaim = true;
                    }
                }

                if (hasClaim == false)
                {
                    player.SendError("You have no claim to the Kingdom C.");
                    return;
                }

                bonuses = bonuses + player.GetGuild().Members().MemberCount();

                if (player.GetGuild().OwnerId == player.Id)
                {
                    bonuses = bonuses + 3;
                }

                for (int i = 0; i <= bonuses; i++)
                {
                    CClaims.Add(player);
                }

                if (CFirstClaim == true)
                {
                    CFirstClaim = false;
                    timer.In(600, () => KingdomsList.GetAt<Kingdom>(2).Ruler = DetermineRuler(CClaims));
                    timer.Once(605, () => CClaims.Clear());
                    timer.Once(610, () => CFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(2).Ruler).SendNews("You are now the Ruler of the Kingdom C. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(2).Ruler).DisplayName + " is the new Ruler of C.", Server.ClientPlayers, Severity.Urgent));
                }
            }
            if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
            {
                if (KingdomsList.GetAt<Kingdom>(3).Ruler != 0)
                {
                    player.SendError("The Kingdom D already has a Ruler.");
                    return;
                }
                if (DClaims.Contains(player))
                {
                    player.SendError("You have already submitted your claim to the Kingdom D");
                    return;
                }


                bool hasClaim = false;

                foreach (uint crestId in KingdomsList.GetAt<Kingdom>(3).MemberGuildsCrests)
                {
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (crestGuildname == player.GetGuild().Name)
                    {
                        hasClaim = true;
                    }
                }

                if (hasClaim == false)
                {
                    player.SendError("You have no claim to the Kingdom D.");
                    return;
                }

                bonuses = bonuses + player.GetGuild().Members().MemberCount();

                if (player.GetGuild().OwnerId == player.Id)
                {
                    bonuses = bonuses + 3;
                }

                for (int i = 0; i <= bonuses; i++)
                {
                    DClaims.Add(player);
                }

                if (DFirstClaim == true)
                {
                    DFirstClaim = false;
                    timer.In(600, () => KingdomsList.GetAt<Kingdom>(3).Ruler = DetermineRuler(DClaims));
                    timer.Once(605, () => DClaims.Clear());
                    timer.Once(610, () => DFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(3).Ruler).SendNews("You are now the Ruler of the Kingdom D. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(3).Ruler).DisplayName + " is the new Ruler of D.", Server.ClientPlayers, Severity.Urgent));
                }
            }
            if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
            {
                if (KingdomsList.GetAt<Kingdom>(4).Ruler != 0)
                {
                    player.SendError("The Kingdom E already has a Ruler.");
                    return;
                }
                if (EClaims.Contains(player))
                {
                    player.SendError("You have already submitted your claim to the Kingdom E");
                    return;
                }

                bool hasClaim = false;

                foreach (uint crestId in KingdomsList.GetAt<Kingdom>(4).MemberGuildsCrests)
                {
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (crestGuildname == player.GetGuild().Name)
                    {
                        hasClaim = true;
                    }
                }

                if (hasClaim == false)
                {
                    player.SendError("You have no claim to the Kingdom E.");
                    return;
                }

                bonuses = bonuses + player.GetGuild().Members().MemberCount();

                if (player.GetGuild().OwnerId == player.Id)
                {
                    bonuses = bonuses + 3;
                }

                for (int i = 0; i <= bonuses; i++)
                {
                    EClaims.Add(player);
                }

                if (EFirstClaim == true)
                {
                    EFirstClaim = false;
                    timer.In(600, () => KingdomsList.GetAt<Kingdom>(4).Ruler = DetermineRuler(EClaims));
                    timer.Once(605, () => EClaims.Clear());
                    timer.Once(610, () => EFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(4).Ruler).SendNews("You are now the Ruler of the Kingdom E. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(4).Ruler).DisplayName + " is the new Ruler of E.", Server.ClientPlayers, Severity.Urgent));
                }
            }
            if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
            {
                if (KingdomsList.GetAt<Kingdom>(5).Ruler != 0)
                {
                    player.SendError("The Kingdom F already has a Ruler.");
                    return;
                }
                if (FClaims.Contains(player))
                {
                    player.SendError("You have already submitted your claim to the Kingdom F");
                    return;
                }


                bool hasClaim = false;

                foreach (uint crestId in KingdomsList.GetAt<Kingdom>(5).MemberGuildsCrests)
                {
                    string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                    if (crestGuildname == player.GetGuild().Name)
                    {
                        hasClaim = true;
                    }
                }

                if (hasClaim == false)
                {
                    player.SendError("You have no claim to the Kingdom F.");
                    return;
                }

                bonuses = bonuses + player.GetGuild().Members().MemberCount();

                if (player.GetGuild().OwnerId == player.Id)
                {
                    bonuses = bonuses + 3;
                }

                for (int i = 0; i <= bonuses; i++)
                {
                    FClaims.Add(player);
                }

                if (FFirstClaim == true)
                {
                    FFirstClaim = false;
                    timer.In(600, () => KingdomsList.GetAt<Kingdom>(5).Ruler = DetermineRuler(FClaims));
                    timer.Once(605, () => FClaims.Clear());
                    timer.Once(610, () => FFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(5).Ruler).SendNews("You are now the Ruler of the Kingdom F. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(5).Ruler).DisplayName + " is the new Ruler of F.", Server.ClientPlayers, Severity.Urgent));
                }
            }
        }

        [ChatCommand("renounce")]
        void RenounceKingdom(Player player, string command, string[] args)
        {
            var kingdom = args[0].ToLower();
            if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
            {
                if (player.Id == KingdomsList.GetAt<Kingdom>(0).Ruler)
                {
                    Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).SendNews("You are no longer the Ruler of the Kingdom A.");
                    KingdomsList.GetAt<Kingdom>(0).Ruler = 0;
                }
            }
            if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
            {
                if (player.Id == KingdomsList.GetAt<Kingdom>(1).Ruler)
                {
                    Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(1).Ruler).SendNews("You are no longer the Ruler of the Kingdom B.");
                    KingdomsList.GetAt<Kingdom>(1).Ruler = 0;
                }
            }
            if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
            {
                if (player.Id == KingdomsList.GetAt<Kingdom>(2).Ruler)
                {
                    Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(2).Ruler).SendNews("You are no longer the Ruler of the Kingdom C.");
                    KingdomsList.GetAt<Kingdom>(2).Ruler = 0;
                }
            }
            if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
            {
                if (player.Id == KingdomsList.GetAt<Kingdom>(3).Ruler)
                {
                    Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(3).Ruler).SendNews("You are no longer the Ruler of the Kingdom D.");
                    KingdomsList.GetAt<Kingdom>(3).Ruler = 0;
                }
            }
            if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
            {
                if (player.Id == KingdomsList.GetAt<Kingdom>(4).Ruler)
                {
                    Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(4).Ruler).SendNews("You are no longer the Ruler of the Kingdom E.");
                    KingdomsList.GetAt<Kingdom>(4).Ruler = 0;
                }
            }
            if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
            {
                if (player.Id == KingdomsList.GetAt<Kingdom>(5).Ruler)
                {
                    Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(5).Ruler).SendNews("You are no longer the Ruler of the Kingdom F.");
                    KingdomsList.GetAt<Kingdom>(5).Ruler = 0;
                }
            }
        }

        [ChatCommand("kingdomAdd")]
        void AddCrestToKingdom(Player player, string command, string[] args)
        {
            if (!player.HasPermission("admin"))
            {
                return;
            }

            uint crestId;

            try
            {
                uint.TryParse(args[1], out crestId);
            }
            catch
            {
                player.SendError("Could not Parse CrestId (string args[1]) to uint.");
                return;
            }

            var kingdom = args[0].ToLower();
            if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(0).MemberGuildsCrests.Add(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom A.");
            }
            if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(1).MemberGuildsCrests.Add(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom B.");
            }
            if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(2).MemberGuildsCrests.Add(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom C.");
            }
            if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(3).MemberGuildsCrests.Add(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom D.");
            }
            if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(4).MemberGuildsCrests.Add(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom E.");
            }
            if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(5).MemberGuildsCrests.Add(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was added to the Kingdom F.");
            }

            SaveLists();
        }

        [ChatCommand("kingdomRemove")]
        void RemoveCrestFromKingdom(Player player, string command, string[] args)
        {
            if (!player.HasPermission("admin"))
            {
                return;
            }

            uint crestId;

            try
            {
                uint.TryParse(args[1], out crestId);
            }
            catch
            {
                player.SendError("Could not Parse CrestId (string args[1]) to uint.");
                return;
            }

            var kingdom = args[0].ToLower();
            if (kingdom == "A".ToLower() || kingdom == "Kingdom A".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(0).MemberGuildsCrests.Remove(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom A.");
            }
            if (kingdom == "B".ToLower() || kingdom == "Kingdom B".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(1).MemberGuildsCrests.Remove(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom B.");
            }
            if (kingdom == "C".ToLower() || kingdom == "Kingdom C".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(2).MemberGuildsCrests.Remove(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom C.");
            }
            if (kingdom == "D".ToLower() || kingdom == "Kingdom D".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(3).MemberGuildsCrests.Remove(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom D.");
            }
            if (kingdom == "E".ToLower() || kingdom == "Kingdom E".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(4).MemberGuildsCrests.Remove(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom E.");
            }
            if (kingdom == "F".ToLower() || kingdom == "Kingdom F".ToLower())
            {
                KingdomsList.GetAt<Kingdom>(5).MemberGuildsCrests.Remove(crestId);
                string crestGuildname = SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName;
                SendReply(player, "The Crest [" + crestId + "] of " + crestGuildname + "was removed to the Kingdom F.");
            }

            SaveLists();
        }

        #endregion

        ulong DetermineRuler (List<Player> KingdomClaims)
        {
            Player potentialNewRuler = null;
            KingdomClaims.Shuffle<Player>();
            KingdomClaims.FastShuffle<Player>();
            KingdomClaims.Shuffle<Player>();
            bool potentialNewRulerIsOnline = false;
            while (!potentialNewRulerIsOnline)
            {
                potentialNewRuler = KingdomClaims.GetRandom<Player>();
                potentialNewRulerIsOnline = potentialNewRuler.IsOnlineAccount;
            }
            ulong newRulerId = potentialNewRuler.Id;
            bool newRulerIsMale = Server.GetPlayerById(newRulerId).GetCharacterGender();
            if (!Server.GetPlayerById(newRulerId).HasPermission("admin"))
            {
                if (newRulerIsMale)
                {
                    Server.Permissions.Load();
                    Server.Permissions.AddUser(Server.GetPlayerById(newRulerId).Name);
                    Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).AddGroup(Server.Permissions.GetGroup("king"));
                    Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).MakePrimaryGroup(Server.Permissions.GetGroup("king"));
                    Server.Permissions.Save();
                }
                else if (!newRulerIsMale)
                {
                    Server.Permissions.Load();
                    Server.Permissions.AddUser(Server.GetPlayerById(newRulerId).Name);
                    Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).AddGroup(Server.Permissions.GetGroup("queen"));
                    Server.Permissions.GetUser(Server.GetPlayerById(newRulerId).Name).MakePrimaryGroup(Server.Permissions.GetGroup("queen"));
                    Server.Permissions.Save();
                }
            }
            IPlayer server = covalence.Players.FindPlayerById("9999999999");
            server.Command("permissions reload");
            timer.Once(5, () => SaveLists());
            return newRulerId;
        }

        void OnEntityDeath(EntityDeathEvent ede)
        {
            if (!ede.Entity.IsPlayer && ede.Entity.name.Contains("Crest"))
            {
                for (int i = 0; i <= 5; i++)
                {
                    int guildCrestsInKingdom = 0;

                    foreach (uint crestId in KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests)
                    {
                        if (SocialAPI.Get<CrestScheme>().GetCrest(crestId).Position == ede.Entity.Position)
                        {
                            KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Remove(crestId);
                        }
                        if (ede.Entity.Owner.GetGuild().Name == SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName)
                        {
                            guildCrestsInKingdom++;
                        }
                    }

                    if (guildCrestsInKingdom == 0 && ede.Entity.Owner.GetGuild().Name == Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).GetGuild().Name)
                    {
                        Server.Permissions.Load();
                        Server.Permissions.GetUser(Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).Name).RemoveGroup("king");
                        Server.Permissions.GetUser(Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).Name).RemoveGroup("queen");
                        KingdomsList.GetAt<Kingdom>(i).Ruler = 0;
                        Server.Permissions.Save();
                        IPlayer server = covalence.Players.FindPlayerById("9999999999");
                        server.Command("permissions reload");
                    }
                }
            }
        }
    }
}
​

Thanks in advance.
Wulf
uMod Admin
Could you provide a little more information on what exactly isn't working?

Also, no need to lookup the server "player":
covalence.Server.Command("permissions reload");​
GeniusPlayUnique
Original Poster
Plugin Developer
First of all thank you for the tip with the  covalence.Server.Command("permissions reload"); . I have changed it righ away.

And second I am sorry but I can't provide further information on what exactly isn't working, because nothing is and I don't have the slightest clue why.
If I use any of the chat commands I don't get an "Unknown command"-error so they seem to be registered as commands but still nothing happens if I use them.

As implied earlier I am absolutely clueless.
Wulf
uMod Admin
In response to GeniusPlayUnique (View post):
First of all thank you for the tip with the  covalence.Server.Command("permissions reload"); . I hav...
The "Unknown commands" in fact means they aren't actually registered, so either the plugin isn't loaded or there's an issue with the command format.

How a command method signature should be formatted:
[ChatCommand("mycommand")]
void YourCommand(Player player, string command, string[] args)​

In most cases, you don't need all of the arguments, but I'd suggest trying it regardless. If you could provide a pastebin or your oxide/logs file, that'd be helpful as well.

GeniusPlayUnique
Original Poster
Plugin Developer
Yeah, but I DO NOT get an "Unknown command"-error and my command are formatted like that as you can see.
Wulf
uMod Admin
In response to GeniusPlayUnique (View post):
Yeah, but I DO NOT get an "Unknown command"-error and my command are formatted like that as you can...
Ahh, misread it there. :P I saw most with that signature, one didn't.
GeniusPlayUnique
Original Poster
Plugin Developer
No Problem. But even though I don't get an error they still aren't working...

Merged post

Do you have an idea why it isn't working?

Merged post

I have found an error in the Oxide logs when I use one of the commands.
I have no idea what the error really means but I hope that this may make sense to you...

[Error] Failed to call hook 'ShowKingdoms' on plugin 'Kingdoms v0.0.1' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.Kingdoms.ShowKingdoms (CodeHatch.Engine.Networking.Player player) [0x00000] in <filename unknown>:0 
  at Oxide.Plugins.Kingdoms.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0 ​

 

[Error] Failed to call hook 'GetAllCrests' on plugin 'Kingdoms v0.0.1' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.Kingdoms.GetAllCrests (CodeHatch.Engine.Networking.Player player, System.String command, System.String[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Plugins.Kingdoms.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0 

Any idea what that means?
Wulf
uMod Admin
I havent been able to look deeply or test your code personally yet, but those errors mean something you are using in those methods isn't set/valid. You can add some null checks and debug output to see what.
GeniusPlayUnique
Original Poster
Plugin Developer
I have worked on the plugin and I don't know why but most of the things are working now except this one:
[...]

[ChatCommand("crests")]
        void GetAllCrests(Player player)
        {
            if (!player.HasPermission("admin"))
            {
                return;
            }

            List<string> unknownCrestsList = new List<string>();
            foreach (IPlayer Ip in covalence.Players.All)
            {
                Player p = Server.GetPlayerByName(Ip.Name);
                bool CrestKnown = false;

                if (SocialAPI.Get<CrestScheme>().HasCrest(p.Id))
                {
                    Crest crest = SocialAPI.Get<CrestScheme>().GetCrest(p.Id);

                    for (int ii = 0; ii < KingdomsList.Count; ii++)
                    {
                        if (KingdomsList.GetAt<Kingdom>(ii).MemberGuildsCrests.Contains(crest.ObjectGUID))
                        {
                            CrestKnown = true;
                        }
                    }

                    if (!CrestKnown)
                    {
                        unknownCrestsList.Add("∙ " + crest.GuildName + "'s Crest [#" + crest.ObjectGUID.ToString() + "] at " + crest.Position.ToString());
                    }
                }
            }

            if (!unknownCrestsList.IsNullOrEmpty<string>())
            {
                string unknownCrests = unknownCrestsList.JoinToString<string>("\n");
                player.ShowPopup("Unknown Crests:", unknownCrests);
            }
            else if (unknownCrestsList.IsNullOrEmpty<string>())
            {
                player.SendError("There are no unknown Crests.");
            }
        }

[...]​

And I have another problem. When I use the command /claim <Kingdom> the server crashes after some time, presumatly after the timers have run out.
Wulf
uMod Admin
What is the issue with that exactly?
GeniusPlayUnique
Original Poster
Plugin Developer
In response to Wulf (View post):
What is the issue with that exactly?
I don't know.
I would assume the same thing that was wrong with the others but I don't know for sure.
Wulf
uMod Admin
In response to GeniusPlayUnique (View post):
I don't know.
I would assume the same thing that was wrong with the others but I don't know for...
No errors in the logs when running the commands?
GeniusPlayUnique
Original Poster
Plugin Developer
In response to GeniusPlayUnique (View post):
No Problem. But even though I don't get an error they still aren't working...

Merged post...
Only this one.

Merged post

[Error] Failed to call hook 'GetAllCrests' on plugin 'Kingdoms v0.0.1' (NullReferenceException: Object reference not set to an instance of an object)
  at Oxide.Plugins.Kingdoms.GetAllCrests (CodeHatch.Engine.Networking.Player player, System.String command, System.String[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Plugins.Kingdoms.DirectCallHook (System.String name, System.Object& ret, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Plugins.CSharpPlugin.InvokeMethod (Oxide.Core.Plugins.HookMethod method, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Core.Plugins.CSPlugin.OnCallHook (System.String name, System.Object[] args) [0x00000] in <filename unknown>:0 
  at Oxide.Core.Plugins.Plugin.CallHook (System.String hook, System.Object[] args) [0x00000] in <filename unknown>:0 
Wulf
uMod Admin
So something still null in that method, likely something with the player or crest. I'd suggest adding null checks still, and outputting some debug logs.
GeniusPlayUnique
Original Poster
Plugin Developer
Do you have a solution for the server-crashing-problem or can you tell me what the reson for the crash could be?
I think that it might be in the DetermineRuler-method because the server isn't crashing immediately after I use the /claim <Kingdom>-command but about ten minutes later. That might indicate that the crash is a result of the ten-minutes-timer running out in the ClaimKingdom-method:
[...]

timer.In(600, () => KingdomsList.GetAt<Kingdom>(0).Ruler = DetermineRuler(AClaims));
                    timer.Once(605, () => AClaims.Clear());
                    timer.Once(610, () => AFirstClaim = true);
                    timer.Once(615, () => Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).SendNews("You are now the Ruler of the Kingdom A. Long may you reign.", Severity.Urgent));
                    timer.Once(615, () => NewsFeed.SendNews("" + Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(0).Ruler).DisplayName + " is the new Ruler of A.", Server.ClientPlayers, Severity.Urgent));

[...]​

And I found another probelm. For whatever reson the crests are not removed from the kingdom when they get destroyed.
So in this method seems to be a mistake too but I can't find it...
void OnEntityDeath(EntityDeathEvent ede)
        {
            if (!ede.Entity.IsPlayer && ede.Entity.name.Contains("Crest"))
            {
                for (int i = 0; i <= 5; i++)
                {
                    int guildCrestsInKingdom = 0;

                    foreach (uint crestId in KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests)
                    {
                        if (SocialAPI.Get<CrestScheme>().GetCrest(crestId).Position == ede.Entity.Position)
                        {
                            KingdomsList.GetAt<Kingdom>(i).MemberGuildsCrests.Remove(crestId);
                        }
                        if (ede.Entity.Owner.GetGuild().Name == SocialAPI.Get<CrestScheme>().GetCrest(crestId).GuildName)
                        {
                            guildCrestsInKingdom++;
                        }
                    }

                    if (guildCrestsInKingdom == 0 && ede.Entity.Owner.GetGuild().Name == Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).GetGuild().Name)
                    {
                        Server.Permissions.Load();
                        Server.Permissions.GetUser(Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).Name).RemoveGroup("king");
                        Server.Permissions.GetUser(Server.GetPlayerById(KingdomsList.GetAt<Kingdom>(i).Ruler).Name).RemoveGroup("queen");
                        KingdomsList.GetAt<Kingdom>(i).Ruler = 0;
                        Server.Permissions.Save();
                        IPlayer server = covalence.Players.FindPlayerById("9999999999");
                        server.Command("permissions reload");
                    }
                }
            }
        }​