Skip to content

Commit

Permalink
Support both /pw join [map num] [player] and /pw join [player] [map n…
Browse files Browse the repository at this point in the history
…um] formats
  • Loading branch information
UnknownShadow200 committed Jul 22, 2017
1 parent dee665b commit 84c74f9
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions fCraft/Commands/WorldCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -869,8 +869,8 @@ static bool ExpandFilename(Player player, CommandReader cmd, ref string fileName
if (fileName.CaselessStarts("pw_") && player.Info.Rank != RankManager.HighestRank) {
player.Message("You cannot make fake personal worlds");
return false;
}
}
// saving to file
fileName = fileName.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
if (!fileName.CaselessEnds(".fcm")) fileName += ".fcm";
Expand Down Expand Up @@ -953,7 +953,7 @@ private static void GenHMHandler(Player player, CommandReader cmd) {
"GenHM: Asked {0} to confirm replacing the map of world {1} (\"this map\").",
player.Name, playerWorld.Name);

player.Confirm(cmd, "Replace THIS MAP with a generated one (HeightMap: &9{0}&S)?", url);
player.Confirm(cmd, "Replace THIS MAP with a generated one (HeightMap: &9{0}&S)?", url);
return;
}

Expand Down Expand Up @@ -3444,19 +3444,34 @@ static void MWDelete(Player player, CommandReader cmd) {
}

static void MWJoin(Player player, CommandReader cmd) {
PlayerInfo info = player.Info;
// Args are supposed to be "<map number> <player>", but handle if user provides <player> first
if (cmd.HasNext) {
string name = cmd.Next();
int temp = 0;

if (!int.TryParse(name, out temp)) {
info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name, SearchOptions.Default);
if (info == null) return;
} else {
cmd.Rewind(); // user provided number, rewind
cmd.Next(); // Skip 'join' arg
}
}

int num = 0; ReadMWNumber(cmd, out num);
string name = cmd.Next();
PlayerInfo info = null;
if (name != null) {
info = PlayerDB.FindPlayerInfoOrPrintMatches(player, name, SearchOptions.Default);
if (info == player.Info && cmd.HasNext) {
info = PlayerDB.FindPlayerInfoOrPrintMatches(player, cmd.Next(), SearchOptions.Default);
if (info == null) return;
}
string mapName = "PW_" + ((info == null) ? player.Name : info.Name) + "_" + num;
string map = WorldManager.FindMapFile(Player.Console, mapName);

string mapName = "PW_" + info.Name + "_" + num;
string map = WorldManager.FindMapFile(Player.Console, mapName);
if (map == null) {
player.Message("{0} no personal worlds by that number: {1}", (info == null) ? "You have" : "There are", num);
player.Message("{0} no personal worlds by that number: {1}", (info == player.Info) ? "You have" : "There are", num);
return;
}

World world = WorldManager.FindWorldExact(mapName);
if (world != null && player.CanJoin(world)) {
player.JoinWorld(world, WorldChangeReason.ManualJoin);
Expand Down

0 comments on commit 84c74f9

Please sign in to comment.