Add getAvailableWorldGenerators method to WorldManager,

This commit is contained in:
benwoo1110 2021-01-08 10:24:51 +08:00
parent 835ca69b78
commit e2bf1a2bbe
2 changed files with 23 additions and 0 deletions

View File

@ -158,6 +158,13 @@ public interface MVWorldManager {
*/
ChunkGenerator getChunkGenerator(String generator, String generatorID, String worldName);
/**
* Get possible generator plugins.
*
* @return A list of plugin names that is detected to have a chunk generator.
*/
List<String> getAvailableWorldGenerators();
/**
* Returns a list of all the worlds Multiverse knows about.
*

View File

@ -51,6 +51,7 @@ import java.util.Stack;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Public facing API to add/remove Multiverse worlds.
@ -104,6 +105,21 @@ public class WorldManager implements MVWorldManager {
}
}
/**
* {@inheritDoc}
*/
public List<String> getAvailableWorldGenerators() {
return Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins())
.filter(Plugin::isEnabled)
.filter(plugin -> this.plugin.getUnsafeCallWrapper().wrap(
() -> plugin.getDefaultWorldGenerator("world", ""),
plugin.getName(),
"Get generator"
) != null)
.map(plugin -> plugin.getDescription().getName())
.collect(Collectors.toList());
}
/**
* {@inheritDoc}
* @deprecated Use {@link #cloneWorld(String, String)} instead.