Skip to content

Commit 3890b31

Browse files
committed
Merge branch 'master' into mc1.20
2 parents 12e0205 + 0189c77 commit 3890b31

File tree

69 files changed

+932
-439
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+932
-439
lines changed

api

common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ node {
3131
version = "20.14.0"
3232
download = true
3333
nodeProjectDir = file("webapp/")
34+
npmInstallCommand = "ci"
3435
}
3536

3637
tasks.register("buildWebapp", type = NpmTask::class) {

common/src/main/java/de/bluecolored/bluemap/common/api/BlueMapAPIImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package de.bluecolored.bluemap.common.api;
2626

27-
import com.github.benmanes.caffeine.cache.Caffeine;
2827
import com.github.benmanes.caffeine.cache.LoadingCache;
2928
import de.bluecolored.bluemap.api.BlueMapAPI;
3029
import de.bluecolored.bluemap.api.BlueMapMap;
@@ -35,6 +34,7 @@
3534
import de.bluecolored.bluemap.core.BlueMap;
3635
import de.bluecolored.bluemap.core.logger.Logger;
3736
import de.bluecolored.bluemap.core.map.BmMap;
37+
import de.bluecolored.bluemap.core.util.Caches;
3838
import de.bluecolored.bluemap.core.world.World;
3939
import lombok.NonNull;
4040
import org.jetbrains.annotations.Nullable;
@@ -68,12 +68,10 @@ public BlueMapAPIImpl(BlueMapService blueMapService, @Nullable Plugin plugin) {
6868
this.webAppImpl = new WebAppImpl(blueMapService, plugin);
6969
this.pluginImpl = plugin != null ? new PluginImpl(plugin) : null;
7070

71-
this.worldCache = Caffeine.newBuilder()
72-
.executor(BlueMap.THREAD_POOL)
71+
this.worldCache = Caches.with()
7372
.weakKeys()
7473
.build(this::getWorldUncached);
75-
this.mapCache = Caffeine.newBuilder()
76-
.executor(BlueMap.THREAD_POOL)
74+
this.mapCache = Caches.with()
7775
.weakKeys()
7876
.build(this::getMapUncached);
7977
}

common/src/main/java/de/bluecolored/bluemap/common/commands/Commands.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.flowpowered.math.vector.Vector3d;
2828
import com.github.benmanes.caffeine.cache.Cache;
29-
import com.github.benmanes.caffeine.cache.Caffeine;
3029
import com.github.benmanes.caffeine.cache.LoadingCache;
3130
import de.bluecolored.bluecommands.*;
3231
import de.bluecolored.bluemap.common.commands.arguments.MapBackedArgumentParser;
@@ -39,8 +38,8 @@
3938
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
4039
import de.bluecolored.bluemap.common.serverinterface.ServerWorld;
4140
import de.bluecolored.bluemap.core.map.BmMap;
41+
import de.bluecolored.bluemap.core.util.Caches;
4242
import de.bluecolored.bluemap.core.world.World;
43-
import net.kyori.adventure.text.event.ClickEvent;
4443
import org.jetbrains.annotations.Nullable;
4544

4645
import java.util.Map;
@@ -53,10 +52,10 @@
5352

5453
public class Commands {
5554

56-
private static final Cache<String, RenderTask> REF_TO_RENDERTASK = Caffeine.newBuilder()
55+
private static final Cache<String, RenderTask> REF_TO_RENDERTASK = Caches.with()
5756
.weakValues()
5857
.build();
59-
private static final LoadingCache<RenderTask, String> RENDERTASK_TO_REF = Caffeine.newBuilder()
58+
private static final LoadingCache<RenderTask, String> RENDERTASK_TO_REF = Caches.with()
6059
.weakKeys()
6160
.build(Commands::safeRandomRef);
6261

common/src/main/java/de/bluecolored/bluemap/common/commands/commands/DebugCommand.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.flowpowered.math.vector.Vector2i;
2828
import com.flowpowered.math.vector.Vector3d;
29-
import com.flowpowered.math.vector.Vector3i;
3029
import de.bluecolored.bluecommands.annotations.Argument;
3130
import de.bluecolored.bluecommands.annotations.Command;
3231
import de.bluecolored.bluemap.common.BlueMapService;
@@ -74,7 +73,7 @@ public int dump(CommandSource source) {
7473
text(BlueMapConfigManager.formatPath(file)).color(HIGHLIGHT_COLOR)
7574
).color(POSITIVE_COLOR));
7675
return 1;
77-
} catch (IOException ex) {
76+
} catch (Exception ex) {
7877
Logger.global.logError("Failed to create dump!", ex);
7978
source.sendMessage(text("Exception trying to create debug-dump! See console for details.").color(NEGATIVE_COLOR));
8079
return 0;
@@ -103,7 +102,6 @@ public Component block(CommandSource source, World world, @Argument("x") int x,
103102

104103
Chunk chunk = world.getChunkAtBlock(x, z);
105104
LightData lightData = chunk.getLightData(x, y, z, new LightData(0, 0));
106-
Vector3i spawnPoint = world.getSpawnPoint();
107105

108106
return paragraph("World-Info (debug)", lines(
109107
item("position", format("( x: % | y: % | z: % )",
@@ -138,12 +136,7 @@ public Component block(CommandSource source, World world, @Argument("x") int x,
138136
.append(details(BASE_COLOR,
139137
item("name", world.getName()),
140138
item("min-y", world.getDimensionType().getMinY()),
141-
item("height", world.getDimensionType().getHeight()),
142-
item("spawn", format("( x: % | y: % | z: % )",
143-
text(spawnPoint.getX()).color(HIGHLIGHT_COLOR),
144-
text(spawnPoint.getY()).color(HIGHLIGHT_COLOR),
145-
text(spawnPoint.getZ()).color(HIGHLIGHT_COLOR)
146-
))
139+
item("height", world.getDimensionType().getHeight())
147140
))
148141
)
149142
));

common/src/main/java/de/bluecolored/bluemap/common/config/MapConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class MapConfig implements MapSettings {
6060

6161
private int sorting = 0;
6262

63-
@Nullable private Vector2i startPos = null;
63+
private Vector2i startPos = Vector2i.ZERO;
6464

6565
private String skyColor = "#7dabff";
6666
private String voidColor = "#000000";

common/src/main/java/de/bluecolored/bluemap/common/debug/StateDumper.java

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
*/
2525
package de.bluecolored.bluemap.common.debug;
2626

27+
import com.github.benmanes.caffeine.cache.Cache;
28+
import com.github.benmanes.caffeine.cache.stats.CacheStats;
2729
import com.google.gson.stream.JsonWriter;
2830
import de.bluecolored.bluemap.core.BlueMap;
2931
import de.bluecolored.bluemap.core.util.Key;
@@ -117,7 +119,57 @@ private void dumpInstance(Object instance, JsonWriter writer, Set<Object> alread
117119
String identityString = toIdentityString(instance);
118120
writer.name("#identity").value(identityString);
119121

122+
if (instance instanceof Cache<?,?> cache) {
123+
writer.name("stats");
124+
dumpInstance(cache.stats(), writer, alreadyDumped);
125+
126+
writer.name("estimated-size").value(cache.estimatedSize());
127+
128+
writer.name("entries").beginArray();
129+
int count = 0;
130+
for (Map.Entry<?, ?> entry : cache.asMap().entrySet()) {
131+
if (++count > 10) {
132+
writer.value("<<more elements>>");
133+
break;
134+
}
135+
136+
writer.beginObject();
137+
try {
138+
139+
writer.name("key");
140+
dumpInstance(entry.getKey(), writer, alreadyDumped);
141+
142+
writer.name("value");
143+
dumpInstance(entry.getValue(), writer, alreadyDumped);
144+
145+
} finally {
146+
writer.endObject();
147+
}
148+
149+
}
150+
writer.endArray();
151+
return;
152+
}
153+
154+
if (instance instanceof CacheStats cacheStats) {
155+
writer.name("request-count").value(cacheStats.requestCount());
156+
writer.name("hit-count").value(cacheStats.hitCount());
157+
writer.name("hit-rate").value(cacheStats.hitRate());
158+
writer.name("miss-count").value(cacheStats.missCount());
159+
writer.name("miss-rate").value(cacheStats.missRate());
160+
writer.name("load-count").value(cacheStats.loadCount());
161+
writer.name("load-success-count").value(cacheStats.loadSuccessCount());
162+
writer.name("load-failure-count").value(cacheStats.loadFailureCount());
163+
writer.name("load-failure-rate").value(cacheStats.loadFailureRate());
164+
writer.name("total-load-time").value(cacheStats.totalLoadTime());
165+
writer.name("average-load-penalty").value(cacheStats.averageLoadPenalty());
166+
writer.name("eviction-count").value(cacheStats.evictionCount());
167+
writer.name("eviction-weight").value(cacheStats.evictionWeight());
168+
return;
169+
}
170+
120171
if (instance instanceof Map<?, ?> map) {
172+
writer.name("size").value(map.size());
121173
writer.name("entries").beginArray();
122174

123175
int count = 0;
@@ -128,21 +180,25 @@ private void dumpInstance(Object instance, JsonWriter writer, Set<Object> alread
128180
}
129181

130182
writer.beginObject();
183+
try {
131184

132-
writer.name("key");
133-
dumpInstance(entry.getKey(), writer, alreadyDumped);
185+
writer.name("key");
186+
dumpInstance(entry.getKey(), writer, alreadyDumped);
134187

135-
writer.name("value");
136-
dumpInstance(entry.getValue(), writer, alreadyDumped);
188+
writer.name("value");
189+
dumpInstance(entry.getValue(), writer, alreadyDumped);
137190

138-
writer.endObject();
191+
} finally {
192+
writer.endObject();
193+
}
139194
}
140195

141196
writer.endArray();
142197
return;
143198
}
144199

145200
if (instance instanceof Collection<?> collection) {
201+
writer.name("size").value(collection.size());
146202
writer.name("entries").beginArray();
147203

148204
int count = 0;
@@ -160,6 +216,7 @@ private void dumpInstance(Object instance, JsonWriter writer, Set<Object> alread
160216
}
161217

162218
if (instance instanceof Object[] array) {
219+
writer.name("length").value(array.length);
163220
writer.name("entries").beginArray();
164221

165222
int count = 0;

common/src/main/java/de/bluecolored/bluemap/common/plugin/MapUpdateService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
import com.flowpowered.math.vector.Vector2i;
2828
import com.github.benmanes.caffeine.cache.Cache;
29-
import com.github.benmanes.caffeine.cache.Caffeine;
3029
import de.bluecolored.bluemap.common.rendermanager.RenderManager;
3130
import de.bluecolored.bluemap.common.rendermanager.WorldRegionRenderTask;
3231
import de.bluecolored.bluemap.core.logger.Logger;
3332
import de.bluecolored.bluemap.core.map.BmMap;
33+
import de.bluecolored.bluemap.core.util.Caches;
3434
import de.bluecolored.bluemap.core.util.WatchService;
3535

3636
import java.io.IOException;
@@ -60,7 +60,7 @@ public MapUpdateService(RenderManager renderManager, BmMap map, Duration regionU
6060
this.regionUpdateCooldown = regionUpdateCooldown;
6161
this.closed = false;
6262
this.scheduledUpdates = new HashMap<>();
63-
this.lastUpdateTimes = Caffeine.newBuilder()
63+
this.lastUpdateTimes = Caches.with()
6464
.expireAfterWrite(regionUpdateCooldown)
6565
.build();
6666
this.watchService = map.getWorld().createRegionWatchService();

common/src/main/java/de/bluecolored/bluemap/common/rendermanager/MapUpdatePreparationTask.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,8 @@ private Collection<RenderTask> createTasks(Collection<Vector2i> regions) {
112112
ArrayList<WorldRegionRenderTask> regionTasks = new ArrayList<>(regions.size());
113113
regions.forEach(region -> regionTasks.add(new WorldRegionRenderTask(map, region, force)));
114114

115-
// get spawn region
116-
World world = map.getWorld();
117-
Vector2i spawnPoint = world.getSpawnPoint().toVector2(true);
118-
Grid regionGrid = world.getRegionGrid();
119-
Vector2i spawnRegion = regionGrid.getCell(spawnPoint);
120-
121-
// sort tasks by distance to the spawn region
122-
regionTasks.sort(WorldRegionRenderTask.defaultComparator(spawnRegion));
115+
// sort tasks by distance to 0/0
116+
regionTasks.sort(WorldRegionRenderTask.defaultComparator(Vector2i.ZERO));
123117

124118
// save map before and after the whole update
125119
ArrayList<RenderTask> tasks = new ArrayList<>(regionTasks.size() + 2);

common/src/main/java/de/bluecolored/bluemap/common/serverinterface/Server.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
package de.bluecolored.bluemap.common.serverinterface;
2626

2727
import com.github.benmanes.caffeine.cache.Cache;
28-
import com.github.benmanes.caffeine.cache.Caffeine;
29-
import com.github.benmanes.caffeine.cache.LoadingCache;
3028
import de.bluecolored.bluemap.common.debug.DebugDump;
29+
import de.bluecolored.bluemap.core.util.Caches;
3130
import de.bluecolored.bluemap.core.util.Tristate;
3231
import de.bluecolored.bluemap.core.world.World;
3332
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
@@ -36,12 +35,10 @@
3635
import java.nio.file.Path;
3736
import java.util.Collection;
3837
import java.util.Optional;
39-
import java.util.concurrent.TimeUnit;
4038

4139
public interface Server {
4240

43-
Cache<World, Optional<ServerWorld>> SERVER_WORLD_CACHE = Caffeine.newBuilder()
44-
.expireAfterWrite(10, TimeUnit.SECONDS)
41+
Cache<World, Optional<ServerWorld>> SERVER_WORLD_CACHE = Caches.with()
4542
.weakKeys()
4643
.weakValues()
4744
.build();

0 commit comments

Comments
 (0)