예제 #1
0
        public async Task GcAsync(CommandContext Context)
        {
            var chatMessage = IChatMessage.Simple("");

            Process currentProcess = Process.GetCurrentProcess();

            //long maxMemory = currentProcess.VirtualMemorySize64;
            //long totalMemory = currentProcess.PeakVirtualMemorySize64;
            //long freeMemory = currentProcess.PeakVirtualMemorySize64-currentProcess.VirtualMemorySize64;
            long maxMemory   = currentProcess.WorkingSet64;
            long totalMemory = currentProcess.PeakWorkingSet64;
            long freeMemory  = totalMemory - maxMemory;

            //long usedMemory = currentProcess.PrivateMemorySize64;
            //long maxMemory = currentProcess.WorkingSet64;

            chatMessage.AddExtra(IChatMessage.Simple($"{Globals.Language.TranslateMessage("gcfree", MemoryFormatter.Fancy(freeMemory, MemoryFormatter.EMemory.MB, false))}\n"));
            chatMessage.AddExtra(IChatMessage.Simple($"{Globals.Language.TranslateMessage("gcmax", MemoryFormatter.Fancy(maxMemory, MemoryFormatter.EMemory.MB, false))}\n"));
            chatMessage.AddExtra(IChatMessage.Simple($"{Globals.Language.TranslateMessage("gctotal", MemoryFormatter.Fancy(totalMemory, MemoryFormatter.EMemory.MB, false))}\n"));
            chatMessage.AddExtra(IChatMessage.Simple($"{Globals.Language.TranslateMessage("tps", Context.Server.TPS)}"));
#if DEBUG
            chatMessage.AddExtra(IChatMessage.Simple($"{ChatColor.DarkGreen}//There are a lot of things here. :o"));
#endif

            await Context.Player.SendMessageAsync(chatMessage);
        }
        public async Task WarpAsync(CommandContext Context, [Remaining] string args_)
        {
            var chatMessage = IChatMessage.Simple("");
            var args        = args_.Contains(" ") ? args_.Split(" ").ToList() : new List <string> {
                args_
            };

            if (args.Count == 1)
            {
                var warp = Globals.Configs.Warps[args[0]];
                try
                {
                    await Context.Player.TeleportAsync(warp.Position.ToObsidianPosition());

                    chatMessage.AddExtra(IChatMessage.Simple($"Successfully warped to {ChatColor.BrightGreen}{warp.Name}{ChatColor.Reset}."));
                }
                catch (Exception ex)
                {
                    chatMessage.AddExtra(IChatMessage.Simple($"Cannot warp to {ChatColor.Red}{warp.Name}{ChatColor.Reset}!"));
                    if (Context.Player.IsOperator)
                    {
                        chatMessage.AddExtra(IChatMessage.Simple($" For more information, see console."));
                    }
                    Globals.Logger.LogError($"{ChatColor.Red}{Context.Player.Username}{ChatColor.Reset} cannot warp to {ChatColor.Red}{warp.Name}{ChatColor.Reset}.\n{ex.ToString()}");
                }
            }
            else
            {
                chatMessage = Globals.RenderCommandUsage("/warp <name>");
            }
            await Context.Player.SendMessageAsync(chatMessage);
        }
예제 #3
0
        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);
        }
예제 #4
0
        public async Task OnPlayerJoin(PlayerJoinEventArgs playerJoinEvent)
        {
            var player = playerJoinEvent.Player;
            var server = playerJoinEvent.Server;

            await player.SendMessageAsync(IChatMessage.Simple($"Welcome {player.Username}!", ChatColor.Gold));
        }
예제 #5
0
파일: Server.cs 프로젝트: ndelta0/Obsidian
        public Task BroadcastAsync(string message, MessageType type = MessageType.Chat)
        {
            this.chatMessages.Enqueue(new QueueChat()
            {
                Message = IChatMessage.Simple(message), Type = type
            });
            this.Logger.LogInformation(message);

            return(Task.CompletedTask);
        }
        public async Task SetWarpAsync(CommandContext Context, [Remaining] string args_)
        {
            var chatMessage = IChatMessage.Simple("");
            var args        = args_.Contains(" ") ? args_.Split(" ").ToList() : new List <string> {
                args_
            };

            if (args.Count == 1)
            {
                var warp = args[0];
                var key  = warp.ReplaceSpecialCharactersWith("_");
                try
                {
                    var cfg = new WarpConfig
                    {
                        LastOwner = Context.Player.Uuid,
                        Name      = warp,
                        World     = Context.Player.WorldLocation.Name,
                        Position  = Context.Player.Position.ToEssentialsPosition()
                    };

                    if (Globals.Configs.AddWarp(warp, cfg, Context.Player))
                    {
                        chatMessage.AddExtra(IChatMessage.Simple($"Successfully created {ChatColor.BrightGreen}{cfg.Name}{ChatColor.Reset} warp on location {cfg.Position.ToColoredString(ChatColor.BrightGreen)}{ChatColor.Reset}."));
                    }
                    else
                    {
                        chatMessage.AddExtra(IChatMessage.Simple($"Cannot created {ChatColor.Red}{warp}{ChatColor.Reset} warp on location {cfg.Position.ToColoredString(ChatColor.Red)}{ChatColor.Reset}."));
                    }
                }
                catch (Exception ex)
                {
                    chatMessage.AddExtra(IChatMessage.Simple($"Cannot create {ChatColor.Red}{warp}{ChatColor.Reset} warp!"));
                    if (Context.Player.IsOperator)
                    {
                        chatMessage.AddExtra(IChatMessage.Simple($" For more information, see console."));
                    }
                    Globals.Logger.LogError($"{ChatColor.Red}{Context.Player.Username}{ChatColor.Reset} cannot warp to {ChatColor.Red}{warp}{ChatColor.Reset}.\n{ex.ToString()}");
                }
            }
            else
            {
                chatMessage = Globals.RenderCommandUsage("/setwarp <name>");
            }
            await Context.Player.SendMessageAsync(chatMessage);
        }
예제 #7
0
        public async Task GamemodeAsync(CommandContext Context, [Remaining] string args_)
        {
            var chatMessage = IChatMessage.Simple("");
            var args        = args_.Contains(" ") ? args_.Split(" ").ToList() : new List <string> {
                args_
            };
            Gamemode?gamemode = null;

            if (args.Count == 1)
            {
                if (args[0].IsInteger())
                {
                    var gmInt = Int32.Parse(args[0]);
                    if (gmInt > 3 && gmInt < 0)
                    {
                        chatMessage = Globals.RenderCommandUsage("/gm <0|1|2|3>");
                    }
                    else
                    {
                        gamemode = (Gamemode)gmInt;
                    }
                }
                else if (args[0].ToLower() == "creative" || args[0].ToLower() == "survival" || args[0].ToLower() == "spectator" || args[0].ToLower() == "adventure")
                {
                    gamemode = (Gamemode)Enum.Parse(typeof(Gamemode), args[0], true);
                }
                if (gamemode != null)
                {
                    await Context.Player.SetGamemodeAsync(gamemode.Value);

                    chatMessage = IChatMessage.Simple(Globals.Language.TranslateMessage("gameMode", gamemode.Value.ToString()));//$"{ChatColor.Reset}Your game mode set to {ChatColor.Red}{gamemode.Value}{ChatColor.Reset}.");
                }
                else
                {
                    chatMessage = IChatMessage.Simple(Globals.Language.TranslateMessage("gameModeInvalid"));
                }
            }
            else
            {
                chatMessage = Globals.RenderCommandUsage("/gm <0|1|2|3>");
            }
            await Context.Player.SendMessageAsync(chatMessage);
        }
        public async Task WarpsAsync(CommandContext Context)
        {
            var chatMessage = IChatMessage.Simple($"{ChatColor.Reset}Warps: ");
            var warps       = IChatMessage.Simple("");
            var warpList    = Globals.Configs.Warps;
            int i           = 0;

            foreach (var warpData in warpList)
            {
                var warp = warpData.Value;
                warps.AddExtra(Globals.RenderClickableCommand(warp.Name, "Click to navigate to warp", suggestionPrefix: "/warp", ChatColor.BrightGreen));
                if (i + 1 < warpList.Count)
                {
                    warps.AddExtra(IChatMessage.Simple($"{ChatColor.Reset}, "));
                }
            }
            chatMessage.AddExtra(warps);
            await Context.Player.SendMessageAsync(chatMessage);
        }
        public async Task HomeAsync(CommandContext Context, [Remaining] string args_)
        {
            var chatMessage = IChatMessage.Simple("");
            var args        = args_.Contains(" ") ? args_.Split(" ").ToList() : new List <string> {
                args_
            };

            if (args.Count == 1)
            {
                var homes = Globals.Configs.PlayerHomes[Context.Player.Uuid];
                var home_ = homes.Where(x => x.Name.ToLower() == args[0].ToLower());
                if (home_.Count() == 1)
                {
                    var home = home_.FirstOrDefault();
                    try
                    {
                        await Context.Player.TeleportAsync(home.Position.ToObsidianPosition());

                        chatMessage.AddExtra(IChatMessage.Simple($"Successfully teleported to {ChatColor.BrightGreen}{home.Name}{ChatColor.Reset}."));
                    }
                    catch (Exception ex)
                    {
                        chatMessage.AddExtra(IChatMessage.Simple($"Cannot teleport to {ChatColor.Red}{home.Name}{ChatColor.Reset}!"));
                        if (Context.Player.IsOperator)
                        {
                            chatMessage.AddExtra(IChatMessage.Simple($" For more information, see console."));
                        }
                        Globals.Logger.LogError($"{ChatColor.Red}{Context.Player.Username}{ChatColor.Reset} cannot teleport to {ChatColor.Red}{home.Name}{ChatColor.Reset}.\n{ex.ToString()}");
                    }
                }
                else
                {
                    chatMessage.AddExtra(IChatMessage.Simple($"Home {ChatColor.Red}{args[0].ToLower()}{ChatColor.Reset} doesn't exists."));
                }
            }
            else
            {
                chatMessage = Globals.RenderCommandUsage("/home [<name>]");
            }
            await Context.Player.SendMessageAsync(chatMessage);
        }
        public async Task HomesAsync(CommandContext Context)
        {
            var chatMessage = IChatMessage.Simple($"{ChatColor.Gray}Your homes: ");

            if (Globals.Configs.PlayerHomes.ContainsKey(Context.Player.Uuid))
            {
                var homes    = IChatMessage.Simple("");
                var homeList = Globals.Configs.PlayerHomes[Context.Player.Uuid];
                int i        = 0;
                foreach (var home in homeList)
                {
                    homes.AddExtra(Globals.RenderClickableCommand(home.Name, "Click to navigate to home", suggestionPrefix: "/home"));
                    if (i + 1 < homeList.Count)
                    {
                        homes.AddExtra(IChatMessage.Simple($"{ChatColor.Gray}, "));
                    }
                }
                chatMessage.AddExtra(homes);
            }
            await Context.Player.SendMessageAsync(chatMessage);
        }
예제 #11
0
        public ItemMetaBuilder AddLore(string lore)
        {
            this.lore.Add(IChatMessage.Simple(lore));

            return(this);
        }
예제 #12
0
        public async Task HandleAsync(Server server, Player player)
        {
            var currentItem = player.GetHeldItem();

            var block = Registry.GetBlock(currentItem.Type);

            var position = this.Position;

            var interactedBlock = server.World.GetBlock(position);

            if (interactedBlock.IsInteractable && !player.Sneaking)
            {
                var arg = await server.Events.InvokeBlockInteractAsync(new BlockInteractEventArgs(player, block, this.Position));

                if (arg.Cancel)
                {
                    return;
                }

                player.LastClickedBlock = interactedBlock;

                //TODO open chests/Crafting inventory ^ ^

                if (Server.LastInventoryId == byte.MaxValue)
                {
                    Server.LastInventoryId = 1;
                }

                var maxId = Math.Max((byte)1, ++Server.LastInventoryId);

                if (server.World.GetBlockMeta(position) is BlockMeta meta && meta.InventoryId != Guid.Empty)
                {
                    if (server.CachedWindows.TryGetValue(meta.InventoryId, out var inventory))
                    {
                        // Globals.PacketLogger.LogDebug($"Opened window with id of: {meta.InventoryId} {(inventory.HasItems() ? JsonConvert.SerializeObject(inventory.Items.Where(x => x != null), Formatting.Indented) : "No Items")}");

                        await player.OpenInventoryAsync(inventory);

                        await player.client.QueuePacketAsync(new BlockAction
                        {
                            Position    = position,
                            ActionId    = 1,
                            ActionParam = 1,
                            BlockType   = interactedBlock.Id
                        });

                        await player.SendSoundAsync(Sounds.BlockChestOpen, position.SoundPosition, SoundCategory.Blocks);

                        player.OpenedInventory = inventory;
                    }

                    return;
                }

                var type = interactedBlock.Material;

                if (type == Material.Chest) // TODO check if chest its next to another single chest
                {
                    var inventory = new Inventory(InventoryType.Generic)
                    {
                        Owner         = player.Uuid,
                        Title         = IChatMessage.Simple("Chest"),
                        Id            = maxId,
                        BlockPosition = position
                    };

                    await player.OpenInventoryAsync(inventory);

                    await player.client.QueuePacketAsync(new BlockAction
                    {
                        Position    = position,
                        ActionId    = 1,
                        ActionParam = 1,
                        BlockType   = interactedBlock.Id
                    });

                    await player.SendSoundAsync(Sounds.BlockChestOpen, position.SoundPosition, SoundCategory.Blocks);

                    var invUuid = Guid.NewGuid();

                    var blockMeta = new BlockMetaBuilder().WithInventoryId(invUuid).Build();

                    server.World.SetBlockMeta(position, blockMeta);

                    server.CachedWindows.TryAdd(invUuid, inventory);

                    player.OpenedInventory = inventory;
                }
                else if (type == Material.EnderChest)
                {
                    var enderChest = new Inventory(InventoryType.Generic)
                    {
                        Owner = player.Uuid,
                        Title = IChatMessage.Simple("Ender Chest"),
                        Id    = maxId
                    };

                    var invUuid = Guid.NewGuid();

                    var blockMeta = new BlockMetaBuilder().WithInventoryId(invUuid).Build();

                    server.World.SetBlockMeta(position, blockMeta);

                    server.CachedWindows.TryAdd(invUuid, enderChest);

                    player.OpenedInventory = enderChest;

                    await player.OpenInventoryAsync(enderChest);

                    await player.client.QueuePacketAsync(new BlockAction
                    {
                        Position    = position,
                        ActionId    = 1,
                        ActionParam = 1,
                        BlockType   = interactedBlock.Id
                    });

                    await player.SendSoundAsync(Sounds.BlockEnderChestOpen, position.SoundPosition, SoundCategory.Blocks);
                }
                else if (type == Material.CraftingTable)
                {
                    var crafting = new Inventory(InventoryType.Crafting)
                    {
                        Title         = IChatMessage.Simple("Crafting Table"),
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = crafting;

                    await player.OpenInventoryAsync(crafting);
                }
                else if (type == Material.Furnace || type == Material.BlastFurnace || type == Material.Smoker)
                {
                    InventoryType actualType = type == Material.Furnace ? InventoryType.Furnace :
                                               type == Material.BlastFurnace ? InventoryType.BlastFurnace : InventoryType.Smoker;

                    var furnace = new Inventory(actualType)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = furnace;

                    await player.OpenInventoryAsync(furnace);
                }
                else if (type == Material.EnchantingTable)
                {
                    var enchantmentTable = new Inventory(InventoryType.Enchantment)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = enchantmentTable;

                    await player.OpenInventoryAsync(enchantmentTable);
                }
                else if (type == Material.Anvil || type == Material.SmithingTable)//TODO implement other anvil types
                {
                    var anvil = new Inventory(InventoryType.Anvil)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = anvil;

                    await player.OpenInventoryAsync(anvil);
                }
                else if (type >= Material.ShulkerBox && type <= Material.BlackShulkerBox)
                {
                    var box = new Inventory(InventoryType.ShulkerBox)//TODO shulker box functionality
                    {
                        Owner         = player.Uuid,
                        Title         = IChatMessage.Simple("Shulker Box"),
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.Loom)
                {
                    var box = new Inventory(InventoryType.Loom)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.Barrel)
                {
                    var box = new Inventory(InventoryType.Generic)
                    {
                        //Owner = player.Uuid,
                        Title         = IChatMessage.Simple("Barrel"),
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.CartographyTable)
                {
                    var box = new Inventory(InventoryType.CartographyTable)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.Stonecutter)
                {
                    var box = new Inventory(InventoryType.Stonecutter)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.Grindstone)
                {
                    var box = new Inventory(InventoryType.Grindstone)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.BrewingStand)
                {
                    var box = new Inventory(InventoryType.BrewingStand)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.Lectern)
                {
                    var box = new Inventory(InventoryType.Lectern)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }
                else if (type == Material.Hopper || type == Material.HopperMinecart)
                {
                    var box = new Inventory(InventoryType.Hopper)
                    {
                        Id            = maxId,
                        BlockPosition = position
                    };

                    player.OpenedInventory = box;

                    await player.OpenInventoryAsync(box);
                }

                return;
            }

            if (player.Gamemode != Gamemode.Creative)
            {
                player.Inventory.RemoveItem(player.CurrentSlot);
            }

            switch (this.Face) // TODO fix this for logs
            {
            case BlockFace.Bottom:
                position.Y -= 1;
                break;

            case BlockFace.Top:
                position.Y += 1;
                break;

            case BlockFace.North:
                position.Z -= 1;
                break;

            case BlockFace.South:
                position.Z += 1;
                break;

            case BlockFace.West:
                position.X -= 1;
                break;

            case BlockFace.East:
                position.X += 1;
                break;

            default:
                break;
            }

            //TODO calculate the block state
            server.World.SetBlock(position, block);

            await server.BroadcastBlockPlacementAsync(player, block, position);
        }
        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);
        }
        // One of server messages, called when an event occurs
        public async Task OnLoad(IServer server)
        {
            #region InitializeComponents
            Globals.PluginInfo = Info;
            Logger.Log($"DiscordChat §9{Globals.VersionFull}{ChatColor.Reset} loading...");

            Logger.Log($"§7[Global]{ChatColor.Reset} Global things are §9loading{ChatColor.Reset}...");
            Globals.Server     = server;
            Globals.Logger     = Logger;
            Globals.FileReader = IFileReader;
            Globals.FileWriter = IFileWriter;
            Logger.Log($"§7[Global]{ChatColor.Reset} Global things {ChatColor.BrightGreen}successfully{ChatColor.Reset} assigned.");

            Logger.Log($"§7[Language]{ChatColor.Reset} §9Detecting{ChatColor.Reset} language...");
            Globals.Language = new LanguageManager();
            Logger.Log($"§7[Language]{ChatColor.Reset} Language loaded {ChatColor.BrightGreen}successfully{ChatColor.Reset}.");

            Logger.Log($"§7[Config]{ChatColor.Reset} Config files are §9loading{ChatColor.Reset}...");
            Globals.Configs = new ConfigManager();
            Logger.Log($"§7[Config]{ChatColor.Reset} Config files are loaded {ChatColor.BrightGreen}successfully{ChatColor.Reset}.");

            Logger.Log($"§7[Commands]{ChatColor.Reset} Registering §9commands{ChatColor.Reset}...");
            server.RegisterCommandClass <DiscordCommandModule>();
            Logger.Log($"§7[Commands]{ChatColor.Reset} Command module {ChatColor.BrightGreen}DiscordCommandModule{ChatColor.Reset} registered.");
            Logger.Log($"§7[Commands]{ChatColor.Reset} Commands {ChatColor.BrightGreen}successfully{ChatColor.Reset} registered...");
            #endregion

            #region InitializeDiscord
            Logger.Log($"§7[DSharpPlus]{ChatColor.Reset} Initializing Discord connection. Please wait...");
            try
            {
                Globals.Discord = new DiscordClient(new DiscordConfiguration()
                {
                    Token         = Globals.Configs.Config.Token,
                    TokenType     = TokenType.Bot,
                    AutoReconnect = true
                });
                await Globals.Discord.ConnectAsync(new DiscordActivity { ActivityType = ActivityType.Playing, Name = "Obsidian Server" }, UserStatus.Online);

                Globals.DiscordChannel = await Globals.Discord.GetChannelAsync(Globals.Configs.Config.ChannelId);

                DiscordMessageDispatcher.Initialize();
                await DiscordMessageDispatcher.Start();

                Globals.Discord.MessageCreated += async(sender, e) =>
                {
                    if (e.Channel.Id == Globals.Configs.Config.ChannelId)
                    {
                        if (!e.Author.IsBot)
                        {
                            var msg = e.Message.Content;
                            foreach (var user in e.MentionedUsers)
                            {
                                var userInfo = await Globals.Discord.GetUserAsync(user.Id);

                                msg = msg.Replace($"<@{user.Id}>", $"{ChatColor.Blue}@{userInfo.Username}:{userInfo.Discriminator}{ChatColor.Reset}");
                                msg = msg.Replace($"<@!{user.Id}>", $"{ChatColor.Blue}@{userInfo.Username}:{userInfo.Discriminator}{ChatColor.Reset}");
                            }
                            await server.BroadcastAsync(IChatMessage.Simple(Globals.Configs.Config.ChatFormat.Minecraft.Replace("{username}", $"{ChatColor.Blue}@{e.Author.Username}:{e.Author.Discriminator}").Replace("{message}", msg)));
                        }
                    }
                };
            }
            catch (System.Exception ex)
            {
                Logger.LogWarning($"{ChatColor.Gray}[DSharpPlus]{ChatColor.White} Further configuration needed. The error was the following:\r\n{ChatColor.Gray}[DSharpPlus] {ChatColor.White}{ex.ToString().Replace("\n", $"\n{ChatColor.Gray}[DSharpPlus] {ChatColor.White}")}");
            }
            #endregion

            Logger.Log($"DiscordChat {ChatColor.BrightGreen}{Globals.VersionFull}{ChatColor.Reset} loaded!");

            await Task.CompletedTask;
        }
예제 #15
0
 /// <summary>
 /// Sends a message to all players on the server.
 /// </summary>
 public Task BroadcastAsync(string message, sbyte position = 0) => BroadcastAsync(IChatMessage.Simple(message), position);
예제 #16
0
 public async Task SendMessageAsync(string message, MessageType type = MessageType.Chat, Guid?sender = null)
 {
     await SendMessageAsync(IChatMessage.Simple(message), type, sender);
 }
예제 #17
0
        public ItemMetaBuilder WithName(string name)
        {
            this.Name = IChatMessage.Simple(name);

            return(this);
        }