forked from BLOCKFANTASY/LOOHP-Limbo
Allow modifying of the spawn location (and thus, the spawn world) of
players joining through the PlayerJoinEvent.
This commit is contained in:
parent
0348f3c5ca
commit
06cdbff2f8
|
|
@ -1,11 +1,22 @@
|
||||||
package com.loohp.limbo.Events;
|
package com.loohp.limbo.Events;
|
||||||
|
|
||||||
|
import com.loohp.limbo.Location.Location;
|
||||||
import com.loohp.limbo.Player.Player;
|
import com.loohp.limbo.Player.Player;
|
||||||
|
|
||||||
public class PlayerJoinEvent extends PlayerEvent {
|
public class PlayerJoinEvent extends PlayerEvent {
|
||||||
|
|
||||||
public PlayerJoinEvent(Player player) {
|
private Location spawnLocation;
|
||||||
|
|
||||||
|
public PlayerJoinEvent(Player player, Location spawnLoc) {
|
||||||
super(player);
|
super(player);
|
||||||
|
spawnLocation = spawnLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getSpawnLocation() {
|
||||||
|
return spawnLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpawnLocation(Location spawnLocation) {
|
||||||
|
this.spawnLocation = spawnLocation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -294,12 +294,16 @@ public class ClientConnection extends Thread {
|
||||||
TimeUnit.MILLISECONDS.sleep(500);
|
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);
|
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);
|
sendPacket(join);
|
||||||
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, p.getDefaultGamemode());
|
Limbo.getInstance().getUnsafe().setPlayerGameModeSilently(player, p.getDefaultGamemode());
|
||||||
|
|
||||||
Location s = p.getWorldSpawn();
|
|
||||||
|
|
||||||
//PacketPlayOutKeepAlive alive = new PacketPlayOutKeepAlive((long) (Math.random() * Long.MAX_VALUE));
|
//PacketPlayOutKeepAlive alive = new PacketPlayOutKeepAlive((long) (Math.random() * Long.MAX_VALUE));
|
||||||
|
|
||||||
World world = s.getWorld();
|
World world = s.getWorld();
|
||||||
|
|
@ -336,8 +340,6 @@ public class ClientConnection extends Thread {
|
||||||
sendPacket(declare);
|
sendPacket(declare);
|
||||||
}
|
}
|
||||||
|
|
||||||
Limbo.getInstance().getEventsManager().callEvent(new PlayerJoinEvent(player));
|
|
||||||
|
|
||||||
PacketPlayOutSpawnPosition spawnPos = new PacketPlayOutSpawnPosition(BlockPosition.from(s));
|
PacketPlayOutSpawnPosition spawnPos = new PacketPlayOutSpawnPosition(BlockPosition.from(s));
|
||||||
sendPacket(spawnPos);
|
sendPacket(spawnPos);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue