Implement getPotentialWorlds

This commit is contained in:
Ben Woo 2023-09-05 15:54:51 +08:00
parent 80ff02a92b
commit fda0e038f5
No known key found for this signature in database
GPG Key ID: FB2A3645536E12C8
2 changed files with 13 additions and 1 deletions

View File

@ -141,7 +141,7 @@ public class MVCommandCompletions extends PaperCommandCompletions {
.toList();
}
case "potential" -> {
return Collections.emptyList(); // TODO: Implement getPotentialWorlds
return worldManager.getPotentialWorlds();
}
}
Logging.severe("Invalid MVWorld scope: " + scope);

View File

@ -29,7 +29,9 @@ import org.jvnet.hk2.annotations.Service;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -343,6 +345,16 @@ public class WorldManager {
return Result.success(DeleteWorldResult.Success.DELETED);
}
public List<String> getPotentialWorlds() {
File[] files = Bukkit.getWorldContainer().listFiles();
if (files == null) {
return Collections.emptyList();
}
return Arrays.stream(files).filter(worldNameChecker::isValidWorldFolder)
.map(File::getName)
.toList();
}
public Option<OfflineWorld> getOfflineOnlyWorld(@Nullable String worldName) {
return isMVWorld(worldName) ? Option.none() : Option.of(offlineWorldsMap.get(worldName));
}