Skip to content

Commit

Permalink
Null pointer fix (section config)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nik authored and Nik committed Dec 7, 2017
1 parent ca065f0 commit 3a7920d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/github/niketion/petfaction/SpawnEntity.java
Expand Up @@ -2,6 +2,7 @@

import github.niketion.petfaction.file.FilePet;
import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -56,7 +57,8 @@ public void onSpawn(CreatureSpawnEvent event){

void spawn() {
force = false;
try {
//try {

FileConfiguration config = main.getConfig();
FileConfiguration petConfig = new FilePet(player).getPetConfig();
World worldPlayer = player.getWorld();
Expand Down Expand Up @@ -89,10 +91,13 @@ void spawn() {
for (PotionEffect effect : player.getActivePotionEffects())
player.removePotionEffect(effect.getType());

for (String strings : petConfig.getConfigurationSection("potion-pet").getKeys(false)) {
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(strings), config.getInt("duration-potion-pet") * 60 * 20,
petConfig.getInt("potion-pet." + strings) - 1));
}
ConfigurationSection sectionPotion = petConfig.getConfigurationSection("potion-pet");

if (sectionPotion != null)
for (String strings : sectionPotion.getKeys(false))
player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(strings), config.getInt("duration-potion-pet") * 60 * 20,
petConfig.getInt("potion-pet." + strings) - 1));

}

if (namePet != null) {
Expand All @@ -104,7 +109,7 @@ void spawn() {
entity.setMetadata(player.getName(), new FixedMetadataValue(Main.getInstance(), "yes!"));

main.getPetFollow(player, entity);
} catch (NullPointerException ignored) {}
//} catch (NullPointerException ignored) {}
force = true;
}
}

0 comments on commit 3a7920d

Please sign in to comment.