Backport to 1.20.1 + rename

This commit is contained in:
Alessandro Proto 2024-08-31 10:29:34 +02:00
parent 98b0ca449a
commit fdcd730819
18 changed files with 64 additions and 136 deletions

View file

@ -24,12 +24,11 @@ loom {
splitEnvironmentSourceSets() splitEnvironmentSourceSets()
mods { mods {
"ct-server" { "rcc-server" {
sourceSet sourceSets.main sourceSet sourceSets.main
sourceSet sourceSets.client sourceSet sourceSets.client
} }
} }
} }
dependencies { dependencies {
@ -57,7 +56,7 @@ processResources {
} }
tasks.withType(JavaCompile).configureEach { tasks.withType(JavaCompile).configureEach {
it.options.release = 21 it.options.release = 17
} }
java { java {
@ -66,8 +65,8 @@ java {
// If you remove this line, sources will not be generated. // If you remove this line, sources will not be generated.
withSourcesJar() withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_21 sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_21 targetCompatibility = JavaVersion.VERSION_17
} }
jar { jar {

View file

@ -4,18 +4,18 @@ org.gradle.parallel=true
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/develop # check these on https://fabricmc.net/develop
minecraft_version=1.21 minecraft_version=1.20.1
yarn_mappings=1.21+build.9 yarn_mappings=1.20.1+build.10
loader_version=0.15.11 loader_version=0.16.3
# Mod Properties # Mod Properties
mod_version=1.5.0 mod_version=1.6.0
maven_group=ct maven_group=cc.reconnected
archives_base_name=ct-server archives_base_name=rcc-server
# Dependencies # Dependencies
fabric_version=0.101.2+1.21 fabric_version=0.92.2+1.20.1
owo_version=0.12.11+1.21 owo_version=0.11.2+1.20
postgresql_version=42.7.3 postgresql_version=42.7.3

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View file

@ -1,10 +0,0 @@
package ct.server;
import net.fabricmc.api.ClientModInitializer;
public class CtserverClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
// This entrypoint is suitable for setting up client-specific logic, such as rendering.
}
}

View file

@ -1,15 +0,0 @@
package ct.server.mixin.client;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MinecraftClient.class)
public class ExampleClientMixin {
@Inject(at = @At("HEAD"), method = "run")
private void init(CallbackInfo info) {
// This code is injected into the start of MinecraftClient.run()V
}
}

View file

@ -1,11 +0,0 @@
{
"required": true,
"package": "ct.server.mixin.client",
"compatibilityLevel": "JAVA_21",
"client": [
"ExampleClientMixin"
],
"injectors": {
"defaultRequire": 1
}
}

View file

@ -1,14 +1,13 @@
package ct.server; package cc.reconnected.server;
import ct.server.database.DatabaseClient; import cc.reconnected.server.database.DatabaseClient;
import ct.server.database.PlayerData; import cc.reconnected.server.database.PlayerData;
import ct.server.database.PlayerTable; import cc.reconnected.server.database.PlayerTable;
import ct.server.events.PlayerWelcome; import cc.reconnected.server.events.PlayerWelcome;
import ct.server.http.ServiceServer; import cc.reconnected.server.http.ServiceServer;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.message.v1.ServerMessageDecoratorEvent;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
@ -22,18 +21,18 @@ import java.sql.SQLException;
import java.util.Date; import java.util.Date;
public class CtServer implements ModInitializer { public class RccServer implements ModInitializer {
public static final String MOD_ID = "ct-server"; public static final String MOD_ID = "rcc-server";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static final ct.server.CtServerConfig CONFIG = ct.server.CtServerConfig.createAndLoad(); public static final cc.reconnected.server.RccServerConfig CONFIG = cc.reconnected.server.RccServerConfig.createAndLoad();
private static float currentTps = 0; private static float currentTps = 0;
private static float currentMspt = 0; private static float currentMspt = 0;
private static int currentPlayerCount = 0; private static int currentPlayerCount = 0;
private static CtServer INSTANCE; private static RccServer INSTANCE;
public static CtServer getInstance() { public static RccServer getInstance() {
return INSTANCE; return INSTANCE;
} }
@ -64,14 +63,14 @@ public class CtServer implements ModInitializer {
return currentPlayerCount; return currentPlayerCount;
} }
public CtServer() { public RccServer() {
INSTANCE = this; INSTANCE = this;
} }
@Override @Override
public void onInitialize() { public void onInitialize() {
LOGGER.info("Starting ct-server"); LOGGER.info("Starting rcc-server");
try { try {
// Jumpstart connection // Jumpstart connection
@ -88,7 +87,7 @@ public class CtServer implements ModInitializer {
} }
ServerTickEvents.END_SERVER_TICK.register(server -> { ServerTickEvents.END_SERVER_TICK.register(server -> {
currentMspt = server.getAverageTickTime(); currentMspt = server.getTickTime();
if (currentMspt != 0) { if (currentMspt != 0) {
currentTps = Math.min(20, 1000 / currentMspt); currentTps = Math.min(20, 1000 / currentMspt);
} }

View file

@ -0,0 +1,9 @@
package cc.reconnected.server;
import io.wispforest.owo.config.annotation.Config;
@Config(name = "rcc-server-config", wrapperName = "RccServerConfig")
public class RccServerConfigModel {
public short httpPort = 25581;
public String databaseUrl = "jdbc:postgresql://127.0.0.1:5432/rcc?user=myuser&password=mypassword";
}

View file

@ -1,6 +1,6 @@
package ct.server.database; package cc.reconnected.server.database;
import ct.server.CtServer; import cc.reconnected.server.RccServer;
import java.sql.*; import java.sql.*;
@ -8,7 +8,7 @@ public class DatabaseClient {
private Connection connection; private Connection connection;
public Connection connection() throws SQLException { public Connection connection() throws SQLException {
if (connection == null || connection.isClosed()) { if (connection == null || connection.isClosed()) {
connection = DriverManager.getConnection(CtServer.CONFIG.databaseUrl()); connection = DriverManager.getConnection(RccServer.CONFIG.databaseUrl());
} }
return connection; return connection;
} }

View file

@ -1,4 +1,4 @@
package ct.server.database; package cc.reconnected.server.database;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;

View file

@ -1,6 +1,6 @@
package ct.server.database; package cc.reconnected.server.database;
import ct.server.CtServer; import cc.reconnected.server.RccServer;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.sql.SQLException; import java.sql.SQLException;
@ -13,7 +13,7 @@ public class PlayerTable {
private final HashMap<UUID, PlayerData> cache = new HashMap<>(); private final HashMap<UUID, PlayerData> cache = new HashMap<>();
private DatabaseClient database() { private DatabaseClient database() {
return CtServer.getInstance().database(); return RccServer.getInstance().database();
} }
public void ensureDatabaseCreated() { public void ensureDatabaseCreated() {
@ -35,7 +35,7 @@ public class PlayerTable {
stmt.close(); stmt.close();
} catch (SQLException e) { } catch (SQLException e) {
CtServer.LOGGER.error("Could not create players data tables", e); RccServer.LOGGER.error("Could not create players data tables", e);
} }
} }
@ -73,7 +73,7 @@ public class PlayerTable {
cache.put(uuid, playerData); cache.put(uuid, playerData);
return playerData; return playerData;
} catch (SQLException e) { } catch (SQLException e) {
CtServer.LOGGER.error("Could not get player data from database", e); RccServer.LOGGER.error("Could not get player data from database", e);
return null; return null;
} }
} }
@ -90,7 +90,7 @@ public class PlayerTable {
cache.remove(uuid); cache.remove(uuid);
return true; return true;
} catch(SQLException e) { } catch(SQLException e) {
CtServer.LOGGER.error("Could not delete player data from database", e); RccServer.LOGGER.error("Could not delete player data from database", e);
return false; return false;
} }
} }
@ -115,7 +115,7 @@ public class PlayerTable {
cache.put(playerData.uuid(), playerData); cache.put(playerData.uuid(), playerData);
return true; return true;
} catch (SQLException e) { } catch (SQLException e) {
CtServer.LOGGER.error("Could not get player data from database", e); RccServer.LOGGER.error("Could not get player data from database", e);
return false; return false;
} }
} }

View file

@ -1,6 +1,6 @@
package ct.server.events; package cc.reconnected.server.events;
import ct.server.database.PlayerData; import cc.reconnected.server.database.PlayerData;
import net.fabricmc.fabric.api.event.Event; import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory; import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;

View file

@ -1,9 +1,9 @@
package ct.server.http; package cc.reconnected.server.http;
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler; import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer; import com.sun.net.httpserver.HttpServer;
import ct.server.CtServer; import cc.reconnected.server.RccServer;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -15,7 +15,7 @@ public class ServiceServer {
} }
public ServiceServer() throws IOException { public ServiceServer() throws IOException {
server = HttpServer.create(new InetSocketAddress(CtServer.CONFIG.httpPort()), 0); server = HttpServer.create(new InetSocketAddress(RccServer.CONFIG.httpPort()), 0);
server.createContext("/tps", new TPSHandler()); server.createContext("/tps", new TPSHandler());
server.createContext("/mspt", new MSPTHandler()); server.createContext("/mspt", new MSPTHandler());
server.createContext("/player", new PlayerCountHandler()); server.createContext("/player", new PlayerCountHandler());
@ -28,7 +28,7 @@ public class ServiceServer {
static class TPSHandler implements HttpHandler { static class TPSHandler implements HttpHandler {
@Override @Override
public void handle(HttpExchange t) throws IOException { public void handle(HttpExchange t) throws IOException {
var tps = String.valueOf(CtServer.getTPS()); var tps = String.valueOf(RccServer.getTPS());
t.sendResponseHeaders(200, tps.length()); t.sendResponseHeaders(200, tps.length());
var body = t.getResponseBody(); var body = t.getResponseBody();
body.write(tps.getBytes()); body.write(tps.getBytes());
@ -39,7 +39,7 @@ public class ServiceServer {
static class MSPTHandler implements HttpHandler { static class MSPTHandler implements HttpHandler {
@Override @Override
public void handle(HttpExchange t) throws IOException { public void handle(HttpExchange t) throws IOException {
var tps = String.valueOf(CtServer.getMSPT()); var tps = String.valueOf(RccServer.getMSPT());
t.sendResponseHeaders(200, tps.length()); t.sendResponseHeaders(200, tps.length());
var body = t.getResponseBody(); var body = t.getResponseBody();
body.write(tps.getBytes()); body.write(tps.getBytes());
@ -50,7 +50,7 @@ public class ServiceServer {
static class PlayerCountHandler implements HttpHandler { static class PlayerCountHandler implements HttpHandler {
@Override @Override
public void handle(HttpExchange t) throws IOException { public void handle(HttpExchange t) throws IOException {
var tps = String.valueOf(CtServer.getPlayerCount()); var tps = String.valueOf(RccServer.getPlayerCount());
t.sendResponseHeaders(200, tps.length()); t.sendResponseHeaders(200, tps.length());
var body = t.getResponseBody(); var body = t.getResponseBody();
body.write(tps.getBytes()); body.write(tps.getBytes());

View file

@ -1,9 +0,0 @@
package ct.server;
import io.wispforest.owo.config.annotation.Config;
@Config(name = "ct-server-config", wrapperName = "CtServerConfig")
public class CtServerConfigModel {
public short httpPort = 25581;
public String databaseUrl = "jdbc:postgresql://127.0.0.1:5432/ct?user=myuser&password=mypassword";
}

View file

@ -1,15 +0,0 @@
package ct.server.mixin;
import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(MinecraftServer.class)
public class ExampleMixin {
@Inject(at = @At("HEAD"), method = "loadWorld")
private void init(CallbackInfo info) {
// This code is injected into the start of MinecraftServer.loadWorld()V
}
}

View file

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -1,11 +0,0 @@
{
"required": true,
"package": "ct.server.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExampleMixin"
],
"injectors": {
"defaultRequire": 1
}
}

View file

@ -1,38 +1,30 @@
{ {
"schemaVersion": 1, "schemaVersion": 1,
"id": "ct-server", "id": "rcc-server",
"version": "${version}", "version": "${version}",
"name": "ct-server", "name": "rcc-server",
"description": "Server mod for the project CT Minecraft server", "description": "Server mod for the ReconnectedCC Minecraft server",
"authors": [ "authors": [
"AlexDevs", "AlexDevs",
"EmmaKnijn" "EmmaKnijn"
], ],
"contact": { "contact": {
"sources": "https://github.com/project-connecticut/ct-server" "sources": "https://github.com/ReconnectedCC/rcc-server"
}, },
"license": "MIT License", "license": "MIT License",
"icon": "assets/ct-server/icon.png", "icon": "assets/rcc-server/icon.png",
"environment": "*", "environment": "*",
"entrypoints": { "entrypoints": {
"main": [ "main": [
"ct.server.CtServer" "cc.reconnected.server.RccServer"
],
"client": [
"ct.server.CtserverClient"
] ]
}, },
"mixins": [ "mixins": [
"ct-server.mixins.json",
{
"config": "ct-server.client.mixins.json",
"environment": "client"
}
], ],
"depends": { "depends": {
"fabricloader": ">=0.15.11", "fabricloader": ">=0.16.0",
"minecraft": "~1.21", "minecraft": "~1.20.1",
"java": ">=21", "java": ">=17",
"fabric-api": "*" "fabric-api": "*"
} }
} }