Add PlayerWelcome event
This commit is contained in:
parent
d40b2d1b3b
commit
c16722fc8e
3 changed files with 24 additions and 4 deletions
|
@ -9,7 +9,7 @@ yarn_mappings=1.21+build.9
|
|||
loader_version=0.15.11
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.4.0
|
||||
mod_version=1.4.1
|
||||
maven_group=ct
|
||||
archives_base_name=ct-server
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package ct.server;
|
|||
import ct.server.database.DatabaseClient;
|
||||
import ct.server.database.PlayerData;
|
||||
import ct.server.database.PlayerTable;
|
||||
import ct.server.events.PlayerWelcome;
|
||||
import ct.server.http.ServiceServer;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
|
||||
|
@ -51,7 +52,7 @@ public class CtServer implements ModInitializer {
|
|||
return database;
|
||||
}
|
||||
|
||||
private PlayerTable playerTable;
|
||||
private final PlayerTable playerTable = new PlayerTable();
|
||||
|
||||
public PlayerTable playerTable() {
|
||||
return playerTable;
|
||||
|
@ -65,7 +66,6 @@ public class CtServer implements ModInitializer {
|
|||
|
||||
try {
|
||||
database = new DatabaseClient();
|
||||
playerTable = new PlayerTable();
|
||||
|
||||
playerTable.ensureDatabaseCreated();
|
||||
} catch (SQLException e) {
|
||||
|
@ -95,6 +95,9 @@ public class CtServer implements ModInitializer {
|
|||
playerData.firstJoinedDate(new Date());
|
||||
playerData.name(player.getName().getString());
|
||||
playerTable.updatePlayerData(playerData);
|
||||
|
||||
PlayerWelcome.PLAYER_WELCOME.invoker().playerWelcome(player, playerData, server);
|
||||
|
||||
broadcastMessage(server, Text.literal("Welcome " + player.getName().getString() + " to the server!").formatted(Formatting.GREEN));
|
||||
} else {
|
||||
if (!playerData.name().equals(player.getName().getString())) {
|
||||
|
@ -105,7 +108,6 @@ public class CtServer implements ModInitializer {
|
|||
});
|
||||
|
||||
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
|
||||
|
||||
currentPlayerCount = server.getCurrentPlayerCount() - 1;
|
||||
});
|
||||
}
|
||||
|
|
18
src/main/java/ct/server/events/PlayerWelcome.java
Normal file
18
src/main/java/ct/server/events/PlayerWelcome.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package ct.server.events;
|
||||
|
||||
import ct.server.database.PlayerData;
|
||||
import net.fabricmc.fabric.api.event.Event;
|
||||
import net.fabricmc.fabric.api.event.EventFactory;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
|
||||
public interface PlayerWelcome {
|
||||
Event<PlayerWelcome> PLAYER_WELCOME = EventFactory.createArrayBacked(PlayerWelcome.class,
|
||||
(listeners) -> (player, playerData, server) -> {
|
||||
for (PlayerWelcome listener : listeners) {
|
||||
listener.playerWelcome(player, playerData, server);
|
||||
}
|
||||
});
|
||||
|
||||
void playerWelcome(ServerPlayerEntity player, PlayerData playerData, MinecraftServer server);
|
||||
}
|
Loading…
Reference in a new issue