Skip to content

Commit

Permalink
Merge branch '1.20.2' into 1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Jun 28, 2024
2 parents 2f59c5a + 33d1f83 commit ea50ef0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.Level;
import xaeroplus.XaeroPlus;
import xaeroplus.util.ChunkUtils;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReadWriteLock;
Expand All @@ -27,7 +28,7 @@ public boolean addHighlight(final int x, final int z, final long foundTime) {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed to add new highlight", e);
XaeroPlus.LOGGER.error("Failed to add new highlight: {}, {}", x, z, e);
}
return true;
}
Expand All @@ -40,7 +41,7 @@ public boolean removeHighlight(final int x, final int z) {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed to add new highlight", e);
XaeroPlus.LOGGER.error("Failed to add new highlight: {}, {}", x, z, e);
}
return true;
}
Expand All @@ -57,7 +58,7 @@ public boolean isHighlighted(final long chunkPos) {
return containsKey;
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Error checking if chunk is highlighted", e);
XaeroPlus.LOGGER.error("Error checking if chunk is highlighted: {}, {}", ChunkUtils.longToChunkX(chunkPos), ChunkUtils.longToChunkZ(chunkPos), e);
}
return false;
}
Expand Down Expand Up @@ -87,7 +88,7 @@ public void loadPreviousState(final Long2LongMap state) {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Error loading previous state", e);
XaeroPlus.LOGGER.error("Error loading previous highlight cache state", e);
}
}

Expand All @@ -99,7 +100,7 @@ public void replaceState(final Long2LongOpenHashMap state) {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed replacing cache state", e);
XaeroPlus.LOGGER.error("Failed replacing highlight cache state", e);
}
}

Expand All @@ -110,7 +111,7 @@ public void reset() {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed resetting cache", e);
XaeroPlus.LOGGER.error("Failed resetting highlight cache", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private void loadHighlightsInWindow() {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Failed to load highlights in window", e);
XaeroPlus.LOGGER.error("Failed to load highlights in window for {} disk cache dimension: {}", database.databaseName, dimension.location(), e);
}
});
}
Expand All @@ -82,7 +82,7 @@ private void writeHighlightsOutsideWindowToDatabase() {
lock.writeLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Error while writing highlights outside window to database", e);
XaeroPlus.LOGGER.error("Error while writing highlights outside window to {} disk cache dimension: {}", database.databaseName, dimension.location(), e);
}
database.insertHighlightList(chunksToWrite, dimension);
});
Expand All @@ -102,7 +102,7 @@ public ListenableFuture<?> writeAllHighlightsToDatabase() {
lock.readLock().unlock();
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Error while writing all chunks to database", e);
XaeroPlus.LOGGER.error("Error while writing all chunks to {} disk cache dimension: {}", database.databaseName, dimension.location(), e);
}
database.insertHighlightList(chunksToWrite, dimension);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ChunkHighlightDatabase(String worldId, String databaseName) {
connection = DriverManager.getConnection("jdbc:rfresh_sqlite:" + dbPath);
MIGRATOR.migrate(dbPath, databaseName, connection);
} catch (Exception e) {
XaeroPlus.LOGGER.error("Error while creating chunk highlight database: {}", databaseName, e);
XaeroPlus.LOGGER.error("Error while creating chunk highlight database: {} for worldId: {}", databaseName, worldId, e);
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -75,7 +75,7 @@ private void insertHighlightsListInternal(final List<ChunkHighlightData> chunks,
stmt.executeUpdate(statement);
}
} catch (Exception e) {
XaeroPlus.LOGGER.error("Error inserting chunks into database", e);
XaeroPlus.LOGGER.error("Error inserting {} chunks into {} database in dimension: {}", chunks.size(), databaseName, dimension.location(), e);
}
}

Expand All @@ -98,7 +98,7 @@ public List<ChunkHighlightData> getHighlightsInWindow(
return chunks;
}
} catch (final Exception e) {
XaeroPlus.LOGGER.error("Error getting chunks from database", e);
XaeroPlus.LOGGER.error("Error getting chunks from {} database in dimension: {}, window: {}-{}, {}-{}", databaseName, dimension.location(), regionXMin, regionXMax, regionZMin, regionZMax, e);
// fall through
}
return Collections.emptyList();
Expand All @@ -108,7 +108,7 @@ public void removeHighlight(final int x, final int z, final ResourceKey<Level> d
try (var statement = connection.createStatement()) {
statement.executeUpdate("DELETE FROM \"" + getTableName(dimension) + "\" WHERE x = " + x + " AND z = " + z);
} catch (Exception e) {
XaeroPlus.LOGGER.error("Error while removing highlight from database", e);
XaeroPlus.LOGGER.error("Error while removing highlight from {} database in dimension: {}, at {}, {}", databaseName, dimension.location(), x, z, e);
}
}

Expand All @@ -117,7 +117,7 @@ public void close() {
try {
connection.close();
} catch (Exception e) {
XaeroPlus.LOGGER.warn("Failed closing database connection", e);
XaeroPlus.LOGGER.warn("Failed closing {} database connection", databaseName, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public boolean addHighlight(final int x, final int z) {
cacheForCurrentDimension.addHighlight(x, z);
return true;
} catch (final Exception e) {
XaeroPlus.LOGGER.debug("Error adding highlight to saving cache: {}", databaseName, e);
XaeroPlus.LOGGER.debug("Error adding highlight to {} disk cache: {}, {}", databaseName, x, z, e);
return false;
}
}
Expand All @@ -61,7 +61,7 @@ public boolean removeHighlight(final int x, final int z) {
cacheForCurrentDimension.removeHighlight(x, z);
return true;
} catch (final Exception e) {
XaeroPlus.LOGGER.debug("Error removing highlight from saving cache: {}, {}", x, z, e);
XaeroPlus.LOGGER.debug("Error removing highlight from {} disk cache: {}, {}", databaseName, x, z, e);
return false;
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ private ChunkHighlightCacheDimensionHandler initializeDimensionCacheHandler(fina
var db = this.database;
var executor = this.executorService;
if (db == null || executor == null) {
XaeroPlus.LOGGER.error("Unable to initialize dimension cache handler for: {}, database or executor is null", dimension.location());
XaeroPlus.LOGGER.error("Unable to initialize {} disk cache handler for: {}, database or executor is null", databaseName, dimension.location());
return null;
}
var cacheHandler = new ChunkHighlightCacheDimensionHandler(dimension, db, executor);
Expand All @@ -130,7 +130,7 @@ public ChunkHighlightCacheDimensionHandler getCacheForDimension(final ResourceKe
var dimensionCache = dimensionCacheMap.get(dimension);
if (dimensionCache == null) {
if (!create) return null;
XaeroPlus.LOGGER.error("Initializing cache for dimension: {}", dimension.location());
XaeroPlus.LOGGER.info("Initializing {} disk cache for dimension: {}", databaseName, dimension.location());
dimensionCache = initializeDimensionCacheHandler(dimension);
}
return dimensionCache;
Expand All @@ -154,15 +154,10 @@ private void initializeWorld() {
try {
final String worldId = XaeroWorldMapCore.currentSession.getMapProcessor().getCurrentWorldId();
if (worldId == null) return;
final ResourceKey<Level> dimension = getActualDimension();
if (dimension != OVERWORLD && dimension != NETHER && dimension != END) {
XaeroPlus.LOGGER.error("Unexpected dimension ID: " + dimension + ". Disable Save/Load to Disk to restore functionality.");
return;
}
this.executorService = MoreExecutors.listeningDecorator(
this.executorService = MoreExecutors.listeningDecorator(
Executors.newSingleThreadExecutor(
new ThreadFactoryBuilder()
.setNameFormat("XaeroPlus-ChunkHighlightCacheHandler-" + currentWorldId)
.setNameFormat("XaeroPlus-" + databaseName + "-DiskCache-" + currentWorldId)
.build()));
this.currentWorldId = worldId;
this.database = new ChunkHighlightDatabase(worldId, databaseName);
Expand Down

0 comments on commit ea50ef0

Please sign in to comment.