Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2 from przebor/master
Browse files Browse the repository at this point in the history
Simplified color command
  • Loading branch information
XtraCube authored Dec 19, 2020
2 parents bcbde5c + 0e65962 commit 0ee1927
Showing 1 changed file with 26 additions and 58 deletions.
84 changes: 26 additions & 58 deletions AllOfUs/GameEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<string, int> Colors = new Dictionary<string, int>();
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])
Expand All @@ -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!");
Expand Down

0 comments on commit 0ee1927

Please sign in to comment.