Add pronouns in PlayerData

This commit is contained in:
Alessandro Proto 2024-08-07 12:12:25 +02:00
parent 417bdad061
commit 98b0ca449a
4 changed files with 30 additions and 18 deletions

View file

@ -9,12 +9,12 @@ yarn_mappings=1.21+build.9
loader_version=0.15.11 loader_version=0.15.11
# Mod Properties # Mod Properties
mod_version=1.4.3 mod_version=1.5.0
maven_group=ct maven_group=ct
archives_base_name=ct-server archives_base_name=ct-server
# Dependencies # Dependencies
fabric_version=0.100.8+1.21 fabric_version=0.101.2+1.21
owo_version=0.12.11+1.21 owo_version=0.12.11+1.21

View file

@ -52,6 +52,18 @@ public class CtServer implements ModInitializer {
return playerTable; return playerTable;
} }
public static float getTPS() {
return currentTps;
}
public static float getMSPT() {
return currentMspt;
}
public static int getPlayerCount() {
return currentPlayerCount;
}
public CtServer() { public CtServer() {
INSTANCE = this; INSTANCE = this;
} }
@ -96,7 +108,7 @@ public class CtServer implements ModInitializer {
PlayerWelcome.PLAYER_WELCOME.invoker().playerWelcome(player, playerData, server); PlayerWelcome.PLAYER_WELCOME.invoker().playerWelcome(player, playerData, server);
// TODO: make it customizable via config // TODO: make it customizable via config
broadcastMessage(server, Text.literal("Welcome " + player.getName().getString() + " to the server!").formatted(Formatting.GREEN)); broadcastMessage(server, Text.literal("Welcome " + player.getName().getString() + " to the server!").formatted(Formatting.LIGHT_PURPLE));
} else { } else {
if (!playerData.name().equals(player.getName().getString())) { if (!playerData.name().equals(player.getName().getString())) {
playerData.name(player.getName().getString()); playerData.name(player.getName().getString());
@ -115,16 +127,4 @@ public class CtServer implements ModInitializer {
player.sendMessage(message, false); player.sendMessage(message, false);
} }
} }
public static float getTPS() {
return currentTps;
}
public static float getMSPT() {
return currentMspt;
}
public static int getPlayerCount() {
return currentPlayerCount;
}
} }

View file

@ -16,6 +16,9 @@ public class PlayerData {
private boolean isBot = false; private boolean isBot = false;
private boolean isAlt = false; private boolean isAlt = false;
@Nullable
private String pronouns = null;
public PlayerData(UUID uuid) { public PlayerData(UUID uuid) {
this.uuid = uuid; this.uuid = uuid;
} }
@ -24,7 +27,6 @@ public class PlayerData {
return uuid; return uuid;
} }
public String name() { public String name() {
if (name == null) { if (name == null) {
return uuid.toString(); return uuid.toString();
@ -62,4 +64,11 @@ public class PlayerData {
public void isAlt(boolean isAlt) { public void isAlt(boolean isAlt) {
this.isAlt = isAlt; this.isAlt = isAlt;
} }
public String pronouns() {
return pronouns;
}
public void pronouns(@Nullable String pronouns) {
this.pronouns = pronouns;
}
} }

View file

@ -27,7 +27,8 @@ public class PlayerTable {
"lastKnownName VARCHAR(16)," + "lastKnownName VARCHAR(16)," +
"discordId VARCHAR," + "discordId VARCHAR," +
"isBot BOOL DEFAULT FALSE," + "isBot BOOL DEFAULT FALSE," +
"isAlt BOOL DEFAULT FALSE" + "isAlt BOOL DEFAULT FALSE," +
"pronouns VARCHAR DEFAULT NULL" +
");"); ");");
stmt.executeUpdate(); stmt.executeUpdate();
@ -65,6 +66,7 @@ public class PlayerTable {
playerData.discordId(set.getString("discordId")); playerData.discordId(set.getString("discordId"));
playerData.isBot(set.getBoolean("isBot")); playerData.isBot(set.getBoolean("isBot"));
playerData.isAlt(set.getBoolean("isAlt")); playerData.isAlt(set.getBoolean("isAlt"));
playerData.pronouns(set.getString("pronouns"));
stmt.close(); stmt.close();
@ -98,7 +100,7 @@ public class PlayerTable {
try { try {
var conn = database().connection(); var conn = database().connection();
var stmt = conn.prepareStatement("INSERT INTO players(uuid, firstJoined, lastKnownName, discordId, isBot, isAlt) VALUES (?,?,?,?,?,?);"); var stmt = conn.prepareStatement("INSERT INTO players(uuid, firstJoined, lastKnownName, discordId, isBot, isAlt, pronouns) VALUES (?,?,?,?,?,?,?);");
stmt.setObject(1, playerData.uuid()); stmt.setObject(1, playerData.uuid());
var timestamp = new Timestamp(playerData.firstJoinedDate().getTime()); var timestamp = new Timestamp(playerData.firstJoinedDate().getTime());
stmt.setTimestamp(2, timestamp); stmt.setTimestamp(2, timestamp);
@ -106,6 +108,7 @@ public class PlayerTable {
stmt.setString(4, playerData.discordId()); stmt.setString(4, playerData.discordId());
stmt.setBoolean(5, playerData.isBot()); stmt.setBoolean(5, playerData.isBot());
stmt.setBoolean(6, playerData.isAlt()); stmt.setBoolean(6, playerData.isAlt());
stmt.setString(7, playerData.pronouns());
stmt.execute(); stmt.execute();
stmt.close(); stmt.close();