Skip to content

Commit

Permalink
Revive using levels, closes #79
Browse files Browse the repository at this point in the history
  • Loading branch information
HeroGamers committed May 26, 2023
1 parent 083b269 commit 2fbf4af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/java/dk/fido2603/mydog/MyDog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions src/main/java/dk/fido2603/mydog/managers/CommandManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 2fbf4af

Please sign in to comment.