diff --git a/CHANGELOG.md b/CHANGELOG.md
index b627f6c6..a84786df 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -70,8 +70,9 @@ Putting this stuff down here so things don't conflict as often.
* Fixed invasions started by TShock not reporting size correctly and probably not working at all. (@hakusaro)
* Removed `GetDataHandlers.TileKill` and replaced it with `GetDataHandlers.PlaceChest` as the packet originally designated as tile kill is now only used for chests. (@hakusaro)
* Added `TSPlayer` to `GetDataHandlers.NPCHome`. (@hakusaro)
-* Added a `TSPlayer` to `GetDataHandlers.ChestItemChanged`. (@hakusaro)
+* Added `TSPlayer` to `GetDataHandlers.ChestItemChanged`. (@hakusaro)
* Fixed chest item changes not triggering any range checks, tile checks, or correct chest checks. (@hakusaro)
+* Added `TSPlayer` to `GetDataHandlers.PlayerBuff`. (@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 5dbf22db..59eab38e 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -42,6 +42,7 @@ namespace TShockAPI
{
// Setup hooks
+ GetDataHandlers.PlayerBuff.Register(OnPlayerBuff);
GetDataHandlers.ChestItemChange.Register(OnChestItemChange);
GetDataHandlers.NPCHome.Register(OnUpdateNPCHome);
GetDataHandlers.ChestOpen.Register(OnChestOpen);
@@ -57,6 +58,63 @@ namespace TShockAPI
GetDataHandlers.TileEdit.Register(OnTileEdit);
}
+ /// Handles Buff events.
+ /// The object that triggered the event.
+ /// The packet arguments that the event has.
+ internal void OnPlayerBuff(object sender, GetDataHandlers.PlayerBuffEventArgs args)
+ {
+ byte id = args.ID;
+ byte type = args.Type;
+ int time = args.Time;
+
+ if (TShock.Players[id] == null)
+ {
+ args.Handled = true;
+ return;
+ }
+
+ if (TShock.CheckIgnores(args.Player))
+ {
+ args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
+ args.Handled = true;
+ return;
+ }
+
+ if (id >= Main.maxPlayers)
+ {
+ args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
+ args.Handled = true;
+ return;
+ }
+
+ if (!TShock.Players[id].TPlayer.hostile || !Main.pvpBuff[type])
+ {
+ args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
+ args.Handled = true;
+ return;
+ }
+
+ if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50))
+ {
+ args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
+ args.Handled = true;
+ return;
+ }
+
+ if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
+ {
+ args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
+ args.Handled = true;
+ return;
+ }
+
+ if (WhitelistBuffMaxTime[type] > 0 && time <= WhitelistBuffMaxTime[type])
+ {
+ args.Handled = false;
+ return;
+ }
+ }
+
/// Handles when a chest item is changed.
/// The object that triggered the event.
/// The packet arguments that the event has.
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 8431a27d..25115035 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -1057,6 +1057,7 @@ namespace TShockAPI
///
public class PlayerBuffEventArgs : HandledEventArgs
{
+ public TSPlayer Player { get; set; }
///
/// The Terraria playerID of the player
///
@@ -1075,13 +1076,14 @@ namespace TShockAPI
///
public static HandlerList PlayerBuff;
- private static bool OnPlayerBuff(byte id, byte type, int time)
+ private static bool OnPlayerBuff(TSPlayer player, byte id, byte type, int time)
{
if (PlayerBuff == null)
return false;
var args = new PlayerBuffEventArgs
{
+ Player = player,
ID = id,
Type = type,
Time = time
@@ -2518,45 +2520,9 @@ namespace TShockAPI
var type = args.Data.ReadInt8();
var time = args.Data.ReadInt32();
- if (OnPlayerBuff(id, type, time))
+ if (OnPlayerBuff(args.Player, id, type, time))
return true;
- if (TShock.Players[id] == null)
- return false;
-
- if (TShock.CheckIgnores(args.Player))
- {
- args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
- return true;
- }
-
- if (id >= Main.maxPlayers)
- {
- args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
- return true;
- }
-
- if (!TShock.Players[id].TPlayer.hostile || !Main.pvpBuff[type])
- {
- args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
- return true;
- }
- if (TShock.CheckRangePermission(args.Player, TShock.Players[id].TileX, TShock.Players[id].TileY, 50))
- {
- args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
- return true;
- }
- if ((DateTime.UtcNow - args.Player.LastThreat).TotalMilliseconds < 5000)
- {
- args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
- return true;
- }
-
- if (WhitelistBuffMaxTime[type] > 0 && time <= WhitelistBuffMaxTime[type])
- {
- return false;
- }
-
args.Player.SendData(PacketTypes.PlayerAddBuff, "", id);
return true;
}