diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c6df366..11b1dad9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -68,6 +68,7 @@ Putting this stuff down here so things don't conflict as often.
* Added `TSPlayer` object to `GetDataHandlers.LiquidSetEventArgs`. (@hakusaro)
* Removed `TShock.StartInvasion` for public use (moved to Utils and marked internal). (@hakusaro)
* 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)
## 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 31b31173..17bd69ef 100644
--- a/TShockAPI/Bouncer.cs
+++ b/TShockAPI/Bouncer.cs
@@ -42,6 +42,7 @@ namespace TShockAPI
{
// Setup hooks
+ GetDataHandlers.PlaceChest.Register(OnPlaceChest);
GetDataHandlers.LiquidSet.Register(OnLiquidSet);
GetDataHandlers.ProjectileKill.Register(OnProjectileKill);
GetDataHandlers.PlayerUpdate.Register(OnPlayerUpdate);
@@ -53,6 +54,61 @@ namespace TShockAPI
GetDataHandlers.TileEdit.Register(OnTileEdit);
}
+ internal void OnPlaceChest(object sender, GetDataHandlers.PlaceChestEventArgs args)
+ {
+ int tileX = args.TileX;
+ int tileY = args.TileY;
+ int flag = args.Flag;
+
+ if (!TShock.Utils.TilePlacementValid(tileX, tileY) || (args.Player.Dead && TShock.Config.PreventDeadModification))
+ args.Handled = true;
+ return;
+
+ if (TShock.CheckIgnores(args.Player))
+ {
+ args.Player.SendTileSquare(tileX, tileY, 3);
+ args.Handled = true;
+ return;
+ }
+
+ if (flag != 0 && flag != 4 // if no container or container2 placement
+ && Main.tile[tileX, tileY].type != TileID.Containers
+ && Main.tile[tileX, tileY].type != TileID.Dressers
+ && Main.tile[tileX, tileY].type != TileID.Containers2
+ && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != TileID.Dirt)) //Chest
+ {
+ args.Player.SendTileSquare(tileX, tileY, 3);
+ args.Handled = true;
+ return;
+ }
+
+ if (flag == 2) //place dresser
+ {
+ if ((TShock.Utils.TilePlacementValid(tileX, tileY + 1) && Main.tile[tileX, tileY + 1].type == TileID.Teleporter) ||
+ (TShock.Utils.TilePlacementValid(tileX + 1, tileY + 1) && Main.tile[tileX + 1, tileY + 1].type == TileID.Teleporter))
+ {
+ //Prevent a dresser from being placed on a teleporter, as this can cause client and server crashes.
+ args.Player.SendTileSquare(tileX, tileY, 3);
+ args.Handled = true;
+ return;
+ }
+ }
+
+ if (TShock.CheckTilePermission(args.Player, tileX, tileY))
+ {
+ args.Player.SendTileSquare(tileX, tileY, 3);
+ args.Handled = true;
+ return;
+ }
+
+ if (TShock.CheckRangePermission(args.Player, tileX, tileY))
+ {
+ args.Player.SendTileSquare(tileX, tileY, 3);
+ args.Handled = true;
+ return;
+ }
+ }
+
/// Handles Bouncer's liquid set anti-cheat.
/// The object that triggered the event.
/// The packet arguments that the event has.
diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs
index 624e6285..a519bc23 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -352,35 +352,41 @@ namespace TShockAPI
}
///
- /// For use in a TileKill event
+ /// For use in a PlaceChest event
///
- public class TileKillEventArgs : HandledEventArgs
+ public class PlaceChestEventArgs : HandledEventArgs
{
+ /// The TSPlayer that triggered the event
+ public TSPlayer Player { get; set; }
+ /// What the packet is doing (see MP packet docs).
+ public int Flag { get; set; }
///
- /// The X coordinate that is being killed
+ /// The X coordinate
///
public int TileX { get; set; }
///
- /// The Y coordinate that is being killed
+ /// The Y coordinate
///
public int TileY { get; set; }
}
///
- /// TileKill - When a tile is removed from the world
+ /// When a chest is added or removed from the world.
///
- public static HandlerList TileKill;
+ public static HandlerList PlaceChest;
- private static bool OnTileKill(int tilex, int tiley)
+ private static bool OnPlaceChest(TSPlayer player, int flag, int tilex, int tiley)
{
- if (TileKill == null)
+ if (PlaceChest == null)
return false;
- var args = new TileKillEventArgs
+ var args = new PlaceChestEventArgs
{
+ Player = player,
+ Flag = flag,
TileX = tilex,
TileY = tiley,
};
- TileKill.Invoke(null, args);
+ PlaceChest.Invoke(null, args);
return args.Handled;
}
@@ -1391,7 +1397,7 @@ namespace TShockAPI
{ PacketTypes.ProjectileNew, HandleProjectileNew },
{ PacketTypes.TogglePvp, HandleTogglePvp },
{ PacketTypes.PlayerTeam, HandlePlayerTeam },
- { PacketTypes.TileKill, HandleTileKill },
+ { PacketTypes.TileKill, HandlePlaceChest },
{ PacketTypes.LiquidSet, HandleLiquidSet },
{ PacketTypes.PlayerSpawn, HandleSpawn },
{ PacketTypes.ChestGetContents, HandleChestOpen },
@@ -2335,56 +2341,16 @@ namespace TShockAPI
return false;
}
- private static bool HandleTileKill(GetDataHandlerArgs args)
+ private static bool HandlePlaceChest(GetDataHandlerArgs args)
{
int flag = args.Data.ReadByte();
int tileX = args.Data.ReadInt16();
int tileY = args.Data.ReadInt16();
args.Data.ReadInt16(); // Ignore style
- if (OnTileKill(tileX, tileY))
+ if (OnPlaceChest(args.Player, flag, tileX, tileY))
return true;
- if (!TShock.Utils.TilePlacementValid(tileX, tileY) || (args.Player.Dead && TShock.Config.PreventDeadModification))
- return true;
-
- if (TShock.CheckIgnores(args.Player))
- {
- args.Player.SendTileSquare(tileX, tileY, 3);
- return true;
- }
-
- if (flag != 0 && flag != 4 // if no container or container2 placement
- && Main.tile[tileX, tileY].type != TileID.Containers
- && Main.tile[tileX, tileY].type != TileID.Dressers
- && Main.tile[tileX, tileY].type != TileID.Containers2
- && (!TShock.Utils.MaxChests() && Main.tile[tileX, tileY].type != TileID.Dirt)) //Chest
- {
- args.Player.SendTileSquare(tileX, tileY, 3);
- return true;
- }
-
- if (flag == 2) //place dresser
- {
- if ((TShock.Utils.TilePlacementValid(tileX, tileY + 1) && Main.tile[tileX, tileY + 1].type == TileID.Teleporter) ||
- (TShock.Utils.TilePlacementValid(tileX + 1, tileY + 1) && Main.tile[tileX + 1, tileY + 1].type == TileID.Teleporter))
- {
- //Prevent a dresser from being placed on a teleporter, as this can cause client and server crashes.
- args.Player.SendTileSquare(tileX, tileY, 3);
- return true;
- }
- }
-
- if (TShock.CheckTilePermission(args.Player, tileX, tileY))
- {
- args.Player.SendTileSquare(tileX, tileY, 3);
- return true;
- }
-
- if (TShock.CheckRangePermission(args.Player, tileX, tileY))
- {
- args.Player.SendTileSquare(tileX, tileY, 3);
- return true;
- }
+
return false;
}