Move UpdateNPCHome to Bouncer
This commit is contained in:
parent
be8cffddfd
commit
943f86615a
2 changed files with 39 additions and 19 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>The Bouncer handler for when an NPC is rehomed.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The Bouncer handler for when chests are opened.</summary>
|
||||
/// <param name="sender">The object that triggered the event.</param>
|
||||
/// <param name="args">The packet arguments that the event has.</param>
|
||||
internal void OnChestOpen(object sender, GetDataHandlers.ChestOpenEventArgs args)
|
||||
{
|
||||
|
||||
if (TShock.CheckIgnores(args.Player))
|
||||
{
|
||||
args.Handled = true;
|
||||
|
|
|
|||
|
|
@ -1008,6 +1008,8 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public class NPCHomeChangeEventArgs : HandledEventArgs
|
||||
{
|
||||
/// <summary>The TSPlayer that caused the event.</summary>
|
||||
public TSPlayer Player { get; set; }
|
||||
/// <summary>
|
||||
/// The Terraria playerID of the player
|
||||
/// </summary>
|
||||
|
|
@ -1030,13 +1032,14 @@ namespace TShockAPI
|
|||
/// </summary>
|
||||
public static HandlerList<NPCHomeChangeEventArgs> 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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue