Code smell reduction.

This commit is contained in:
tastybento 2021-03-28 20:59:51 -07:00
parent c9371ab859
commit 1e962f93d0
4 changed files with 28 additions and 25 deletions

View File

@ -231,7 +231,7 @@ public class Boxed extends GameModeAddon {
if (id != null && id.equals("delete")) {
return delChunks;
}
return worldName.endsWith("_nether") ? netherChunkGenerator : chunkGenerator;
return worldName.endsWith(NETHER) ? netherChunkGenerator : chunkGenerator;
}
@Override

View File

@ -25,7 +25,7 @@ import world.bentobox.boxed.Boxed;
* @author tastybento
*
*/
public abstract class AbstractBoxedBiomeGenerator implements BiomeGenerator {
abstract class AbstractBoxedBiomeGenerator implements BiomeGenerator {
private static final Map<Environment, String> ENV_MAP;
static {
@ -77,24 +77,25 @@ public abstract class AbstractBoxedBiomeGenerator implements BiomeGenerator {
private SortedMap<Double, Biome> loadQuad(YamlConfiguration config, String string) {
SortedMap<Double, Biome> result = new TreeMap<>();
if (config.contains(string)) {
for (String ring : config.getStringList(string)) {
String[] split = ring.split(":");
if (split.length == 2 && NumberUtils.isNumber(split[0])) {
try {
double d = Double.parseDouble(split[0]);
Biome biome = Enums.getIfPresent(Biome.class, split[1].toUpperCase(Locale.ENGLISH)).orNull();
if (biome == null) {
addon.logError(split[1].toUpperCase(Locale.ENGLISH) + " is an unknown biome on this server.");
} else {
result.put(d, biome);
}
} catch(Exception e) {
addon.logError(string + ": " + split[0] + " does not seem to be a double. For integers add a .0 to the end");
if (!config.contains(string)) {
return result;
}
for (String ring : config.getStringList(string)) {
String[] split = ring.split(":");
if (split.length == 2 && NumberUtils.isNumber(split[0])) {
try {
double d = Double.parseDouble(split[0]);
Biome biome = Enums.getIfPresent(Biome.class, split[1].toUpperCase(Locale.ENGLISH)).orNull();
if (biome == null) {
addon.logError(split[1].toUpperCase(Locale.ENGLISH) + " is an unknown biome on this server.");
} else {
result.put(d, biome);
}
} else {
addon.logError(ring + " must be in the format ratio:biome where ratio is a double.");
} catch(Exception e) {
addon.logError(string + ": " + split[0] + " does not seem to be a double. For integers add a .0 to the end");
}
} else {
addon.logError(ring + " must be in the format ratio:biome where ratio is a double.");
}
}
return result;

View File

@ -23,7 +23,8 @@ import world.bentobox.boxed.Boxed;
*/
public class NetherGenerator implements BaseNoiseGenerator {
private final BiomeNoise DEFAULT_NOISE = new BiomeNoise(10D, 0D, 2D);
private static final String NETHER_BIOMES = "nether.biomes";
private final BiomeNoise defaultNoise = new BiomeNoise(10D, 0D, 2D);
private final NoiseGenerator mainNoiseGenerator;
private final Boxed addon;
private final YamlConfiguration config;
@ -41,11 +42,11 @@ public class NetherGenerator implements BaseNoiseGenerator {
}
config = YamlConfiguration.loadConfiguration(biomeFile);
biomeNoiseMap = new EnumMap<>(Biome.class);
if (config.isConfigurationSection("nether.biomes")) {
for (String key : config.getConfigurationSection("nether.biomes").getKeys(false)) {
double noiseScaleHorizontal = config.getDouble("nether.biomes." + key + ".scale", 10D);
double height = config.getDouble("nether.biomes." + key + ".height", 0D);
double noiseScaleVertical = config.getDouble("nether.biomes." + key + ".vscale", 2D);
if (config.isConfigurationSection(NETHER_BIOMES)) {
for (String key : config.getConfigurationSection(NETHER_BIOMES).getKeys(false)) {
double noiseScaleHorizontal = config.getDouble(NETHER_BIOMES + "." + key + ".scale", 10D);
double height = config.getDouble(NETHER_BIOMES + "." + key + ".height", 0D);
double noiseScaleVertical = config.getDouble(NETHER_BIOMES + "." + key + ".vscale", 2D);
Enums.getIfPresent(Biome.class, key).toJavaUtil()
.ifPresent(biome -> biomeNoiseMap.put(biome, new BiomeNoise(noiseScaleHorizontal, height, noiseScaleVertical)));
}
@ -92,7 +93,7 @@ public class NetherGenerator implements BaseNoiseGenerator {
// edge of island
biome = Biome.NETHER_WASTES;
}
BiomeNoise bm = this.biomeNoiseMap.getOrDefault(biome, DEFAULT_NOISE);
BiomeNoise bm = this.biomeNoiseMap.getOrDefault(biome, defaultNoise);
double x = ((((double)scaledX*4) % dist) / 4) / bm.noiseScaleHorizontal;
double z = ((((double)scaledZ*4) % dist) / 4) / bm.noiseScaleHorizontal;
for (int y = 0; y < 16; y++) {

View File

@ -235,6 +235,7 @@ public class AdvancementListener implements Listener {
user.getPlayer().setStatistic(s, m, 0);
}
}
break;
case ITEM:
for (Material m: Material.values()) {
if (m.isItem() && !m.isLegacy()) {