From 2fbf4afe951f94980af6591a575eab4c7fa0e70c Mon Sep 17 00:00:00 2001 From: HeroGamers Date: Sat, 27 May 2023 01:11:01 +0200 Subject: [PATCH] Revive using levels, closes #79 --- src/main/java/dk/fido2603/mydog/MyDog.java | 3 +++ .../mydog/managers/CommandManager.java | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/dk/fido2603/mydog/MyDog.java b/src/main/java/dk/fido2603/mydog/MyDog.java index 8fe31ec..baf30ea 100644 --- a/src/main/java/dk/fido2603/mydog/MyDog.java +++ b/src/main/java/dk/fido2603/mydog/MyDog.java @@ -56,6 +56,7 @@ public class MyDog extends JavaPlugin { public boolean allowNametagRename = true; public boolean allowRevival = true; public int revivalPrice = 200; + public boolean revivalUsingPlayerExp = true; public boolean allowArrowDamage = false; public String levelUpSound = "ENTITY_WOLF_HOWL"; @@ -288,6 +289,7 @@ public void loadSettings() { this.allowNametagRename = config.getBoolean("DogSettings.AllowNametagRename", true); this.allowRevival = config.getBoolean("DogSettings.AllowRevival", true); this.revivalPrice = config.getInt("DogSettings.RevivalPricePerLevel", 200); + this.revivalUsingPlayerExp = config.getBoolean("DogSettings.RevivalUsingPlayerExp", false); this.allowArrowDamage = config.getBoolean("DogSettings.AllowArrowDamage", false); if (config.contains("DogSettings.DogNames") && !config.getStringList("DogSettings.DogNames").isEmpty()) { this.dogNames = config.getStringList("DogSettings.DogNames"); @@ -354,6 +356,7 @@ public void saveSettings() { config.set("DogSettings.DogNames", this.dogNames); config.set("DogSettings.AllowRevival", this.allowRevival); config.set("DogSettings.RevivalPricePerLevel", this.revivalPrice); + config.set("DogSettings.RevivalUsingPlayerExp", this.revivalUsingPlayerExp); config.set("DogSettings.AllowArrowDamage", this.allowArrowDamage); // Levels diff --git a/src/main/java/dk/fido2603/mydog/managers/CommandManager.java b/src/main/java/dk/fido2603/mydog/managers/CommandManager.java index 7b4a6ed..11a9a26 100644 --- a/src/main/java/dk/fido2603/mydog/managers/CommandManager.java +++ b/src/main/java/dk/fido2603/mydog/managers/CommandManager.java @@ -678,12 +678,22 @@ private boolean commandReviveDog(Player player, CommandSender sender, int dogIde return false; } - if (MyDog.getEconomy() != null) { - if (!MyDog.getEconomy().has(player, deadDog.getRevivalPrice())) { - sender.sendMessage(ChatColor.RED + "You don't have enough funds to resurrect the dog."); + int revivalPrice = deadDog.getRevivalPrice(); + if (!plugin.revivalUsingPlayerExp) { + if (MyDog.getEconomy() != null) { + if (!MyDog.getEconomy().has(player, revivalPrice)) { + sender.sendMessage(ChatColor.RED + "You don't have enough funds to resurrect the dog."); + return false; + } + MyDog.getEconomy().withdrawPlayer(player, revivalPrice); + } + } + else { + if (player.getLevel() < revivalPrice) { + sender.sendMessage(ChatColor.RED + "You don't have enough power to resurrect the dog. You need " + ChatColor.GOLD + (revivalPrice - player.getLevel()) + ChatColor.RED + " more levels!"); return false; } - MyDog.getEconomy().withdrawPlayer(player, deadDog.getRevivalPrice()); + player.setLevel(player.getLevel() - revivalPrice); } Wolf wolf = player.getWorld().spawn(player.getLocation(), Wolf.class); @@ -695,7 +705,7 @@ private boolean commandReviveDog(Player player, CommandSender sender, int dogIde deadDog.setDead(false); deadDog.updateWolf(); - sender.sendMessage(ChatColor.GREEN + "Your dog is resurrected."); + sender.sendMessage(ChatColor.GREEN + "Your dog has been resurrected."); return true; }