Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Terraria;
  5. using TerrariaApi.Server;
  6. using System.Reflection;
  7. using TShockAPI;
  8.  
  9. namespace JewsusPlugin
  10. {
  11.     [ApiVersion(1, 20)]
  12.     public class JewChat : TerrariaPlugin
  13.     {
  14.         private bool all;
  15.         private int chatIndex;
  16.         private bool[] rainbow = new bool[255];
  17.         private Color[] colors;
  18.  
  19.         public override Version Version { get { return Assembly.GetExecutingAssembly().GetName().Version; } }
  20.  
  21.         public override string Name { get { return "Rainbow Chat"; } }
  22.  
  23.         public override string Author { get { return "Jewsus"; } }
  24.  
  25.         public override string Description { get { return "Creates Rainbow Chat"; } }
  26.  
  27.         public JewChat(Main game) : base(game)
  28.         {
  29.             Order = 1;
  30.         }
  31.  
  32.         public override void Initialize()
  33.         {
  34.             colors = new Color[]
  35.             {
  36.                 new Color(255, 0, 0),
  37.                 new Color(0, 255, 0),
  38.                 new Color(0, 0, 255)
  39.             };
  40.  
  41.             ServerApi.Hooks.ServerChat.Register(this, OnChat);
  42.             ServerApi.Hooks.ServerLeave.Register(this, OnLeave);
  43.             Commands.ChatCommands.Add(new Command("rainbow", RainbowToggle, new string[] { "rainbow", "rb" }));
  44.         }
  45.  
  46.         private void OnLeave(LeaveEventArgs args)
  47.         {
  48.             rainbow[args.Who] = false;
  49.         }
  50.  
  51.         protected override void Dispose(bool disposing)
  52.         {
  53.             if (disposing)
  54.             {
  55.                 ServerApi.Hooks.ServerChat.Deregister(this, OnChat);
  56.                 ServerApi.Hooks.ServerLeave.Deregister(this, OnLeave);
  57.             }
  58.             base.Dispose(disposing);
  59.         }
  60.  
  61.         private void RainbowToggle(CommandArgs args)
  62.         {
  63.             if (args.Parameters.Count <= 0)
  64.             {
  65.                 args.Player.SendMessage("Usage: /rainbow [true/false] - set rainbow for the whole server.", Color.Red);
  66.                 args.Player.SendMessage("       /rainbow [playername] [true/false] - set rainbow for the specified player.", Color.Red);
  67.                 return;
  68.             }
  69.  
  70.             if (args.Parameters.Count == 1)
  71.             {
  72.                 if (args.Parameters[0].ToLower() == "true")
  73.                     all = true;
  74.                 else if (args.Parameters[0].ToLower() == "false")
  75.                     all = false;
  76.                 else
  77.                     all = !all;
  78.  
  79.                 TSPlayer.All.SendMessage(string.Format("The server will {0} talk in rainbow.", all ? "now" : "not"), Color.Green);
  80.             }
  81.             else if (args.Parameters.Count == 2)
  82.             {
  83.                 List<TSPlayer> list = TShock.Utils.FindPlayer(args.Parameters[0]);
  84.                 if (list.Count == 0)
  85.                     args.Player.SendMessage("No player matches.", Color.Red);
  86.  
  87.                 else if (list.Count > 1)
  88.                     TShock.Utils.SendMultipleMatchError(args.Player, from p in list select p.Name);
  89.                 else if (args.Parameters[1].ToLower() == "true")
  90.                     rainbow[list[0].Index] = true;
  91.                 else if (args.Parameters[1].ToLower() == "false")
  92.                     rainbow[list[0].Index] = false;
  93.                 else
  94.                     rainbow[list[0].Index] = !all;
  95.  
  96.                 TShock.Utils.Broadcast(string.Format("{0} will {1} talk in rainbow.", list[0].Name, rainbow[list[0].Index] ? "now" : "not"), Color.Green);
  97.             }
  98.         }
  99.  
  100.         private void OnChat(ServerChatEventArgs args)
  101.         {
  102.             if (args.Handled || args.Text.StartsWith(Commands.Specifier))
  103.                 return;
  104.  
  105.             TSPlayer player = TShock.Players[args.Who];
  106.             if (all || rainbow[args.Who])
  107.             {
  108.                 args.Handled = true;
  109.                 Chat(colors[chatIndex++], args.Text, player);
  110.                 if (chatIndex > colors.Length - 1)
  111.                     chatIndex = 0;
  112.             }
  113.         }
  114.  
  115.         private void Chat(Color color, string message, TSPlayer player)
  116.         {
  117.             TSPlayer.All.SendMessage(string.Format(TShock.Config.ChatFormat, player.Group.Name, player.Group.Prefix, player.Name, player.Group.Suffix, message), color);
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement