I want have a lobby world. I want this lobby world can be change in the config.yml. To load this world, I need to use the command:
WorldCreator lobby = new WorldCreator("MyLobbyWorldName");
Bukkit.createWorld(lobby);
Problem, my current lobby is in the end. So I need to do this:
WorldCreator lobby = new WorldCreator("MyLobbyWorldName");
lobby.environment(World.Environment.THE_END);
Bukkit.createWorld(lobby);
So to put this in my config.yml, I need to put "MyLobbyWorldName" and "World.Environment.THE_END" in my config.yml.
I can put "MyLobbyWorldName" in the config.yml easily.
WorldCreator lobby = new WorldCreator(getConfig().getString("lobby.world.name"));
lobby.environment(World.Environment.THE_END);
Bukkit.createWorld(lobby);
But I don't now how to formulate the "World.Environment.THE_END" in the config.yml file and how to put it back in the code. Now I have that:
WorldCreator lobby = new WorldCreator(getConfig().getString("lobby.world.name"));
lobby.environment((World.Environment) getConfig().get("lobby.world.environement"));
Bukkit.createWorld(lobby);
but I have an "org.bukkit.configuration.InvalidConfigurationException: could not determine a constructor for the tag tag:yaml.org,2002:org.bukkit.World$Environment in 'string', line 9, column 19: environement: !!org.bukkit.World$Environment ' ..." error.
In the config, it's easy to manage enum as World.Environment
:
myEnum.name()
to put in config with getConfig().set("lobby.world.environement", lobby.environment().name())
THE_END
with World.Environment.valueOf(getConfig().getString("lobby.world.environement"))
With that, you will only have simple string in config. Before using Enum#valueOf
, you can check if it exists or try/catch for exception if user entered wrong input.