From 4fd5313986a563b6de4672b134bb3ff27706300f Mon Sep 17 00:00:00 2001 From: Shansen Date: Thu, 28 Feb 2013 18:21:43 +0100 Subject: [PATCH] Added health percentage check --- .../me/shansen/EggCatcher/EggCatcher.java | 33 +++++++++++++++++-- .../listeners/EggCatcherEntityListener.java | 21 ++++++++---- src/main/resources/config.yml | 28 +++++++++++++++- src/main/resources/plugin.yml | 2 +- 4 files changed, 74 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/shansen/EggCatcher/EggCatcher.java b/src/main/java/me/shansen/EggCatcher/EggCatcher.java index 35852e3..7f36f17 100644 --- a/src/main/java/me/shansen/EggCatcher/EggCatcher.java +++ b/src/main/java/me/shansen/EggCatcher/EggCatcher.java @@ -72,8 +72,37 @@ public class EggCatcher extends JavaPlugin { public void CheckConfigurationFile() { double configVersion = this.getConfig().getDouble("ConfigVersion", 0.0); - if (configVersion == 1.22) { - // + if (configVersion == 1.25) { + // + this.saveConfig(); + } + else if (configVersion == 1.22) { + this.getConfig().set("UseHealthPercentage", false); + this.getConfig().set("HealthPercentage.Pig", 100.0); + this.getConfig().set("HealthPercentage.Sheep", 100.0); + this.getConfig().set("HealthPercentage.MushroomCow", 100.0); + this.getConfig().set("HealthPercentage.Cow", 100.0); + this.getConfig().set("HealthPercentage.Chicken", 100.0); + this.getConfig().set("HealthPercentage.Squid", 100.0); + this.getConfig().set("HealthPercentage.Wolf", 100.0); + this.getConfig().set("HealthPercentage.Creeper", 100.0); + this.getConfig().set("HealthPercentage.Skeleton", 100.0); + this.getConfig().set("HealthPercentage.CaveSpider", 100.0); + this.getConfig().set("HealthPercentage.Spider", 100.0); + this.getConfig().set("HealthPercentage.PigZombie", 100.0); + this.getConfig().set("HealthPercentage.Zombie", 100.0); + this.getConfig().set("HealthPercentage.MagmaCube", 100.0); + this.getConfig().set("HealthPercentage.Slime", 100.0); + this.getConfig().set("HealthPercentage.Ghast", 100.0); + this.getConfig().set("HealthPercentage.Enderman", 100.0); + this.getConfig().set("HealthPercentage.Silverfish", 100.0); + this.getConfig().set("HealthPercentage.Blaze", 100.0); + this.getConfig().set("HealthPercentage.Villager", 100.0); + this.getConfig().set("HealthPercentage.Ocelot", 100.0); + this.getConfig().set("HealthPercentage.Witch", 100.0); + this.getConfig().set("HealthPercentage.Bat", 100.0); + this.getConfig().set("Messages.HealthPercentageFail", "The mob has more than %s percent health left and cannot be caught!"); + this.getConfig().set("ConfigVersion", 1.25); this.saveConfig(); }else if (configVersion == 1.21) { this.getConfig().set("VaultTargetBankAccount", ""); diff --git a/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java b/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java index dced7bd..1e8f756 100644 --- a/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java +++ b/src/main/java/me/shansen/EggCatcher/listeners/EggCatcherEntityListener.java @@ -24,12 +24,7 @@ import me.shansen.EggCatcher.EggType; import org.bukkit.Effect; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Animals; -import org.bukkit.entity.Egg; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Sheep; -import org.bukkit.entity.Tameable; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -44,6 +39,7 @@ public class EggCatcherEntityListener implements Listener { JavaPlugin plugin; private final Boolean usePermissions; private final Boolean useCatchChance; + private final Boolean useHealthPercentage; private final Boolean looseEggOnFail; private final Boolean useVaultCost; private final Boolean useItemCost; @@ -56,6 +52,7 @@ public class EggCatcherEntityListener implements Listener { private final String catchChanceSuccessMessage; private final String catchChanceFailMessage; + private final String healthPercentageFailMessage; private final String vaultTargetBankAccount; @@ -67,6 +64,7 @@ public class EggCatcherEntityListener implements Listener { this.plugin = plugin; this.usePermissions = this.config.getBoolean("UsePermissions", true); this.useCatchChance = this.config.getBoolean("UseCatchChance", true); + this.useHealthPercentage = this.config.getBoolean("UseHealthPercentage", false); this.looseEggOnFail = this.config.getBoolean("LooseEggOnFail", true); this.useVaultCost = this.config.getBoolean("UseVaultCost", false); this.useItemCost = this.config.getBoolean("UseItemCost", false); @@ -78,6 +76,7 @@ public class EggCatcherEntityListener implements Listener { .getString("Messages.CatchChanceSuccess"); this.catchChanceFailMessage = this.config .getString("Messages.CatchChanceFail"); + this.healthPercentageFailMessage = this.config.getString("Messages.HealthPercentageFail"); this.preventCatchingBabyAnimals = this.config.getBoolean( "PreventCatchingBabyAnimals", true); this.preventCatchingTamableAnimals = this.config.getBoolean( @@ -166,6 +165,16 @@ public class EggCatcherEntityListener implements Listener { } } + if (this.useHealthPercentage) { + double healthPercentage = config.getDouble("HealthPercentage." + + eggType.getFriendlyName()); + double currentHealth = ((LivingEntity)entity).getHealth() * 100.0 / ((LivingEntity)entity).getMaxHealth(); + if(healthPercentage < currentHealth) { + player.sendMessage(String.format(this.healthPercentageFailMessage, healthPercentage)); + return; + } + } + if (this.useCatchChance) { double catchChance = config.getDouble("CatchChance." + eggType.getFriendlyName()); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 86c1eff..7297f88 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,6 +3,7 @@ UseCatchChance: true LooseEggOnFail: true UseVaultCost: false UseItemCost: false +UseHealthPercentage: false ExplosionEffect: true SmokeEffect: false NonPlayerCatching: true @@ -86,6 +87,30 @@ ItemCost: Ocelot: 0 Witch: 0 Bat: 0 +HealthPercentage: + Pig: 100.0 + Sheep: 100.0 + MushroomCow: 100.0 + Cow: 100.0 + Chicken: 100.0 + Squid: 100.0 + Wolf: 100.0 + Creeper: 100.0 + Skeleton: 100.0 + CaveSpider: 100.0 + Spider: 100.0 + PigZombie: 100.0 + Zombie: 100.0 + MagmaCube: 100.0 + Slime: 100.0 + Ghast: 100.0 + Enderman: 100.0 + Silverfish: 100.0 + Blaze: 100.0 + Villager: 100.0 + Ocelot: 100.0 + Witch: 100.0 + Bat: 100.0 Messages: PermissionFail: "You do not have permission to catch this mob!" VaultFail: "It costs %s dollars to catch this mob!" @@ -94,4 +119,5 @@ Messages: ItemCostSuccess: "You paid %s gold nugget(s) for catching this mob!" CatchChanceFail: "You failed to catch this mob!" CatchChanceSuccess: "" -ConfigVersion: 1.22 \ No newline at end of file + HealthPercentageFail: "The mob has more than %s percent health left and cannot be caught!" +ConfigVersion: 1.25 \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a5d09dd..76cc003 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: EggCatcher -version: 1.24 +version: 1.25 description: This plugin allows you to catch mobs in eggs. author: shansen