Skip to content

Commit 466a1f3

Browse files
committed
Merge branch 'mc/1.13' into mc/1.12
2 parents 3cf3ddd + 7c319d7 commit 466a1f3

File tree

13 files changed

+372
-35
lines changed

13 files changed

+372
-35
lines changed

BlueMapBukkit/src/main/java/de/bluecolored/bluemap/bukkit/BukkitPlugin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ public UUID getUUIDForWorld(File worldFolder) throws IOException {
150150
}
151151
}
152152

153+
@Override
154+
public String getWorldName(UUID worldUUID) {
155+
World world = getServer().getWorld(worldUUID);
156+
if (world != null) return world.getName();
157+
158+
return null;
159+
}
160+
153161
private UUID getUUIDForWorldSync (File worldFolder) throws IOException {
154162
for (World world : getServer().getWorlds()) {
155163
if (worldFolder.equals(world.getWorldFolder().getCanonicalFile())) return world.getUID();

BlueMapBukkit/src/main/resources/plugin.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ description: "A 3d-map of your Minecraft worlds view-able in your browser using
33
main: de.bluecolored.bluemap.bukkit.BukkitPlugin
44
version: ${version}
55
author: "Blue (TBlueF / Lukas Rieger)"
6-
authors: [Blue (TBlueF / Lukas Rieger)]
76
website: "https://github.com/BlueMap-Minecraft"
87
commands:
98
permissions:
@@ -15,6 +14,7 @@ permissions:
1514
bluemap.resume: true
1615
bluemap.render: true
1716
bluemap.debug: true
17+
bluemap.marker: true
1818
default: op
1919
bluemap.status:
2020
default: op
@@ -27,4 +27,6 @@ permissions:
2727
bluemap.render:
2828
default: op
2929
bluemap.debug:
30+
default: op
31+
bluemap.marker:
3032
default: op

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/Plugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public synchronized void load() throws IOException, ParseResourceException {
189189
World world = worlds.get(worldUUID);
190190
if (world == null) {
191191
try {
192-
world = MCAWorld.load(worldFolder.toPath(), worldUUID, configManager.getBlockIdConfig(), configManager.getBlockPropertiesConfig(), configManager.getBiomeConfig());
192+
world = MCAWorld.load(worldFolder.toPath(), worldUUID, configManager.getBlockIdConfig(), configManager.getBlockPropertiesConfig(), configManager.getBiomeConfig(), serverInterface.getWorldName(worldUUID));
193193
worlds.put(worldUUID, world);
194194
} catch (IOException e) {
195195
Logger.global.logError("Failed to load map '" + id + "': Failed to read level.dat", e);

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/commands/AbstractSuggestionProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,15 @@
2727
import java.util.Collection;
2828
import java.util.concurrent.CompletableFuture;
2929

30+
import com.mojang.brigadier.arguments.StringArgumentType;
3031
import com.mojang.brigadier.context.CommandContext;
3132
import com.mojang.brigadier.exceptions.CommandSyntaxException;
3233
import com.mojang.brigadier.suggestion.SuggestionProvider;
3334
import com.mojang.brigadier.suggestion.Suggestions;
3435
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
3536

3637
public abstract class AbstractSuggestionProvider<S> implements SuggestionProvider<S> {
37-
38+
3839
@Override
3940
public CompletableFuture<Suggestions> getSuggestions(CommandContext<S> context, SuggestionsBuilder builder) throws CommandSyntaxException {
4041
Collection<String> possibleValues = getPossibleValues();
@@ -43,7 +44,7 @@ public CompletableFuture<Suggestions> getSuggestions(CommandContext<S> context,
4344
String remaining = builder.getRemaining().toLowerCase();
4445
for (String str : possibleValues) {
4546
if (str.toLowerCase().startsWith(remaining)) {
46-
builder.suggest(str);
47+
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
4748
}
4849
}
4950

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

Lines changed: 193 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
import com.mojang.brigadier.exceptions.CommandSyntaxException;
4646
import com.mojang.brigadier.tree.LiteralCommandNode;
4747

48+
import de.bluecolored.bluemap.api.BlueMapAPI;
49+
import de.bluecolored.bluemap.api.BlueMapMap;
50+
import de.bluecolored.bluemap.api.marker.MarkerAPI;
51+
import de.bluecolored.bluemap.api.marker.MarkerSet;
52+
import de.bluecolored.bluemap.api.marker.POIMarker;
4853
import de.bluecolored.bluemap.common.MapType;
4954
import de.bluecolored.bluemap.common.RenderTask;
5055
import de.bluecolored.bluemap.common.plugin.Plugin;
@@ -59,6 +64,8 @@
5964
import de.bluecolored.bluemap.core.world.World;
6065

6166
public class Commands<S> {
67+
68+
public static final String DEFAULT_MARKER_SET_ID = "markers";
6269

6370
private final Plugin plugin;
6471
private final CommandDispatcher<S> dispatcher;
@@ -95,15 +102,11 @@ public void init() {
95102
.requires(requirements("bluemap.debug"))
96103
.executes(this::debugCommand)
97104

98-
.then(argument("world", StringArgumentType.word()).suggests(new WorldSuggestionProvider<>(plugin))
105+
.then(argument("world", StringArgumentType.string()).suggests(new WorldSuggestionProvider<>(plugin))
99106
.then(argument("x", DoubleArgumentType.doubleArg())
100107
.then(argument("y", DoubleArgumentType.doubleArg())
101108
.then(argument("z", DoubleArgumentType.doubleArg())
102-
.executes(this::debugCommand)
103-
)
104-
)
105-
)
106-
)
109+
.executes(this::debugCommand)))))
107110
.build();
108111

109112
LiteralCommandNode<S> pauseCommand =
@@ -124,45 +127,74 @@ public void init() {
124127
.executes(this::renderCommand) // /bluemap render
125128

126129
.then(argument("radius", IntegerArgumentType.integer())
127-
.executes(this::renderCommand) // /bluemap render <radius>
128-
)
130+
.executes(this::renderCommand)) // /bluemap render <radius>
129131

130132
.then(argument("x", DoubleArgumentType.doubleArg())
131133
.then(argument("z", DoubleArgumentType.doubleArg())
132134
.then(argument("radius", IntegerArgumentType.integer())
133-
.executes(this::renderCommand) // /bluemap render <x> <z> <radius>
134-
)
135-
)
136-
)
135+
.executes(this::renderCommand)))) // /bluemap render <x> <z> <radius>
137136

138-
.then(argument("world|map", StringArgumentType.word()).suggests(new WorldOrMapSuggestionProvider<>(plugin))
137+
.then(argument("world|map", StringArgumentType.string()).suggests(new WorldOrMapSuggestionProvider<>(plugin))
139138
.executes(this::renderCommand) // /bluemap render <world|map>
140139

141140
.then(argument("x", DoubleArgumentType.doubleArg())
142141
.then(argument("z", DoubleArgumentType.doubleArg())
143142
.then(argument("radius", IntegerArgumentType.integer())
144-
.executes(this::renderCommand) // /bluemap render <world|map> <x> <z> <radius>
145-
)
146-
)
147-
)
148-
)
149-
143+
.executes(this::renderCommand))))) // /bluemap render <world|map> <x> <z> <radius>
150144
.build();
151145

152146
LiteralCommandNode<S> prioRenderCommand =
153147
literal("prioritize")
154148
.requires(requirements("bluemap.render"))
155-
.then(argument("uuid", StringArgumentType.word())
156-
.executes(this::prioritizeRenderTaskCommand)
157-
)
149+
.then(argument("uuid", StringArgumentType.string())
150+
.executes(this::prioritizeRenderTaskCommand))
158151
.build();
159152

160153
LiteralCommandNode<S> cancelRenderCommand =
161154
literal("cancel")
162155
.requires(requirements("bluemap.render"))
163-
.then(argument("uuid", StringArgumentType.word())
164-
.executes(this::cancelRenderTaskCommand)
165-
)
156+
.then(argument("uuid", StringArgumentType.string())
157+
.executes(this::cancelRenderTaskCommand))
158+
.build();
159+
160+
LiteralCommandNode<S> worldsCommand =
161+
literal("worlds")
162+
.requires(requirements("bluemap.status"))
163+
.executes(this::worldsCommand)
164+
.build();
165+
166+
LiteralCommandNode<S> mapsCommand =
167+
literal("maps")
168+
.requires(requirements("bluemap.status"))
169+
.executes(this::mapsCommand)
170+
.build();
171+
172+
LiteralCommandNode<S> markerCommand =
173+
literal("marker")
174+
.requires(requirements("bluemap.marker"))
175+
.build();
176+
177+
LiteralCommandNode<S> createMarkerCommand =
178+
literal("create")
179+
.requires(requirements("bluemap.marker"))
180+
.then(argument("id", StringArgumentType.word())
181+
.then(argument("map", StringArgumentType.string()).suggests(new MapSuggestionProvider<>(plugin))
182+
183+
.then(argument("label", StringArgumentType.string())
184+
.executes(this::createMarkerCommand))
185+
186+
.then(argument("x", DoubleArgumentType.doubleArg())
187+
.then(argument("y", DoubleArgumentType.doubleArg())
188+
.then(argument("z", DoubleArgumentType.doubleArg())
189+
.then(argument("label", StringArgumentType.string())
190+
.executes(this::createMarkerCommand)))))))
191+
.build();
192+
193+
LiteralCommandNode<S> removeMarkerCommand =
194+
literal("remove")
195+
.requires(requirements("bluemap.marker"))
196+
.then(argument("id", StringArgumentType.word()).suggests(MarkerIdSuggestionProvider.getInstance())
197+
.executes(this::removeMarkerCommand))
166198
.build();
167199

168200
// command tree
@@ -174,6 +206,11 @@ public void init() {
174206
baseCommand.addChild(renderCommand);
175207
renderCommand.addChild(prioRenderCommand);
176208
renderCommand.addChild(cancelRenderCommand);
209+
baseCommand.addChild(worldsCommand);
210+
baseCommand.addChild(mapsCommand);
211+
baseCommand.addChild(markerCommand);
212+
markerCommand.addChild(createMarkerCommand);
213+
markerCommand.addChild(removeMarkerCommand);
177214
}
178215

179216
private Predicate<S> requirements(String permission){
@@ -454,4 +491,135 @@ public int cancelRenderTaskCommand(CommandContext<S> context) {
454491
source.sendMessage(Text.of(TextColor.RED, "There is no render-task with this UUID: " + uuidString));
455492
return 0;
456493
}
494+
495+
public int worldsCommand(CommandContext<S> context) {
496+
CommandSource source = commandSourceInterface.apply(context.getSource());
497+
498+
source.sendMessage(Text.of(TextColor.BLUE, "Worlds loaded by BlueMap:"));
499+
for (World world : plugin.getWorlds()) {
500+
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, world.getName()).setHoverText(Text.of(TextColor.GRAY, world.getUUID())));
501+
}
502+
503+
return 1;
504+
}
505+
506+
public int mapsCommand(CommandContext<S> context) {
507+
CommandSource source = commandSourceInterface.apply(context.getSource());
508+
509+
source.sendMessage(Text.of(TextColor.BLUE, "Maps loaded by BlueMap:"));
510+
for (MapType map : plugin.getMapTypes()) {
511+
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, map.getId(), TextColor.GRAY, " (" + map.getName() + ")").setHoverText(Text.of(TextColor.WHITE, "World: ", TextColor.GRAY, map.getWorld().getName())));
512+
}
513+
514+
return 1;
515+
}
516+
517+
public int createMarkerCommand(CommandContext<S> context) {
518+
CommandSource source = commandSourceInterface.apply(context.getSource());
519+
520+
String markerId = context.getArgument("id", String.class);
521+
String markerLabel = context.getArgument("label", String.class)
522+
.replace("<", "&lt;")
523+
.replace(">", "&gt;"); //no html via commands
524+
525+
// parse world/map argument
526+
String mapString = context.getArgument("map", String.class);
527+
MapType map = parseMap(mapString).orElse(null);
528+
529+
if (map == null) {
530+
source.sendMessage(Text.of(TextColor.RED, "There is no ", helper.mapHelperHover(), " with this name: ", TextColor.WHITE, mapString));
531+
return 0;
532+
}
533+
534+
// parse position
535+
Optional<Double> x = getOptionalArgument(context, "x", Double.class);
536+
Optional<Double> y = getOptionalArgument(context, "y", Double.class);
537+
Optional<Double> z = getOptionalArgument(context, "z", Double.class);
538+
539+
Vector3d position;
540+
541+
if (x.isPresent() && y.isPresent() && z.isPresent()) {
542+
position = new Vector3d(x.get(), y.get(), z.get());
543+
} else {
544+
position = source.getPosition().orElse(null);
545+
546+
if (position == null) {
547+
source.sendMessage(Text.of(TextColor.RED, "Can't detect a position from this command-source, you'll have to define the x,y,z coordinates for the marker!").setHoverText(Text.of(TextColor.GRAY, "/bluemap marker create " + markerId + " " + "[world|map] <x> <y> <z> <label>")));
548+
return 0;
549+
}
550+
}
551+
552+
// get api
553+
BlueMapAPI api = BlueMapAPI.getInstance().orElse(null);
554+
if (api == null) {
555+
source.sendMessage(Text.of(TextColor.RED, "MarkerAPI is not available, try ", TextColor.GRAY, "/bluemap reload"));
556+
return 0;
557+
}
558+
559+
// resolve api-map
560+
Optional<BlueMapMap> apiMap = api.getMap(map.getId());
561+
if (!apiMap.isPresent()) {
562+
source.sendMessage(Text.of(TextColor.RED, "Failed to get map from API, try ", TextColor.GRAY, "/bluemap reload"));
563+
return 0;
564+
}
565+
566+
// add marker
567+
try {
568+
MarkerAPI markerApi = api.getMarkerAPI();
569+
570+
MarkerSet set = markerApi.getMarkerSet(DEFAULT_MARKER_SET_ID).orElse(null);
571+
if (set == null) {
572+
set = markerApi.createMarkerSet(DEFAULT_MARKER_SET_ID);
573+
set.setLabel("Markers");
574+
}
575+
576+
if (set.getMarker(markerId).isPresent()) {
577+
source.sendMessage(Text.of(TextColor.RED, "There already is a marker with this id: ", TextColor.WHITE, markerId));
578+
return 0;
579+
}
580+
581+
POIMarker marker = set.createPOIMarker(markerId, apiMap.get(), position);
582+
marker.setLabel(markerLabel);
583+
584+
markerApi.save();
585+
MarkerIdSuggestionProvider.getInstance().forceUpdate();
586+
} catch (IOException e) {
587+
source.sendMessage(Text.of(TextColor.RED, "There was an error trying to add the marker, please check the console for details!"));
588+
Logger.global.logError("Exception trying to add a marker!", e);
589+
}
590+
591+
source.sendMessage(Text.of(TextColor.GREEN, "Marker added!"));
592+
return 1;
593+
}
594+
595+
public int removeMarkerCommand(CommandContext<S> context) {
596+
CommandSource source = commandSourceInterface.apply(context.getSource());
597+
598+
String markerId = context.getArgument("id", String.class);
599+
600+
BlueMapAPI api = BlueMapAPI.getInstance().orElse(null);
601+
if (api == null) {
602+
source.sendMessage(Text.of(TextColor.RED, "MarkerAPI is not available, try ", TextColor.GRAY, "/bluemap reload"));
603+
return 0;
604+
}
605+
606+
try {
607+
MarkerAPI markerApi = api.getMarkerAPI();
608+
609+
MarkerSet set = markerApi.createMarkerSet("markers");
610+
if (!set.removeMarker(markerId)) {
611+
source.sendMessage(Text.of(TextColor.RED, "There is no marker with this id: ", TextColor.WHITE, markerId));
612+
}
613+
614+
markerApi.save();
615+
MarkerIdSuggestionProvider.getInstance().forceUpdate();
616+
} catch (IOException e) {
617+
source.sendMessage(Text.of(TextColor.RED, "There was an error trying to remove the marker, please check the console for details!"));
618+
Logger.global.logError("Exception trying to remove a marker!", e);
619+
}
620+
621+
source.sendMessage(Text.of(TextColor.GREEN, "Marker removed!"));
622+
return 1;
623+
}
624+
457625
}

0 commit comments

Comments
 (0)