public override void Initialize() { UsingInfiniteSigns = ServerApi.Plugins.Any(p => p.Plugin.Name.Equals("InfiniteSigns", StringComparison.InvariantCulture)); ServerApi.Hooks.NetGetData.Register(this, OnGetData); #region Commands Commands.ChatCommands.Add(new Command(Permissions.Info, DoSignInfo, "sign") { HelpDesc = Help.Info }); Commands.ChatCommands.Add(new Command(Permissions.Load, DoSignLoad, "signload", "sload") { AllowServer = false, HelpDesc = Help.Load }); Commands.ChatCommands.Add(new Command(Permissions.Save, DoSignSave, "signsave", "ssave") { AllowServer = false, HelpDesc = Help.Save }); Commands.ChatCommands.Add(new Command( new List <string>() { Permissions.Load, Permissions.Save, Permissions.Clipboard }, DoSignClear, "signclear", "sclear") { AllowServer = false, HelpText = "Cancels the current sign action and empties the clipboard." }); Commands.ChatCommands.Add(new Command(Permissions.Clipboard, DoSignCopy, "signcopy", "scopy") { AllowServer = false, HelpDesc = Help.Copy }); Commands.ChatCommands.Add(new Command(Permissions.Clipboard, DoSignPaste, "signpaste", "spaste") { AllowServer = false, HelpDesc = Help.Paste }); Commands.ChatCommands.Add(new Command(Permissions.Files, DoSignFiles, "signfiles", "sfiles") { AllowServer = false, HelpText = "Returns a list of all valid files for reading inside the Sign Editor folder." }); #endregion if (!FileTools.CheckDir(FileTools.DirPath)) { TShock.Log.ConsoleInfo("Created Sign Editor directory."); } if (UsingInfiniteSigns) { Utils.DbConnect(); } // Debug command to check if InfiniteSigns is in use //Commands.ChatCommands.Add(new Command(AmIUsingIS, "checkis")); }
void OnGetData(GetDataEventArgs args) { var ply = args.Msg.whoAmI; if (args.MsgID == PacketTypes.SignRead && Memory[ply].Active) { using (var reader = new BinaryReader(new MemoryStream(args.Msg.readBuffer, args.Index, args.Length))) { int x = reader.ReadInt16(); int y = reader.ReadInt16(); int signID = Sign.ReadSign(x, y); Sign sign = UsingInfiniteSigns ? Utils.DbGetSign(x, y) : Main.sign[signID]; if (sign == null) { TShock.Log.Debug("Utils.DbGetSign(int x, int y) returned null."); } else { switch (Memory[ply].Action) { case SignAction.LOAD: if (UsingInfiniteSigns) { var text = FileTools.Load(Memory[ply].File); if (!Utils.DbSetSignText(sign.x, sign.y, text)) { TShock.Players[ply].PluginErrorMessage( "Failed to load to InfiniteSigns sign."); break; } } else { Sign.TextSign(signID, FileTools.Load(Memory[ply].File)); } TShock.Players[ply].PluginInfoMessage("Loaded file '{0}' to sign.", Memory[ply].File); break; case SignAction.SAVE: if (FileTools.Save(Memory[ply].File, sign.text)) { TShock.Players[ply].PluginInfoMessage("Saved sign's contents to file '{0}'.", Memory[ply].File); } else { TShock.Players[ply].PluginErrorMessage( "Failed to save to file. Check logs for details."); } break; case SignAction.COPY: Memory[ply].Clipboard = sign.text; TShock.Players[ply].PluginInfoMessage( "Copied sign's contents to clipboard."); break; case SignAction.PASTE: case SignAction.PERSISTENT: if (UsingInfiniteSigns) { var text = Memory[ply].Clipboard; if (!Utils.DbSetSignText(sign.x, sign.y, text)) { TShock.Players[ply].PluginErrorMessage( "Failed to paste to InfiniteSigns sign."); break; } } else { Sign.TextSign(signID, Memory[ply].Clipboard); } TShock.Players[ply].PluginInfoMessage("Pasted selection."); break; } Memory[ply].Active = Memory[ply].Action == SignAction.PERSISTENT; args.Handled = true; } } } }