2024-07-04 18:04:46 +02:00
|
|
|
package net.pivipi;
|
|
|
|
|
|
|
|
import net.minestom.server.coordinate.Pos;
|
|
|
|
import net.minestom.server.entity.GameMode;
|
|
|
|
import net.minestom.server.entity.Player;
|
2024-07-06 16:15:39 +02:00
|
|
|
import net.minestom.server.entity.attribute.Attribute;
|
2024-07-04 18:04:46 +02:00
|
|
|
import net.minestom.server.event.GlobalEventHandler;
|
|
|
|
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
|
2024-07-05 15:13:16 +02:00
|
|
|
import net.minestom.server.event.player.PlayerDisconnectEvent;
|
2024-07-04 18:04:46 +02:00
|
|
|
import net.minestom.server.event.player.PlayerSpawnEvent;
|
|
|
|
import net.minestom.server.instance.Instance;
|
|
|
|
import net.pivipi.ball.Ball;
|
2024-07-05 15:13:16 +02:00
|
|
|
import net.pivipi.ball.BallKicker;
|
|
|
|
import net.pivipi.world.Stadium;
|
2024-07-04 18:04:46 +02:00
|
|
|
|
|
|
|
public class LoginHandler {
|
|
|
|
private final Instance spawningInstance;
|
2024-07-05 15:13:16 +02:00
|
|
|
private final Stadium stadium = new Stadium();
|
2024-07-04 18:04:46 +02:00
|
|
|
|
|
|
|
public LoginHandler(Instance spawningInstance) {
|
|
|
|
this.spawningInstance = spawningInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setup(GlobalEventHandler globalEventHandler) {
|
2024-07-05 15:13:16 +02:00
|
|
|
globalEventHandler.addListener(AsyncPlayerConfigurationEvent.class, event -> onLogin(event));
|
|
|
|
globalEventHandler.addListener(PlayerDisconnectEvent.class, event -> onQuit(event));
|
|
|
|
globalEventHandler.addListener(PlayerSpawnEvent.class, event -> onSpawn(event));
|
|
|
|
new BallKicker(stadium).setup(globalEventHandler);
|
2024-07-04 18:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onLogin(AsyncPlayerConfigurationEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
event.setSpawningInstance(spawningInstance);
|
|
|
|
event.setHardcore(true);
|
|
|
|
|
2024-07-06 16:15:39 +02:00
|
|
|
player.setRespawnPoint(new Pos(5, 5, 0));
|
2024-07-05 15:13:16 +02:00
|
|
|
stadium.players.add(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onQuit(PlayerDisconnectEvent event) {
|
|
|
|
stadium.players.remove(event.getPlayer());
|
2024-07-04 18:04:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void onSpawn(PlayerSpawnEvent event) {
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
|
|
|
player.setGameMode(GameMode.CREATIVE);
|
2024-07-06 16:15:39 +02:00
|
|
|
player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(0.2);
|
|
|
|
player.getAttribute(Attribute.GENERIC_JUMP_STRENGTH).setBaseValue(0.36813); // just enough to jump a block
|
2024-07-05 15:13:16 +02:00
|
|
|
|
|
|
|
if (stadium.ball == null) {
|
|
|
|
Ball ball = new Ball(stadium);
|
|
|
|
ball.setInstance(event.getInstance());
|
2024-07-06 16:15:39 +02:00
|
|
|
ball.teleport(new Pos(0, 15, 0));
|
2024-07-05 15:13:16 +02:00
|
|
|
stadium.ball = ball;
|
|
|
|
}
|
2024-07-04 18:04:46 +02:00
|
|
|
}
|
|
|
|
}
|