From cdba07c62e0fd268c2a3e9549f9072ef1f44f73e Mon Sep 17 00:00:00 2001 From: Lucas Nicodemus Date: Fri, 15 Dec 2017 21:50:20 -0700 Subject: [PATCH] Move OnPlayerAnimation to Bouncer --- CHANGELOG.md | 1 + TShockAPI/Bouncer.cs | 23 ++++++++++++++++++++++- TShockAPI/GetDataHandlers.cs | 23 ++++++++--------------- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index abd236ca..83383492 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,7 @@ Putting this stuff down here so things don't conflict as often. * Added `TSPlayer` to `GetDataHandlers.PlayerBuff`. (@hakusaro) * Added `TSPlayer` and `PlayerDeathReason` to `GetDataHandlers.PlayerDamage`. (@hakusaro) * Added `TSPlayer` to `GetDataHandlers.NPCStrike`. (@hakusaro) +* Added `TSPlayer` to `GetDataHandlers.PlayerAnimation`. (@hakusaro) ## TShock 4.3.25 * Fixed a critical exploit in the Terraria protocol that could cause massive unpreventable world corruption as well as a number of other problems. Thanks to @bartico6 for reporting. Fixed by the efforts of @QuiCM, @hakusaro, and tips in the right directioon from @bartico6. diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index f1e62ab8..ab291c3a 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -41,6 +41,7 @@ namespace TShockAPI { // Setup hooks + GetDataHandlers.PlayerAnimation.Register(OnPlayerAnimation); GetDataHandlers.NPCStrike.Register(OnNPCStrike); GetDataHandlers.ItemDrop.Register(OnItemDrop); GetDataHandlers.PlayerBuff.Register(OnPlayerBuff); @@ -59,6 +60,26 @@ namespace TShockAPI GetDataHandlers.TileEdit.Register(OnTileEdit); } + /// Handles basic animation throttling for disabled players. + /// sender + /// args + internal void OnPlayerAnimation(object sender, GetDataHandlers.PlayerAnimationEventArgs args) + { + if (TShock.CheckIgnores(args.Player)) + { + args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index); + args.Handled = true; + return; + } + + if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000) + { + args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index); + args.Handled = true; + return; + } + } + /// Handles the NPC Strike event for Bouncer. /// The object that triggered the event. /// The packet arguments that the event has. @@ -69,7 +90,7 @@ namespace TShockAPI short damage = args.Damage; float knockback = args.Knockback; byte crit = args.Critical; - + if (Main.npc[id] == null) { args.Handled = true; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e6555cc3..b6d182b7 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1298,6 +1298,8 @@ namespace TShockAPI /// public class PlayerAnimationEventArgs : HandledEventArgs { + /// The TSPlayer that triggered the event. + public TSPlayer Player { get; set; } } /// @@ -1305,12 +1307,15 @@ namespace TShockAPI /// public static HandlerList PlayerAnimation; - private static bool OnPlayerAnimation() + private static bool OnPlayerAnimation(TSPlayer player) { if (PlayerAnimation == null) return false; - var args = new PlayerAnimationEventArgs { }; + var args = new PlayerAnimationEventArgs + { + Player = player, + }; PlayerAnimation.Invoke(null, args); return args.Handled; } @@ -2635,21 +2640,9 @@ namespace TShockAPI private static bool HandlePlayerAnimation(GetDataHandlerArgs args) { - if (OnPlayerAnimation()) + if (OnPlayerAnimation(args.Player)) return true; - if (TShock.CheckIgnores(args.Player)) - { - args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index); - return true; - } - - if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000) - { - args.Player.SendData(PacketTypes.PlayerAnimation, "", args.Player.Index); - return true; - } - return false; }