Skip to content

Commit

Permalink
use try/catch to handle any bad config values for entities
Browse files Browse the repository at this point in the history
  • Loading branch information
msudol committed Jan 16, 2020
1 parent cbfe358 commit c36db04
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/com/pwn9/PwnChickenLay/PwnChickenLayEggDrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
import org.bukkit.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.World;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Item;
import org.bukkit.event.EventHandler;
Expand Down Expand Up @@ -300,13 +298,26 @@ public void doReplacement(World eworld, Location eLoc, String randomReplacement

eworld.dropItem(eLoc, getSpecial);
}

// interface to spawn an entity rather than a material
//TODO: add enum from config check
else if (randomReplacement.startsWith("e_"))
{
EntityType e = EntityType.valueOf(randomReplacement.substring(2));
// so this is a bit hacky, still I want primed_tnt
eworld.spawnEntity(eLoc, e);
try
{
eworld.spawnEntity(eLoc, e);
}
catch (IllegalArgumentException err)
{
if (PwnChickenLay.logEnabled)
{
PwnChickenLay.logToFile("Tried to lay invalid entity: " + randomReplacement.substring(2) + " - check your config for invalid values.");
}
}
}

// if not a special item, then is a standard drop
else if ((Material.getMaterial(randomReplacement) != Material.AIR) && (Material.getMaterial(randomReplacement) != null))
{
Expand Down

0 comments on commit c36db04

Please sign in to comment.