Merge pull request #13 from drunderscore/master

Allow modifying of the spawn location (and thus, the spawn world) of players joining through the PlayerJoinEvent
This commit is contained in:
LOOHP 2021-02-27 16:48:04 +08:00 committed by GitHub
commit 201bafcc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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

@ -294,12 +294,16 @@ public class ClientConnection extends Thread {
TimeUnit.MILLISECONDS.sleep(500);
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);