Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
cjburkey01 committed May 8, 2024
1 parent d6669c9 commit e65d60c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 31 deletions.
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ 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";
// Goldmensch's SmartCommandDispatcher. Thank you!!
// const val SMART_COMMAND_DISPATCHER_VERSION = "2.0.1";
// And internationalization library!
// const val JALL_I18N_VERSION = "1.0.2"

// Directories
const val TEST_SERVER_DIR = "run";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,44 @@
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Collection;
import java.util.Map;
import java.util.UUID;
import java.util.*;

/*
* I've actually just decided that we're gonna do it this way:
* - SQLite backing database *file* similar to current MySQL integration (which will
* be removed and automatically converted).
* - Have some intermediary layer that can
* - Keep some regions in memory and unload when no players are within them
* for a minute or two.
* - Respond immediately and asynchronously update database.
*/

/**
* The SHINY, NEW........data handler that tries to fix the data loss issues by which this project
* has been plagued since its conception.
* <p>
* I've actually just decided that we're gonna do it this way:
* - SQLite backing database similar to current MySQL integration (which will
* be removed and automatically converted).
* - Keep some regions in memory and unload when no players are within them
* for a minute or two.
* I hope this is better :)
*
* @since 0.0.25
*/
public class JournaledDataHandler implements IClaimChunkDataHandler {

private boolean init = false;

@Getter private final File claimChunkDb;
private boolean init = false;
private HashMap<UUID, FullPlayerData> joinedPlayers;
private HashMap<RegionPos, ClaimRegion> claimRegions;
private SqLiteWrapper sqLiteWrapper;

public JournaledDataHandler(@NotNull File claimChunkDb) {
this.claimChunkDb = claimChunkDb;
}

@Override
public void init() {
joinedPlayers = new HashMap<>();
claimRegions = new HashMap<>();
sqLiteWrapper = new SqLiteWrapper(claimChunkDb);

init = true;
}

Expand All @@ -54,19 +63,29 @@ public boolean getHasInit() {
public void exit() {}

@Override
public void save() throws Exception {}
public void save() {
// Don't do anything, async handler should have us safe
}

@Override
public void load() throws Exception {}
public void load() throws Exception {
// TODO: THIS
}

@Override
public void addClaimedChunk(ChunkPos pos, UUID player) {}
public void addClaimedChunk(ChunkPos pos, UUID player) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void addClaimedChunks(DataChunk[] chunks) {}
public void addClaimedChunks(DataChunk[] chunks) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void removeClaimedChunk(ChunkPos pos) {}
public void removeClaimedChunk(ChunkPos pos) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public boolean isChunkClaimed(ChunkPos pos) {
Expand Down Expand Up @@ -100,48 +119,81 @@ public void addPlayer(
@Nullable String chunkName,
long lastOnlineTime,
boolean alerts,
int maxClaims) {}
int extraMaxClaims) {
joinedPlayers.put(
player,
new FullPlayerData(
player, lastIgn, chunkName, lastOnlineTime, alerts, extraMaxClaims));

// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void addPlayers(FullPlayerData[] players) {}
public void addPlayers(FullPlayerData[] players) {
Arrays.stream(players).forEach(player -> joinedPlayers.put(player.player, player));

// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public @Nullable String getPlayerUsername(UUID player) {
return null;
FullPlayerData ply = joinedPlayers.get(player);
return ply == null ? null : ply.lastIgn;
}

@Override
public @Nullable UUID getPlayerUUID(String username) {
// TODO: THIS

return null;
}

@Override
public void setPlayerLastOnline(UUID player, long time) {}
public void setPlayerLastOnline(UUID player, long time) {
FullPlayerData ply = joinedPlayers.get(player);
if (ply != null) ply.lastOnlineTime = time;

// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void setPlayerChunkName(UUID player, @Nullable String name) {}
public void setPlayerChunkName(UUID player, @Nullable String name) {
FullPlayerData ply = joinedPlayers.get(player);
if (ply != null) ply.chunkName = name;

// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public @Nullable String getPlayerChunkName(UUID player) {
return null;
FullPlayerData ply = joinedPlayers.get(player);
return ply == null ? null : ply.chunkName;
}

@Override
public void setPlayerReceiveAlerts(UUID player, boolean alerts) {}
public void setPlayerReceiveAlerts(UUID player, boolean alerts) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public boolean getPlayerReceiveAlerts(UUID player) {
return false;
}

@Override
public void setPlayerExtraMaxClaims(UUID player, int maxClaims) {}
public void setPlayerExtraMaxClaims(UUID player, int maxClaims) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void addPlayerExtraMaxClaims(UUID player, int numToAdd) {}
public void addPlayerExtraMaxClaims(UUID player, int numToAdd) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void takePlayerExtraMaxClaims(UUID player, int numToTake) {}
public void takePlayerExtraMaxClaims(UUID player, int numToTake) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public int getPlayerExtraMaxClaims(UUID player) {
Expand All @@ -165,10 +217,14 @@ public FullPlayerData[] getFullPlayerData() {

@Override
public void givePlayerAccess(
ChunkPos chunk, UUID accessor, ChunkPlayerPermissions permissions) {}
ChunkPos chunk, UUID accessor, ChunkPlayerPermissions permissions) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public void takePlayerAccess(ChunkPos chunk, UUID accessor) {}
public void takePlayerAccess(ChunkPos chunk, UUID accessor) {
// TODO: mutating methods must call sqLiteWrapper methods
}

@Override
public Map<UUID, ChunkPlayerPermissions> getPlayersWithAccess(ChunkPos chunk) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cjburkey.claimchunk.data.journaled;

import lombok.Getter;

import java.io.File;

public class SqLiteWrapper {

private final File dbFile;

public SqLiteWrapper(File dbFile) {
this.dbFile = dbFile;
}
}

0 comments on commit e65d60c

Please sign in to comment.