Skip to content

Commit 97df064

Browse files
Fix creating portals without a name creating portals with duplicate names
1 parent 2c12179 commit 97df064

3 files changed

Lines changed: 12 additions & 37 deletions

File tree

fCraft/Commands/WorldCommands.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3712,12 +3712,13 @@ static void PortalCreate(Player player, CommandReader cmd) {
37123712
return;
37133713
}
37143714

3715-
string portalName = cmd.Next();
3716-
if (string.IsNullOrEmpty(portalName)) {
3717-
} else if (!Portal.Exists(player.World, portalName)) {
3718-
player.PortalName = portalName;
3715+
player.PortalName = null;
3716+
string name = cmd.Next();
3717+
if (string.IsNullOrEmpty(name)) {
3718+
} else if (!Portal.Exists(player.World, name)) {
3719+
player.PortalName = name;
37193720
} else {
3720-
player.Message("A portal with name {0} already exists in this world.", portalName);
3721+
player.Message("A portal named {0} already exists in this world.", name);
37213722
return;
37223723
}
37233724

@@ -3904,12 +3905,11 @@ static void PortalCreateCallback(Player player, Vector3I[] marks, object tag) {
39043905
}
39053906
}
39063907

3907-
if (player.PortalName == null) {
3908-
player.PortalName = Portal.GenerateName(player.World);
3909-
}
3908+
string name = player.PortalName;
3909+
if (name == null) name = Portal.GenerateName(player.World);
39103910

39113911
Portal portal = new Portal(player.PortalWorld, new PortalRange(Xmin, Xmax, Ymin, Ymax, Zmin, Zmax),
3912-
player.PortalName, player.Name, player.World.Name, player.PortalTPPos);
3912+
name, player.Name, player.World.Name, player.PortalTPPos);
39133913
PortalHandler.CreatePortal(portal, player.World);
39143914
op.AnnounceCompletion = false;
39153915
op.Context = BlockChangeContext.Portal;

fCraft/Portals/Portal.cs

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,9 @@ public bool IsInRange(Vector3I vector) {
7878
}
7979

8080
public static string GenerateName(World world) {
81-
if (world.Portals != null) {
82-
if (world.Portals.Count > 0) {
83-
bool found = false;
84-
85-
86-
while (!found) {
87-
bool taken = false;
88-
89-
foreach (Portal portal in world.Portals) {
90-
if (portal.Name.Equals("portal" + world.portalID)) {
91-
taken = true;
92-
break;
93-
}
94-
}
95-
96-
if (!taken) {
97-
found = true;
98-
} else {
99-
world.portalID++;
100-
}
101-
}
102-
103-
return "portal" + world.portalID;
104-
}
105-
}
106-
107-
return "portal1";
81+
int id = 1;
82+
while (Exists(world, "portal" + id)) id++;
83+
return "portal" + id;
10884
}
10985

11086
public static bool Exists(World world, string name) {

fCraft/World/World.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public string MapChangedByClassy {
8686
public Array Signs { get; set; }
8787

8888
public ArrayList Portals;
89-
public int portalID = 1;
9089

9190
public BlockDefinition[] BlockDefs;
9291

0 commit comments

Comments
 (0)