Fix world render argument parsing and catch an uncaught error
This commit is contained in:
parent
f570c2088e
commit
8c90b3a38e
|
@ -33,6 +33,7 @@ import java.io.RandomAccessFile;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -44,6 +45,7 @@ import com.google.common.cache.Cache;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.collect.Multimap;
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.collect.MultimapBuilder;
|
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.logger.Logger;
|
||||||
import de.bluecolored.bluemap.core.mca.extensions.BlockStateExtension;
|
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));
|
Chunk chunk = CHUNK_CACHE.get(new WorldChunkHash(this, chunkPos), () -> this.loadChunk(chunkPos));
|
||||||
if (!chunk.isGenerated()) throw new ChunkNotGeneratedException();
|
if (!chunk.isGenerated()) throw new ChunkNotGeneratedException();
|
||||||
return chunk;
|
return chunk;
|
||||||
} catch (ExecutionException e) {
|
} catch (UncheckedExecutionException | ExecutionException e) {
|
||||||
Throwable cause = e.getCause();
|
Throwable cause = e.getCause();
|
||||||
|
|
||||||
if (cause instanceof IOException) {
|
if (cause instanceof IOException) {
|
||||||
|
@ -261,6 +263,8 @@ public class MCAWorld implements World {
|
||||||
public Collection<Vector2i> getChunkList(long modifiedSinceMillis){
|
public Collection<Vector2i> getChunkList(long modifiedSinceMillis){
|
||||||
List<Vector2i> chunks = new ArrayList<>(10000);
|
List<Vector2i> chunks = new ArrayList<>(10000);
|
||||||
|
|
||||||
|
if (!getRegionFolder().toFile().isDirectory()) return Collections.emptyList();
|
||||||
|
|
||||||
for (File file : getRegionFolder().toFile().listFiles()) {
|
for (File file : getRegionFolder().toFile().listFiles()) {
|
||||||
if (!file.getName().endsWith(".mca")) continue;
|
if (!file.getName().endsWith(".mca")) continue;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.spongepowered.api.text.action.TextActions;
|
||||||
import org.spongepowered.api.text.format.TextColors;
|
import org.spongepowered.api.text.format.TextColors;
|
||||||
import org.spongepowered.api.world.Locatable;
|
import org.spongepowered.api.world.Locatable;
|
||||||
import org.spongepowered.api.world.Location;
|
import org.spongepowered.api.world.Location;
|
||||||
|
import org.spongepowered.api.world.storage.WorldProperties;
|
||||||
|
|
||||||
import com.flowpowered.math.vector.Vector2i;
|
import com.flowpowered.math.vector.Vector2i;
|
||||||
import com.flowpowered.math.vector.Vector3i;
|
import com.flowpowered.math.vector.Vector3i;
|
||||||
|
@ -150,11 +151,14 @@ public class Commands {
|
||||||
.child(createRemoveTaskCommand(), "remove")
|
.child(createRemoveTaskCommand(), "remove")
|
||||||
.arguments(GenericArguments.optional(GenericArguments.world(Text.of("world"))))
|
.arguments(GenericArguments.optional(GenericArguments.world(Text.of("world"))))
|
||||||
.executor((source, args) -> {
|
.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) {
|
if (spongeWorld == null && source instanceof Locatable) {
|
||||||
Location<org.spongepowered.api.world.World> loc = ((Locatable) source).getLocation();
|
Location<org.spongepowered.api.world.World> loc = ((Locatable) source).getLocation();
|
||||||
spongeWorld = loc.getExtent();
|
spongeWorld = loc.getExtent().getProperties();
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
if (spongeWorld == null){
|
||||||
source.sendMessage(Text.of(TextColors.RED, "You have to define a world to render!"));
|
source.sendMessage(Text.of(TextColors.RED, "You have to define a world to render!"));
|
||||||
return CommandResult.empty();
|
return CommandResult.empty();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue