From d71aacc58d4f7ce2094bd2da5aa27d97e1f5a50f Mon Sep 17 00:00:00 2001 From: Zack Piispanen Date: Mon, 30 Sep 2013 19:34:43 -0400 Subject: [PATCH] Did some tweaks to Teleport to make the bounds checks in one place. Fixed item drop packet, as well as update the bounds. --- TShockAPI/Commands.cs | 18 ----------------- TShockAPI/GetDataHandlers.cs | 39 ++++++++++++++---------------------- TShockAPI/TSPlayer.cs | 23 ++++++++++++++++++--- TShockAPI/Utils.cs | 2 +- 4 files changed, 36 insertions(+), 46 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 61e9baad..5b64bdc2 100644 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -1651,24 +1651,6 @@ namespace TShockAPI float x, y; if (float.TryParse(args.Parameters[0], out x) && float.TryParse(args.Parameters[1], out y)) { - - - if (x < 500) - { - x = 500; - } - if (y < 500) - { - y = 500; - } - if (x > Main.rightWorld - 500) - { - x = Main.rightWorld - 500; - } - if (y > Main.bottomWorld - 500) - { - y = Main.bottomWorld - 500; - } args.Player.Teleport(x, y); args.Player.SendSuccessMessage("Teleported!"); } diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index e2532a7d..eff01fa6 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -924,6 +924,10 @@ namespace TShockAPI /// public byte Prefix { get; set; } /// + /// No Delay on pickup + /// + public bool NoDelay { get; set; } + /// /// Item type /// public short Type { get; set; } @@ -933,7 +937,7 @@ namespace TShockAPI /// public static HandlerList ItemDrop; - private static bool OnItemDrop(short id, Vector2 pos, Vector2 vel, byte stacks, byte prefix, short type) + private static bool OnItemDrop(short id, Vector2 pos, Vector2 vel, byte stacks, byte prefix, bool noDelay, short type) { if (ItemDrop == null) return false; @@ -945,6 +949,7 @@ namespace TShockAPI Velocity = vel, Stacks = stacks, Prefix = prefix, + NoDelay = noDelay, Type = type, }; ItemDrop.Invoke(null, args); @@ -2746,13 +2751,14 @@ namespace TShockAPI var vel = new Vector2(args.Data.ReadSingle(), args.Data.ReadSingle()); var stacks = args.Data.ReadInt8(); var prefix = args.Data.ReadInt8(); + var noDelay = args.Data.ReadBoolean(); var type = args.Data.ReadInt16(); - if (OnItemDrop(id, pos, vel, stacks, prefix, type)) + if (OnItemDrop(id, pos, vel, stacks, prefix, noDelay, type)) return true; // player is attempting to crash clients - if (type < -24 || type >= Main.maxItemTypes) + if (type < -48 || type >= Main.maxItemTypes) { return true; } @@ -3065,7 +3071,7 @@ namespace TShockAPI if (OnTeleport(id, flag, x, y)) return true; - var style = 0; + byte style = 0; var isNPC = false; if ((flag & 1) == 1) { @@ -3089,29 +3095,12 @@ namespace TShockAPI return true; } - if (x > Main.rightWorld - 500) - { - x = Main.rightWorld - 500; - } - if (x < 500) - { - x = 500; - } - if (y > Main.bottomWorld - 500) - { - y = Main.bottomWorld - 500; - } - if (y < 500) - { - y = 500; - } - if (Main.player[id] == null || TShock.Players[id] == null) { return true; } - if (!args.Player.Group.HasPermission(Permissions.tp)) + if (!isNPC && !args.Player.Group.HasPermission(Permissions.tp)) { args.Player.SendErrorMessage("You do not have permission to teleport."); Main.player[id].Teleport(new Vector2(Main.player[id].position.X, Main.player[id].position.Y), style); @@ -3119,8 +3108,10 @@ namespace TShockAPI return true; } - Main.player[id].Teleport(new Vector2(x, y), style); - NetMessage.SendData(65, -1, -1, "", 0, (float)id, x, y, style); + if (!isNPC) + { + TShock.Players[id].Teleport(x, y, style); + } } return true; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index c9a1f23e..eeeaa29b 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -510,10 +510,27 @@ namespace TShockAPI } } - public bool Teleport(float x, float y) + public bool Teleport(float x, float y, byte style = 1) { - TPlayer.Teleport(new Vector2(x, y), 1); - NetMessage.SendData(65, -1, -1, "", 0, (float)TPlayer.whoAmi, x, y, 1); + if (x > Main.rightWorld - 500) + { + x = Main.rightWorld - 500; + } + if (x < 500) + { + x = 500; + } + if (y > Main.bottomWorld - 500) + { + y = Main.bottomWorld - 500; + } + if (y < 500) + { + y = 500; + } + + TPlayer.Teleport(new Vector2(x, y), style); + NetMessage.SendData(65, -1, -1, "", 0, TPlayer.whoAmi, x, y, style); return true; } diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 1f301b3f..351d5e77 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -371,7 +371,7 @@ namespace TShockAPI var found = new List(); Item item = new Item(); string nameLower = name.ToLower(); - for (int i = -24; i < Main.maxItemTypes; i++) + for (int i = -48; i < Main.maxItemTypes; i++) { item.netDefaults(i); if (item.name.ToLower() == nameLower)