Skip to content

Commit 0535a29

Browse files
committed
Command and world-name improvements
1 parent acaff30 commit 0535a29

File tree

10 files changed

+131
-10
lines changed

10 files changed

+131
-10
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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.util.Collection;
2828
import java.util.concurrent.CompletableFuture;
29+
import java.util.regex.Pattern;
2930

3031
import com.mojang.brigadier.context.CommandContext;
3132
import com.mojang.brigadier.exceptions.CommandSyntaxException;
@@ -35,13 +36,19 @@
3536

3637
public abstract class AbstractSuggestionProvider<S> implements SuggestionProvider<S> {
3738

39+
private static final Pattern ESCAPE_PATTERN = Pattern.compile("[^a-zA-Z0-9_-]");
40+
3841
@Override
3942
public CompletableFuture<Suggestions> getSuggestions(CommandContext<S> context, SuggestionsBuilder builder) throws CommandSyntaxException {
4043
Collection<String> possibleValues = getPossibleValues();
4144
if(possibleValues.isEmpty()) return Suggestions.empty();
4245

4346
String remaining = builder.getRemaining().toLowerCase();
4447
for (String str : possibleValues) {
48+
if (ESCAPE_PATTERN.matcher(str).find() && str.indexOf('"') == -1) {
49+
str = "\"" + str + "\"";
50+
}
51+
4552
if (str.toLowerCase().startsWith(remaining)) {
4653
builder.suggest(str);
4754
}

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

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void init() {
9595
.requires(requirements("bluemap.debug"))
9696
.executes(this::debugCommand)
9797

98-
.then(argument("world", StringArgumentType.word()).suggests(new WorldSuggestionProvider<>(plugin))
98+
.then(argument("world", StringArgumentType.string()).suggests(new WorldSuggestionProvider<>(plugin))
9999
.then(argument("x", DoubleArgumentType.doubleArg())
100100
.then(argument("y", DoubleArgumentType.doubleArg())
101101
.then(argument("z", DoubleArgumentType.doubleArg())
@@ -135,7 +135,7 @@ public void init() {
135135
)
136136
)
137137

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

141141
.then(argument("x", DoubleArgumentType.doubleArg())
@@ -152,19 +152,31 @@ public void init() {
152152
LiteralCommandNode<S> prioRenderCommand =
153153
literal("prioritize")
154154
.requires(requirements("bluemap.render"))
155-
.then(argument("uuid", StringArgumentType.word())
155+
.then(argument("uuid", StringArgumentType.string())
156156
.executes(this::prioritizeRenderTaskCommand)
157157
)
158158
.build();
159159

160160
LiteralCommandNode<S> cancelRenderCommand =
161161
literal("cancel")
162162
.requires(requirements("bluemap.render"))
163-
.then(argument("uuid", StringArgumentType.word())
163+
.then(argument("uuid", StringArgumentType.string())
164164
.executes(this::cancelRenderTaskCommand)
165165
)
166166
.build();
167167

168+
LiteralCommandNode<S> worldsCommand =
169+
literal("worlds")
170+
.requires(requirements("bluemap.status"))
171+
.executes(this::worldsCommand)
172+
.build();
173+
174+
LiteralCommandNode<S> mapsCommand =
175+
literal("maps")
176+
.requires(requirements("bluemap.status"))
177+
.executes(this::mapsCommand)
178+
.build();
179+
168180
// command tree
169181
dispatcher.getRoot().addChild(baseCommand);
170182
baseCommand.addChild(reloadCommand);
@@ -174,6 +186,8 @@ public void init() {
174186
baseCommand.addChild(renderCommand);
175187
renderCommand.addChild(prioRenderCommand);
176188
renderCommand.addChild(cancelRenderCommand);
189+
baseCommand.addChild(worldsCommand);
190+
baseCommand.addChild(mapsCommand);
177191
}
178192

179193
private Predicate<S> requirements(String permission){
@@ -454,4 +468,27 @@ public int cancelRenderTaskCommand(CommandContext<S> context) {
454468
source.sendMessage(Text.of(TextColor.RED, "There is no render-task with this UUID: " + uuidString));
455469
return 0;
456470
}
471+
472+
public int worldsCommand(CommandContext<S> context) {
473+
CommandSource source = commandSourceInterface.apply(context.getSource());
474+
475+
source.sendMessage(Text.of(TextColor.BLUE, "Worlds loaded by BlueMap:"));
476+
for (World world : plugin.getWorlds()) {
477+
source.sendMessage(Text.of(TextColor.GRAY, " - ", TextColor.WHITE, world.getName()).setHoverText(Text.of(TextColor.GRAY, world.getUUID())));
478+
}
479+
480+
return 1;
481+
}
482+
483+
public int mapsCommand(CommandContext<S> context) {
484+
CommandSource source = commandSourceInterface.apply(context.getSource());
485+
486+
source.sendMessage(Text.of(TextColor.BLUE, "Maps loaded by BlueMap:"));
487+
for (MapType map : plugin.getMapTypes()) {
488+
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())));
489+
}
490+
491+
return 1;
492+
}
493+
457494
}

BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/plugin/serverinterface/ServerInterface.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ public interface ServerInterface {
5050
*/
5151
UUID getUUIDForWorld(File worldFolder) throws IOException;
5252

53+
/**
54+
* Returns the name of the world with that UUID, the name is used in commands and should therefore be unique.<br>
55+
* A return-value of <code>null</code> makes bluemap load the world-name from the level.dat and dimension-folder.
56+
*
57+
* @param worldUUID the uuid of the world
58+
* @return the worlds name
59+
*/
60+
default String getWorldName(UUID worldUUID) {
61+
return null;
62+
}
63+
5364
/**
5465
* Returns the Folder containing the configurations for the plugin
5566
*/

BlueMapCore/src/main/java/de/bluecolored/bluemap/core/mca/MCAWorld.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,11 +377,18 @@ private Path getRegionFolder() {
377377
private Path getMCAFilePath(Vector2i region) {
378378
return getRegionFolder().resolve(MCAUtil.createNameFromRegionLocation(region.getX(), region.getY()));
379379
}
380-
380+
381381
public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper) throws IOException {
382+
return load(worldFolder, uuid, blockIdMapper, blockPropertiesMapper, biomeIdMapper, null);
383+
}
384+
385+
public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMapper, BlockPropertiesMapper blockPropertiesMapper, BiomeMapper biomeIdMapper, String name) throws IOException {
382386
try {
387+
boolean subDimension = false;
388+
383389
File levelFile = new File(worldFolder.toFile(), "level.dat");
384390
if (!levelFile.exists()) {
391+
subDimension = true;
385392
levelFile = new File(worldFolder.toFile().getParentFile(), "level.dat");
386393
if (!levelFile.exists()) {
387394
throw new FileNotFoundException("Could not find a level.dat file for this world!");
@@ -391,7 +398,11 @@ public static MCAWorld load(Path worldFolder, UUID uuid, BlockIdMapper blockIdMa
391398
CompoundTag level = (CompoundTag) NBTUtil.readTag(levelFile);
392399
CompoundTag levelData = level.getCompoundTag("Data");
393400

394-
String name = levelData.getString("LevelName");
401+
if (name == null) {
402+
name = levelData.getString("LevelName");
403+
if (subDimension) name += "/" + worldFolder.toFile().getName();
404+
}
405+
395406
int worldHeight = 255;
396407
int seaLevel = 63;
397408
Vector3i spawnPoint = new Vector3i(

BlueMapForge/src/main/java/de/bluecolored/bluemap/forge/ForgeCommandSource.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,28 @@
2424
*/
2525
package de.bluecolored.bluemap.forge;
2626

27+
import java.io.IOException;
28+
import java.util.Optional;
29+
30+
import com.flowpowered.math.vector.Vector3d;
31+
32+
import de.bluecolored.bluemap.common.plugin.Plugin;
2733
import de.bluecolored.bluemap.common.plugin.serverinterface.CommandSource;
2834
import de.bluecolored.bluemap.common.plugin.text.Text;
35+
import de.bluecolored.bluemap.core.world.World;
36+
import net.minecraft.util.math.Vec3d;
2937
import net.minecraft.util.text.ITextComponent;
38+
import net.minecraft.world.server.ServerWorld;
3039

3140
public class ForgeCommandSource implements CommandSource {
3241

42+
private ForgeMod mod;
43+
private Plugin plugin;
3344
private net.minecraft.command.CommandSource delegate;
3445

35-
public ForgeCommandSource(net.minecraft.command.CommandSource delegate) {
46+
public ForgeCommandSource(ForgeMod mod, Plugin plugin, net.minecraft.command.CommandSource delegate) {
47+
this.mod = mod;
48+
this.plugin = plugin;
3649
this.delegate = delegate;
3750
}
3851

@@ -46,4 +59,26 @@ public boolean hasPermission(String permission) {
4659
return delegate.hasPermissionLevel(1);
4760
}
4861

62+
@Override
63+
public Optional<Vector3d> getPosition() {
64+
Vec3d pos = delegate.getPos();
65+
if (pos != null) {
66+
return Optional.of(new Vector3d(pos.x, pos.y, pos.z));
67+
}
68+
69+
return Optional.empty();
70+
}
71+
72+
@Override
73+
public Optional<World> getWorld() {
74+
try {
75+
ServerWorld world = delegate.getWorld();
76+
if (world != null) {
77+
return Optional.ofNullable(plugin.getWorld(mod.getUUIDForWorld(world)));
78+
}
79+
} catch (IOException ignore) {}
80+
81+
return Optional.empty();
82+
}
83+
4984
}

BlueMapForge/src/main/java/de/bluecolored/bluemap/forge/ForgeMod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void onServerStarting(FMLServerStartingEvent event) {
8888
}
8989

9090
//register commands
91-
this.commands = new Commands<>(bluemap, event.getCommandDispatcher(), ForgeCommandSource::new);
91+
this.commands = new Commands<>(bluemap, event.getCommandDispatcher(), forgeSource -> new ForgeCommandSource(this, bluemap, forgeSource));
9292

9393
new Thread(() -> {
9494
try {

BlueMapSponge/src/main/java/de/bluecolored/bluemap/sponge/SpongePlugin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.File;
2828
import java.io.IOException;
2929
import java.nio.file.Path;
30+
import java.util.Optional;
3031
import java.util.UUID;
3132

3233
import javax.inject.Inject;
@@ -39,6 +40,7 @@
3940
import org.spongepowered.api.event.game.state.GameStartingServerEvent;
4041
import org.spongepowered.api.event.game.state.GameStoppingEvent;
4142
import org.spongepowered.api.scheduler.SpongeExecutorService;
43+
import org.spongepowered.api.world.World;
4244
import org.spongepowered.api.world.storage.WorldProperties;
4345

4446
import de.bluecolored.bluemap.common.plugin.Plugin;
@@ -145,6 +147,14 @@ public UUID getUUIDForWorld(File worldFolder) throws IOException {
145147
throw new IOException("Failed to read level_sponge.dat", t);
146148
}
147149
}
150+
151+
@Override
152+
public String getWorldName(UUID worldUUID) {
153+
Optional<World> world = Sponge.getServer().getWorld(worldUUID);
154+
if (world.isPresent()) return world.get().getName();
155+
156+
return null;
157+
}
148158

149159
@Override
150160
public File getConfigFolder() {

0 commit comments

Comments
 (0)