Fix world render argument parsing and catch an uncaught error

This commit is contained in:
Blue (Lukas Rieger) 2019-11-12 18:41:40 +01:00
parent f570c2088e
commit 8c90b3a38e
2 changed files with 12 additions and 4 deletions

View File

@ -33,6 +33,7 @@ import java.io.RandomAccessFile;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@ -44,6 +45,7 @@ import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Multimap;
import com.google.common.collect.MultimapBuilder;
import com.google.common.util.concurrent.UncheckedExecutionException;
import de.bluecolored.bluemap.core.logger.Logger;
import de.bluecolored.bluemap.core.mca.extensions.BlockStateExtension;
@ -196,7 +198,7 @@ public class MCAWorld implements World {
Chunk chunk = CHUNK_CACHE.get(new WorldChunkHash(this, chunkPos), () -> this.loadChunk(chunkPos));
if (!chunk.isGenerated()) throw new ChunkNotGeneratedException();
return chunk;
} catch (ExecutionException e) {
} catch (UncheckedExecutionException | ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof IOException) {
@ -261,6 +263,8 @@ public class MCAWorld implements World {
public Collection<Vector2i> getChunkList(long modifiedSinceMillis){
List<Vector2i> chunks = new ArrayList<>(10000);
if (!getRegionFolder().toFile().isDirectory()) return Collections.emptyList();
for (File file : getRegionFolder().toFile().listFiles()) {
if (!file.getName().endsWith(".mca")) continue;

View File

@ -20,6 +20,7 @@ import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.storage.WorldProperties;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3i;
@ -150,11 +151,14 @@ public class Commands {
.child(createRemoveTaskCommand(), "remove")
.arguments(GenericArguments.optional(GenericArguments.world(Text.of("world"))))
.executor((source, args) -> {
org.spongepowered.api.world.World spongeWorld = args.<org.spongepowered.api.world.World>getOne("world").orElse(null);
WorldProperties spongeWorld = args.<WorldProperties>getOne("world").orElse(null);
if (spongeWorld == null && source instanceof Locatable) {
Location<org.spongepowered.api.world.World> loc = ((Locatable) source).getLocation();
spongeWorld = loc.getExtent();
} else {
spongeWorld = loc.getExtent().getProperties();
}
if (spongeWorld == null){
source.sendMessage(Text.of(TextColors.RED, "You have to define a world to render!"));
return CommandResult.empty();
}