Skip to content

Commit

Permalink
Fix /back not working with /tpa
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Dec 30, 2023
1 parent 170deda commit 0621ce1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
2 changes: 1 addition & 1 deletion MCGalaxy/Bots/Instructions/FunInstructions.cs
Expand Up @@ -49,7 +49,7 @@ protected class Metadata { public short Seconds, Speed; }
return data;
}

public override void Output(Player p, string[] args, TextWriter w) {
public override void Output(Player p, string[] args, TextWriter w) {
string time = args.Length > 3 ? args[3] : "10";
string speed = args.Length > 4 ? args[4] : "2";
w.WriteLine(Name + " " + short.Parse(time) + " " + short.Parse(speed));
Expand Down
27 changes: 3 additions & 24 deletions MCGalaxy/Commands/other/CmdTp.cs
Expand Up @@ -53,22 +53,8 @@ public sealed class CmdTp : Command2 {
Help(p); return;
}

SavePreTeleportState(p);
Level lvl = bot != null ? bot.level : target.level;

if (p.level != lvl) PlayerActions.ChangeMap(p, lvl.name);
if (target != null && target.Loading) {
p.Message("Waiting for {0} &Sto spawn..", p.FormatNick(target));
target.BlockUntilLoad(10);
}

// Player wasn't able to join target map, so don't move
if (p.level != lvl) return;

Position pos = bot != null ? bot.Pos : target.Pos;
Orientation rot = bot != null ? bot.Rot : target.Rot;
p.BlockUntilLoad(10); //Wait for player to spawn in new map
p.SendPosition(pos, rot);
Entity dst = bot != null ? (Entity)bot : (Entity)target;
PlayerOperations.TeleportToEntity(p, dst);
}

internal static bool GetTeleportCoords(Player p, Entity ori, string[] args, bool precise,
Expand Down Expand Up @@ -104,14 +90,7 @@ public sealed class CmdTp : Command2 {
Position pos; byte yaw, pitch;
if (!GetTeleportCoords(p, p, args, precise, out pos, out yaw, out pitch)) return;

SavePreTeleportState(p);
p.SendPosition(pos, new Orientation(yaw, pitch));
}

static void SavePreTeleportState(Player p) {
p.PreTeleportMap = p.level.name;
p.PreTeleportPos = p.Pos;
p.PreTeleportRot = p.Rot;
PlayerOperations.TeleportToCoords(p, pos, new Orientation(yaw, pitch));
}

static bool CheckPlayer(Player p, Player target, CommandData data) {
Expand Down
11 changes: 3 additions & 8 deletions MCGalaxy/Commands/other/CmdTpA.cs
Expand Up @@ -49,7 +49,7 @@ public sealed class CmdTpA : Command2 {
p.Message("You still have a pending teleport request with this player."); return;
}
if (p.level != target.level && target.level.IsMuseum) {
p.Message("Player \"{0}\" is in a museum.", p.FormatNick(target)); return;
p.Message("{0} &Sis in a museum.", p.FormatNick(target)); return;
}
if (target.Loading) {
p.Message("Waiting for {0} &Sto spawn...", p.FormatNick(target));
Expand Down Expand Up @@ -99,13 +99,8 @@ public sealed class CmdTpA : Command2 {
p.Message("You have accepted {0}&S's teleportation request.", p.FormatNick(sender));
sender.Message("{0} &Shas accepted your request. Teleporting now...", sender.FormatNick(p));
sender.currentTpa = "";
Thread.Sleep(1000);
if (p.level != sender.level) {
PlayerActions.ChangeMap(sender, p.level);
Thread.Sleep(1000);
}

sender.SendPosition(p.Pos, p.Rot);

PlayerOperations.TeleportToEntity(sender, p);
}

void DoDeny(Player p) {
Expand Down
28 changes: 28 additions & 0 deletions MCGalaxy/Player/PlayerOperations.cs
Expand Up @@ -170,5 +170,33 @@ public static class PlayerOperations
Chat.MessageAll(message);
}
}


public static void TeleportToCoords(Player p, Position pos, Orientation ori) {
SavePreTeleportState(p);
p.SendPosition(pos, ori);
}

public static void TeleportToEntity(Player p, Entity dst) {
SavePreTeleportState(p);
Level lvl = dst.Level;

Player target = dst as Player;
if (target != null && target.Loading) {
p.Message("Waiting for {0} &Sto spawn..", p.FormatNick(target));
target.BlockUntilLoad(10);
}

if (p.level != lvl && !PlayerActions.ChangeMap(p, lvl.name)) return;

p.BlockUntilLoad(10); // Wait for player to spawn in new map
p.SendPosition(dst.Pos, dst.Rot);
}

static void SavePreTeleportState(Player p) {
p.PreTeleportMap = p.level.name;
p.PreTeleportPos = p.Pos;
p.PreTeleportRot = p.Rot;
}
}
}

0 comments on commit 0621ce1

Please sign in to comment.