Skip to content
Permalink
Browse files

Fix /ent reload erroring when an entity exists in a now deleted world.

Also general cleanup of Entity class
  • Loading branch information...
UnknownShadow200 committed Jun 14, 2017
1 parent f7b9470 commit f20bd61484286374e2891d700cc69cf290e99621
@@ -102,15 +102,15 @@ static class CpeCommands {
World world = WorldManager.FindWorldOrPrintMatches(player, search);
if (world != null) {
player.Message("Entities on &f{0}&S: ", world.Name);
player.Message(" &F" + Entity.EntityList.Where(w => Entity.getWorld(w) == world).JoinToString("&S, &F", n => n.Name));
player.Message(" &F" + Entity.AllIn(world).JoinToString("&S, &F", n => n.Name));
}
return;
}
if (option.CaselessEquals("removeall")) {
string search = cmd.Next() ?? player.World.Name;
World world = WorldManager.FindWorldOrPrintMatches(player, search);
if (cmd.IsConfirmed) {
Entity.RemoveAll(world);
Entity.RemoveAllIn(world);
player.Message("All entities on &f{0}&S removed.", player.World.Name);
} else {
player.Confirm(cmd, "This will remove all the entites on {0}, are you sure?", player.World.Name);
@@ -151,20 +151,20 @@ static class CpeCommands {
}

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

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

entity = Entity.CreateEntity(entityName, skinString1, requestedModel, player.World, player.Position, getNewID(player.World));
entity = Entity.Create(entityName, skinString1, requestedModel, player.World, player.Position, getNewID(player.World));
player.Message("Successfully created entity {0}&S with id:{1} and skin {2}.", entity.Name, entity.ID, entity.Skin, entity.Name);
break;
case "remove":
player.Message("{0} was removed from {1}", entity.Name, player.World.Name);
Entity.RemoveEntity(entity);
Entity.Remove(entity);
break;
case "model":
if (cmd.HasNext) {
@@ -181,24 +181,24 @@ static class CpeCommands {
break;
}
player.Message("Changed entity model to {0}.", model);
Entity.ChangeEntityModel(entity, model);
entity.ChangeModel(model);
} else {
player.Message(
"Usage is /Ent model <bot> <model>. Valid models are chibi, chicken, creeper, giant, human, pig, sheep, skeleton, spider, zombie, or any block ID/Name.");
}
break;
case "bring":
Entity.TeleportEntity(entity, player.Position);
entity.TeleportTo(player.Position);
break;
case "tp":
case "teleport":
World targetWorld = Entity.getWorld(entity);
World targetWorld = entity.WorldIn();
if (targetWorld == player.World) {
if (player.World != null) {
player.LastWorld = player.World;
player.LastPosition = player.Position;
}
player.TeleportTo(Entity.getPos(entity));
player.TeleportTo(entity.GetPos());
} else {
if (targetWorld.Name.StartsWith("PW_") &&
!targetWorld.AccessSecurity.ExceptionList.Included.Contains(player.Info)) {
@@ -223,7 +223,7 @@ static class CpeCommands {
break;
}
player.StopSpectating();
player.JoinWorld(targetWorld, WorldChangeReason.Tp, Entity.getPos(entity));
player.JoinWorld(targetWorld, WorldChangeReason.Tp, entity.GetPos());
break;
case SecurityCheckResult.BlackListed:
player.Message("Cannot teleport to {0}&S because you are blacklisted on world {1}",
@@ -246,7 +246,7 @@ static class CpeCommands {
break;
}
player.StopSpectating();
player.JoinWorld(targetWorld, WorldChangeReason.Tp, Entity.getPos(entity));
player.JoinWorld(targetWorld, WorldChangeReason.Tp, entity.GetPos());
break;
}
player.Message("Cannot teleport to {0}&S because world {1}&S requires {2}+&S to join.",
@@ -265,7 +265,7 @@ static class CpeCommands {
skinString3 = ParseSkin(skinString3);
}
player.Message("Changed entity skin to {0}.", skinString3 ?? entity.Name);
Entity.ChangeEntitySkin(entity, skinString3);
entity.ChangeSkin(skinString3);
break;
default:
CdEntity.PrintUsage(player);
@@ -276,7 +276,7 @@ static class CpeCommands {
public static sbyte getNewID(World world) {
sbyte i = 1;
go:
foreach (Entity entity in Entity.EntityList.Where(e => Entity.getWorld(e) == world)) {
foreach (Entity entity in Entity.AllIn(world)) {
if (entity.ID == i) {
i++;
goto go;
@@ -807,7 +807,7 @@ class BlockDBCounterProcessor : IBlockDBQueryProcessor {
Logger.Log(LogType.UserActivity,
"Gen: Asked {0} to confirm replacing the map of world {1} (\"this map\").",
player.Name, playerWorld.Name);
if (!Entity.existsAny(player.World)) {
if (!Entity.AnyIn(player.World)) {
player.Confirm(cmd, "Replace THIS MAP with a generated one ({0})?", templateFullName);
} else {
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 @@ class BlockDBCounterProcessor : IBlockDBQueryProcessor {
Logger.Log(LogType.UserActivity,
"GenHM: Asked {0} to confirm replacing the map of world {1} (\"this map\").",
player.Name, playerWorld.Name);
if (!Entity.existsAny(player.World)) {
if (!Entity.AnyIn(player.World)) {
player.Confirm(cmd, "Replace THIS MAP with a generated one (HeightMap: &9{0}&S)?", url);
} else {
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 @@ static void WorldClearHandler(Player player, CommandReader cmd)
player.LastUsedWorldName = newName;
Logger.Log(LogType.UserActivity, "{0} renamed the world \"{1}\" to \"{2}\".", player.Name, oldName, newName);
Server.Message("{0}&S renamed the world \"{1}\" to \"{2}\"", player.ClassyName, oldName, newName);
foreach(Entity bot in Entity.EntityList.Where(e => oldName.CaselessEquals(e.World))) {
Entity.UpdateEntityWorld(bot, newName);

foreach (Entity e in Entity.AllIn(oldName)) {
e.ChangeWorld(newName);
}
}

@@ -3433,7 +3434,7 @@ static void WorldClearHandler(Player player, CommandReader cmd)
player.Message("You have no personal worlds by that number: {0}", num); return;
}
if (!cmd.IsConfirmed) {
if (!Entity.existsAny(player.World)) {
if (!Entity.AnyIn(player.World)) {
player.Confirm(cmd, "This will reset your personal world: " + mapName +
"&N&cThis cannot be undone!");
} else {
@@ -1211,13 +1211,14 @@ bool LoginSequence()

internal void RemoveOldEntities(World world) {
if (world == null) return;
foreach (Entity entity in Entity.EntityList.Where(e => Entity.getWorld(e) == world)) {

foreach (Entity entity in Entity.AllIn(world)) {
SendNow(Packet.MakeRemoveEntity(entity.ID));
}
}

internal void SendNewEntities(World world) {
foreach (Entity entity in Entity.EntityList.Where(e => Entity.getWorld(e) == world)) {
foreach (Entity entity in Entity.AllIn(world)) {
Entities.Spawn(this, true, entity);
}
}
@@ -25,7 +25,7 @@ public static class Entities {

public static void Spawn(Player dst, bool sendNow, Entity entity) {
Spawn(dst, sendNow, entity.ID, entity.Name, entity.Skin,
entity.Model, Entity.getPos(entity), 0, 0);
entity.Model, entity.GetPos(), 0, 0);
}

public static void Spawn(Player dst, bool sendNow, sbyte id, string name,
Oops, something went wrong.

0 comments on commit f20bd61

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