-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sormula for easier SQLite access once I implement it
- Loading branch information
1 parent
b66efec
commit e5e2f55
Showing
22 changed files
with
299 additions
and
294 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,5 @@ source_visual.ppm | |
source_visual.mp4 | ||
|
||
# Leftover from tests | ||
tmp/ | ||
*.tmp.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/cjburkey/claimchunk/data/sqlite/SqlClaimedChunk.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cjburkey.claimchunk.data.sqlite; | ||
|
||
import com.cjburkey.claimchunk.chunk.ChunkPos; | ||
|
||
import org.sormula.annotation.Column; | ||
import org.sormula.annotation.ImplicitType; | ||
import org.sormula.annotation.Row; | ||
|
||
import java.util.UUID; | ||
|
||
@Row(tableName = "claimed_chunks") | ||
public class SqlClaimedChunk { | ||
|
||
@Column(primaryKey = true, name = "chunk_pos") | ||
@ImplicitType(translator = Translators.ChunkPosTranslator.class) | ||
public ChunkPos chunkPos; | ||
|
||
@Column(name = "owner_uuid") | ||
@ImplicitType(translator = Translators.UUIDTranslator.class) | ||
public UUID chunkOwner; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/cjburkey/claimchunk/data/sqlite/SqlDataPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,37 @@ | ||
package com.cjburkey.claimchunk.data.sqlite; | ||
|
||
import org.sormula.annotation.Row; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Id; | ||
import javax.persistence.Table; | ||
|
||
@Table(name = "player_data") | ||
@Row(tableName = "player_data") | ||
public class SqlDataPlayer { | ||
|
||
@Id | ||
@Column(name = "player_uuid") | ||
@org.sormula.annotation.Column(primaryKey = true, name = "player_uuid") | ||
public String uuid; | ||
|
||
@Column(name = "last_ign") | ||
@org.sormula.annotation.Column(name = "lastIgn") | ||
public String lastIgn; | ||
|
||
@Column(name = "chunk_name") | ||
@org.sormula.annotation.Column(name = "chunk_name") | ||
public String chunkName; | ||
|
||
@Column(name = "last_online_time") | ||
@org.sormula.annotation.Column(name = "last_online_time") | ||
public long lastOnlineTime; | ||
|
||
@Column(name = "alerts_enabled") | ||
@org.sormula.annotation.Column(name = "alerts_enabled") | ||
public boolean alert; | ||
|
||
@Column(name = "extra_max_claims") | ||
@org.sormula.annotation.Column(name = "extra_max_claims") | ||
public int extraMaxClaims; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/com/cjburkey/claimchunk/data/sqlite/SqlFlagEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.cjburkey.claimchunk.data.sqlite; | ||
|
||
import com.cjburkey.claimchunk.chunk.ChunkPos; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
import org.sormula.annotation.Column; | ||
import org.sormula.annotation.ImplicitType; | ||
import org.sormula.annotation.Row; | ||
|
||
import java.util.UUID; | ||
|
||
@Row(tableName = "flag_permissions") | ||
public class SqlFlagEntry { | ||
|
||
@Column(name = "player_uuid") | ||
@ImplicitType(translator = Translators.UUIDTranslator.class) | ||
public UUID playerUUID; | ||
|
||
@Column(name = "other_player_uuid") | ||
@ImplicitType(translator = Translators.UUIDTranslator.class) | ||
public @Nullable UUID otherPlayerUUID; | ||
|
||
@Column(name = "chunk_pos") | ||
@ImplicitType(translator = Translators.ChunkPosTranslator.class) | ||
public @Nullable ChunkPos chunkPos; | ||
|
||
@Column(name = "flag_name") | ||
public String flagName; | ||
|
||
@Column(name = "allow_deny") | ||
public boolean allowDeny; | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/com/cjburkey/claimchunk/data/sqlite/Translators.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.cjburkey.claimchunk.data.sqlite; | ||
|
||
import com.cjburkey.claimchunk.chunk.ChunkPos; | ||
|
||
import org.sormula.translator.TypeTranslator; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.util.UUID; | ||
|
||
public final class Translators { | ||
|
||
public record UUIDTranslator() implements TypeTranslator<UUID> { | ||
@Override | ||
public UUID read(ResultSet resultSet, int columnIndex) throws Exception { | ||
String str = resultSet.getString(columnIndex); | ||
if (str.isEmpty()) { | ||
return null; | ||
} | ||
|
||
return UUID.fromString(str); | ||
} | ||
|
||
@Override | ||
public void write(PreparedStatement preparedStatement, int parameterIndex, UUID parameter) | ||
throws Exception { | ||
preparedStatement.setString( | ||
parameterIndex, parameter != null ? parameter.toString() : ""); | ||
} | ||
} | ||
|
||
public record ChunkPosTranslator() implements TypeTranslator<ChunkPos> { | ||
@Override | ||
public ChunkPos read(ResultSet resultSet, int columnIndex) throws Exception { | ||
String val = resultSet.getString(columnIndex); | ||
if (val.isEmpty()) { | ||
return null; | ||
} | ||
|
||
String[] str = val.split(","); | ||
String world = str[0]; | ||
int x = Integer.parseInt(str[1]); | ||
int z = Integer.parseInt(str[2]); | ||
return new ChunkPos(world, x, z); | ||
} | ||
|
||
@Override | ||
public void write( | ||
PreparedStatement preparedStatement, int parameterIndex, ChunkPos parameter) | ||
throws Exception { | ||
preparedStatement.setString( | ||
parameterIndex, | ||
parameter != null | ||
? String.format( | ||
"%s,%s,%s", parameter.world(), parameter.x(), parameter.z()) | ||
: ""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.