Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AmejiOrape's Commented Source Code for TextNotifications.dll for KRelay (This isn't the whole code, this is just the main file of the plugin for beginners to understand.) The comments may be garbled because I pasted from Visual Studio.
- //These are the references that your code makes. This plugin uses all of these.
- using Lib_K_Relay;
- using Lib_K_Relay.Interface;
- using Lib_K_Relay.Networking;
- using Lib_K_Relay.Networking.Packets;
- using Lib_K_Relay.Networking.Packets.Server;
- using Lib_K_Relay.Networking.Packets.Client;
- using Lib_K_Relay.Utilities;
- using System.Windows.Forms;
- using System.Collections.Generic;
- using System.Linq;
- using Notifag; //This reference is an inside reference; it is created by a .settings file and is the needed to use NotifierConfig.Default
- namespace Notifier
- {
- public class Notifier : IPlugin //Say that the following code uses the IPlugin
- {
- public string GetAuthor() //The GetAuthor() string of IPlugin; it is simply your name.
- {
- return "Ameji";
- }
- public string GetName() //The GetName() string of IPlugin; it is the name of your plugin.
- {
- return "Text Notifier";
- }
- public string GetDescription() //The GetDescription() string of IPlugin; it is the description of your plugin.
- {
- return "Displays a notification when someone's chat message contains a keyword.";
- }
- public string[] GetCommands() //The GetCommands() string[] of IPlugin; it is all the commands for the plugin.
- {
- return new string[] { "/notif on:off\n/notif words\n/notif color\n/tpto" };
- }
- public void Initialize(Proxy proxy) //When the proxy starts, hook the events that will trigger specialized code.
- {
- proxy.HookCommand("notif", OnNotifierCommand);
- proxy.HookCommand("tpto", OnTpCommand);
- proxy.HookPacket(PacketType.TEXT, OnText);
- }
- /* private void OnKey(Keys key)
- {
- Code not implemented
- }
- */
- private void OnNotifierCommand(Client client, string command, string[] args) //When the user types /notif *
- {
- if (args.Length == 0) //If there is nothing after "/notif"
- return; //Cancel
- if (args[0] == "words") //If the command is /notif words
- PluginUtils.ShowGUI((Form)new Form1()); //Show the form to fill in the keywords
- else if (args[0] == "color") //On the otherhand, if the command is /notif color
- {
- PluginUtils.ShowGUI((Form)new Form2()); //Show the form to choose a color
- }
- else if (args[0] == "on") //If the command is /notif on
- {
- NotifierConfig.Default.Enabled = true; //Make the variable NotifierConfig.Default.Enabled true (used later)
- client.SendToClient((Packet)PluginUtils.CreateNotification(client.ObjectId, "Notifications Enabled!")); //Display a notification that the plugin is turned on.
- }
- else if (args[0] == "off") //I'll let you figure this one out.
- {
- NotifierConfig.Default.Enabled = false;
- client.SendToClient((Packet)PluginUtils.CreateNotification(client.ObjectId, "Notifications Disabled!"));
- }
- }
- private void OnTpCommand(Client client, string command, string[] args) //When the user sends "/tpto"
- {
- if (!NotifierConfig.Default.Enabled) return; //If the plugin isn't turned on, do not do anything.
- if (args.Length == 0) //Make sure it is just /tpto, nothing after it.
- {
- PlayerTextPacket telePort = (PlayerTextPacket)Packet.Create(PacketType.PLAYERTEXT); //Create a "player text" packet named telePort
- telePort.Text = "/teleport " + NotifierConfig.Default.tp; //The text info of this packet is "/teleport " + the name of someone who triggered the notifier.
- client.SendToServer(telePort); //Send the player text packet to the server.
- }
- }
- private void OnText(Client client, Packet packet) //When the proxy recieves a text packet
- {
- if (!NotifierConfig.Default.Enabled) return; //If the plugin isn't turned on, cancel the event.
- //Side note :: the ! means opposite of, so in a true/false case, !true = false; !false = true. the return; command breaks the programs eyes from this block of code (OnText() {This stuff in the brackets}) to the outside of it.
- //So basically, it takes the opposite of the "Enabled" boolean, and if that is true, then the "Enabled" boolean is false, so the event is canceled.
- TextPacket textPacket = (TextPacket)packet; //Assign the textpacket to a variable
- List<string> Input = textPacket.Text.Split(' ').ToList(); //Put the textpacket's text value into a list of strings, based on every space.
- List<string> whiteListed = (from i in Input where NotifierConfig.Default.Whitelist.Contains(i) select i).ToList(); //Make a list of words that both the Whitelist and the textpacket have
- List<string> blackListed = (from i in Input where NotifierConfig.Default.Blacklist.Contains(i) select i).ToList(); //Make a list of words that both the Blacklist and the textpacket have
- if (blackListed.Count == 0 && whiteListed.Count > 0) //If the textpacket has no blacklist words and more than 0 whitelist words
- {
- NotifierConfig.Default.tp = textPacket.Name; //Set the Default.tp to the name of the person who said the text.
- client.SendToClient(PluginUtils.CreateNotification(client.ObjectId, NotifierConfig.Default.NotifColor.ToArgb(), whiteListed[0] + " called!")); //Send a notification that the whitelisted word was called. Only counts the first match to prevent overlaps.
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment