From faa261de243b8488d922cc010170b93750e1bcd8 Mon Sep 17 00:00:00 2001 From: shansen Date: Sat, 12 Mar 2016 02:34:04 +0100 Subject: [PATCH] Added DeleteVillagerInventoryOnCatch option. --- src/main/java/me/shansen/EggCatcher/EggCatcher.java | 7 ++++++- .../EggCatcher/listeners/EggCatcherEntityListener.java | 5 ++++- src/main/resources/config.yml | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/shansen/EggCatcher/EggCatcher.java b/src/main/java/me/shansen/EggCatcher/EggCatcher.java index d50e38d..3ee4f09 100644 --- a/src/main/java/me/shansen/EggCatcher/EggCatcher.java +++ b/src/main/java/me/shansen/EggCatcher/EggCatcher.java @@ -64,9 +64,14 @@ public class EggCatcher extends JavaPlugin { public void CheckConfigurationFile() { double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0); - if (configVersion == 2.2) { + if (configVersion == 2.5) { // this.saveConfig(); + } else if (configVersion == 2.2) { + this.getConfig().set("DeleteVillagerInventoryOnCatch", false); + + this.getConfig().set("ConfigVersion", 2.5); + this.saveConfig(); } else if (configVersion == 2.0) { this.getConfig().set("CatchChance.Endermite", 100.0); this.getConfig().set("VaultCost.Endermite", 0); diff --git a/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java b/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java index b087285..5154b7f 100644 --- a/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java +++ b/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java @@ -57,6 +57,7 @@ public class EggCatcherEntityListener implements Listener { private final String vaultTargetBankAccount; private final boolean spawnChickenOnFail; private final boolean spawnChickenOnSuccess; + private final boolean deleteVillagerInventoryOnCatch; FileConfiguration config; JavaPlugin plugin; @@ -81,6 +82,7 @@ public class EggCatcherEntityListener implements Listener { this.spawnChickenOnFail = this.config.getBoolean("SpawnChickenOnFail", true); this.spawnChickenOnSuccess = this.config.getBoolean("SpawnChickenOnSuccess", false); this.vaultTargetBankAccount = this.config.getString("VaultTargetBankAccount", ""); + this.deleteVillagerInventoryOnCatch = this.config.getBoolean("DeleteVillagerInventoryOnCatch", false); } @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) @@ -279,7 +281,8 @@ public class EggCatcherEntityListener implements Listener { } } - if(entity instanceof InventoryHolder){ + if((entity instanceof Villager && !this.deleteVillagerInventoryOnCatch) || + (!(entity instanceof Villager) && entity instanceof InventoryHolder)) { ItemStack[] items = ((InventoryHolder) entity).getInventory().getContents(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e4cb98c..84c2693 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -13,6 +13,7 @@ PreventCatchingShearedSheeps: true SpawnChickenOnSuccess: false SpawnChickenOnFail: true VaultTargetBankAccount: "" +DeleteVillagerInventoryOnCatch: false CatchChance: Pig: 100.0 Sheep: 100.0 @@ -137,4 +138,4 @@ Messages: CatchChanceFail: "You failed to catch this mob!" CatchChanceSuccess: "" HealthPercentageFail: "The mob has more than %s percent health left and cannot be caught!" -ConfigVersion: 2.2 \ No newline at end of file +ConfigVersion: 2.5 \ No newline at end of file