Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Fix INSTANCE being null
Browse files Browse the repository at this point in the history
  • Loading branch information
Ale32bit committed Aug 6, 2024
1 parent c16722f commit 17e839c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn_mappings=1.21+build.9
loader_version=0.15.11

# Mod Properties
mod_version=1.4.1
mod_version=1.4.2
maven_group=ct
archives_base_name=ct-server

Expand Down
20 changes: 8 additions & 12 deletions src/main/java/ct/server/CtServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
import ct.server.events.PlayerWelcome;
import ct.server.http.ServiceServer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerEntityEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;

import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.text.TextColor;
import net.minecraft.text.Texts;
import net.minecraft.util.Formatting;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -34,39 +31,38 @@ public class CtServer implements ModInitializer {
private static float currentMspt = 0;
private static int currentPlayerCount = 0;

private static CtServer INSTANCE;
public static CtServer getInstance() {
return INSTANCE;
}

private static CtServer INSTANCE;

private ServiceServer serviceServer;

public ServiceServer serviceServer() {
return serviceServer;
}

private DatabaseClient database;

private final DatabaseClient database = new DatabaseClient();
public DatabaseClient database() {
return database;
}

private final PlayerTable playerTable = new PlayerTable();

public PlayerTable playerTable() {
return playerTable;
}

public CtServer() {
INSTANCE = this;
}

@Override
public void onInitialize() {
INSTANCE = this;

LOGGER.info("Starting ct-server");

try {
database = new DatabaseClient();

// Jumpstart connection
database.connection();
playerTable.ensureDatabaseCreated();
} catch (SQLException e) {
LOGGER.error("Database error", e);
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/ct/server/database/DatabaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,4 @@ public Connection connection() throws SQLException {
}
return connection;
}

// Prepare a connection to the DB ready for use
// TODO: Consider creating a pool
public DatabaseClient() throws SQLException {
connection();
}
}

0 comments on commit 17e839c

Please sign in to comment.