Skip to content

Commit

Permalink
setup config for custom chicken names and an easter egg i may reveal …
Browse files Browse the repository at this point in the history
…at a later date after some error checking
  • Loading branch information
msudol committed Jan 3, 2020
1 parent 1d7e815 commit cbfe358
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
1 change: 1 addition & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ perWorld:
GOLD_INGOT: 1
AIR: 10

# Named chickens can lay eggs or replacements as well. Named chickens do not have per biome settings.
custom:
Clucky:
enabled: true
Expand Down
53 changes: 50 additions & 3 deletions src/com/pwn9/PwnChickenLay/PwnChickenLayEggDrop.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 @@ -58,6 +59,40 @@ public void onDrop(EntityDropItemEvent event)

if (chic.getCustomName() != null) {
PwnChickenLay.logToFile("Egg spawn event was from custom chicken: " + chic.getCustomName());

// if there is a config for this custom name
if (plugin.getConfig().getBoolean("custom."+chic.getCustomName()+".enabled"))
{
PwnChickenLay.logToFile("Config is set for custom chicken: " + chic.getCustomName());

if (PwnChickenLay.random(plugin.getConfig().getInt("custom."+chic.getCustomName()+".layChance")))
{

List<String> repWith = new ArrayList<String>();

for (String key : plugin.getConfig().getConfigurationSection("custom."+chic.getCustomName()+".replaceWith").getKeys(false))
{
Integer loop = plugin.getConfig().getInt("custom."+chic.getCustomName()+".replaceWith."+key, 1);
for (int x = 0; x < loop; x = x+1)
{
repWith.add(key);
}
}

// Pick an item from the replacement list randomly
String randomReplacement = repWith.get(PwnChickenLay.randomNumberGenerator.nextInt(repWith.size()));

// Cancel event and remove the egg
event.getItemDrop().remove();
event.setCancelled(true);

// doReplacement func
this.doReplacement(eworld, eLoc, randomReplacement);

return;
}
}

}

// check per world settings
Expand Down Expand Up @@ -92,7 +127,9 @@ public void onDrop(EntityDropItemEvent event)
event.setCancelled(true);

// doReplacement func
this.doReplacement(eworld, eLoc, randomReplacement);
this.doReplacement(eworld, eLoc, randomReplacement);

return;

}
else
Expand Down Expand Up @@ -128,7 +165,9 @@ public void onDrop(EntityDropItemEvent event)
event.setCancelled(true);

// doReplacement func
this.doReplacement(eworld, eLoc, randomReplacement);
this.doReplacement(eworld, eLoc, randomReplacement);

return;

}
else
Expand Down Expand Up @@ -164,6 +203,8 @@ else if (PwnChickenLay.random(PwnChickenLay.layChance))
// doReplacement func
this.doReplacement(eworld, eLoc, randomReplacement);

return;

}
else
{
Expand Down Expand Up @@ -259,7 +300,13 @@ public void doReplacement(World eworld, Location eLoc, String randomReplacement

eworld.dropItem(eLoc, getSpecial);
}

// interface to spawn an entity rather than a material
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);
}
// 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 cbfe358

Please sign in to comment.