Added health percentage check

This commit is contained in:
Shansen 2013-02-28 18:21:43 +01:00
parent 46a96a6475
commit 4fd5313986
4 changed files with 74 additions and 10 deletions

View File

@ -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", "");

View File

@ -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());

View File

@ -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
HealthPercentageFail: "The mob has more than %s percent health left and cannot be caught!"
ConfigVersion: 1.25

View File

@ -1,5 +1,5 @@
name: EggCatcher
version: 1.24
version: 1.25
description: This plugin allows you to catch mobs in eggs.
author: shansen