mirror of
https://github.com/shansen/EggCatcher.git
synced 2025-01-05 23:37:44 +01:00
fix issue, when you got money withdrawn, but you did not have the item. fix issue with generating the config
This commit is contained in:
parent
45500ec06b
commit
1a12161a66
@ -49,6 +49,7 @@ public class EggCatcher extends JavaPlugin {
|
||||
if (configVersion < 6.0) {
|
||||
MigrateConfigFile();
|
||||
this.saveConfig();
|
||||
this.reloadConfig();
|
||||
return;
|
||||
}
|
||||
if (configVersion == 6.0) {
|
||||
@ -65,50 +66,38 @@ public class EggCatcher extends JavaPlugin {
|
||||
String[] keysWithStringValue = {"VaultTargetBankAccount"};
|
||||
String[] entitiesInConfig = {"Axolotl", "Bat", "Bee", "Blaze", "Cat", "CaveSpider", "Chicken", "Cod", "Cow", "Creeper", "Dolphin", "Donkey", "Drowned", "ElderGuardian", "Enderman", "Endermite", "Evoker", "Fox", "Ghast", "GlowSquid", "Goat", "Guardian", "Hoglin", "Horse", "Husk", "Llama", "MagmaCube", "Mule", "MushroomCow", "Ocelot", "Panda", "Parrot", "Phantom", "Pig", "Piglin", "PiglinBrute", "PigZombie", "Pillager", "PolarBear", "Pufferfish", "Rabbit", "Ravager", "Salmon", "Sheep", "Shulker", "Silverfish", "Skeleton", "SkeletonHorse", "Slime", "Spider", "Squid", "Stray", "Strider", "TraderLlama", "TropicalFish", "Turtle", "Vex", "Villager", "Vindicator", "WanderingTrader", "Witch", "WitherSkeleton", "Wolf", "Zoglin", "Zombie", "ZombieHorse", "ZombieVillager", "ZombifiedPiglin"};
|
||||
|
||||
|
||||
FileConfiguration config = this.getConfig();
|
||||
|
||||
HashMap <String, HashMap> entityList = new HashMap<>();
|
||||
|
||||
for (int i = 0; i < keysWithBoolValue.length; i++) {
|
||||
config.set(keysWithBoolValue[i], config.getBoolean(keysWithBoolValue[i], true));
|
||||
for (String value : keysWithBoolValue) {
|
||||
config.set(value, config.getBoolean(value, true));
|
||||
|
||||
}
|
||||
for (int i = 0; i < keysWithStringValue.length; i++) {
|
||||
config.set(keysWithStringValue[i], config.getString(keysWithStringValue[i], ""));
|
||||
for (String s : keysWithStringValue) {
|
||||
config.set(s, config.getString(s, ""));
|
||||
}
|
||||
|
||||
for (int i = 0; i < entitiesInConfig.length; i++) {
|
||||
HashMap<String, HashMap> entity = new HashMap<>();
|
||||
HashMap<String, Double> HealthPercentage = new HashMap<String, Double>();
|
||||
HashMap<String, Double> CatchChance = new HashMap<>();
|
||||
HashMap<String, Double> VaultCost = new HashMap<>();
|
||||
HashMap<String, HashMap> ItemCost = new HashMap<>();
|
||||
HashMap<String, Double> ItemAmount = new HashMap<>();
|
||||
HashMap<String, String> ItemName = new HashMap<>();
|
||||
for (String s : entitiesInConfig) {
|
||||
HashMap<String, Object> entity = new HashMap<String, Object>();
|
||||
HashMap<String, Object> ItemCost = new HashMap<String, Object>();
|
||||
|
||||
// generate ItemCost
|
||||
ItemName.put("ItemName", config.getString("ItemCost.ItemId", "gold_nugget"));
|
||||
ItemAmount.put("Amount", config.getDouble("ItemCost.Amount." + entitiesInConfig[i], 0.0));
|
||||
ItemCost.put("ItemCost", ItemAmount);
|
||||
ItemCost.put("ItemCost", ItemName);
|
||||
ItemCost.put("ItemName", config.getString("ItemCost.ItemId", "gold_nugget"));
|
||||
ItemCost.put("Amount", config.getDouble("ItemCost.Amount." + s, 0.0));
|
||||
entity.put("ItemCost", ItemCost);
|
||||
|
||||
// generate VaultCost
|
||||
VaultCost.put("VaultCost", config.getDouble("VaultCost." + entitiesInConfig[i], 0.0));
|
||||
entity.put("VaultCost", config.getDouble("VaultCost." + s, 0.0));
|
||||
|
||||
// generate CatchChance
|
||||
CatchChance.put("CatchChance", config.getDouble("CatchChance." + entitiesInConfig[i], 0.0));
|
||||
entity.put("CatchChance", config.getDouble("CatchChance." + s, 0.0));
|
||||
|
||||
// generate HealthPercentage
|
||||
HealthPercentage.put("HealthPercentage", config.getDouble("HealthPercentage." + entitiesInConfig[i], 0.0));
|
||||
entity.put("HealthPercentage", config.getDouble("HealthPercentage." + s, 0.0));
|
||||
|
||||
// Build new Config Hash for entity
|
||||
entity.put(entitiesInConfig[i], ItemCost);
|
||||
entity.put(entitiesInConfig[i], VaultCost);
|
||||
entity.put(entitiesInConfig[i], HealthPercentage);
|
||||
entity.put(entitiesInConfig[i], CatchChance);
|
||||
|
||||
entityList.put(entitiesInConfig[i], entity);
|
||||
entityList.put(s, entity);
|
||||
}
|
||||
config.set("Entity", entityList);
|
||||
config.set("ConfigVersion", 6.0);
|
||||
|
@ -158,92 +158,31 @@ public class EggCatcherEntityListener implements Listener {
|
||||
if (egg.getShooter() instanceof Player) {
|
||||
Player player = (Player) egg.getShooter();
|
||||
|
||||
if (this.usePermissions) {
|
||||
if (!player.hasPermission("eggcatcher.catch." + eggType.getFriendlyName().toLowerCase())) {
|
||||
player.sendMessage(config.getString("Messages.PermissionFail"));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
// check if player meets all requirements
|
||||
if (!playerHasRequirements(entity, player, egg, eggType.getFriendlyName())) {
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.useHealthPercentage) {
|
||||
double healthPercentage = config.getDouble("Entity." + eggType.getFriendlyName() + ".HealthPercentage");
|
||||
double currentHealth = ((LivingEntity) entity).getHealth() * 100.0 / ((LivingEntity) entity)
|
||||
.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||
if (healthPercentage < currentHealth) {
|
||||
if (this.healthPercentageFailMessage.length() > 0) {
|
||||
player.sendMessage(String.format(this.healthPercentageFailMessage, healthPercentage));
|
||||
}
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Withdraw money
|
||||
vaultCost = config.getDouble("Entity." + eggType.getFriendlyName() + ".VaultCost");
|
||||
EggCatcher.economy.withdrawPlayer(player, vaultCost);
|
||||
if (!this.vaultTargetBankAccount.isEmpty()) {
|
||||
EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||
}
|
||||
player.sendMessage(String.format(config.getString("Messages.VaultSuccess"), vaultCost));
|
||||
|
||||
if (this.useCatchChance) {
|
||||
double catchChance = config.getDouble("Entity." + eggType.getFriendlyName() + ".CatchChance");
|
||||
if (Math.random() * 100 <= catchChance) {
|
||||
if (this.catchChanceSuccessMessage.length() > 0) {
|
||||
player.sendMessage(catchChanceSuccessMessage);
|
||||
}
|
||||
} else {
|
||||
if (this.catchChanceFailMessage.length() > 0) {
|
||||
player.sendMessage(this.catchChanceFailMessage);
|
||||
}
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
boolean freeCatch = player.hasPermission("eggcatcher.free");
|
||||
// Take Items
|
||||
Material itemMaterial = Material.matchMaterial(config.getString("Entity." + eggType.getFriendlyName() + ".ItemCost.ItemName", "gold_nugget"));
|
||||
int itemAmount = config.getInt("Entity." + eggType.getFriendlyName() + ".ItemCost.Amount", 0);
|
||||
ItemStack itemStack = new ItemStack(itemMaterial, itemAmount);
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostSuccess"),
|
||||
String.valueOf(itemAmount)));
|
||||
player.getInventory().removeItem(itemStack);
|
||||
|
||||
if (this.useVaultCost && !freeCatch) {
|
||||
vaultCost = config.getDouble("Entity." + eggType.getFriendlyName() + ".VaultCost");
|
||||
if (!EggCatcher.economy.has(player, vaultCost)) {
|
||||
player.sendMessage(String.format(config.getString("Messages.VaultFail"), vaultCost));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
EggCatcher.economy.withdrawPlayer(player, vaultCost);
|
||||
|
||||
if (!this.vaultTargetBankAccount.isEmpty()) {
|
||||
EggCatcher.economy.bankDeposit(this.vaultTargetBankAccount, vaultCost);
|
||||
}
|
||||
|
||||
player.sendMessage(String.format(config.getString("Messages.VaultSuccess"), vaultCost));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useItemCost && !freeCatch) {
|
||||
Material itemMaterial = Material.matchMaterial(config.getString("Entity." + eggType.getFriendlyName() + ".ItemCost.ItemName", "gold_nugget"));
|
||||
int itemData = config.getInt("Entity." + eggType.getFriendlyName() + ".ItemCost.ItemData", 0);
|
||||
int itemAmount = config.getInt("Entity." + eggType.getFriendlyName() + ".ItemCost.Amount", 0);
|
||||
ItemStack itemStack = new ItemStack(itemMaterial, itemAmount);
|
||||
if (player.getInventory().containsAtLeast(itemStack, itemStack.getAmount())) {
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostSuccess"),
|
||||
String.valueOf(itemAmount)));
|
||||
player.getInventory().removeItem(itemStack);
|
||||
} else {
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostFail"),
|
||||
String.valueOf(itemAmount)));
|
||||
if (!this.looseEggOnFail) {
|
||||
player.getInventory().addItem(new ItemStack(Material.EGG, 1));
|
||||
EggCatcher.eggs.add(egg);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Dispenser
|
||||
if (!this.nonPlayerCatching) {
|
||||
@ -312,4 +251,68 @@ public class EggCatcherEntityListener implements Listener {
|
||||
captureLogger.logToFile("Player " + ((Player) egg.getShooter()).getName() + " caught " + entity.getType() + " at X" + Math.round(entity.getLocation().getX()) + ",Y" + Math.round(entity.getLocation().getY()) + ",Z" + Math.round(entity.getLocation().getZ()));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean playerHasRequirements(Entity entity, Player player, Egg egg, String eggtype) {
|
||||
boolean hasRequirements = true;
|
||||
double vaultCost = 0.0;
|
||||
boolean freeCatch = player.hasPermission("eggcatcher.free");
|
||||
|
||||
if (this.usePermissions) {
|
||||
if (!player.hasPermission("eggcatcher.catch." + eggtype.toLowerCase())) {
|
||||
player.sendMessage(config.getString("Messages.PermissionFail"));
|
||||
|
||||
hasRequirements = false;
|
||||
}
|
||||
}
|
||||
if (this.useHealthPercentage) {
|
||||
double healthPercentage = config.getDouble("Entity." + eggtype + ".HealthPercentage");
|
||||
double currentHealth = ((LivingEntity) entity).getHealth() * 100.0 / ((LivingEntity) entity)
|
||||
.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue();
|
||||
if (healthPercentage < currentHealth) {
|
||||
if (this.healthPercentageFailMessage.length() > 0) {
|
||||
player.sendMessage(String.format(this.healthPercentageFailMessage, healthPercentage));
|
||||
}
|
||||
|
||||
hasRequirements = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useCatchChance) {
|
||||
double catchChance = config.getDouble("Entity." + eggtype + ".CatchChance");
|
||||
if (Math.random() * 100 <= catchChance) {
|
||||
if (this.catchChanceSuccessMessage.length() > 0) {
|
||||
player.sendMessage(catchChanceSuccessMessage);
|
||||
}
|
||||
} else {
|
||||
if (this.catchChanceFailMessage.length() > 0) {
|
||||
player.sendMessage(this.catchChanceFailMessage);
|
||||
}
|
||||
|
||||
hasRequirements = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useVaultCost && !freeCatch) {
|
||||
vaultCost = config.getDouble("Entity." + eggtype + ".VaultCost");
|
||||
if (!EggCatcher.economy.has(player, vaultCost)) {
|
||||
player.sendMessage(String.format(config.getString("Messages.VaultFail"), vaultCost));
|
||||
|
||||
hasRequirements = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.useItemCost && !freeCatch) {
|
||||
Material itemMaterial = Material.matchMaterial(config.getString("Entity." + eggtype + ".ItemCost.ItemName", "gold_nugget"));
|
||||
int itemAmount = config.getInt("Entity." + eggtype + ".ItemCost.Amount", 0);
|
||||
ItemStack itemStack = new ItemStack(itemMaterial, itemAmount);
|
||||
if (!player.getInventory().containsAtLeast(itemStack, itemStack.getAmount())) {
|
||||
player.sendMessage(String.format(config.getString("Messages.ItemCostFail"),
|
||||
String.valueOf(itemAmount)));
|
||||
|
||||
hasRequirements = false;
|
||||
}
|
||||
}
|
||||
|
||||
return hasRequirements;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user