From bcbde5c4bebd35e35b3ae3aa9c73536a4e4694f7 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Thu, 10 Dec 2020 16:50:34 -0500 Subject: [PATCH 1/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6d5cc7a..8341464 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # AllOfUsBot -A simplified version of the All of Us Plugin for Impostor. +A simplified version of the All of Us Plugin for Impostor v1.2.2 # Commands This version of the plugin has some useful commands, but it won't contain as much as the official All of Us server plugin From 0e659622fe815fa6dc796646cdef785ac1a9d3db Mon Sep 17 00:00:00 2001 From: Przebor Date: Fri, 18 Dec 2020 09:06:12 +0100 Subject: [PATCH 2/2] Simplified color command Added colors to the dict, simplified the command (bloat switch statement), corected a typo and added .ToLower() in arguments list. --- AllOfUs/GameEventListener.cs | 84 +++++++++++------------------------- 1 file changed, 26 insertions(+), 58 deletions(-) diff --git a/AllOfUs/GameEventListener.cs b/AllOfUs/GameEventListener.cs index a94c5fa..9dbc4d2 100644 --- a/AllOfUs/GameEventListener.cs +++ b/AllOfUs/GameEventListener.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Logging; using System.Threading.Tasks; using XtraCube.Plugins.AllofUs; +using System.Collections.Generic; namespace XtraCube.Plugins.AllOfUs.Handlers { @@ -45,9 +46,22 @@ public async void OnLobbyCreate(IPlayerSpawnedEvent e) [EventListener] public async void OnPlayerChat(IPlayerChatEvent e) { - string[] args = e.Message.Trim().Split(" "); + string[] args = e.Message.Trim().ToLower().Split(" "); string name = e.PlayerControl.PlayerInfo.PlayerName; byte color = e.PlayerControl.PlayerInfo.ColorId; + Dictionary Colors = new Dictionary(); + Colors.Add("red", 0); + Colors.Add("blue", 1); + Colors.Add("green", 2); + Colors.Add("pink", 3); + Colors.Add("orange", 4); + Colors.Add("yellow", 5); + Colors.Add("black", 6); + Colors.Add("white", 7); + Colors.Add("purple", 8); + Colors.Add("brown", 9); + Colors.Add("cyan", 10); + Colors.Add("lime", 11); if (e.Game.GameState == GameStates.NotStarted) { switch (args[0]) @@ -67,65 +81,19 @@ public async void OnPlayerChat(IPlayerChatEvent e) case "/color": if (args.Length > 1) { - switch (args[1]) + if (Colors.ContainsKey(args[1])) { - case "red": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)0); - break; - - case "blue": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)1); - break; - case "green": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)2); - break; - case "pink": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)3); - break; - case "orange": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)4); - break; - - case "yellow": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)5); - break; - case "black": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)6); - break; - case "white": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)7); - break; - case "purple": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)8); - break; - case "brown": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)9); - break; - case "cyan": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)10); - break; - case "lime": - await SendMessage(e.PlayerControl, "Color changed successfuly!"); - await e.PlayerControl.SetColorAsync((byte)11); - break; - default: - await SendMessage(e.PlayerControl, "[FF0000FF]Invaid color!"); - await SendMessage(e.PlayerControl, "Available colors: Red, Blue, Green, Pink, Orange, Yellow, Black, White, Purple, Brown, Cyan, Lime"); - break; + await SendMessage(e.PlayerControl, "Color changed successfuly!"); + await e.PlayerControl.SetColorAsync((byte)Colors[args[1]]); + break; + } + else + { + await SendMessage(e.PlayerControl, "[FF0000FF]Invalid color!"); + await SendMessage(e.PlayerControl, "Available colors: Red, Blue, Green, Pink, Orange, Yellow, Black, White, Purple, Brown, Cyan, Lime"); + break; + } } - - } else if (args.Length == 1) { await SendMessage(e.PlayerControl, "/color {color}\n Change your color!");