Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GlowHumanEntity's profile field should be set before the entity is spawned in the world #890

Open
aramperes opened this issue Mar 28, 2018 · 0 comments

Comments

@aramperes
Copy link
Member

aramperes commented Mar 28, 2018

The profile field inside GlowHumanEntity is set after the super() call to Glow[Living]Entity, which in turn spawns the entity by allocating the entity ID and setting the location field. However, the PlayerSpawnLocationEvent should be fired:

  • Before the player entity is spawned in the world, and the location set
  • After the Player instance is created (because it is required in the event constructor), and the profile field set.

Right now, the event is fired before both the entity spawn and the profile being set:

public GlowHumanEntity(Location location, PlayerProfile profile) {
super(location);
this.profile = profile;

public GlowEntity(Location location) {
// this is so dirty I washed my hands after writing it.
if (this instanceof GlowPlayer) {
// spawn location event
location = EventFactory.callEvent(new PlayerSpawnLocationEvent((Player) this, location))
.getSpawnLocation();
}
this.origin = location.clone();
this.location = location.clone();
world = (GlowWorld) location.getWorld();
server = world.getServer();
server.getEntityIdManager().allocate(this);
world.getEntityManager().register(this);
previousLocation = location.clone();
}

I think the solution to this would be to fire the event inside the GlowSession.setPlayer method (which creates the GlowPlayer instance) before creating the actual entity.

However, because the event needs the entity instance to be passed, I think one solution would be to create a "mock GlowPlayer" that would have stubs for the needed GlowPlayer methods, while not actually spawning that mock player in the world. After the event is fired, an actual entity is created from the spawnLocation result.

Alternatively, the entity spawning could be externalized from the GlowEntity constructor to be called after all subconstructors are completed.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant