Allow modifying of the spawn location (and thus, the spawn world) of

players joining through the PlayerJoinEvent.
This commit is contained in:
James Puleo 2021-02-27 01:43:24 -05:00
parent 0348f3c5ca
commit 06cdbff2f8
No known key found for this signature in database
GPG Key ID: 3E16C7EFA34FB15D
2 changed files with 22 additions and 9 deletions

View File

@ -1,11 +1,22 @@
package com.loohp.limbo.Events;
import com.loohp.limbo.Location.Location;
import com.loohp.limbo.Player.Player;
public class PlayerJoinEvent extends PlayerEvent {
public PlayerJoinEvent(Player player) {
private Location spawnLocation;
public PlayerJoinEvent(Player player, Location spawnLoc) {
super(player);
spawnLocation = spawnLoc;
}
public Location getSpawnLocation() {
return spawnLocation;
}
public void setSpawnLocation(Location spawnLocation) {
this.spawnLocation = spawnLocation;
}
}

View File

@ -292,14 +292,18 @@ public class ClientConnection extends Thread {
if (state == ClientState.PLAY) {
TimeUnit.MILLISECONDS.sleep(500);
ServerProperties p = Limbo.getInstance().getServerProperties();
ServerProperties p = Limbo.getInstance().getServerProperties();
Location s = p.getWorldSpawn();
PlayerJoinEvent evt = new PlayerJoinEvent(player, s);
Limbo.getInstance().getEventsManager().callEvent(evt);
s = evt.getSpawnLocation();
PacketPlayOutLogin join = new PacketPlayOutLogin(player.getEntityId(), false, p.getDefaultGamemode(), Limbo.getInstance().getWorlds().stream().map(each -> new NamespacedKey(each.getName()).toString()).collect(Collectors.toList()).toArray(new String[Limbo.getInstance().getWorlds().size()]), Limbo.getInstance().getDimensionRegistry().getCodec(), p.getWorldSpawn().getWorld(), 0, (byte) p.getMaxPlayers(), 8, p.isReducedDebugInfo(), true, false, true);
sendPacket(join);
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, p.getDefaultGamemode());
Location s = p.getWorldSpawn();
//PacketPlayOutKeepAlive alive = new PacketPlayOutKeepAlive((long) (Math.random() * Long.MAX_VALUE));
World world = s.getWorld();
@ -336,8 +340,6 @@ public class ClientConnection extends Thread {
sendPacket(declare);
}
Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player));
PacketPlayOutSpawnPosition spawnPos = new PacketPlayOutSpawnPosition(BlockPosition.from(s));
sendPacket(spawnPos);