Using configured settings within your plugin
The current EventHandler method
of the MobEnhancer
plugin sets the health of zombies to 40
, where the number 40 is
hardcoded. This means that the value of 40
is a part of the code itself, and this cannot be changed after the code is compiled. We wish to make this value
softcoded, that is, we want to retrieve the value from an external source, which is config.yml
in our case:
Currently, the onMobSpawn
method is as follows:
@EventHandler public void onMobSpawn(CreatureSpawnEvent event) { if (event.getEntityType() == EntityType.ZOMBIE) { int health = 40; event.getEntity().setMaxHealth(health); event.getEntity().setHealth(health); } }
We will work from this existing code. The if
statement is no longer needed, because we don't want to limit the plugin to zombies only. As discussed earlier, we also want to replace the hardcoded 40 value
with a double
value, which will be read from the config
file. Therefore, 40
should...