diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 1aa1bb27..f10c0bb9 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -654,16 +654,16 @@ namespace TShockAPI private static void Home(CommandArgs args) { - TShock.Teleport(args.Player.Index, args.TPlayer.SpawnX * 16 + 8 - args.TPlayer.width / 2, - args.TPlayer.SpawnY * 16 - args.TPlayer.height); + args.Player.Spawn(); args.Player.SendMessage("Teleported to your spawnpoint."); } private static void Spawn(CommandArgs args) { - TShock.Teleport(args.Player.Index, Main.spawnTileX * 16 + 8 - args.TPlayer.width / 2, - Main.spawnTileY * 16 - args.TPlayer.height); - args.Player.SendMessage("Teleported to the map's spawnpoint."); + if (args.Player.Teleport(Main.spawnTileX, Main.spawnTileY)) + args.Player.SendMessage("Teleported to the map's spawnpoint."); + else + args.Player.SendMessage("Can't teleport because you have set custom spawnpoint.", Color.Red); } private static void TP(CommandArgs args) @@ -683,8 +683,10 @@ namespace TShockAPI else { var plr = players[0]; - TShock.Teleport(args.Player.Index, plr.X, plr.Y); - args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name)); + if (args.Player.Teleport(plr.TileX, plr.TileY)) + args.Player.SendMessage(string.Format("Teleported to {0}", plr.Name)); + else + args.Player.SendMessage("Can't teleport because you have set custom spawnpoint.", Color.Red); } } @@ -709,9 +711,14 @@ namespace TShockAPI else { var plr = players[0]; - TShock.Teleport(plr.Index, args.Player.X, args.Player.Y); - plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name)); - args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name)); + if (plr.Teleport(args.Player.TileX, args.Player.TileY)) + { + plr.SendMessage(string.Format("You were teleported to {0}.", plr.Name)); + args.Player.SendMessage(string.Format("You brought {0} here.", plr.Name)); + } + else + args.Player.SendMessage("Can't teleport because target player has set custom spawnpoint.", Color.Red); + } } diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 7a4b9835..e026b201 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -130,6 +130,31 @@ namespace TShockAPI NetMessage.SendData((int)PacketTypes.Disconnect, Index, -1, reason, 0x0, 0f, 0f, 0f); } + public bool Teleport(int tileX, int tileY) + { + if (TPlayer.SpawnX >= 0 && TPlayer.SpawnY >= 0) + return false; + + int oldSpawnX = Main.spawnTileX; + int oldSpawnY = Main.spawnTileY; + Main.spawnTileX = tileX; + Main.spawnTileY = tileY; + //Send only that player the new spawn point data + NetMessage.SendData((int)PacketTypes.WorldInfo, Index, -1, "", 0, 0f, 0f, 0f); + //Force them to respawn + Spawn(); + //Reset to old spawnpoint and send spawn data back to player + Main.spawnTileX = (int)oldSpawnX; + Main.spawnTileY = (int)oldSpawnY; + NetMessage.SendData((int)PacketTypes.WorldInfo, Index, -1, "", 0, 0f, 0f, 0f); + return true; + } + + public void Spawn() + { + NetMessage.SendData((int)PacketTypes.PlayerSpawn, Index, -1, "", Index, 0.0f, 0.0f, 0.0f); + } + public virtual void SendTileSquare(int x, int y, int size = 10) { NetMessage.SendData((int)PacketTypes.TileSendSquare, Index, -1, "", size, (float)(x - (size / 2)), (float)(y - (size / 2)), 0f); diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 0eff0d8f..64421f3b 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -417,27 +417,6 @@ namespace TShockAPI * Useful stuff: * */ - public static void Teleport(int ply, int x, int y) - { - int oldSpawnX = Main.spawnTileX; - int oldSpawnY = Main.spawnTileY; - Main.spawnTileX = x/16; - Main.spawnTileY = y/16; - //Send only that player the new spawn point data - NetMessage.SendData(7, ply, -1, "", 0, 0f, 0f, 0f); - //Force them to respawn - NetMessage.SendData(12, ply, -1, "", ply, 0.0f, 0.0f, 0.0f); - //Reset to old spawnpoint and send spawn data back to player - Main.spawnTileX = (int)oldSpawnX; - Main.spawnTileY = (int)oldSpawnY; - NetMessage.SendData(7, ply, -1, "", 0, 0f, 0f, 0f); - } - - public static void Teleport(int ply, float x, float y) - { - Teleport(ply, (int)x, (int)y); - } - public static void StartInvasion() { Main.invasionType = 1;