From 7845b9064d8327f2753547ffcc712b127bbbe286 Mon Sep 17 00:00:00 2001 From: Noelle-Ai Date: Fri, 3 May 2024 00:54:09 +0200 Subject: [PATCH] V1.0.17 Adding entities in lib --- build.gradle.kts | 10 +++- .../stmarygate/coral/entities/Account.java | 32 +++++++++++++ .../com/stmarygate/coral/entities/Player.java | 20 ++++++++ .../client/PacketGetPlayerInformations.java | 48 +++++++++++++++++++ .../PacketGetPlayerInformationsResult.java | 7 +++ 5 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/stmarygate/coral/entities/Account.java create mode 100644 src/main/java/com/stmarygate/coral/entities/Player.java create mode 100644 src/main/java/com/stmarygate/coral/network/packets/client/PacketGetPlayerInformations.java create mode 100644 src/main/java/com/stmarygate/coral/network/packets/server/PacketGetPlayerInformationsResult.java diff --git a/build.gradle.kts b/build.gradle.kts index 0e9748d..8176e98 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.stmarygate" -version = "1.0.16" +version = "1.0.17" repositories { mavenCentral() @@ -46,6 +46,14 @@ dependencies { implementation("org.jetbrains:annotations:24.1.0") + // Database + implementation("org.postgresql:postgresql:42.7.0") + implementation("com.zaxxer:HikariCP:5.0.1") + implementation("org.hibernate.orm:hibernate-core:6.4.1.Final") + implementation("org.hibernate.orm:hibernate-hikaricp:6.4.1.Final") + implementation("io.hypersistence:hypersistence-utils-hibernate-63:3.7.3") + implementation("com.fasterxml.jackson.core:jackson-databind:2.16.1") + // Jupiter testImplementation(platform("org.junit:junit-bom:5.9.1")) testImplementation("org.junit.jupiter:junit-jupiter") diff --git a/src/main/java/com/stmarygate/coral/entities/Account.java b/src/main/java/com/stmarygate/coral/entities/Account.java new file mode 100644 index 0000000..d806d53 --- /dev/null +++ b/src/main/java/com/stmarygate/coral/entities/Account.java @@ -0,0 +1,32 @@ +package com.stmarygate.coral.entities; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@Entity +@Table(name = "accounts") +public class Account { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(nullable = false, unique = true) + private String username; + + @Column(nullable = false) + private String password; // Hashed password + + @Column(nullable = false, unique = true) + private String email; + + @Column(nullable = true) + private String jwt; + + @OneToOne() + @JoinColumn(name = "player_id") + private Player player; +} diff --git a/src/main/java/com/stmarygate/coral/entities/Player.java b/src/main/java/com/stmarygate/coral/entities/Player.java new file mode 100644 index 0000000..b50a135 --- /dev/null +++ b/src/main/java/com/stmarygate/coral/entities/Player.java @@ -0,0 +1,20 @@ +package com.stmarygate.coral.entities; + +import jakarta.persistence.*; +import java.util.UUID; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@Entity +@Table(name = "players") +public class Player { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private UUID id; + + @OneToOne(mappedBy = "player") + private Account account; +} diff --git a/src/main/java/com/stmarygate/coral/network/packets/client/PacketGetPlayerInformations.java b/src/main/java/com/stmarygate/coral/network/packets/client/PacketGetPlayerInformations.java new file mode 100644 index 0000000..f5ae421 --- /dev/null +++ b/src/main/java/com/stmarygate/coral/network/packets/client/PacketGetPlayerInformations.java @@ -0,0 +1,48 @@ +package com.stmarygate.coral.network.packets.client; + +import com.stmarygate.coral.network.packets.Packet; +import com.stmarygate.coral.network.packets.PacketBuffer; +import com.stmarygate.coral.network.packets.PacketHandler; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class PacketGetPlayerInformations extends Packet { + + /** + * Constructs a new {@code PacketGetPlayerInformations}. + */ + public PacketGetPlayerInformations() { + + } + + /** + * Encodes the packet data into the provided {@link PacketBuffer}. + * + * @param packet The {@link PacketBuffer} to which the packet data will be written. + */ + @Override + public void encode(PacketBuffer packet) throws Exception { + } + + /** + * Handles the packet using the specified {@link PacketHandler}. + * + * @param handler The {@link PacketHandler} responsible for handling the packet. + */ + @Override + public void handle(PacketHandler handler) throws Exception { + handler.handlePacket(this); + } + + /** + * Returns a string representation of the {@code PacketVersion}. + * + * @return A string representation containing version information. + */ + @Override + public String toString() { + return ""; + } +} diff --git a/src/main/java/com/stmarygate/coral/network/packets/server/PacketGetPlayerInformationsResult.java b/src/main/java/com/stmarygate/coral/network/packets/server/PacketGetPlayerInformationsResult.java new file mode 100644 index 0000000..f4700dd --- /dev/null +++ b/src/main/java/com/stmarygate/coral/network/packets/server/PacketGetPlayerInformationsResult.java @@ -0,0 +1,7 @@ +package com.stmarygate.coral.network.packets.server; + +import com.stmarygate.coral.network.packets.Packet; + +public class PacketGetPlayerInformationsResult extends Packet { + +}