Skip to content
Permalink
Browse files

Fix creating portals without a name creating portals with duplicate n…

…ames
  • Loading branch information...
UnknownShadow200 committed Sep 1, 2018
1 parent 2c12179 commit 97df0640ff3ddf0585cad63d81c078f733d8a468
Showing with 12 additions and 37 deletions.
  1. +9 −9 fCraft/Commands/WorldCommands.cs
  2. +3 −27 fCraft/Portals/Portal.cs
  3. +0 −1 fCraft/World/World.cs
@@ -3712,12 +3712,13 @@ static void WorldClearHandler(Player player, CommandReader cmd)
return;
}

string portalName = cmd.Next();
if (string.IsNullOrEmpty(portalName)) {
} else if (!Portal.Exists(player.World, portalName)) {
player.PortalName = portalName;
player.PortalName = null;
string name = cmd.Next();
if (string.IsNullOrEmpty(name)) {
} else if (!Portal.Exists(player.World, name)) {
player.PortalName = name;
} else {
player.Message("A portal with name {0} already exists in this world.", portalName);
player.Message("A portal named {0} already exists in this world.", name);
return;
}

@@ -3904,12 +3905,11 @@ static void WorldClearHandler(Player player, CommandReader cmd)
}
}

if (player.PortalName == null) {
player.PortalName = Portal.GenerateName(player.World);
}
string name = player.PortalName;
if (name == null) name = Portal.GenerateName(player.World);

Portal portal = new Portal(player.PortalWorld, new PortalRange(Xmin, Xmax, Ymin, Ymax, Zmin, Zmax),
player.PortalName, player.Name, player.World.Name, player.PortalTPPos);
name, player.Name, player.World.Name, player.PortalTPPos);
PortalHandler.CreatePortal(portal, player.World);
op.AnnounceCompletion = false;
op.Context = BlockChangeContext.Portal;
@@ -78,33 +78,9 @@ public class Portal {
}

public static string GenerateName(World world) {
if (world.Portals != null) {
if (world.Portals.Count > 0) {
bool found = false;


while (!found) {
bool taken = false;

foreach (Portal portal in world.Portals) {
if (portal.Name.Equals("portal" + world.portalID)) {
taken = true;
break;
}
}

if (!taken) {
found = true;
} else {
world.portalID++;
}
}

return "portal" + world.portalID;
}
}

return "portal1";
int id = 1;
while (Exists(world, "portal" + id)) id++;
return "portal" + id;
}

public static bool Exists(World world, string name) {
@@ -86,7 +86,6 @@ public sealed class World : IClassy {
public Array Signs { get; set; }

public ArrayList Portals;
public int portalID = 1;

public BlockDefinition[] BlockDefs;

0 comments on commit 97df064

Please sign in to comment.
You can’t perform that action at this time.