Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Terraria;
- using TerrariaApi.Server;
- using System.Reflection;
- using TShockAPI;
- namespace JewsusPlugin
- {
- [ApiVersion(1, 20)]
- public class JewChat : TerrariaPlugin
- {
- private bool all;
- private int chatIndex;
- private bool[] rainbow = new bool[255];
- private Color[] colors;
- public override Version Version { get { return Assembly.GetExecutingAssembly().GetName().Version; } }
- public override string Name { get { return "Rainbow Chat"; } }
- public override string Author { get { return "Jewsus"; } }
- public override string Description { get { return "Creates Rainbow Chat"; } }
- public JewChat(Main game) : base(game)
- {
- Order = 1;
- }
- public override void Initialize()
- {
- colors = new Color[]
- {
- new Color(255, 0, 0),
- new Color(0, 255, 0),
- new Color(0, 0, 255)
- };
- ServerApi.Hooks.ServerChat.Register(this, OnChat);
- ServerApi.Hooks.ServerLeave.Register(this, OnLeave);
- Commands.ChatCommands.Add(new Command("rainbow", RainbowToggle, new string[] { "rainbow", "rb" }));
- }
- private void OnLeave(LeaveEventArgs args)
- {
- rainbow[args.Who] = false;
- }
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- ServerApi.Hooks.ServerChat.Deregister(this, OnChat);
- ServerApi.Hooks.ServerLeave.Deregister(this, OnLeave);
- }
- base.Dispose(disposing);
- }
- private void RainbowToggle(CommandArgs args)
- {
- if (args.Parameters.Count <= 0)
- {
- args.Player.SendMessage("Usage: /rainbow [true/false] - set rainbow for the whole server.", Color.Red);
- args.Player.SendMessage(" /rainbow [playername] [true/false] - set rainbow for the specified player.", Color.Red);
- return;
- }
- if (args.Parameters.Count == 1)
- {
- if (args.Parameters[0].ToLower() == "true")
- all = true;
- else if (args.Parameters[0].ToLower() == "false")
- all = false;
- else
- all = !all;
- TSPlayer.All.SendMessage(string.Format("The server will {0} talk in rainbow.", all ? "now" : "not"), Color.Green);
- }
- else if (args.Parameters.Count == 2)
- {
- List<TSPlayer> list = TShock.Utils.FindPlayer(args.Parameters[0]);
- if (list.Count == 0)
- args.Player.SendMessage("No player matches.", Color.Red);
- else if (list.Count > 1)
- TShock.Utils.SendMultipleMatchError(args.Player, from p in list select p.Name);
- else if (args.Parameters[1].ToLower() == "true")
- rainbow[list[0].Index] = true;
- else if (args.Parameters[1].ToLower() == "false")
- rainbow[list[0].Index] = false;
- else
- rainbow[list[0].Index] = !all;
- TShock.Utils.Broadcast(string.Format("{0} will {1} talk in rainbow.", list[0].Name, rainbow[list[0].Index] ? "now" : "not"), Color.Green);
- }
- }
- private void OnChat(ServerChatEventArgs args)
- {
- if (args.Handled || args.Text.StartsWith(Commands.Specifier))
- return;
- TSPlayer player = TShock.Players[args.Who];
- if (all || rainbow[args.Who])
- {
- args.Handled = true;
- Chat(colors[chatIndex++], args.Text, player);
- if (chatIndex > colors.Length - 1)
- chatIndex = 0;
- }
- }
- private void Chat(Color color, string message, TSPlayer player)
- {
- TSPlayer.All.SendMessage(string.Format(TShock.Config.ChatFormat, player.Group.Name, player.Group.Prefix, player.Name, player.Group.Suffix, message), color);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement