-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring: use Terra-- when possible (#13)
* Refactor generation offsets. Terra-- already has the capabilities to deal with offsets, we can rely on it to make the generation code cleaner. * Generate terrain noise in the dedicated method * Refactor surface generation * Do not generate grass underground * Implement RealWorldGenerator#getBaseHeight()
- Loading branch information
Showing
2 changed files
with
180 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/de/btegermany/terraplusminus/utils/ConfigurationHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package de.btegermany.terraplusminus.utils; | ||
|
||
import de.btegermany.terraplusminus.Terraplusminus; | ||
import org.bukkit.Material; | ||
import org.bukkit.configuration.file.FileConfiguration; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public final class ConfigurationHelper { | ||
|
||
/** | ||
* Returns a material from the configuration, | ||
* or a default value if the configuration path is either missing or the value is not a valid material identifier. | ||
* | ||
* @param config the configuration file to read from | ||
* @param path the configuration path to retrieve | ||
* @param defaultValue a default value to return if the value is missing from the config or invalid | ||
* @return a {@link Material} from the configuration, or {@code defaultValue} as a fallback | ||
*/ | ||
public static Material getMaterial(@NotNull FileConfiguration config, @NotNull String path, Material defaultValue) { | ||
String materialName = config.getString(path); | ||
if (materialName == null) { | ||
return defaultValue; | ||
} | ||
Material material = Material.getMaterial(materialName); | ||
if (material == null) { | ||
return defaultValue; | ||
} | ||
return material; | ||
} | ||
|
||
private ConfigurationHelper() { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
} |