mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-02-16 20:41:57 +01:00
Add /bluemap version command and improve /bluemap worlds
This commit is contained in:
parent
981a12e349
commit
68561b1860
@ -393,5 +393,9 @@ public boolean isLoaded() {
|
||||
public String getImplementationType() {
|
||||
return implementationType;
|
||||
}
|
||||
|
||||
public MinecraftVersion getMinecraftVersion() {
|
||||
return minecraftVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -61,18 +61,18 @@ public List<Text> createStatusMessage(){
|
||||
|
||||
lines.add(Text.of());
|
||||
lines.add(Text.of(TextColor.BLUE, "Tile-Updates:"));
|
||||
|
||||
|
||||
if (renderer.isRunning()) {
|
||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||
Text.of(TextColor.GREEN, "running")
|
||||
.setHoverText(Text.of("click to pause rendering"))
|
||||
.setClickCommand("/bluemap pause"),
|
||||
.setHoverText(Text.of("click to pause rendering"))
|
||||
.setClickAction(Text.ClickAction.RUN_COMMAND, "/bluemap pause"),
|
||||
TextColor.GRAY, "!"));
|
||||
} else {
|
||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||
lines.add(Text.of(TextColor.WHITE, " Render-Threads are ",
|
||||
Text.of(TextColor.RED, "paused")
|
||||
.setHoverText(Text.of("click to resume rendering"))
|
||||
.setClickCommand("/bluemap resume"),
|
||||
.setHoverText(Text.of("click to resume rendering"))
|
||||
.setClickAction(Text.ClickAction.RUN_COMMAND, "/bluemap resume"),
|
||||
TextColor.GRAY, "!"));
|
||||
}
|
||||
|
||||
@ -118,11 +118,11 @@ public List<Text> createStatusMessage(){
|
||||
}
|
||||
|
||||
private Text createCancelTaskText(RenderTask task) {
|
||||
return Text.of(TextColor.RED, "[X]").setHoverText(Text.of(TextColor.GRAY, "click to cancel this render-task")).setClickCommand("/bluemap render cancel " + task.getUuid());
|
||||
return Text.of(TextColor.RED, "[X]").setHoverText(Text.of(TextColor.GRAY, "click to cancel this render-task")).setClickAction(Text.ClickAction.RUN_COMMAND,"/bluemap render cancel " + task.getUuid());
|
||||
}
|
||||
|
||||
private Text createPrioritizeTaskText(RenderTask task) {
|
||||
return Text.of(TextColor.GREEN, "[^]").setHoverText(Text.of(TextColor.GRAY, "click to prioritize this render-task")).setClickCommand("/bluemap render prioritize " + task.getUuid());
|
||||
return Text.of(TextColor.GREEN, "[^]").setHoverText(Text.of(TextColor.GRAY, "click to prioritize this render-task")).setClickAction(Text.ClickAction.RUN_COMMAND,"/bluemap render prioritize " + task.getUuid());
|
||||
}
|
||||
|
||||
public void createWorldRenderTask(CommandSource source, World world, Vector2i center, long blockRadius) {
|
||||
|
@ -31,6 +31,9 @@
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import de.bluecolored.bluemap.common.plugin.text.TextFormat;
|
||||
import de.bluecolored.bluemap.core.BlueMap;
|
||||
import de.bluecolored.bluemap.core.MinecraftVersion;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
|
||||
import com.flowpowered.math.vector.Vector2i;
|
||||
@ -45,7 +48,6 @@
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
|
||||
import de.bluecolored.bluemap.api.BlueMapAPI;
|
||||
@ -73,9 +75,9 @@ public class Commands<S> {
|
||||
|
||||
private final Plugin plugin;
|
||||
private final CommandDispatcher<S> dispatcher;
|
||||
private Function<S, CommandSource> commandSourceInterface;
|
||||
private final Function<S, CommandSource> commandSourceInterface;
|
||||
|
||||
private CommandHelper helper;
|
||||
private final CommandHelper helper;
|
||||
|
||||
public Commands(Plugin plugin, CommandDispatcher<S> dispatcher, Function<S, CommandSource> commandSourceInterface) {
|
||||
this.plugin = plugin;
|
||||
@ -94,6 +96,12 @@ public void init() {
|
||||
.requires(requirementsUnloaded("bluemap.status"))
|
||||
.executes(this::statusCommand)
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> versionCommand =
|
||||
literal("version")
|
||||
.requires(requirementsUnloaded("bluemap.version"))
|
||||
.executes(this::versionCommand)
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> helpCommand =
|
||||
literal("help")
|
||||
@ -142,36 +150,29 @@ public void init() {
|
||||
.requires(requirements("bluemap.resume"))
|
||||
.executes(this::resumeCommand)
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> renderCommand =
|
||||
|
||||
LiteralCommandNode<S> renderCommand =
|
||||
literal("render")
|
||||
.requires(requirements("bluemap.render"))
|
||||
.executes(this::renderCommand) // /bluemap render
|
||||
|
||||
.then(argument("radius", IntegerArgumentType.integer())
|
||||
.executes(this::renderCommand)) // /bluemap render <radius>
|
||||
|
||||
|
||||
.then(argument("x", DoubleArgumentType.doubleArg())
|
||||
.then(argument("z", DoubleArgumentType.doubleArg())
|
||||
.then(argument("radius", IntegerArgumentType.integer())
|
||||
.executes(this::renderCommand)))) // /bluemap render <x> <z> <radius>
|
||||
|
||||
|
||||
.then(argument("world|map", StringArgumentType.string()).suggests(new WorldOrMapSuggestionProvider<>(plugin))
|
||||
.executes(this::renderCommand) // /bluemap render <world|map>
|
||||
|
||||
|
||||
.then(argument("x", DoubleArgumentType.doubleArg())
|
||||
.then(argument("z", DoubleArgumentType.doubleArg())
|
||||
.then(argument("radius", IntegerArgumentType.integer())
|
||||
.executes(this::renderCommand))))) // /bluemap render <world|map> <x> <z> <radius>
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> purgeCommand =
|
||||
literal("purge")
|
||||
.requires(requirements("bluemap.render"))
|
||||
.then(argument("map", StringArgumentType.string()).suggests(new MapSuggestionProvider<>(plugin))
|
||||
.executes(this::purgeCommand))
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> prioRenderCommand =
|
||||
literal("prioritize")
|
||||
.requires(requirements("bluemap.render"))
|
||||
@ -188,6 +189,13 @@ public void init() {
|
||||
.executes(this::cancelRenderTaskCommand))
|
||||
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> purgeCommand =
|
||||
literal("purge")
|
||||
.requires(requirements("bluemap.render"))
|
||||
.then(argument("map", StringArgumentType.string()).suggests(new MapSuggestionProvider<>(plugin))
|
||||
.executes(this::purgeCommand))
|
||||
.build();
|
||||
|
||||
LiteralCommandNode<S> worldsCommand =
|
||||
literal("worlds")
|
||||
@ -231,6 +239,7 @@ public void init() {
|
||||
|
||||
// command tree
|
||||
dispatcher.getRoot().addChild(baseCommand);
|
||||
baseCommand.addChild(versionCommand);
|
||||
baseCommand.addChild(helpCommand);
|
||||
baseCommand.addChild(reloadCommand);
|
||||
baseCommand.addChild(debugCommand);
|
||||
@ -262,11 +271,11 @@ private Predicate<S> requirementsUnloaded(String permission){
|
||||
}
|
||||
|
||||
private LiteralArgumentBuilder<S> literal(String name){
|
||||
return LiteralArgumentBuilder.<S>literal(name);
|
||||
return LiteralArgumentBuilder.literal(name);
|
||||
}
|
||||
|
||||
private <T> RequiredArgumentBuilder<S, T> argument(String name, ArgumentType<T> type){
|
||||
return RequiredArgumentBuilder.<S, T>argument(name, type);
|
||||
return RequiredArgumentBuilder.argument(name, type);
|
||||
}
|
||||
|
||||
private <T> Optional<T> getOptionalArgument(CommandContext<S> context, String argumentName, Class<T> type) {
|
||||
@ -319,6 +328,32 @@ public int statusCommand(CommandContext<S> context) {
|
||||
source.sendMessages(helper.createStatusMessage());
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int versionCommand(CommandContext<S> context) {
|
||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
source.sendMessage(Text.of(TextFormat.BOLD, TextColor.BLUE, "Version: ", TextColor.WHITE, BlueMap.VERSION));
|
||||
source.sendMessage(Text.of(TextColor.GRAY, "Implementation: ", TextColor.WHITE, plugin.getImplementationType()));
|
||||
source.sendMessage(Text.of(TextColor.GRAY, "Minecraft compatibility: ", TextColor.WHITE, plugin.getMinecraftVersion().getVersionString()));
|
||||
source.sendMessage(Text.of(TextColor.GRAY, "Render-threads: ", TextColor.WHITE, plugin.getRenderManager().getRenderThreadCount()));
|
||||
source.sendMessage(Text.of(TextColor.GRAY, "Available processors: ", TextColor.WHITE, Runtime.getRuntime().availableProcessors()));
|
||||
source.sendMessage(Text.of(TextColor.GRAY, "Available memory: ", TextColor.WHITE, (Runtime.getRuntime().maxMemory() / 1024L / 1024L) + " MiB"));
|
||||
|
||||
if (plugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MC_1_15)) {
|
||||
String clipboardValue =
|
||||
"Version: " + BlueMap.VERSION + "\n" +
|
||||
"Implementation: " + plugin.getImplementationType() + "\n" +
|
||||
"Minecraft compatibility: " + plugin.getMinecraftVersion().getVersionString() + "\n" +
|
||||
"Render-threads: " + plugin.getRenderManager().getRenderThreadCount() + "\n" +
|
||||
"Available processors: " + Runtime.getRuntime().availableProcessors() + "\n" +
|
||||
"Available memory: " + Runtime.getRuntime().maxMemory() / 1024L / 1024L + " MiB";
|
||||
source.sendMessage(Text.of(TextColor.DARK_GRAY, "[copy to clipboard]")
|
||||
.setClickAction(Text.ClickAction.COPY_TO_CLIPBOARD, clipboardValue)
|
||||
.setHoverText(Text.of(TextColor.GRAY, "click to copy the above text .. ", TextFormat.ITALIC, TextColor.GRAY, "duh!")));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int helpCommand(CommandContext<S> context) {
|
||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
@ -342,7 +377,7 @@ public int helpCommand(CommandContext<S> context) {
|
||||
|
||||
source.sendMessage(
|
||||
Text.of(TextColor.BLUE, "\nOpen this link to get a description for each command:\n")
|
||||
.addChild(Text.of(TextColor.GRAY, "https://bluecolo.red/bluemap-commands").setClickLink("https://bluecolo.red/bluemap-commands"))
|
||||
.addChild(Text.of(TextColor.GRAY, "https://bluecolo.red/bluemap-commands").setClickAction(Text.ClickAction.OPEN_URL, "https://bluecolo.red/bluemap-commands"))
|
||||
);
|
||||
|
||||
return 1;
|
||||
@ -372,7 +407,7 @@ public int reloadCommand(CommandContext<S> context) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int debugClearCacheCommand(CommandContext<S> context) throws CommandSyntaxException {
|
||||
public int debugClearCacheCommand(CommandContext<S> context) {
|
||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
for (World world : plugin.getWorlds()) {
|
||||
@ -384,7 +419,7 @@ public int debugClearCacheCommand(CommandContext<S> context) throws CommandSynta
|
||||
}
|
||||
|
||||
|
||||
public int debugFlushCommand(CommandContext<S> context) throws CommandSyntaxException {
|
||||
public int debugFlushCommand(CommandContext<S> context) {
|
||||
CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
// parse arguments
|
||||
@ -424,7 +459,7 @@ public int debugFlushCommand(CommandContext<S> context) throws CommandSyntaxExce
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int debugBlockCommand(CommandContext<S> context) throws CommandSyntaxException {
|
||||
public int debugBlockCommand(CommandContext<S> context) {
|
||||
final CommandSource source = commandSourceInterface.apply(context.getSource());
|
||||
|
||||
// parse arguments
|
||||
@ -671,7 +706,7 @@ public int worldsCommand(CommandContext<S> context) {
|
||||
|
||||
source.sendMessage(Text.of(TextColor.BLUE, "Worlds loaded by BlueMap:"));
|
||||
for (World world : plugin.getWorlds()) {
|
||||
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, world.getName()).setHoverText(Text.of(TextColor.GRAY, world.getUUID())));
|
||||
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, world.getName()).setHoverText(Text.of(world.getSaveFolder(), TextColor.GRAY, " (" + world.getUUID() + ")")));
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
@ -35,8 +35,8 @@ public class Text {
|
||||
private TextColor color;
|
||||
private Set<TextFormat> formats = new HashSet<>();
|
||||
private Text hoverText;
|
||||
private String clickCommand;
|
||||
private String clickLink;
|
||||
private ClickAction clickAction;
|
||||
private String clickActionValue;
|
||||
private List<Text> children = new ArrayList<>();
|
||||
|
||||
public Text setHoverText(Text hoverText) {
|
||||
@ -45,14 +45,9 @@ public Text setHoverText(Text hoverText) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Text setClickCommand(String clickCommand) {
|
||||
this.clickCommand = clickCommand;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Text setClickLink(String clickLink) {
|
||||
this.clickLink = clickLink;
|
||||
public Text setClickAction(ClickAction action, String value) {
|
||||
this.clickAction = action;
|
||||
this.clickActionValue = value;
|
||||
|
||||
return this;
|
||||
}
|
||||
@ -84,17 +79,10 @@ public String toJSONString() {
|
||||
sb.append("},");
|
||||
}
|
||||
|
||||
if (clickCommand != null) {
|
||||
if (clickAction != null && clickActionValue != null) {
|
||||
sb.append(quote("clickEvent")).append(":{");
|
||||
sb.append(quote("action")).append(":").append(quote("run_command")).append(',');
|
||||
sb.append(quote("value")).append(":").append(quote(clickCommand));
|
||||
sb.append("},");
|
||||
}
|
||||
|
||||
else if (clickLink != null) {
|
||||
sb.append(quote("clickEvent")).append(":{");
|
||||
sb.append(quote("action")).append(":").append(quote("open_url")).append(',');
|
||||
sb.append(quote("value")).append(":").append(quote(clickLink));
|
||||
sb.append(quote("action")).append(":").append(quote(clickAction.getActionId())).append(',');
|
||||
sb.append(quote("value")).append(":").append(quote(clickActionValue));
|
||||
sb.append("},");
|
||||
}
|
||||
|
||||
@ -151,7 +139,9 @@ private Text withParentFormat(Text parent) {
|
||||
Text text = new Text();
|
||||
|
||||
text.content = this.content;
|
||||
text.clickCommand = this.clickCommand;
|
||||
text.clickAction = this.clickAction;
|
||||
text.clickActionValue = this.clickActionValue;
|
||||
text.hoverText = this.hoverText;
|
||||
text.children = this.children;
|
||||
|
||||
text.color = this.color != null ? this.color : parent.color;
|
||||
@ -241,5 +231,24 @@ public static Text of(Object... objects) {
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
public enum ClickAction {
|
||||
|
||||
OPEN_URL ("open_url"),
|
||||
RUN_COMMAND ("run_command"),
|
||||
SUGGEST_COMMAND ("suggest_command"),
|
||||
COPY_TO_CLIPBOARD ("copy_to_clipboard");
|
||||
|
||||
private final String action;
|
||||
|
||||
ClickAction (String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getActionId() {
|
||||
return action;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,19 +29,21 @@
|
||||
|
||||
public enum MinecraftVersion {
|
||||
|
||||
MC_1_12 ("1.12", "mc1_12", "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"),
|
||||
MC_1_13 ("1.13", "mc1_13", "https://launcher.mojang.com/v1/objects/30bfe37a8db404db11c7edf02cb5165817afb4d9/client.jar"),
|
||||
MC_1_14 ("1.14", "mc1_13", "https://launcher.mojang.com/v1/objects/8c325a0c5bd674dd747d6ebaa4c791fd363ad8a9/client.jar"),
|
||||
MC_1_15 ("1.15", "mc1_15", "https://launcher.mojang.com/v1/objects/e3f78cd16f9eb9a52307ed96ebec64241cc5b32d/client.jar"),
|
||||
MC_1_16 ("1.16", "mc1_16", "https://launcher.mojang.com/v1/objects/653e97a2d1d76f87653f02242d243cdee48a5144/client.jar");
|
||||
MC_1_12 (101200, "1.12", "mc1_12", "https://launcher.mojang.com/v1/objects/0f275bc1547d01fa5f56ba34bdc87d981ee12daf/client.jar"),
|
||||
MC_1_13 (101300, "1.13", "mc1_13", "https://launcher.mojang.com/v1/objects/30bfe37a8db404db11c7edf02cb5165817afb4d9/client.jar"),
|
||||
MC_1_14 (101400, "1.14", "mc1_13", "https://launcher.mojang.com/v1/objects/8c325a0c5bd674dd747d6ebaa4c791fd363ad8a9/client.jar"),
|
||||
MC_1_15 (101500, "1.15", "mc1_15", "https://launcher.mojang.com/v1/objects/e3f78cd16f9eb9a52307ed96ebec64241cc5b32d/client.jar"),
|
||||
MC_1_16 (101600, "1.16", "mc1_16", "https://launcher.mojang.com/v1/objects/653e97a2d1d76f87653f02242d243cdee48a5144/client.jar");
|
||||
|
||||
private static final Pattern VERSION_REGEX = Pattern.compile("(?:(?<major>\\d+)\\.(?<minor>\\d+))(?:\\.(?<patch>\\d+))?(?:\\-(?:pre|rc)\\d+)?");
|
||||
|
||||
|
||||
private final int versionOrdinal;
|
||||
private final String versionString;
|
||||
private final String resourcePrefix;
|
||||
private final String clientDownloadUrl;
|
||||
|
||||
MinecraftVersion(String versionString, String resourcePrefix, String clientDownloadUrl) {
|
||||
MinecraftVersion(int versionOrdinal, String versionString, String resourcePrefix, String clientDownloadUrl) {
|
||||
this.versionOrdinal = versionOrdinal;
|
||||
this.versionString = versionString;
|
||||
this.resourcePrefix = resourcePrefix;
|
||||
this.clientDownloadUrl = clientDownloadUrl;
|
||||
@ -58,7 +60,15 @@ public String getResourcePrefix() {
|
||||
public String getClientDownloadUrl() {
|
||||
return this.clientDownloadUrl;
|
||||
}
|
||||
|
||||
|
||||
public boolean isAtLeast(MinecraftVersion minVersion) {
|
||||
return this.versionOrdinal >= minVersion.versionOrdinal;
|
||||
}
|
||||
|
||||
public boolean isAtMost(MinecraftVersion maxVersion) {
|
||||
return this.versionOrdinal <= maxVersion.versionOrdinal;
|
||||
}
|
||||
|
||||
public static MinecraftVersion fromVersionString(String versionString) {
|
||||
Matcher matcher = VERSION_REGEX.matcher(versionString);
|
||||
if (!matcher.matches()) throw new IllegalArgumentException("Not a valid version string!");
|
||||
@ -71,7 +81,7 @@ public static MinecraftVersion fromVersionString(String versionString) {
|
||||
|
||||
throw new IllegalArgumentException("No matching version found!");
|
||||
}
|
||||
|
||||
|
||||
public static MinecraftVersion getLatest() {
|
||||
return MC_1_16;
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ permissions:
|
||||
bluemap.*:
|
||||
children:
|
||||
bluemap.status: true
|
||||
bluemap.version: true
|
||||
bluemap.help: true
|
||||
bluemap.reload: true
|
||||
bluemap.pause: true
|
||||
@ -20,6 +21,8 @@ permissions:
|
||||
default: op
|
||||
bluemap.status:
|
||||
default: op
|
||||
bluemap.version:
|
||||
default: op
|
||||
bluemap.help:
|
||||
default: op
|
||||
bluemap.reload:
|
||||
|
Loading…
Reference in New Issue
Block a user