diff --git a/gradle.properties b/gradle.properties index 4b0bdfa..9594c12 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/ct/server/CtServer.java b/src/main/java/ct/server/CtServer.java index 67dcd87..c5b46ec 100644 --- a/src/main/java/ct/server/CtServer.java +++ b/src/main/java/ct/server/CtServer.java @@ -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; }); } diff --git a/src/main/java/ct/server/events/PlayerWelcome.java b/src/main/java/ct/server/events/PlayerWelcome.java new file mode 100644 index 0000000..573062e --- /dev/null +++ b/src/main/java/ct/server/events/PlayerWelcome.java @@ -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 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); +}