Skip to content

Commit 6c8d691

Browse files
committed
Merge tag 'v5.7' into mc1.20
Version 5.7
2 parents 1b6a1f0 + 8c74686 commit 6c8d691

File tree

369 files changed

+7845
-4078
lines changed

Some content is hidden

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

369 files changed

+7845
-4078
lines changed

api

buildSrc/src/main/kotlin/bluemap.base.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ version = gitVersion()
1010

1111
repositories {
1212
maven ("https://repo.bluecolored.de/releases") {
13-
content { includeGroupByRegex ("de\\.bluecolored\\..*") }
13+
content { includeGroupByRegex ("de\\.bluecolored.*") }
14+
}
15+
maven ("https://repo.bluecolored.de/snapshots") {
16+
content { includeGroupByRegex ("de\\.bluecolored.*") }
1417
}
1518
maven ("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") {
1619
content { includeGroup ("org.spigotmc") }

buildSrc/src/main/kotlin/versioning.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ fun Project.gitHash(): String {
88
}
99

1010
fun Project.gitClean(): Boolean {
11-
return runCommand("git status --porcelain", "NOT_CLEAN").isEmpty()
11+
if (runCommand("git update-index --refresh", "NOT-CLEAN").equals("NOT-CLEAN")) return false;
12+
return runCommand("git diff-index HEAD --", "NOT-CLEAN").isEmpty();
1213
}
1314

1415
fun Project.gitVersion(): String {
1516
val lastTag = if (runCommand("git tag", "").isEmpty()) "" else runCommand("git describe --tags --abbrev=0", "")
1617
val lastVersion = if (lastTag.isEmpty()) "0.0" else lastTag.substring(1) // remove the leading 'v'
1718
val commits = runCommand("git rev-list --count $lastTag..HEAD", "0")
19+
val branch = runCommand("git branch --show-current", "master")
1820
val gitVersion = lastVersion +
21+
(if (branch == "master" || branch.isEmpty()) "" else "-${branch.replace('/', '.')}") +
1922
(if (commits == "0") "" else "-$commits") +
2023
(if (gitClean()) "" else "-dirty")
2124

@@ -50,8 +53,10 @@ private fun Project.runCommand(cmd: String, fallback: String? = null): String {
5053
throw TimeoutException("Failed to execute command: '$cmd'")
5154
}
5255
.run {
56+
val exitCode = waitFor()
57+
if (exitCode == 0) return inputStream.bufferedReader().readText().trim()
58+
5359
val error = errorStream.bufferedReader().readText().trim()
54-
if (error.isEmpty()) return inputStream.bufferedReader().readText().trim()
5560
logger.warn("Failed to execute command '$cmd': $error")
5661
if (fallback != null) return fallback
5762
throw IOException(error)

common/build.gradle.kts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ plugins {
99
dependencies {
1010
api ( project( ":core" ) )
1111

12-
api ( libs.brigadier )
12+
api ( libs.adventure.api )
13+
api ( libs.bluecommands.core )
14+
15+
compileOnly ( libs.bluecommands.brigadier )
16+
compileOnly ( libs.brigadier )
1317

1418
compileOnly ( libs.jetbrains.annotations )
1519
compileOnly ( libs.lombok )

common/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ public synchronized Storage getOrLoadStorage(String storageId) throws Configurat
313313
return storage;
314314
}
315315

316+
public Map<String, Storage> getLoadedStorages() {
317+
return Collections.unmodifiableMap(storages);
318+
}
319+
316320
public @Nullable ResourcePack getResourcePack() {
317321
return resourcePack;
318322
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import de.bluecolored.bluemap.api.BlueMapWorld;
3131
import de.bluecolored.bluemap.api.markers.MarkerSet;
3232
import de.bluecolored.bluemap.common.plugin.Plugin;
33+
import de.bluecolored.bluemap.common.rendermanager.MapUpdatePreparationTask;
3334
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
3435
import de.bluecolored.bluemap.common.rendermanager.WorldRegionRenderTask;
3536
import de.bluecolored.bluemap.core.map.BmMap;
@@ -117,7 +118,8 @@ private synchronized void unfreeze() {
117118
BmMap map = unpack(this.map);
118119
plugin.startWatchingMap(map);
119120
plugin.getPluginState().getMapState(map).setUpdateEnabled(true);
120-
plugin.getRenderManager().scheduleRenderTask(new MapUpdateTask(map));
121+
plugin.getRenderManager().scheduleRenderTaskNext(MapUpdatePreparationTask
122+
.updateMap(map, plugin.getRenderManager()));
121123
}
122124

123125
private synchronized void freeze() {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import de.bluecolored.bluemap.api.RenderManager;
3030
import de.bluecolored.bluemap.common.plugin.Plugin;
3131
import de.bluecolored.bluemap.common.rendermanager.MapPurgeTask;
32+
import de.bluecolored.bluemap.common.rendermanager.MapUpdatePreparationTask;
3233
import de.bluecolored.bluemap.common.rendermanager.MapUpdateTask;
3334
import de.bluecolored.bluemap.common.rendermanager.TileUpdateStrategy;
3435

@@ -49,7 +50,8 @@ public RenderManagerImpl(BlueMapAPIImpl api, Plugin plugin) {
4950
@Override
5051
public boolean scheduleMapUpdateTask(BlueMapMap map, boolean force) {
5152
BlueMapMapImpl cmap = castMap(map);
52-
return renderManager.scheduleRenderTask(new MapUpdateTask(cmap.map(), TileUpdateStrategy.fixed(force)));
53+
return renderManager.scheduleRenderTask(MapUpdatePreparationTask
54+
.updateMap(cmap.map(), TileUpdateStrategy.fixed(force), renderManager));
5355
}
5456

5557
@Override
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package de.bluecolored.bluemap.common.commands;
26+
27+
import com.mojang.brigadier.Message;
28+
import com.mojang.brigadier.exceptions.CommandSyntaxException;
29+
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
30+
import de.bluecolored.bluecommands.ParseFailure;
31+
import de.bluecolored.bluecommands.ParseResult;
32+
import de.bluecolored.bluecommands.brigadier.CommandExecutionHandler;
33+
import de.bluecolored.bluemap.common.plugin.Plugin;
34+
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
35+
36+
import java.util.Comparator;
37+
38+
public class BrigadierExecutionHandler extends CommandExecutor implements CommandExecutionHandler<CommandSource, Object> {
39+
private static final Message DEFAULT_FAILURE_MESSAGE = () -> "Unknown or incomplete command!";
40+
41+
public BrigadierExecutionHandler(Plugin plugin) {
42+
super(plugin);
43+
}
44+
45+
@Override
46+
public int handle(ParseResult<CommandSource, Object> parseResult) throws CommandSyntaxException {
47+
ExecutionResult executionResult = this.execute(parseResult);
48+
if (executionResult.parseFailure())
49+
return parseFailure(parseResult);
50+
return executionResult.resultCode();
51+
}
52+
53+
private int parseFailure(ParseResult<CommandSource, Object> result) throws CommandSyntaxException {
54+
ParseFailure<CommandSource, Object> failure = result.getFailures().stream()
55+
.max(Comparator.comparing(ParseFailure::getPosition))
56+
.orElseThrow(() -> new CommandSyntaxException(
57+
new SimpleCommandExceptionType(DEFAULT_FAILURE_MESSAGE),
58+
DEFAULT_FAILURE_MESSAGE
59+
));
60+
throw new CommandSyntaxException(
61+
new SimpleCommandExceptionType(failure::getReason),
62+
failure::getReason,
63+
result.getInput(),
64+
failure.getPosition()
65+
);
66+
}
67+
68+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package de.bluecolored.bluemap.common.commands;
26+
27+
import de.bluecolored.bluecommands.ParseMatch;
28+
import de.bluecolored.bluecommands.ParseResult;
29+
import de.bluecolored.bluemap.common.plugin.Plugin;
30+
import de.bluecolored.bluemap.common.serverinterface.CommandSource;
31+
import de.bluecolored.bluemap.core.BlueMap;
32+
import de.bluecolored.bluemap.core.logger.Logger;
33+
import lombok.RequiredArgsConstructor;
34+
import net.kyori.adventure.text.ComponentLike;
35+
36+
import java.util.Comparator;
37+
import java.util.concurrent.CompletableFuture;
38+
import java.util.concurrent.TimeUnit;
39+
40+
import static de.bluecolored.bluemap.common.commands.TextFormat.NEGATIVE_COLOR;
41+
import static net.kyori.adventure.text.Component.text;
42+
43+
@RequiredArgsConstructor
44+
public class CommandExecutor {
45+
46+
private final Plugin plugin;
47+
48+
public ExecutionResult execute(ParseResult<CommandSource, Object> parseResult) {
49+
if (parseResult.getMatches().isEmpty()) {
50+
51+
// check if the plugin is not loaded first
52+
if (!Commands.checkPluginLoaded(plugin, parseResult.getContext()))
53+
return new ExecutionResult(0, false);
54+
55+
return new ExecutionResult(0, true);
56+
}
57+
58+
ParseMatch<CommandSource, Object> match = parseResult.getMatches().stream()
59+
.max(Comparator.comparing(ParseMatch::getPriority))
60+
.orElseThrow(IllegalStateException::new);
61+
62+
if (!Commands.checkExecutablePreconditions(plugin, match.getContext(), match.getExecutable()))
63+
return new ExecutionResult(0, false);
64+
65+
return CompletableFuture.supplyAsync(match::execute, BlueMap.THREAD_POOL)
66+
.thenApply(result -> switch (result) {
67+
case Number n -> n.intValue();
68+
case ComponentLike c -> {
69+
match.getContext().sendMessage(c.asComponent());
70+
yield 1;
71+
}
72+
case Boolean b -> b ? 1 : 0;
73+
case null, default -> 1;
74+
})
75+
.exceptionally(e -> {
76+
Logger.global.logError("Command execution for '%s' failed".formatted(parseResult.getInput()), e);
77+
parseResult.getContext().sendMessage(text("There was an error executing this command! See logs or console for details.")
78+
.color(NEGATIVE_COLOR));
79+
return 0;
80+
})
81+
.completeOnTimeout(1, 100, TimeUnit.MILLISECONDS)
82+
.thenApply(code -> new ExecutionResult(code, false))
83+
.join();
84+
}
85+
86+
public record ExecutionResult (
87+
int resultCode,
88+
boolean parseFailure
89+
) {}
90+
91+
}

0 commit comments

Comments
 (0)