Skip to content

Commit

Permalink
Switch to library but now it doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 21, 2024
1 parent 9e7f675 commit b091558
Show file tree
Hide file tree
Showing 8 changed files with 399 additions and 441 deletions.
32 changes: 21 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import com.vanniktech.maven.publish.SonatypeHost
import org.apache.tools.ant.filters.ReplaceTokens
import de.undercouch.gradle.tasks.download.Download
Expand Down Expand Up @@ -37,7 +38,10 @@ object DepData {
const val JETBRAINS_ANNOTATIONS_VERSION = "23.0.0"
const val JUNIT_VERSION = "5.10.2"
const val JUNIT_LAUNCHER_VERSION = "1.10.2"
const val SANS_ORM_VERSION = "3.7"
const val SQLITE_JDBC_VERSION = "3.42.0.1"
const val JAVAX_PERSISTENCE_VERSION = "2.1.0"
const val JAVAX_TRANSACTION_VERSION = "1.1"
const val SANS_ORM_VERSION = "3.17"

// Directories
const val TEST_SERVER_DIR = "run"
Expand Down Expand Up @@ -75,6 +79,8 @@ java {

tasks {
compileJava {
mustRunAfter("googleFormat")

// Disable incremental compilation (module system bs and spigot no mesh
// well)
options.isIncremental = false
Expand All @@ -96,15 +102,16 @@ tasks {
archiveClassifier.set("plugin")
archiveVersion.set(project.version.toString())

relocate("com.zaxxer.sansorm", "claimchunk.dependency.com.zaxxer.sansorm")
dependencies {
exclude(dependency("org.slf4j:slf4j-api"))
exclude(dependency("org.xerial:sqlite-jdbc"))
}

// Move SmartCommandDispatcher to a unique package to avoid clashes with
// any other plugins that might include it in their jar files.
// relocate("de.goldmensch.commanddispatcher",
// "claimchunk.dependency.de.goldmensch.commanddispatcher");
// Do the same with JALL
// relocate("io.github.goldmensch.jall",
// "claimchunk.dependency.io.github.goldmensch.jall");
relocate("com.zaxxer", "claimchunk.dependency.com.zaxxer")
relocate("javax.persistence", "claimchunk.dependency.javax.persistence")
relocate("javax.transaction", "claimchunk.dependency.javax.transaction")
relocate("org.eclipse", "claimchunk.dependency.org.eclipse")
relocate("org.osgi", "claimchunk.dependency.org.osgi")
}

test {
Expand Down Expand Up @@ -287,8 +294,11 @@ dependencies {
compileOnly("com.sk89q.worldguard:worldguard-bukkit:${DepData.WORLD_GUARD_BUKKIT_VERSION}")
compileOnly("me.clip:placeholderapi:${DepData.PLACEHOLDER_API_VERSION}")

// We need to shade this!
implementation("com.zaxxer:sansorm:${DepData.SANS_ORM_VERSION}")
// We need these during runtime!
implementation("org.xerial:sqlite-jdbc:${DepData.SQLITE_JDBC_VERSION}")
implementation("org.eclipse.persistence:javax.persistence:${DepData.JAVAX_PERSISTENCE_VERSION}")
implementation("javax.transaction:transaction-api:${DepData.JAVAX_TRANSACTION_VERSION}")
implementation("com.github.h-thurow:q2o:${DepData.SANS_ORM_VERSION}")

testImplementation("org.junit.jupiter:junit-jupiter:${DepData.JUNIT_VERSION}")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:${DepData.JUNIT_LAUNCHER_VERSION}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public boolean getHasInit() {
}

@Override
public void exit() {}
public void exit() {
sqLiteWrapper.close();
}

@Override
public void save() {
Expand Down Expand Up @@ -234,15 +236,8 @@ public void givePlayerAccess(
ChunkPos chunk, UUID accessor, ChunkPlayerPermissions permissions) {
DataChunk chunkData = claimedChunks.get(chunk);
if (chunkData != null) {
ChunkPlayerPermissions previousPerms =
chunkData.playerPermissions.put(accessor, permissions);
if (previousPerms == null) {
// Player doesn't already have any access
sqLiteWrapper.addPlayerAccess(chunk, accessor, permissions.permissionFlags);
} else {
// Player has access, we're changing it
sqLiteWrapper.updatePlayerAccess(chunk, accessor, permissions.permissionFlags);
}
chunkData.playerPermissions.put(accessor, permissions);
sqLiteWrapper.updateOrInsertPlayerAccess(chunk, accessor, permissions.permissionFlags);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,95 +1,63 @@
package com.cjburkey.claimchunk.data.sqlite;

import org.jetbrains.annotations.NotNull;
import com.zaxxer.q2o.Q2Sql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.function.Supplier;

/** This class is responsible for creating, loading, and upgrading the database file. */
public class SqLiteTableMigrationManager {

public static void go(Supplier<Connection> connectionSupplier)
throws RuntimeException, SQLException {
try (Connection connection = ensureConnection(connectionSupplier)) {
// Make tables if they don't exist
initializeTables(connection);
public static void go() {
// Make tables if they don't exist
tryCreateTables();

// Call migration check methods here.
}
// Call migration check methods here.
}

private static @NotNull Connection ensureConnection(Supplier<Connection> connectionSupplier)
throws RuntimeException {
Connection connection = connectionSupplier.get();
try {
if (connection != null && !connection.isClosed()) {
return connection;
} else {
throw new RuntimeException("Connection provided was not valid.");
}
} catch (SQLException e) {
throw new RuntimeException(
"Failed to create connection to ClaimChunk SQLite database file", e);
}
}

private static void initializeTables(Connection connection) throws SQLException {
tryCreateTables(connection);

// Call migration methods here.
// Add table column exist checks inside each method to make this method
// cleaner.
}

private static void tryCreateTables(Connection connection) throws SQLException {
// Player data table
connection
.prepareStatement(
"""
CREATE TABLE IF NOT EXISTS player_data (
player_uuid TEXT PRIMARY KEY 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
) STRICT
""")
.execute();
private static void tryCreateTables() {
// Create player data table
Q2Sql.executeUpdate(
"""
CREATE TABLE IF NOT EXISTS player_data (
player_uuid TEXT PRIMARY KEY 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
) STRICT
""");

// Chunk data table
connection
.prepareStatement(
"""
CREATE TABLE IF NOT EXISTS chunk_data (
chunk_id INTEGER PRIMARY KEY,
chunk_world TEXT NOT NULL,
chunk_x INTEGER NOT NULL,
chunk_z INTEGER NOT NULL,
owner_uuid TEXT NOT NULL,
FOREIGN KEY(owner_uuid) REFERENCES player_data(player_uuid)
) STRICT
""")
.execute();
Q2Sql.executeUpdate(
"""
CREATE TABLE IF NOT EXISTS chunk_data (
chunk_id INTEGER PRIMARY KEY,
chunk_world TEXT NOT NULL,
chunk_x INTEGER NOT NULL,
chunk_z INTEGER NOT NULL,
owner_uuid TEXT NOT NULL,
FOREIGN KEY(owner_uuid) REFERENCES player_data(player_uuid)
) STRICT
""");

// Granular chunk player permission table
connection
.prepareStatement(
"""
CREATE TABLE IF NOT EXISTS chunk_permissions (
chunk_id INTEGER NOT NULL,
other_player_uuid TEXT NOT NULL,
permission_bits INTEGER NOT NULL,
FOREIGN KEY(chunk_id) REFERENCES chunk_data(chunk_id),
FOREIGN KEY(other_player_uuid) REFERENCES player_data(player_uuid)
) STRICT
""")
.execute();
Q2Sql.executeUpdate(
"""
CREATE TABLE IF NOT EXISTS chunk_permissions (
perm_id INTEGER PRIMARY KEY,
chunk_id INTEGER NOT NULL,
other_player_uuid TEXT NOT NULL,
permission_bits INTEGER NOT NULL,
FOREIGN KEY(chunk_id) REFERENCES chunk_data(chunk_id),
FOREIGN KEY(other_player_uuid) REFERENCES player_data(player_uuid)
) STRICT
""");
}

// Use this method to determine if a column exists in a table to perform migrations
Expand Down
Loading

0 comments on commit b091558

Please sign in to comment.