Skip to content

Commit

Permalink
Fire PlayerInitialSpawnEvent (#922) (#1051)
Browse files Browse the repository at this point in the history

* No longer fire PlayerInitialSpawnEvent in GlowPlayer

It will be fired in player-specific code in GlowEntity, instead.

* Fire PlayerInitialSpawnEvent in GlowEntity

This way, it is ordered correctly with other event calls.

* Fix setting events' world not affecting player
  • Loading branch information
clabe45 authored and mastercoms committed Aug 5, 2019
1 parent 760bff1 commit cdf3bb8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/net/glowstone/entity/GlowEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.destroystokyo.paper.event.player.PlayerInitialSpawnEvent;
import com.flowpowered.network.Message;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -310,19 +311,31 @@ public boolean isInvulnerable() {
* @param location The location of the entity.
*/
public GlowEntity(Location location) {
// Set initial locations for events.
this.origin = location.clone();
this.previousLocation = location.clone();
this.location = location.clone();

world = (GlowWorld) location.getWorld();
server = world.getServer();
// this is so dirty I washed my hands after writing it.
if (this instanceof GlowPlayer) {
// spawn location event
// initial spawn event, first
location = EventFactory.getInstance()
.callEvent(new PlayerInitialSpawnEvent((Player) this, location))
.getSpawnLocation();

// then, spawn location event (with location updated from initial spawn event)
location = EventFactory.getInstance()
.callEvent(new PlayerSpawnLocationEvent((Player) this, location))
.getSpawnLocation();

// Update from modifications done on events.
Position.copyLocation(location, this.origin);
Position.copyLocation(location, this.previousLocation);
Position.copyLocation(location, this.location);
}
world = (GlowWorld) location.getWorld();
server = world.getServer();

server.getEntityIdManager().allocate(this);
world.getEntityManager().register(this);
}
Expand Down

0 comments on commit cdf3bb8

Please sign in to comment.