diff --git a/PlayerInfo.cs b/PlayerInfo.cs new file mode 100644 index 0000000..a8e9140 --- /dev/null +++ b/PlayerInfo.cs @@ -0,0 +1,162 @@ +using Microsoft.Xna.Framework; +using System; +using System.Collections.Generic; +using Terraria; +using TerrariaApi.Server; +using TShockAPI; +using System.Linq; + +namespace PlayerInfo +{ + [ApiVersion(2, 1)] + + public class PlayerInfo : TerrariaPlugin + { + public override Version Version + { + get { return new Version(1, 8); } + } + + public override string Name + { + get { return "PlayerInfo"; } + } + + public override string Author + { + get { return "Comdar"; } + } + + public override string Description + { + get { return "Player info plugin"; } + } + + public PlayerInfo(Main game) + : base(game) + { + Order = +4; + } + + public override void Initialize() + { + Commands.ChatCommands.Add(new Command("playerinfo.hpnmana", SetStats, "stats")); + Commands.ChatCommands.Add(new Command("playerinfo.selfname", SelfName, "nick", "name")); + Commands.ChatCommands.Add(new Command("playerinfo.checkinfo", CheckInfo, "checkinfo", "cinfo")); + } + + void CheckInfo(CommandArgs args) + { + TSPlayer plr = args.Player; + if (args.Parameters.Count != 1) + { + plr.SendErrorMessage("Invalid Syntax! Proper Syntax: /checkinfo "); + return; + } + var foundPlr = TSPlayer.FindByNameOrID(args.Parameters[0]); + if (foundPlr.Count == 0) + { + args.Player.SendErrorMessage("Invalid player!"); + return; + } + else { + var iPlayer = foundPlr[0]; + string name = iPlayer.Name; + var hp = iPlayer.TPlayer.statLifeMax2; + var mana = iPlayer.TPlayer.statManaMax2; + var currentHp = iPlayer.TPlayer.statLife; + var currentMana = iPlayer.TPlayer.statMana; + var groupName = iPlayer.Group.Name; + var groupPrefix = iPlayer.Group.Prefix; + string array = "Name: " + name + "\nHP: " + hp + ", Current HP: " + currentHp + "\nMana: " + mana + ", Current Mana: " + currentMana + "\nGroup: " + groupName + ", Group Prefix: " + groupPrefix; + plr.SendMessage(array, Color.LightSteelBlue); + } + } + + void SetStats(CommandArgs args) + { + if (args.Parameters.Count < 3 || args.Parameters.Count > 4) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /stats "); + return; + } + int health = 0; + int mana = 0; + var foundPlr = TSPlayer.FindByNameOrID(args.Parameters[0]); + if (foundPlr.Count == 0) + { + args.Player.SendErrorMessage("Invalid player!"); + return; + } + // if (foundplr.Count > 1) + // { + // TShock.Utils.SendMultipleMatchError(args.Player, foundPlr.Select(p => p.Name)); + // return; + // } + else + { + var iPlayer = foundPlr[0]; + if (!int.TryParse(args.Parameters[1], out health)) + { + if (health < 100) + { + args.Player.SendErrorMessage("Invalid Health Amount!"); + return; + } + } + if (!int.TryParse(args.Parameters[2], out mana)) + { + if (mana < 20) + { + args.Player.SendErrorMessage("Invalid Mana Amount!"); + return; + } + } + iPlayer.TPlayer.statLifeMax = health; + iPlayer.TPlayer.statManaMax = mana; + NetMessage.SendData(16, -1, -1, null, iPlayer.Index, 0f, 0f, 0f, 0); // Sends Health Packet + NetMessage.SendData(42, -1, -1, null, iPlayer.Index, 0f, 0f, 0f, 0); // Sends Mana Packet + args.Player.SendSuccessMessage(string.Format("The Player's Stats have been set!")); + iPlayer.SendSuccessMessage(string.Format("Your Stats have been modified!")); + } + } + void SelfName(CommandArgs args) + { + if (args.Player == null) return; + + var plr = args.Player; + if (args.Parameters.Count < 1) + { + args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /nick "); + return; + } + string newName = string.Join(" ", args.Parameters).Trim(); + + #region Checks + if (newName.Length < 2) + { + args.Player.SendMessage("A name must be at least 2 characters long.", Color.DeepPink); + return; + } + + if (newName.Length > 20) + { + args.Player.SendMessage("A name must not be longer than 20 characters.", Color.DeepPink); + return; + } + + List SameName = TShock.Players.Where(player => (player != null && player.Name == newName)).ToList(); + if (SameName.Count > 0) + { + args.Player.SendMessage("This name is taken by another player.", Color.DeepPink); + return; + } + #endregion Checks + + string oldName = plr.TPlayer.name; + plr.TPlayer.name = newName; + TShock.Utils.Broadcast(string.Format("{0} has changed his name to {1}.", oldName, newName), Color.DeepPink); + plr.SendData(PacketTypes.PlayerInfo, newName, plr.Index); + } + } +} diff --git a/PlayerInfo.csproj b/PlayerInfo.csproj new file mode 100644 index 0000000..9636d14 --- /dev/null +++ b/PlayerInfo.csproj @@ -0,0 +1,54 @@ + + + + Debug + AnyCPU + {C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2} + Library + PlayerInfo + PlayerInfo + v4.5 + + + true + full + false + .\ + DEBUG; + prompt + 4 + false + x86 + + + true + D:\Terraria\steamapps\common\Terraria\Legit Terraria Server\ServerPlugins + prompt + 4 + false + + + + + ..\Refs\Newtonsoft.Json.dll + + + ..\Refs\OTAPI.dll + + + ..\Refs\TerrariaServer.exe + + + ..\Refs\TShockAPI.dll + + + + + + + + + + + + \ No newline at end of file diff --git a/PlayerInfo.csproj.user b/PlayerInfo.csproj.user new file mode 100644 index 0000000..7306da1 --- /dev/null +++ b/PlayerInfo.csproj.user @@ -0,0 +1,7 @@ + + + + Project + true + + \ No newline at end of file diff --git a/PlayerInfo.sln b/PlayerInfo.sln new file mode 100644 index 0000000..e7e3d82 --- /dev/null +++ b/PlayerInfo.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayerInfo", "PlayerInfo\PlayerInfo.csproj", "{C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C04AAE3B-7FAC-4FE0-B3BC-7977008BBAE2}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {31CA7400-8BB2-4B8C-AC44-8E68D0F9C297} + EndGlobalSection +EndGlobal diff --git a/PlayerInfo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/PlayerInfo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..b722f5d Binary files /dev/null and b/PlayerInfo/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/PlayerInfo/obj/Debug/PlayerInfo.csproj.AssemblyReference.cache b/PlayerInfo/obj/Debug/PlayerInfo.csproj.AssemblyReference.cache new file mode 100644 index 0000000..8dbe2ac Binary files /dev/null and b/PlayerInfo/obj/Debug/PlayerInfo.csproj.AssemblyReference.cache differ diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..00237a2 --- /dev/null +++ b/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("PlayerInfo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("PlayerInfo")] +[assembly: AssemblyCopyright("Copyright © Comdar 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.0.0")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/README.md b/README.md index 9bcd47f..692a212 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,3 @@ -# Title -Update for the latest TShock version. - - # PlayerInfo A player info modifier/checker for TShock @@ -10,4 +6,3 @@ A player info modifier/checker for TShock | checkinfo, cinfo | playerinfo.checkinfo | Check another player's max and current HP and mana | | nick, name | playerinfo.selfname | Change your nickname | | stats | playerinfo.hpnmana | Set another player's max HP and mana | - diff --git a/Refs/Newtonsoft.Json.dll b/Refs/Newtonsoft.Json.dll new file mode 100644 index 0000000..77a5d89 Binary files /dev/null and b/Refs/Newtonsoft.Json.dll differ diff --git a/Refs/OTAPI.dll b/Refs/OTAPI.dll new file mode 100644 index 0000000..c6e9b1b Binary files /dev/null and b/Refs/OTAPI.dll differ diff --git a/Refs/TShockAPI.dll b/Refs/TShockAPI.dll new file mode 100644 index 0000000..378bd0a Binary files /dev/null and b/Refs/TShockAPI.dll differ diff --git a/Refs/TerrariaServer.exe b/Refs/TerrariaServer.exe new file mode 100644 index 0000000..9bb2390 Binary files /dev/null and b/Refs/TerrariaServer.exe differ diff --git a/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache new file mode 100644 index 0000000..b722f5d Binary files /dev/null and b/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache differ diff --git a/obj/Debug/PlayerInfo.csproj.AssemblyReference.cache b/obj/Debug/PlayerInfo.csproj.AssemblyReference.cache new file mode 100644 index 0000000..8dbe2ac Binary files /dev/null and b/obj/Debug/PlayerInfo.csproj.AssemblyReference.cache differ