Skip to content

Commit f20bd61

Browse files
Fix /ent reload erroring when an entity exists in a now deleted world.
Also general cleanup of Entity class
1 parent f7b9470 commit f20bd61

File tree

6 files changed

+165
-137
lines changed

6 files changed

+165
-137
lines changed

fCraft/Commands/CpeCommands.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,15 @@ private static void EntityHandler(Player player, CommandReader cmd) {
102102
World world = WorldManager.FindWorldOrPrintMatches(player, search);
103103
if (world != null) {
104104
player.Message("Entities on &f{0}&S: ", world.Name);
105-
player.Message(" &F" + Entity.EntityList.Where(w => Entity.getWorld(w) == world).JoinToString("&S, &F", n => n.Name));
105+
player.Message(" &F" + Entity.AllIn(world).JoinToString("&S, &F", n => n.Name));
106106
}
107107
return;
108108
}
109109
if (option.CaselessEquals("removeall")) {
110110
string search = cmd.Next() ?? player.World.Name;
111111
World world = WorldManager.FindWorldOrPrintMatches(player, search);
112112
if (cmd.IsConfirmed) {
113-
Entity.RemoveAll(world);
113+
Entity.RemoveAllIn(world);
114114
player.Message("All entities on &f{0}&S removed.", player.World.Name);
115115
} else {
116116
player.Confirm(cmd, "This will remove all the entites on {0}, are you sure?", player.World.Name);
@@ -151,20 +151,20 @@ private static void EntityHandler(Player player, CommandReader cmd) {
151151
}
152152

153153
//if a botname has already been chosen, ask player for a new name
154-
if (Entity.exists(player.World, entityName)) {
154+
if (Entity.Exists(player.World, entityName)) {
155155
player.Message("An entity with that name already exists! To view all entities, type /ent list.");
156156
return;
157157
}
158158

159159
string skinString1 = (cmd.Next() ?? entityName);
160160
if (skinString1 != null) skinString1 = ParseSkin(skinString1);
161161

162-
entity = Entity.CreateEntity(entityName, skinString1, requestedModel, player.World, player.Position, getNewID(player.World));
162+
entity = Entity.Create(entityName, skinString1, requestedModel, player.World, player.Position, getNewID(player.World));
163163
player.Message("Successfully created entity {0}&S with id:{1} and skin {2}.", entity.Name, entity.ID, entity.Skin, entity.Name);
164164
break;
165165
case "remove":
166166
player.Message("{0} was removed from {1}", entity.Name, player.World.Name);
167-
Entity.RemoveEntity(entity);
167+
Entity.Remove(entity);
168168
break;
169169
case "model":
170170
if (cmd.HasNext) {
@@ -181,24 +181,24 @@ private static void EntityHandler(Player player, CommandReader cmd) {
181181
break;
182182
}
183183
player.Message("Changed entity model to {0}.", model);
184-
Entity.ChangeEntityModel(entity, model);
184+
entity.ChangeModel(model);
185185
} else {
186186
player.Message(
187187
"Usage is /Ent model <bot> <model>. Valid models are chibi, chicken, creeper, giant, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name.");
188188
}
189189
break;
190190
case "bring":
191-
Entity.TeleportEntity(entity, player.Position);
191+
entity.TeleportTo(player.Position);
192192
break;
193193
case "tp":
194194
case "teleport":
195-
World targetWorld = Entity.getWorld(entity);
195+
World targetWorld = entity.WorldIn();
196196
if (targetWorld == player.World) {
197197
if (player.World != null) {
198198
player.LastWorld = player.World;
199199
player.LastPosition = player.Position;
200200
}
201-
player.TeleportTo(Entity.getPos(entity));
201+
player.TeleportTo(entity.GetPos());
202202
} else {
203203
if (targetWorld.Name.StartsWith("PW_") &&
204204
!targetWorld.AccessSecurity.ExceptionList.Included.Contains(player.Info)) {
@@ -223,7 +223,7 @@ private static void EntityHandler(Player player, CommandReader cmd) {
223223
break;
224224
}
225225
player.StopSpectating();
226-
player.JoinWorld(targetWorld, WorldChangeReason.Tp, Entity.getPos(entity));
226+
player.JoinWorld(targetWorld, WorldChangeReason.Tp, entity.GetPos());
227227
break;
228228
case SecurityCheckResult.BlackListed:
229229
player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}",
@@ -246,7 +246,7 @@ private static void EntityHandler(Player player, CommandReader cmd) {
246246
break;
247247
}
248248
player.StopSpectating();
249-
player.JoinWorld(targetWorld, WorldChangeReason.Tp, Entity.getPos(entity));
249+
player.JoinWorld(targetWorld, WorldChangeReason.Tp, entity.GetPos());
250250
break;
251251
}
252252
player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
@@ -265,7 +265,7 @@ private static void EntityHandler(Player player, CommandReader cmd) {
265265
skinString3 = ParseSkin(skinString3);
266266
}
267267
player.Message("Changed entity skin to {0}.", skinString3 ?? entity.Name);
268-
Entity.ChangeEntitySkin(entity, skinString3);
268+
entity.ChangeSkin(skinString3);
269269
break;
270270
default:
271271
CdEntity.PrintUsage(player);
@@ -276,7 +276,7 @@ private static void EntityHandler(Player player, CommandReader cmd) {
276276
public static sbyte getNewID(World world) {
277277
sbyte i = 1;
278278
go:
279-
foreach (Entity entity in Entity.EntityList.Where(e => Entity.getWorld(e) == world)) {
279+
foreach (Entity entity in Entity.AllIn(world)) {
280280
if (entity.ID == i) {
281281
i++;
282282
goto go;

fCraft/Commands/WorldCommands.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ private static void GenHandler(Player player, CommandReader cmd) {
807807
Logger.Log(LogType.UserActivity,
808808
"Gen: Asked {0} to confirm replacing the map of world {1} (\"this map\").",
809809
player.Name, playerWorld.Name);
810-
if (!Entity.existsAny(player.World)) {
810+
if (!Entity.AnyIn(player.World)) {
811811
player.Confirm(cmd, "Replace THIS MAP with a generated one ({0})?", templateFullName);
812812
} else {
813813
player.Confirm(cmd, "Replace THIS MAP with a generated one ({0})?&NThis will also remove all the Entities/Bots on the world.", templateFullName);
@@ -949,7 +949,7 @@ private static void GenHMHandler(Player player, CommandReader cmd) {
949949
Logger.Log(LogType.UserActivity,
950950
"GenHM: Asked {0} to confirm replacing the map of world {1} (\"this map\").",
951951
player.Name, playerWorld.Name);
952-
if (!Entity.existsAny(player.World)) {
952+
if (!Entity.AnyIn(player.World)) {
953953
player.Confirm(cmd, "Replace THIS MAP with a generated one (HeightMap: &9{0}&S)?", url);
954954
} else {
955955
player.Confirm(cmd, "Replace THIS MAP with a generated one (HeightMap: &9{0}&S)?&NThis will also remove all the Entities/Bots on the world.", url);
@@ -2694,8 +2694,9 @@ private static void WorldRenameHandler(Player player, CommandReader cmd) {
26942694
player.LastUsedWorldName = newName;
26952695
Logger.Log(LogType.UserActivity, "{0} renamed the world \"{1}\" to \"{2}\".", player.Name, oldName, newName);
26962696
Server.Message("{0}&S renamed the world \"{1}\" to \"{2}\"", player.ClassyName, oldName, newName);
2697-
foreach(Entity bot in Entity.EntityList.Where(e => oldName.CaselessEquals(e.World))) {
2698-
Entity.UpdateEntityWorld(bot, newName);
2697+
2698+
foreach (Entity e in Entity.AllIn(oldName)) {
2699+
e.ChangeWorld(newName);
26992700
}
27002701
}
27012702

@@ -3433,7 +3434,7 @@ static void MWReset(Player player, CommandReader cmd) {
34333434
player.Message("You have no personal worlds by that number: {0}", num); return;
34343435
}
34353436
if (!cmd.IsConfirmed) {
3436-
if (!Entity.existsAny(player.World)) {
3437+
if (!Entity.AnyIn(player.World)) {
34373438
player.Confirm(cmd, "This will reset your personal world: " + mapName +
34383439
"&N&cThis cannot be undone!");
34393440
} else {

fCraft/Network/Player.Networking.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,13 +1211,14 @@ void SendJoinCpeExtensions() {
12111211

12121212
internal void RemoveOldEntities(World world) {
12131213
if (world == null) return;
1214-
foreach (Entity entity in Entity.EntityList.Where(e => Entity.getWorld(e) == world)) {
1214+
1215+
foreach (Entity entity in Entity.AllIn(world)) {
12151216
SendNow(Packet.MakeRemoveEntity(entity.ID));
12161217
}
12171218
}
12181219

12191220
internal void SendNewEntities(World world) {
1220-
foreach (Entity entity in Entity.EntityList.Where(e => Entity.getWorld(e) == world)) {
1221+
foreach (Entity entity in Entity.AllIn(world)) {
12211222
Entities.Spawn(this, true, entity);
12221223
}
12231224
}

fCraft/World/Entities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static void Spawn(Player dst, bool sendNow, Player entity, sbyte id) {
2525

2626
public static void Spawn(Player dst, bool sendNow, Entity entity) {
2727
Spawn(dst, sendNow, entity.ID, entity.Name, entity.Skin,
28-
entity.Model, Entity.getPos(entity), 0, 0);
28+
entity.Model, entity.GetPos(), 0, 0);
2929
}
3030

3131
public static void Spawn(Player dst, bool sendNow, sbyte id, string name,

0 commit comments

Comments
 (0)