Skip to content

Commit

Permalink
Fix creating portals without a name creating portals with duplicate n…
Browse files Browse the repository at this point in the history
…ames
  • Loading branch information
UnknownShadow200 committed Sep 1, 2018
1 parent 2c12179 commit 97df064
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 37 deletions.
18 changes: 9 additions & 9 deletions fCraft/Commands/WorldCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3712,12 +3712,13 @@ static void PortalCreate(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;
}

Expand Down Expand Up @@ -3904,12 +3905,11 @@ static void PortalCreateCallback(Player player, Vector3I[] marks, object tag) {
}
}

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;
Expand Down
30 changes: 3 additions & 27 deletions fCraft/Portals/Portal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,9 @@ public bool IsInRange(Vector3I vector) {
}

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) {
Expand Down
1 change: 0 additions & 1 deletion fCraft/World/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public string MapChangedByClassy {
public Array Signs { get; set; }

public ArrayList Portals;
public int portalID = 1;

public BlockDefinition[] BlockDefs;

Expand Down

0 comments on commit 97df064

Please sign in to comment.