Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/main/java/pro/cloudnode/smp/smpcore/Nation.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public final class Nation {
*/
public final @NotNull Date founded;

/**
* In-game absolute ticks when this nation was founded (based on {@link org.bukkit.World#getFullTime()})
*/
public final long foundedTicks;

/**
* National bank account of the nation
*/
Expand All @@ -71,16 +76,18 @@ public final class Nation {
* @param leaderUUID See {@link #leaderUUID}
* @param viceLeaderUUID See {@link #viceLeaderUUID}
* @param founded See {@link #founded}
* @param foundedTicks See {@link #foundedTicks}
* @param bank See {@link #bank}
*/
public Nation(final @NotNull String id, final @NotNull String name, final @NotNull String shortName, final @NotNull String colour, final @NotNull UUID leaderUUID, final @NotNull UUID viceLeaderUUID, final @NotNull Date founded, final @NotNull String bank) {
public Nation(final @NotNull String id, final @NotNull String name, final @NotNull String shortName, final @NotNull String colour, final @NotNull UUID leaderUUID, final @NotNull UUID viceLeaderUUID, final @NotNull Date founded, final long foundedTicks, final @NotNull String bank) {
this.id = id;
this.name = name;
this.shortName = shortName;
this.color = colour;
this.leaderUUID = leaderUUID;
this.viceLeaderUUID = viceLeaderUUID;
this.founded = founded;
this.foundedTicks = foundedTicks;
this.bank = bank;
}

Expand Down Expand Up @@ -126,14 +133,15 @@ public Nation(final @NotNull ResultSet rs) throws @NotNull SQLException {
UUID.fromString(rs.getString("leader")),
UUID.fromString(rs.getString("vice")),
rs.getTimestamp("founded"),
rs.getLong("founded_ticks"),
rs.getString("bank")
);
}

public void save() {
try (
final @NotNull Connection conn = SMPCore.getInstance().db()
.getConnection(); final @NotNull PreparedStatement stmt = conn.prepareStatement("INSERT OR REPLACE INTO `nations` (`id`, `name`, `short_name`, `color`, `leader`, `vice`, `founded`, `bank`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")
.getConnection(); final @NotNull PreparedStatement stmt = conn.prepareStatement("INSERT OR REPLACE INTO `nations` (`id`, `name`, `short_name`, `color`, `leader`, `vice`, `founded`, `founded_ticks`, `bank`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
) {
stmt.setString(1, id);
stmt.setString(2, name);
Expand All @@ -142,7 +150,8 @@ public void save() {
stmt.setString(5, leaderUUID.toString());
stmt.setString(6, viceLeaderUUID.toString());
stmt.setTimestamp(7, new java.sql.Timestamp(founded.getTime()));
stmt.setString(8, bank);
stmt.setLong(8, foundedTicks);
stmt.setString(9, bank);
stmt.executeUpdate();
}
catch (final @NotNull SQLException e) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/pro/cloudnode/smp/smpcore/Rest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ private void e404 (final @NotNull io.javalin.http.Context ctx) {
obj.addProperty("viceLeader", nation.viceLeaderUUID.toString());
obj.addProperty("members", nation.members().size());
obj.addProperty("founded", nation.founded.getTime());
obj.addProperty("foundedGameTicks", nation.foundedTicks);
obj.addProperty("foundedGameDate", SMPCore.gameTime(nation.foundedTicks).getTime());
obj.addProperty("bank", nation.bank);
return obj;
}
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/pro/cloudnode/smp/smpcore/SMPCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public static boolean ifDisallowedCharacters(final @NotNull String source, final
}

public static @NotNull Date gameTime() {
return new Date(overworld().getFullTime() * 3600 + 21600000);
return gameTime(overworld().getFullTime());
}

public static @NotNull Date gameTime(final long ticks) {
return new Date(ticks * 3600 + 21600000);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CREATE TABLE IF NOT EXISTS `nations` (
`color` CHAR(6) NOT NULL COLLATE NOCASE,
`leader` CHAR(36) NOT NULL COLLATE NOCASE,
`vice` CHAR(36) NOT NULL COLLATE NOCASE,
`founded` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`founded` DATETIME NOT NULL,
`founded_ticks` INTEGER NOT NULL,
`bank` CHAR(16) NOT NULL COLLATE BINARY
);