CSUtility mods (Colony Survival 0.2.7)

CSUtility

Simplified command parsing



Configuration management



Logger



Player/Position extensions

[drive.google.com]

Announcer

[drive.google.com]

BannerTracker

[drive.google.com]

BetterChat

{ "ColorArea": "name", "Color": "#00ccff", "Permission": "betterchat.lightbluename" }, { "ColorArea": "text", "Color": "red", "Permission": "betterchat.redtext" }

[drive.google.com]

ColonistCapacity

{ "Permission": "colonistcapacity.tier1", "Capacity": 100 }

[drive.google.com]

UtilityCommands

[drive.google.com]

//Make sure you have referenced CSUtility in your project. //Example command using ChatCommands; using CSUtility; using Pipliz.Chatting; using System; using Permissions; namespace UtilityCommands { internal class DefaultCommand : IChatCommand { public static PermissionsManager.Permission CommandPermission = new PermissionsManager.Permission("defaultmod.defaultcommand"); public bool IsCommand(string chat) { return chat.ToLower().StartsWith("/default") || chat.StartsWith("/df"); } public bool TryDoCommand(NetworkID owner, string chat) { if (PermissionsManager.HasPermission(owner, CommandPermission)) try { //Easy chat command parsing with support for spaces with quotes var parameters = chat.ParseChatCommand(); switch (parameters.Length) { case 1: //command execution for 1 parameter Players.Player player; Players.TryMatchName(parameters[0], out player); if (player != null) { //Easy access to related classes var playerStockpile = player.GetStockpile(); var playerColony = player.GetColony(); //Easy access to information var playerColonistsCount = player.GetColonistsCount(); //Added extension to Vector3Int to find players in particular places Players.Player stranger = playerColony.Location.GetClosestPlayer(); return true; } else { Chat.Send(owner, $"Unable to find player by the name {parameters[0]}"); return true; } case 2: //command execution for 2 parameters return true; case 3: //command execution for 3 parameters return true; default: Chat.Send(owner, "command information"); return true; } } catch (Exception ex) { Chat.Send(owner, "command error message"); Logger.LogMessage("default.txt", ex.Message); Logger.LogMessage("default.txt", ex.StackTrace); return false; } Chat.Send(owner, "You do not have permission to use this command."); return true; } } }

//Example from ColonistCapacity using ConfigurationManger using System.Reflection; using CSUtility; using Pipliz; using Pipliz.JSON; namespace ColonistCapacity { //Create your own configuration class internal class CapacityConfiguration { public bool CheckOfflinePlayers { get; set; } //It can also contain other created classes public CapacityPermission[] settings { get; set; } public CapacityConfiguration() { } public CapacityConfiguration(CapacityPermission[] settings) { this.settings = settings; } } //Like this class public class CapacityPermission { public string Permission { get; set; } public int Capacity { get; set; } } [ModLoader.ModManager] public class Initialization { [ModLoader.ModCallback(ModLoader.EModCallbackType.AfterItemTypesServer)] public static void AfterItemTypesServer() { //Create your configuration var config = new ConfigurationManager ("ColonistCapacity"); //If the file doesnt exist, generate it with default settings if (!config.Exists) config.ResetConfiguration(new CapacityConfiguration(new[] { new CapacityPermission { Permission = "colonistcapacity.tier1", Capacity = 100 }, new CapacityPermission { Permission = "colonistcapacity.tier2", Capacity = 200 }, new CapacityPermission { Permission = "colonistcapacity.tier3", Capacity = 300 }, new CapacityPermission { Permission = "colonistcapacity.tier4", Capacity = 400 }, new CapacityPermission { Permission = "colonistcapacity.tier5", Capacity = 500 } })); //Get settings from the file CapacityConfiguration settings = config.GetConfigurationSettings(); } [ModLoader.ModCallback(ModLoader.EModCallbackType.AfterStartup)] public static void AfterStartup() { Log.Write($"Loaded {Assembly.GetExecutingAssembly().GetName().Name} {Assembly.GetExecutingAssembly().GetName().Version} by Crone"); } [ModLoader.ModCallback(ModLoader.EModCallbackType.OnPlayerConnected)] public static void OnPlayerConnected(Players.Player player) { } [ModLoader.ModCallback(ModLoader.EModCallbackType.OnPlayerDisconnected)] public static void OnPlayerDisconnected(Players.Player player) { } [ModLoader.ModCallback(ModLoader.EModCallbackType.OnSavingPlayer)] public static void OnSavingPlayer(JSONNode node, Players.Player player) { } } }