Skip to content

Commit

Permalink
Create sqlite tables
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 11, 2024
1 parent 6cc12a4 commit 9cca6f9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/main/java/com/cjburkey/claimchunk/ClaimChunk.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.cjburkey.claimchunk.cmd.*;
import com.cjburkey.claimchunk.config.ClaimChunkWorldProfileHandler;
import com.cjburkey.claimchunk.config.ccconfig.*;
import com.cjburkey.claimchunk.data.journaled.JournaledDataHandler;
import com.cjburkey.claimchunk.data.newdata.*;
import com.cjburkey.claimchunk.event.*;
import com.cjburkey.claimchunk.i18n.V2JsonMessages;
Expand Down Expand Up @@ -365,9 +366,10 @@ private void initAnonymousData() {
}
}

@SuppressWarnings("CommentedOutCode")
private boolean initDataHandler() {
// Initialize the data handler if another plugin hasn't substituted one already
if (dataHandler == null) {
/*if (dataHandler == null) {
// The ternary operator is great
// But it's ugly sometimes
// Yuck!
Expand All @@ -383,6 +385,11 @@ private boolean initDataHandler() {
this::createJsonDataHandler,
JsonDataHandler::deleteFiles))
: createJsonDataHandler();
}*/
if (dataHandler == null) {
dataHandler =
new JournaledDataHandler(
new File(getDataFolder(), "/data/claimAndPlayerData.sqlite"));
}
Utils.debug("Using data handler \"%s\"", dataHandler.getClass().getName());
try {
Expand All @@ -400,6 +407,7 @@ private boolean initDataHandler() {
"Please double check your config and make sure it's set to the correct data"
+ " information to ensure ClaimChunk can operate normally");
}
System.exit(-1);
return false;
}

Expand Down Expand Up @@ -448,6 +456,7 @@ private void initEcon() {
Utils.log("Economy not enabled.");
}

@SuppressWarnings("unused")
private JsonDataHandler createJsonDataHandler() {
// Create the basic JSON data handler
return new JsonDataHandler(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cjburkey.claimchunk.data.journaled;

import lombok.Getter;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -11,7 +13,7 @@

public class SqLiteWrapper {

private final File dbFile;
@Getter private final File dbFile;
private Connection connection;

public SqLiteWrapper(@NotNull File dbFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,30 @@ private static void initializeTables(Connection connection) throws SQLException
// cleaner.
}

// TODO: CHECK THESE WORK!
private static void tryCreateTables(Connection connection) throws SQLException {
// Player data table
connection
.prepareCall(
.prepareStatement(
"""
CREATE TABLE IF NOT EXISTS player_data (
player_id INTEGER PRIMARY KEY,
player_uuid VARCHAR(36) UNIQUE NOT NULL,
last_ign VARCHAR(32) NOT NULL,
chunk_name VARCHAR(32),
player_uuid TEXT UNIQUE NOT NULL,
last_ign TEXT NOT NULL,
chunk_name TEXT,
last_online_time INTEGER NOT NULL,
alerts_enabled INTEGER NOT NULL,
extra_max_claims INTEGER NOT NULL,
extra_max_claims INTEGER NOT NULL
) STRICT
""")
.execute();

// Chunk data table
connection
.prepareCall(
.prepareStatement(
"""
CREATE TABLE IF NOT EXISTS chunk_data (
chunk_id INTEGER PRIMARY KEY,
chunk_world VARCHAR(32) NOT NULL,
chunk_world TEXT NOT NULL,
chunk_x INTEGER NOT NULL,
chunk_z INTEGER NOT NULL,
owner_id INTEGER NOT NULL,
Expand All @@ -80,14 +79,14 @@ FOREIGN KEY(owner_id) REFERENCES player_data(player_id)

// Granular chunk player permission table
connection
.prepareCall(
.prepareStatement(
"""
CREATE TABLE IF NOT EXISTS chunk_permissions (
chunk_id INTEGER NOT NULL,
other_player_id INTEGER NOT NULL,
permission_bits INTEGER NOT NULL,
FOREIGN KEY(chunk_id) REFERENCES chunk_data(chunk_id)
FOREIGN KEY(chunk_id) REFERENCES chunk_data(chunk_id),
FOREIGN KEY(other_player_id) REFERENCES player_data(player_id)
) STRICT
""")
Expand Down

0 comments on commit 9cca6f9

Please sign in to comment.