internal static IChatMessage RenderClickableCommand(string name, string hoverText = "Click to suggest the command.", string suggestionPrefix = "", ChatColor?color = null) { color ??= ChatColor.Red; var command = name.Contains(" ") ? string.Join(" ", name.Split(" ").Where(x => !x.StartsWith("<"))) + " " : name; if (suggestionPrefix != "") { command = $"{suggestionPrefix.Trim(' ')} {name}"; } var chatMessage = IChatMessage.CreateNew(); chatMessage.Text = $"{color}{(suggestionPrefix != "" ? "" : (!name.StartsWith("/") ? "/" : ""))}{name}"; var clickEvent = ITextComponent.CreateNew(); clickEvent.Action = ETextAction.SuggestCommand; clickEvent.Value = $"{(!command.StartsWith("/") ? "/" : "")}{command}"; chatMessage.ClickEvent = clickEvent; var hoverEvent = ITextComponent.CreateNew(); hoverEvent.Action = ETextAction.ShowText; hoverEvent.Value = $"{hoverText}"; chatMessage.HoverEvent = hoverEvent; return(chatMessage); }
internal static IChatMessage RenderCommandUsage(string commandUsage, string hoverText = "Click to suggest the command.", ChatColor?color = null) { color ??= ChatColor.Red; var chatMessage = IChatMessage.Simple(""); #region prefix var prefix = IChatMessage.CreateNew(); prefix.Text = $"{color}Usage: "; chatMessage.AddExtra(prefix); #endregion #region usage var usage = IChatMessage.CreateNew(); var commandSuggest = commandUsage.Contains(" ") ? $"{commandUsage.Split(" ").FirstOrDefault()} " : commandUsage; usage.Text = $"{color}{commandUsage}"; var clickEvent = ITextComponent.CreateNew(); clickEvent.Action = ETextAction.SuggestCommand; clickEvent.Value = $"{commandSuggest}"; usage.ClickEvent = clickEvent; var hoverEvent = ITextComponent.CreateNew(); hoverEvent.Action = ETextAction.ShowText; hoverEvent.Value = $"{hoverText}"; usage.HoverEvent = hoverEvent; chatMessage.AddExtra(usage); #endregion return(chatMessage); }
public static IChatMessage ConvertToIChatMessage(this Message message) { var tmp = IChatMessage.CreateNew(); tmp.Bold = message.Bold; tmp.ClickEvent = message.ClickEvent; tmp.HoverEvent = message.HoverEvent; tmp.Insertion = message.Insertion; tmp.Italic = message.Italic; tmp.Obfuscated = message.Obfuscated; tmp.Strikethrough = message.Strikethrough; var color = Globals.Colors.TryGetValue(message.Color ?? "", out var _color) ? $"§{_color}" : ""; tmp.Text = $"{color}{message.Text}"; tmp.Underline = message.Underline; tmp.HoverEvent = message.HoverEvent; tmp.ClickEvent = message.ClickEvent; return(tmp); }
public async Task TestCmd(ObsidianContext ctx, string arg) { switch (arg) { case "reload": try { Globals.Config = await ConfigManager.LoadConfig(); await ctx.Player.SendMessageAsync($"§aConfig reloaded successfully"); await Broadcaster.StartBroadcasting(); } catch (Exception e) { await ctx.Player.SendMessageAsync($"§cAn error occurred when loading a config. Broadcasting stopped\n{e.Message}"); Broadcaster.StopBroadcasting(); } break; default: case "about": var msg = IChatMessage.CreateNew(); msg.Text = "§aObsidian Announcer §f- §dInterval auto announcement for JSON messages"; var clickComponent = ITextComponent.CreateNew(); clickComponent.Action = ETextAction.OpenUrl; clickComponent.Value = "https://github.com/roxxel/ObsidianAnnouncer"; var hoverComponent = ITextComponent.CreateNew(); hoverComponent.Action = ETextAction.ShowText; hoverComponent.Value = "§aPlugin github repo"; msg.HoverEvent = hoverComponent; msg.ClickEvent = clickComponent; await ctx.Player.SendMessageAsync(msg); break; } }
public async Task EssentialsAsync(CommandContext Context, [Remaining] string args_) { var args = args_.Contains(" ") ? args_.Split(" ").ToList() : new List <string> { args_ }; var chatMessage = IChatMessage.Simple(""); switch (args[0].ToLower()) { #region commands case "commands": // List all of the commands of this plugin //It will be necessary when the plugin system works fully and I does not really need to hard code this into the server to work properly. chatMessage = IChatMessage.Simple(""); var cmds_prefix = IChatMessage.CreateNew(); cmds_prefix.Text = $"{ChatColor.Gray}Essentials {ChatColor.Red}{Globals.VersionFull}{ChatColor.Gray} commands:"; chatMessage.AddExtra(cmds_prefix); var cmds_list = IChatMessage.Simple(""); foreach (var cmd in Globals.Commands) { var commandName = IChatMessage.Simple("\n"); commandName.AddExtra(Globals.RenderClickableCommand(cmd.Key)); var commandInfo = IChatMessage.CreateNew(); commandInfo.Text = $"{ChatColor.Gray}:{ChatColor.Reset} {cmd.Value}{ChatColor.Reset}"; cmds_list.AddExtra(commandName); cmds_list.AddExtra(commandInfo); } chatMessage.AddExtra(cmds_list); break; #endregion #region debug case "debug": var msg = $"{ChatColor.Red}Welcome to the {ChatColor.Obfuscated}debug{ChatColor.Reset}{ChatColor.Red}!"; #if DEBUG msg += $"{ChatColor.DarkGreen} // You're looking soo pretty today. :3"; #endif await Context.Player.SendMessageAsync(msg); break; #endregion #region reload case "reload": //It will be necessary when the plugin system works fully and I does not really need to hard code this into the server to work properly. chatMessage = IChatMessage.Simple(""); var message = IChatMessage.CreateNew(); message.Text = $"{ChatColor.Gray}Essentials {ChatColor.Red}{Globals.VersionFull}{ChatColor.Gray} successfully reloaded."; //#if DEBUG message.Text += $" {ChatColor.DarkGreen}// This command does not actually do anything right now, beside telling you that it does not do anything. "; //#endif chatMessage.AddExtra(message); break; #endregion #region Not valid args[0] default: chatMessage = Globals.RenderCommandUsage("/essentials <reload|debug|commands>"); break; #endregion } await Context.Player.SendMessageAsync(chatMessage); }
public ChatMessage() { _chatMessage = IChatMessage.CreateNew(); }