-
Notifications
You must be signed in to change notification settings - Fork 277
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
Fire PlayerInitialSpawnEvent (#922) #1051
Conversation
I think PlayerInitialSpawnEvent should be called not on first join but just before spawning player entity in world. Paper original patch here (removed) |
@SHADOWDANCH Contributions based on source code (patches or otherwise) from CraftBukkit or any of its forks are prohibited by our CLA. I've removed the link in your comment as a precaution. If the documentation is insufficient for this particular event, I suggest contacting the PaperMC team on Discord for clarification and/or suggesting they update their docs. |
@Momothereal if i myself show how this event works on paper (screenshots or something) it be correct? |
@SHADOWDANCH Yes, that is considered reverse-engineering and it is encouraged by the project :) |
So i created simple test plugin and here is source code. And here results i get
Output after second spawn:
Ss you can see event called on second spawn too. So |
@SHADOWDANCH so you're saying it should be fired every time the player joins? |
@clabe45 yes every time before player spawning in world |
@SHADOWDANCH so before |
@clabe45 yes, i think |
I would do it in |
@Momothereal what do you think? |
This is tricky because the event has a setter, Glowstone/src/main/java/net/glowstone/entity/GlowPlayer.java Lines 579 to 580 in 760bff1
This is due to our Entity implementation which requires a Location in the constructor. I think this has been a limitation in other parts of Glowstone before which should be revamped. So I looked for where Glowstone/src/main/java/net/glowstone/entity/GlowEntity.java Lines 319 to 325 in 760bff1
It seems like the @SHADOWDANCH Maybe you could test the ordering of these events in your plugin? |
@Momothereal yes.
So |
@SHADOWDANCH Cool. Could you test that setting the If it does carry over, then I think the correct implementation is to copy the firing of |
@Momothereal yes.
SpawnLocation same in this events so it passes from |
Ok, points noted. Could we move that player-specific code in |
Unfortunately, moving this code to GlowPlayer is not possible since it would be fired after the GlowEntity, GlowLivingEntity, and GlowHumanEntity constructors are done executing. The GlowEntity constructor depends on the spawnLocation to determine which world to allocate the entity to. The revamp I mentioned would move the allocation portion out of the GlowEntity constructor, but that is not in the scope of this PR. If you want to simply implement the event with our current architecture, it has to be fired in the GlowEntity constructor just like Also, looking at the GlowEntity constructor totally shows a bug with the world being chosen before the event is fired. Maybe you could fix this by declaring the Glowstone/src/main/java/net/glowstone/entity/GlowEntity.java Lines 317 to 327 in 760bff1
|
Ahh ok, so I will fire the |
Hm that's interesting. The field is set at the beginning so that calling public GlowEntity(Location location) {
// Set initial locations for event calls
this.origin = location.clone();
this.previousLocation = location.clone();
this.location = location.clone();
// this is so dirty I washed my hands after writing it.
if (this instanceof GlowPlayer) {
// TODO: Fire PlayerInitialSpawnEvent
// spawn location event
location = EventFactory.getInstance()
.callEvent(new PlayerSpawnLocationEvent((Player) this, location.clone()))
.getSpawnLocation().clone();
// Update locations again
this.origin = location.clone();
this.previousLocation = location.clone();
this.location = location.clone();
}
// ID allocation
world = (GlowWorld) location.getWorld();
world.getServer().getEntityIdManager().allocate(this);
world.getEntityManager().register(this);
} |
Ok noted. |
I tried that, but |
You can use |
It will be fired in player-specific code in GlowEntity, instead.
This way, it is ordered correctly with other event calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Awesome! This will be the first PR of many :D |
Thank you for your contribution to Glowstone! |
My pleasure |
A
PlayerInitialSpawnEvent
is now fired the first timespawnAt
is called for a player.