public void ShouldGetTextCommands() { const string textCommandStr = "help"; var textCommand = TextCommands.GetTextCommands(textCommandStr); textCommand.Should().Be(TextCommands.EnumTextCommand.Help); }
public void AddCommand(TextCommand c) { List <TextCommand> a = TextCommands.ToList(); a.Add(c); TextCommands = a.ToArray(); }
public void ShouldHydrateAndTimeHydrateReturnInformations() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "Il n'a jamais bu Kappa"; const string command = "timehydrate"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); var writeSrv0 = new TestWriteService(); const string command0 = "hydrate"; TextCommands.Execute(command0, writeSrv0); writeSrv0.WrittenChat.Should().BeOneOf(TextCommands.HydrateResults); Thread.Sleep(300); writeSrv = new TestWriteService(); const string expectedMessageToWrite2 = "Il a bu pour la dernière fois, il y a 0.005 minute(s)."; const string command2 = "timehydrate"; TextCommands.Execute(command2, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite2); }
public void ShouldGetNothingFromTextCommandsIfWrongCommand() { const int expectedEnumValue = 0; const string textCommandStr = "notACommand"; var textCommand = TextCommands.GetTextCommands(textCommandStr); textCommand.Should().Be(expectedEnumValue); }
public virtual void Draw(float x, float y, float width, float height) { float rectWidth = width; float rectHeight = height; float rectX = x + rectWidth * 0.5f; float rectY = y + rectHeight * 0.5f; Color barColor = Selected ? HighlightedBackColor : BackColor; if (barColor != Color.Empty) { UIMenu.DrawSprite(UIMenu.CommonTxd, UIMenu.NavBarTextureName, rectX, rectY, rectWidth, rectHeight, barColor); } if (Hovered && !Selected) { Color hoveredColor = Color.FromArgb(25, 255, 255, 255); UIMenu.DrawRect(rectX, rectY - 0.00138888f * 0.5f, rectWidth, rectHeight - 0.00138888f, hoveredColor); } if (LeftBadgeInfo != null) { DrawBadge(LeftBadgeInfo, true, x, y, width, height, out leftBadgeOffset); } else { leftBadgeOffset = 0.0f; } if (RightBadgeInfo != null) { DrawBadge(RightBadgeInfo, false, x, y, width, height, out rightBadgeOffset); } else { rightBadgeOffset = 0.0f; } SetTextCommandOptions(); TextCommands.Display(Text, x + 0.0046875f + leftBadgeOffset, y + 0.00277776f); if (!String.IsNullOrEmpty(RightLabel)) { SetTextCommandOptions(false); float labelWidth = TextCommands.GetWidth(RightLabel); float labelX = x + width - 0.00390625f - labelWidth - rightBadgeOffset; float labelY = y + 0.00277776f; SetTextCommandOptions(false); TextCommands.Display(RightLabel, labelX, labelY); } }
public void ShouldExecuteFalseCommandDoNothing() { var writeSrv = new TestWriteService(); const string command = "notACommand"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().BeNull(); }
void Start() { eventManager = GetComponent <EventManager>(); dialogueManager = GetComponent <DialogueManager>(); textCommands = GetComponent <TextCommands>(); data = GetComponent <Data>(); speaker = data.speakerList[0]; }
public void ShouldGiveUpCommandWriteSpecificMsg() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "https://www.youtube.com/watch?v=dQw4w9WgXcQ LUL"; const string command = "giveup"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); }
public void ShouldIndelivrablesCommandWriteSpecificMsg() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "Allez tous regarder la chaîne YouTube des Indélivrables : https://www.youtube.com/channel/UCl7djHZZcnOt-t05QMYx90g"; const string command = "indelivrables"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); }
public void ShouldRigCommandWriteSpecificMsg() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "Il a 4 écrans et il ne parle que de ça..."; const string command = "rig"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); }
public void ShouldBonjourCommandWriteSpecificMsg() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "HeyGuys"; const string command = "bonjour"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); }
public void ShouldTotoCommandWriteSpecificMsg() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "Votre langage est très évolué."; const string command = "toto"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); }
public void ShouldHelpCommandWriteSpecificMsg() { var writeSrv = new TestWriteService(); const string expectedMessageToWrite = "Liste des commandes : '!Help' '!Hydrate' '!Toto' '!Bonjour' '!Rig' '!Indelivrables' '!GiveUp' '!TimeHydrate' '!Discord Pub'"; const string command = "help"; TextCommands.Execute(command, writeSrv); writeSrv.WrittenChat.Should().Be(expectedMessageToWrite); }
/// <summary> /// Draw item. /// </summary> public override void Draw(float x, float y, float width, float height) { base.Draw(x, y, width, height); string selectedOption = Collection == null ? (_items.Count > 0 ? _items[Index].ToString() : " ") : (Collection.Count > 0 ? Collection[Index].DisplayText : " "); SetTextCommandOptions(false); float optTextWidth = TextCommands.GetWidth(selectedOption); GetBadgeOffsets(out _, out float badgeOffset); if (Selected && Enabled) { Color textColor = CurrentForeColor; float optTextX = x + width - 0.00390625f - optTextWidth - (0.0046875f * 1.5f) - badgeOffset; float optTextY = y + 0.00277776f; SetTextCommandOptions(false); TextCommands.Display(selectedOption, optTextX, optTextY); { UIMenu.GetTextureDrawSize(UIMenu.CommonTxd, UIMenu.ArrowRightTextureName, out float w, out float h); w *= 0.65f; h *= 0.65f; float spriteX = x + width - (0.00390625f * 1.0f) - (w * 0.5f) - badgeOffset; float spriteY = y + (0.034722f * 0.5f); UIMenu.DrawSprite(UIMenu.CommonTxd, UIMenu.ArrowRightTextureName, spriteX, spriteY, w, h, textColor); } { UIMenu.GetTextureDrawSize(UIMenu.CommonTxd, UIMenu.ArrowLeftTextureName, out float w, out float h); w *= 0.65f; h *= 0.65f; float spriteX = x + width - (0.00390625f * 1.0f) - (w * 0.5f) - optTextWidth - (0.0046875f * 1.5f) - badgeOffset; float spriteY = y + (0.034722f * 0.5f); UIMenu.DrawSprite(UIMenu.CommonTxd, UIMenu.ArrowLeftTextureName, spriteX, spriteY, w, h, textColor); } } else { float optTextX = x + width - 0.00390625f - optTextWidth - badgeOffset; float optTextY = y + 0.00277776f;// + 0.00416664f; SetTextCommandOptions(false); TextCommands.Display(selectedOption, optTextX, optTextY); } }
public static void DoAction(OnMessageReceivedArgs e, TwitchClient client) { var writeSrv = new WriteService(client, e.ChatMessage.Channel); string message = e.ChatMessage.Message; string command = GetCommand(message); if (command == null) { return; } DiscordCommands.Execute(command, writeSrv); TextCommands.Execute(command, writeSrv); }
void Start() //Load appropriate assets for the scene { gameManager = GetComponent <GameManager>(); eventManager = GetComponent <EventManager>(); textCommands = GetComponent <TextCommands>(); dialogueBoxScript = GameObject.Find("DialogueBox").GetComponent <DialogueBoxScript>(); nameTextObject = GameObject.FindWithTag("NameText"); dialogueTextObject = GameObject.FindWithTag("DialogueText"); historyTextObject = GameObject.FindWithTag("HistoryText"); dialogueText = dialogueTextObject.GetComponent <TextMeshPro>(); historyText = historyTextObject.GetComponent <TextMeshProUGUI>(); historyTextContainer = historyTextObject.GetComponent <RectTransform>(); historyTextObject.SetActive(false); dialogueText.text = ""; historyText.text = ""; LoadScript("Assets/Script/testScript.txt"); }
public Boolean DeleteCommand(String Command) { int Index = -1; for (int i = 0; i < TextCommands.Length; i++) { if (TextCommands[i].Command == Command) { Index = i; break; } } if (Index < 0) { return(false); } List <TextCommand> t = TextCommands.ToList(); t.RemoveAt(Index); TextCommands = t.ToArray(); Console.WriteLine("Removed " + Index); return(true); }
// Load other things based in the Config. private void ConfigPostLoad() { if (Config.Economy.UseXp) { EconomyProvider = Optional <IEconomyProvider> .Of(new ExpEconomyProvider()); } else if (HookManager.GetActiveByType <AviEconomyHook>().IsPresent) { EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <AviEconomyHook>().Value); } else if (HookManager.GetActiveByType <UconomyHook>().IsPresent) { EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <UconomyHook>().Value); } else { EconomyProvider = Optional <IEconomyProvider> .Empty(); } if (Config.AutoAnnouncer.Enabled) { Config.AutoAnnouncer.Start(); } if (Config.AutoCommands.Enabled) { Config.AutoCommands.Start(); } if (Config.ServerFrameRate != -1) { var frameRate = Config.ServerFrameRate; if (Config.ServerFrameRate < -1) { frameRate = -1; // Set to default } UnityEngine.Application.targetFrameRate = frameRate; } Config.DisabledCommands.ForEach(cmdName => { var command = CommandManager.GetByName(cmdName); if (command == null || command is CommandEssentials) { Logger.LogWarning($"There is no command named '{cmdName}' to disable."); } else { CommandManager.Unregister(command); Logger.LogInfo($"Disabled command: '{command.Name}'"); } }); if (Config.EnableTextCommands) { TextCommands = new TextCommands(); var textCommandsFile = Path.Combine(Folder, TextCommands.FileName); TextCommands.Load(textCommandsFile); TextCommands.Commands.ForEach(txtCommand => { CommandManager.Register(new TextCommand(txtCommand)); }); } // TODO: FEATURE: Maybe we could have some kind of conditional // event register -- directly in EventManager? if (!Config.EnableJoinLeaveMessage) { EventManager.Unregister <EssentialsEventHandler>("JoinMessage"); EventManager.Unregister <EssentialsEventHandler>("LeaveMessage"); } if (!Config.Updater.AlertOnJoin) { EventManager.Unregister <EssentialsEventHandler>("UpdateAlert"); } if (!Config.EnableDeathMessages) { EventManager.Unregister <EssentialsEventHandler>("DeathMessages"); } }
protected override void Load() { try { var stopwatch = Stopwatch.StartNew(); Instance = this; try { var essPermProvider = new EssentialsPermissionsProvider(); R.Permissions = essPermProvider; } catch (Exception ex) { Console.Error.WriteLine(ex); } TaskExecutor = new EssentialsTaskExecutor(); Logger = new ConsoleLogger("[uEssentials] "); ConnectedPlayers = new Dictionary <ulong, UPlayer>(); Debug.Listeners.Add(new EssentialsConsoleTraceListener()); Provider.onServerDisconnected += PlayerDisconnectCallback; Provider.onServerConnected += PlayerConnectCallback; Logger.LogInfo("Enabling uEssentials..."); if (Provider.Players.Count > 0) { Provider.Players.ForEach(p => { ConnectedPlayers.Add(p.SteamPlayerID.CSteamID.m_SteamID, new UPlayer(UnturnedPlayer.FromSteamPlayer(p))); }); } _folder = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/"; _translationFolder = Folder + "translations/"; _dataFolder = Folder + "data/"; _modulesFolder = Folder + "modules/"; WebResources = new WebResources(); Config = new EssConfig(); var webRscPath = Path.Combine(Folder, WebResources.FileName); var configPath = Path.Combine(Folder, Config.FileName); WebResources.Load(webRscPath); // TODO: Remove // Load old webkit/webconfig try { if (File.Exists(configPath) && !WebResources.Enabled) { var json = JObject.Parse(File.ReadAllText(configPath)); var save = false; foreach (var opt in new[] { "Config", "Kits" }) { JToken val; if (json.TryGetValue($"Web{opt}", out val)) { if (val.Value <bool>("Enabled")) { WebResources.Enabled = true; WebResources.URLs[opt] = val.Value <string>("Url"); save = true; } } } if (save) { WebResources.Save(webRscPath); WebResources.Load(webRscPath); } } } catch (Exception ex) { Debug.Print(ex.ToString()); } // Sync web config with local config.json if (WebResources.Loaded.ContainsKey("Config")) { File.WriteAllText(configPath, WebResources.Loaded["Config"]); } Config.Load(configPath); CommandOptions = new CommandOptions(); CommandOptions.Load(Path.Combine(Folder, CommandOptions.FileName)); Updater = new GithubUpdater(); EventManager = new EventManager(); CommandManager = new CommandManager(); ModuleManager = new ModuleManager(); HookManager = new HookManager(); EssLang.Load(); new [] { "Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO, "Recommended Rocket version: ~white~" + ROCKET_VERSION, "Recommended Unturned version: ~white~" + UNTURNED_VERSION, "Author: ~white~leonardosnt", "Wiki: ~white~uessentials.github.io", }.ForEach(text => Logger.LogInfo(text, true)); EventManager.RegisterAll(GetType().Assembly); if (!Config.EnableJoinLeaveMessage) { EventManager.Unregister <EssentialsEventHandler>("JoinMessage"); EventManager.Unregister <EssentialsEventHandler>("LeaveMessage"); } CommandManager.RegisterAll("Essentials.Commands"); HookManager.RegisterAll(); HookManager.LoadAll(); if (Config.Economy.UseXp) { EconomyProvider = Optional <IEconomyProvider> .Of(new ExpEconomyProvider()); } else if (HookManager.GetActiveByType <UconomyHook>().IsPresent) { EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <UconomyHook>().Value); } else { EconomyProvider = Optional <IEconomyProvider> .Empty(); } /* * Load native modules */ Assembly.GetTypes() .Where(t => typeof(NativeModule).IsAssignableFrom(t)) .WhereNot(t => t.IsAbstract) .Where(t => { var moduleInfo = (ModuleInfo)t.GetCustomAttributes(typeof(ModuleInfo), false)[0]; return(Config.EnabledSystems.Any(s => s.Equals(moduleInfo.Name, StringComparison.OrdinalIgnoreCase))); }) .ForEach(t => { ModuleManager.LoadModule((NativeModule)Activator.CreateInstance(t)); }); Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands"); Logger.LogInfo("Loading modules..."); ModuleManager.LoadAll(ModulesFolder); Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules"); if (Config.AutoAnnouncer.Enabled) { Config.AutoAnnouncer.Start(); } if (Config.AutoCommands.Enabled) { Config.AutoCommands.Start(); } if (!Config.Updater.AlertOnJoin) { EventManager.Unregister <EssentialsEventHandler>("UpdateAlert"); } if (Config.ServerFrameRate != -1) { var frameRate = Config.ServerFrameRate; if (Config.ServerFrameRate < -1) { frameRate = -1; // Set to default } UnityEngine.Application.targetFrameRate = frameRate; } if (Config.DisabledCommands.Count != 0) { Config.DisabledCommands.ForEach(cmdName => { var command = CommandManager.GetByName(cmdName); if (command == null || command is CommandEssentials) { Logger.LogWarning($"There is no command named '{cmdName}' to disable."); } else { CommandManager.Unregister(command); Logger.LogInfo($"Disabled command: '{command.Name}'"); } }); } if (Config.EnableTextCommands) { TextCommands = new TextCommands(); var textCommandsFile = Path.Combine(Folder, TextCommands.FileName); TextCommands.Load(textCommandsFile); TextCommands.Commands.ForEach(txtCommand => { CommandManager.Register(new TextCommand(txtCommand)); }); } if (!Config.EnableDeathMessages) { EventManager.Unregister <EssentialsEventHandler>("DeathMessages"); } #if EXPERIMENTAL Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY."); Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY."); #endif Task.Create() .Id("Delete Xml Files") .Delay(TimeSpan.FromSeconds(1)) .Async() .Action(() => { File.Delete($"{Folder}uEssentials.en.translation.xml"); File.Delete($"{Folder}uEssentials.configuration.xml"); }) .Submit(); Task.Create() .Id("Unregister Rocket Commands") .Delay(TimeSpan.FromSeconds(3)) .Action(() => UnregisterRocketCommands(true)) // Second check, silently. .Submit(); CommandWindow.ConsoleInput.onInputText += ReloadCallback; UnregisterRocketCommands(); // First check. Logger.LogInfo($"Enabled ({stopwatch.ElapsedMilliseconds} ms)"); } catch (Exception e) { var msg = new List <string>() { "An error occurred while enabling uEssentials.", "If this error is not related with wrong configuration please report", "immediatly here https://github.com/uEssentials/uEssentials/issues", "Error: " + e }; if (!Provider.APP_VERSION.EqualsIgnoreCase(UNTURNED_VERSION)) { msg.Add("I detected that you are using a different version of the recommended, " + "please update your uEssentials/Unturned."); msg.Add("If you are using the latest uEssentials release, please wait for update."); } if (Logger == null) { Console.BackgroundColor = ConsoleColor.Red; msg.ForEach(Console.WriteLine); Console.BackgroundColor = ConsoleColor.White; } else { msg.ForEach(Logger.LogError); } } #if !DEV TriggerGaData($"Server/{Parser.getIPFromUInt32(Provider.ip)}"); #endif #if DEV CommandWindow.ConsoleOutput.title = "Unturned Server"; #else CheckUpdates(); #endif }
protected override void Load() { try { var stopwatch = Stopwatch.StartNew(); Instance = this; try { var essPermProvider = new EssentialsPermissionsProvider(); R.Permissions = essPermProvider; } catch (Exception ex) { Console.Error.WriteLine(ex); } R.Plugins.OnPluginsLoaded += OverrideCommands; TaskExecutor = new EssentialsTaskExecutor(); SteamGameServer.SetKeyValue("essversion", PLUGIN_VERSION); Logger = new ConsoleLogger("[uEssentials] "); ConnectedPlayers = new Dictionary <ulong, UPlayer>(); Debug.Listeners.Add(new EssentialsConsoleTraceListener()); Provider.onServerDisconnected += PlayerDisconnectCallback; Provider.onServerConnected += PlayerConnectCallback; Logger.LogInfo("Enabling uEssentials..."); if (Provider.clients.Count > 0) { Provider.clients.ForEach(p => { ConnectedPlayers.Add(p.playerID.steamID.m_SteamID, new UPlayer(UnturnedPlayer.FromSteamPlayer(p))); }); } _folder = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/"; _translationFolder = Folder + "translations/"; _dataFolder = Folder + "data/"; _modulesFolder = Folder + "modules/"; WebResources = new WebResources(); Config = new EssConfig(); var webResourcesPath = Path.Combine(Folder, WebResources.FileName); var configPath = Path.Combine(Folder, Config.FileName); WebResources.Load(webResourcesPath); // Sync web config with local config.json if (WebResources.Loaded.ContainsKey("Config")) { File.WriteAllText(configPath, WebResources.Loaded["Config"]); } Config.Load(configPath); CommandOptions = new CommandOptions(); CommandOptions.Load(Path.Combine(Folder, CommandOptions.FileName)); Updater = new GithubUpdater(); EventManager = new EventManager(); CommandManager = new CommandManager(); ModuleManager = new ModuleManager(); HookManager = new HookManager(); EssLang.Load(); new [] { "Plugin version: ~white~" + PLUGIN_VERSION + BUILD_INFO, "Recommended Rocket version: ~white~" + ROCKET_VERSION, "Recommended Unturned version: ~white~" + UNTURNED_VERSION, "Author: ~white~leonardosnt", "Wiki: ~white~uessentials.github.io", }.ForEach(text => Logger.LogInfo(text, true)); EventManager.RegisterAll(GetType().Assembly); if (!Config.EnableJoinLeaveMessage) { EventManager.Unregister <EssentialsEventHandler>("JoinMessage"); EventManager.Unregister <EssentialsEventHandler>("LeaveMessage"); } // Register all commands from namespace Essentials.Commands CommandManager.RegisterAll("Essentials.Commands"); HookManager.RegisterAll(); HookManager.LoadAll(); if (Config.Economy.UseXp) { EconomyProvider = Optional <IEconomyProvider> .Of(new ExpEconomyProvider()); } else if (HookManager.GetActiveByType <AviEconomyHook>().IsPresent) { EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <AviEconomyHook>().Value); } else if (HookManager.GetActiveByType <UconomyHook>().IsPresent) { EconomyProvider = Optional <IEconomyProvider> .Of(HookManager.GetActiveByType <UconomyHook>().Value); } else { EconomyProvider = Optional <IEconomyProvider> .Empty(); } LoadNativeModules(); Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands"); Logger.LogInfo("Loading modules..."); ModuleManager.LoadAll(ModulesFolder); Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules"); if (Config.AutoAnnouncer.Enabled) { Config.AutoAnnouncer.Start(); } if (Config.AutoCommands.Enabled) { Config.AutoCommands.Start(); } if (!Config.Updater.AlertOnJoin) { EventManager.Unregister <EssentialsEventHandler>("UpdateAlert"); } if (Config.ServerFrameRate != -1) { var frameRate = Config.ServerFrameRate; if (Config.ServerFrameRate < -1) { frameRate = -1; // Set to default } UnityEngine.Application.targetFrameRate = frameRate; } if (Config.DisabledCommands.Count != 0) { Config.DisabledCommands.ForEach(cmdName => { var command = CommandManager.GetByName(cmdName); if (command == null || command is CommandEssentials) { Logger.LogWarning($"There is no command named '{cmdName}' to disable."); } else { CommandManager.Unregister(command); Logger.LogInfo($"Disabled command: '{command.Name}'"); } }); } if (Config.EnableTextCommands) { TextCommands = new TextCommands(); var textCommandsFile = Path.Combine(Folder, TextCommands.FileName); TextCommands.Load(textCommandsFile); TextCommands.Commands.ForEach(txtCommand => { CommandManager.Register(new TextCommand(txtCommand)); }); } if (!Config.EnableDeathMessages) { EventManager.Unregister <EssentialsEventHandler>("DeathMessages"); } #if EXPERIMENTAL Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY."); Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY."); #endif // Delete useless files generated by Rocket Task.Create() .Id("Delete Xml Files") .Delay(TimeSpan.FromSeconds(1)) .Async() .Action(() => { File.Delete($"{Folder}uEssentials.en.translation.xml"); File.Delete($"{Folder}uEssentials.configuration.xml"); }) .Submit(); CommandWindow.input.onInputText += ReloadCallback; Logger.LogInfo($"Enabled ({stopwatch.ElapsedMilliseconds} ms)"); } catch (Exception e) { var msg = new List <string>() { "An error occurred while enabling uEssentials.", "If this error is not related with wrong configuration please report", "immediatly here https://github.com/uEssentials/uEssentials/issues", "Error: " + e }; if (!Provider.APP_VERSION.EqualsIgnoreCase(UNTURNED_VERSION)) { msg.Add("I detected that you are using a different version of the recommended, " + "please update your uEssentials/Unturned."); msg.Add("If you are using the latest uEssentials release, please wait for update."); } if (Logger == null) { Console.BackgroundColor = ConsoleColor.Red; msg.ForEach(Console.WriteLine); Console.BackgroundColor = ConsoleColor.White; } else { msg.ForEach(Logger.LogError); } } #if !DEV Analytics.SendEvent($"ServerInit"); #endif #if DEV Console.Title = "Unturned Server"; #else CheckUpdates(); #endif }
protected override void Load() { try { var stopwatch = Stopwatch.StartNew(); Instance = this; R.Permissions = new EssentialsPermissionsProvider(); Provider.onServerDisconnected += PlayerDisconnectCallback; Provider.onServerConnected += PlayerConnectCallback; Logger = new EssLogger("[uEssentials] "); ConnectedPlayers = new Dictionary <ulong, UPlayer>(); Logger.Log("Enabling uEssentials.", ConsoleColor.Green); if (Provider.Players.Count > 0) { Provider.Players.ForEach(p => { ConnectedPlayers.Add(p.SteamPlayerID.CSteamID.m_SteamID, new UPlayer(UnturnedPlayer.FromSteamPlayer(p))); }); } _folder = Rocket.Core.Environment.PluginsDirectory + "/uEssentials/"; _translationFolder = Folder + "translations/"; _dataFolder = Folder + "data/"; _modulesFolder = Folder + "modules/"; var configPath = $"{Folder}config.json"; Config = new EssConfig(); Config.Load(configPath); if (Config.WebConfig.Enabled) { var conf = new EssWebConfig(); conf.Load(configPath); Config = conf; } CommandsConfig = new CommandsConfig(); CommandsConfig.Load($"{Folder}commands.json"); Updater = new GithubUpdater(); EventManager = new EventManager(); CommandManager = new CommandManager(); ModuleManager = new ModuleManager(); HookManager = new HookManager(); EssLang.Load(); Logger.Log("Plugin version: ", ConsoleColor.Green, suffix: ""); #if EXPERIMENTAL const string label = "experimental" #if EXPERIMENTAL_HASH + "-commit-$COMMIT_HASH$" #endif ; Logger.Log($"{PLUGIN_VERSION} {label}", ConsoleColor.White, ""); #else Logger.Log(PLUGIN_VERSION, ConsoleColor.White, ""); #endif Logger.Log("Recommended Rocket version: ", ConsoleColor.Green, suffix: ""); Logger.Log(ROCKET_VERSION, ConsoleColor.White, ""); Logger.Log("Recommended Unturned version: ", ConsoleColor.Green, suffix: ""); Logger.Log(UNTURNED_VERSION, ConsoleColor.White, ""); Logger.Log("Author: ", ConsoleColor.Green, suffix: ""); Logger.Log("leonardosc", ConsoleColor.White, ""); Logger.Log("Wiki: ", ConsoleColor.Green, suffix: ""); Logger.Log("uessentials.github.io", ConsoleColor.White, ""); EventManager.RegisterAll(GetType().Assembly); if (!Config.EnableJoinLeaveMessage) { EventManager.Unregister <EssentialsEventHandler>("JoinMessage"); EventManager.Unregister <EssentialsEventHandler>("LeaveMessage"); } CommandManager.RegisterAll("Essentials.Commands"); HookManager.RegisterAll(); HookManager.LoadAll(); if (Config.Economy.UseXp) { EconomyProvider = Optional <IEconomyProvider> .Of(new ExpEconomyProvider()); } else if (HookManager.GetActiveByType <UconomyHook>().IsPresent) { EconomyProvider = Optional <IEconomyProvider> .Of( HookManager.GetActiveByType <UconomyHook>().Value); } else { EconomyProvider = Optional <IEconomyProvider> .Empty(); } /* * Load native modules */ ( from type in Assembly.GetTypes() where typeof(NativeModule).IsAssignableFrom(type) where !type.IsAbstract let mAttr = (ModuleInfo)type.GetCustomAttributes(typeof(ModuleInfo), false)[0] where Config.EnabledSystems.Any(s => s.Equals(mAttr.Name, StringComparison.OrdinalIgnoreCase)) select type ).ForEach(type => { ModuleManager.LoadModule((NativeModule)Activator.CreateInstance(type)); }); Logger.LogInfo($"Loaded {CommandManager.Commands.Count()} commands"); Logger.LogInfo("Loading modules..."); ModuleManager.LoadAll(ModulesFolder); Logger.LogInfo($"Loaded {ModuleManager.RunningModules.Count(t => !(t is NativeModule))} modules"); if (Config.AutoAnnouncer.Enabled) { Config.AutoAnnouncer.Start(); } if (Config.AutoCommands.Enabled) { Config.AutoCommands.Start(); } if (!Config.Updater.AlertOnJoin) { EventManager.Unregister <EssentialsEventHandler>("UpdateAlert"); } if (Config.ServerFrameRate != -1) { var frameRate = Config.ServerFrameRate; if (Config.ServerFrameRate < -1) { frameRate = -1; // Set to default } UnityEngine.Application.targetFrameRate = frameRate; } if (Config.DisabledCommands.Count != 0) { Config.DisabledCommands.ForEach(cmdName => { var command = CommandManager.GetByName(cmdName); if (command == null || command is CommandEssentials) { Logger.LogWarning($"There is no command named '{cmdName}' to disable."); } else { CommandManager.Unregister(command); Logger.LogInfo($"Disabled command: '{command.Name}'"); } }); } if (Config.EnableTextCommands) { var textCommandsFile = $"{Folder}textcommands.json"; TextCommands = new TextCommands(); TextCommands.Load(textCommandsFile); TextCommands.Commands.ForEach(txtCommand => { CommandManager.Register(new TextCommand(txtCommand)); }); } if (!Config.EnableDeathMessages) { EventManager.Unregister <EssentialsEventHandler>("DeathMessages"); } #if EXPERIMENTAL Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY."); Logger.LogWarning("THIS IS AN EXPERIMENTAL BUILD, CAN BE BUGGY."); #endif TryAddComponent <Tasks.TaskExecutor>(); Tasks.New(t => { File.Delete($"{Folder}uEssentials.en.translation.xml"); File.Delete($"{Folder}uEssentials.configuration.xml"); }).Delay(100).Go(); Tasks.New(t => { UnregisterRocketCommands(true); // Second check, silently. }).Delay(3000).Go(); CommandWindow.ConsoleInput.onInputText += ReloadCallback; UnregisterRocketCommands(); // First check. Logger.Log($"Enabled ({stopwatch.ElapsedMilliseconds} ms)", ConsoleColor.Green); } catch (Exception e) { var msg = new List <string>() { "An error occurred while enabling uEssentials.", "If this error is not related with wrong configuration please report", "immediatly here https://github.com/uEssentials/uEssentials/issues", "Error: " + e }; if (!Provider.Version.EqualsIgnoreCase(UNTURNED_VERSION)) { msg.Add("I detected that you are using an different version of the recommended, " + "please update your uEssentials/Unturned."); msg.Add("If you are using the latest uEssentials release, please wait for update."); } if (Logger == null) { Console.BackgroundColor = ConsoleColor.Red; msg.ForEach(Console.WriteLine); Console.BackgroundColor = ConsoleColor.White; } else { msg.ForEach(Logger.LogError); } } #if DEV CommandWindow.ConsoleOutput.title = "Unturned Server"; #else CheckUpdates(); #endif #if DUMP_COMMANDS DumpCommands(); #endif }
public override void Draw() { if (!Visible) { return; } base.Draw(); int blackAlpha = Focused ? 200 : 100; int fullAlpha = Focused ? 255 : 150; int subMenuWidth = (BottomRight.X - TopLeft.X); Size itemSize = new Size(subMenuWidth, 40); int i = 0; for (int c = minItem; c < Math.Min(Items.Count, maxItem); c++) { //bool hovering = UIMenu.IsMouseInBounds(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)), itemSize); bool hasLeftBadge = Items[c].LeftBadgeInfo != null; bool hasRightBadge = Items[c].RightBadgeInfo != null; bool hasBothBadges = hasRightBadge && hasLeftBadge; bool hasAnyBadge = hasRightBadge || hasLeftBadge; ResRectangle.Draw(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * i)), itemSize, (Index == c && Focused) ? Color.FromArgb(fullAlpha, Color.White) : /*Focused && hovering ? Color.FromArgb(100, 50, 50, 50) :*/ Color.FromArgb(blackAlpha, Color.Black)); ResText.Draw(Items[c].Text, SafeSize.AddPoints(new Point((hasBothBadges ? 60 : hasAnyBadge ? 30 : 6), 5 + (itemSize.Height + 3) * i)), 0.35f, Color.FromArgb(fullAlpha, (Index == c && Focused) ? Color.Black : Color.White), Common.EFont.ChaletLondon, false); bool selected = (Index == c && Focused); if (hasLeftBadge && !hasRightBadge && !Items[c].LeftBadgeInfo.IsBlank && BadgeToSprite(Items[c].LeftBadgeInfo, selected, out string badgeTxd, out string badgeTex)) { Sprite.Draw(badgeTxd, badgeTex, SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f, BadgeToColor(Items[c].LeftBadgeInfo, selected)); } if (!hasLeftBadge && hasRightBadge && !Items[c].RightBadgeInfo.IsBlank && BadgeToSprite(Items[c].RightBadgeInfo, selected, out badgeTxd, out badgeTex)) { Sprite.Draw(badgeTxd, badgeTex, SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f, BadgeToColor(Items[c].RightBadgeInfo, selected)); } if (hasLeftBadge && hasRightBadge) { if (!Items[c].LeftBadgeInfo.IsBlank && BadgeToSprite(Items[c].LeftBadgeInfo, selected, out badgeTxd, out badgeTex)) { Sprite.Draw(badgeTxd, badgeTex, SafeSize.AddPoints(new Point(-2, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f, BadgeToColor(Items[c].LeftBadgeInfo, selected)); } if (!Items[c].RightBadgeInfo.IsBlank && BadgeToSprite(Items[c].RightBadgeInfo, selected, out badgeTxd, out badgeTex)) { Sprite.Draw(badgeTxd, badgeTex, SafeSize.AddPoints(new Point(25, 1 + (itemSize.Height + 3) * i)), new Size(40, 40), 0f, BadgeToColor(Items[c].RightBadgeInfo, selected)); } } if (!String.IsNullOrEmpty(Items[c].RightLabel)) { ResText.Draw(Items[c].RightLabel, SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 5, 5 + (itemSize.Height + 3) * i)), 0.35f, Color.FromArgb(fullAlpha, (Index == c && Focused) ? Color.Black : Color.White), Common.EFont.ChaletLondon, ResText.Alignment.Right, false, false, Size.Empty); } if (Items[c] is UIMenuCheckboxItem) { string textureName; if (c == Index && Focused) { textureName = ((UIMenuCheckboxItem)Items[c]).Checked ? "shop_box_tickb" : "shop_box_blankb"; } else { textureName = ((UIMenuCheckboxItem)Items[c]).Checked ? "shop_box_tick" : "shop_box_blank"; } Sprite.Draw("commonmenu", textureName, SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 60, -5 + (itemSize.Height + 3) * i)), new Size(50, 50), 0f, Color.White); } else if (Items[c] is UIMenuListItem) { var convItem = (UIMenuListItem)Items[c]; var yoffset = 5; var basePos = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 30, yoffset + (itemSize.Height + 3) * i)); var arrowLeft = new Sprite("commonmenu", "arrowleft", basePos, new Size(30, 30)); var arrowRight = new Sprite("commonmenu", "arrowright", basePos, new Size(30, 30)); var itemText = new ResText("", basePos, 0.35f, Color.White, Common.EFont.ChaletLondon, ResText.Alignment.Right); string caption = (convItem.Collection == null ? convItem.IndexToItem(convItem.Index) : convItem.Collection[convItem.Index]).ToString(); { // prepare text style for TextCommands.GetWidth int screenw = Game.Resolution.Width; int screenh = Game.Resolution.Height; const float height = 1080f; float ratio = (float)screenw / screenh; var width = height * ratio; float x = (itemText.Position.X) / width; N.SetTextFont((int)itemText.FontEnum); N.SetTextScale(0.0f, itemText.Scale); N.SetTextRightJustify(true); N.SetTextWrap(0.0f, x); } int offset = (int)(TextCommands.GetWidth(caption) * Game.Resolution.Width); itemText.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148); itemText.Caption = caption; arrowLeft.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148); arrowRight.Color = convItem.Enabled ? selected ? Color.Black : Color.WhiteSmoke : Color.FromArgb(163, 159, 148); arrowLeft.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 60 - offset, yoffset + (itemSize.Height + 3) * i)); if (selected) { arrowLeft.Draw(); arrowRight.Draw(); itemText.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 30, yoffset + (itemSize.Height + 3) * i)); } else { itemText.Position = SafeSize.AddPoints(new Point(BottomRight.X - SafeSize.X - 5, yoffset + (itemSize.Height + 3) * i)); } itemText.Draw(); } //if (Focused && hovering && (Common.IsDisabledControlJustPressed(0, GameControl.CursorAccept) || Game.IsControlJustPressed(0, GameControl.CursorAccept))) //{ // bool open = Index == c; // Index = (1000 - (1000 % Items.Count) + c) % Items.Count; // if (!open) // Common.PlaySound("NAV_UP_DOWN", "HUD_FRONTEND_DEFAULT_SOUNDSET"); // else // { // if (Items[Index] is UIMenuCheckboxItem) // { // Common.PlaySound("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET"); // UIMenuCheckboxItem cb = (UIMenuCheckboxItem)Items[Index]; // cb.Checked = !cb.Checked; // cb.CheckboxEventTrigger(); // } // else // { // Common.PlaySound("SELECT", "HUD_FRONTEND_DEFAULT_SOUNDSET"); // Items[Index].ItemActivate(null); // } // } //} i++; } }
public override void Draw() { base.Draw(); if (Heists.Count == 0) { return; } res = UIMenu.GetScreenResolutionMantainRatio(); var activeWidth = res.Width - SafeSize.X * 2; var itemSize = new Size((int)activeWidth - 515, 40); var alpha = Focused ? 120 : 30; var blackAlpha = Focused ? 200 : 100; var fullAlpha = Focused ? 255 : 150; var counter = 0; for (int i = _minItem; i < Math.Min(Heists.Count, _maxItem); i++) { ResRectangle.Draw(SafeSize.AddPoints(new Point(0, (itemSize.Height + 3) * counter)), itemSize, (Index == i && Focused) ? Color.FromArgb(fullAlpha, Color.White) : Color.FromArgb(blackAlpha, Color.Black)); ResText.Draw(Heists[i].Name, SafeSize.AddPoints(new Point(6, 5 + (itemSize.Height + 3) * counter)), 0.35f, Color.FromArgb(fullAlpha, (Index == i && Focused) ? Color.Black : Color.White), Common.EFont.ChaletLondon, false); counter++; } if (Heists[Index].Logo == null || (Heists[Index].Logo.Sprite == null && Heists[Index].Logo.Texture == null)) { drawTexture = false; _noLogo.Position = new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y); _noLogo.Color = Color.FromArgb(blackAlpha, 0, 0, 0); _noLogo.Draw(); } else if (Heists[Index].Logo != null && Heists[Index].Logo.Texture != null && !Heists[Index].Logo.IsGameSprite) { drawTexture = true; } else if (Heists[Index].Logo != null && Heists[Index].Logo.Sprite != null && Heists[Index].Logo.IsGameSprite) { drawTexture = false; Sprite sprite = Heists[Index].Logo.Sprite; sprite.Position = new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y); sprite.Color = Color.FromArgb(blackAlpha, 0, 0, 0); sprite.Draw(); } else { drawTexture = false; } ResRectangle.Draw(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256), new Size(512, 40), Color.FromArgb(fullAlpha, Color.Black)); ResText.Draw(Heists[Index].Name, new Point((int)res.Width - SafeSize.X - 4, SafeSize.Y + 260), 0.5f, Color.FromArgb(fullAlpha, Color.White), Common.EFont.HouseScript, ResText.Alignment.Right, false, false, Size.Empty); for (int i = 0; i < Heists[Index].ValueList.Count; i++) { ResRectangle.Draw(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 40 + (40 * i)), new Size(512, 40), i % 2 == 0 ? Color.FromArgb(alpha, 0, 0, 0) : Color.FromArgb(blackAlpha, 0, 0, 0)); var text = Heists[Index].ValueList[i].Item1; var label = Heists[Index].ValueList[i].Item2; ResText.Draw(text, new Point((int)res.Width - SafeSize.X - 506, SafeSize.Y + 260 + 42 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White), Common.EFont.ChaletLondon, false); ResText.Draw(label, new Point((int)res.Width - SafeSize.X - 6, SafeSize.Y + 260 + 42 + (40 * i)), 0.35f, Color.FromArgb(fullAlpha, Color.White), Common.EFont.ChaletLondon, ResText.Alignment.Right, false, false, Size.Empty); } if (!string.IsNullOrEmpty(Heists[Index].Description)) { var propLen = Heists[Index].ValueList.Count; ResRectangle.Draw(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 42 + 40 * propLen), new Size(512, 2), Color.FromArgb(fullAlpha, Color.White)); ResText.Draw(Heists[Index].Description, new Point((int)res.Width - SafeSize.X - 508, SafeSize.Y + 256 + 45 + 40 * propLen + 4), 0.35f, Color.FromArgb(fullAlpha, Color.White), Common.EFont.ChaletLondon, ResText.Alignment.Left, false, false, new Size(508, 0)); int lineCount = TextCommands.GetLineCount(Heists[Index].Description, 0.0f, 0.0f); ResRectangle.Draw(new Point((int)res.Width - SafeSize.X - 512, SafeSize.Y + 256 + 44 + 40 * propLen), new Size(512, 45 * lineCount), Color.FromArgb(blackAlpha, 0, 0, 0)); } }