diff --git a/TShockAPI/Bouncer.cs b/TShockAPI/Bouncer.cs index 30268f41..8bb255a0 100644 --- a/TShockAPI/Bouncer.cs +++ b/TShockAPI/Bouncer.cs @@ -42,6 +42,7 @@ namespace TShockAPI { // Setup hooks + GetDataHandlers.NPCHome.Register(OnUpdateNPCHome); GetDataHandlers.ChestOpen.Register(OnChestOpen); GetDataHandlers.PlaceChest.Register(OnPlaceChest); GetDataHandlers.LiquidSet.Register(OnLiquidSet); @@ -55,9 +56,41 @@ namespace TShockAPI GetDataHandlers.TileEdit.Register(OnTileEdit); } + /// The Bouncer handler for when an NPC is rehomed. + /// The object that triggered the event. + /// The packet arguments that the event has. + internal void OnUpdateNPCHome(object sender, GetDataHandlers.NPCHomeChangeEventArgs args) + { + int id = args.ID; + short x = args.X; + short y = args.Y; + byte homeless = args.Homeless; + + // Calls to TShock.CheckTilePermission need to be broken up into different subsystems + // In particular, this handles both regions and other things. Ouch. + if (TShock.CheckTilePermission(args.Player, x, y)) + { + args.Player.SendErrorMessage("You do not have access to modify this area."); + args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, + Convert.ToByte(Main.npc[id].homeless)); + args.Handled = true; + return; + } + + if (TShock.CheckRangePermission(args.Player, x, y)) + { + args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, + Convert.ToByte(Main.npc[id].homeless)); + args.Handled = true; + return; + } + } + + /// The Bouncer handler for when chests are opened. + /// The object that triggered the event. + /// The packet arguments that the event has. internal void OnChestOpen(object sender, GetDataHandlers.ChestOpenEventArgs args) { - if (TShock.CheckIgnores(args.Player)) { args.Handled = true; diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 5606c50b..dead02ec 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -1008,6 +1008,8 @@ namespace TShockAPI /// public class NPCHomeChangeEventArgs : HandledEventArgs { + /// The TSPlayer that caused the event. + public TSPlayer Player { get; set; } /// /// The Terraria playerID of the player /// @@ -1030,13 +1032,14 @@ namespace TShockAPI /// public static HandlerList NPCHome; - private static bool OnUpdateNPCHome(short id, short x, short y, byte homeless) + private static bool OnUpdateNPCHome(TSPlayer player, short id, short x, short y, byte homeless) { if (NPCHome == null) return false; var args = new NPCHomeChangeEventArgs { + Player = player, ID = id, X = x, Y = y, @@ -2514,7 +2517,7 @@ namespace TShockAPI var y = args.Data.ReadInt16(); var homeless = args.Data.ReadInt8(); - if (OnUpdateNPCHome(id, x, y, homeless)) + if (OnUpdateNPCHome(args.Player, id, x, y, homeless)) return true; if (!args.Player.HasPermission(Permissions.movenpc)) @@ -2524,22 +2527,6 @@ namespace TShockAPI Convert.ToByte(Main.npc[id].homeless)); return true; } - - if (TShock.CheckTilePermission(args.Player, x, y)) - { - args.Player.SendErrorMessage("You do not have access to modify this area."); - args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, - Convert.ToByte(Main.npc[id].homeless)); - return true; - } - - //removed until NPC Home packet actually sends their home coords. - /*if (TShock.CheckRangePermission(args.Player, x, y)) - { - args.Player.SendData(PacketTypes.UpdateNPCHome, "", id, Main.npc[id].homeTileX, Main.npc[id].homeTileY, - Convert.ToByte(Main.npc[id].homeless)); - return true; - }*/ return false; }