Skip to content

Commit

Permalink
Fixed withdraw amount restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
KartoffelChipss committed Apr 28, 2024
1 parent da46d85 commit af0a6a3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.strassburger</groupId>
<artifactId>LifeStealZ</artifactId>
<name>LifeStealZ</name>
<version>1.1.3</version>
<version>1.1.4</version>
<description>A LifeSteal SMP plugin providing you all the features you need!</description>
<build>
<resources>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.strassburger</groupId>
<artifactId>LifeStealZ</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
<packaging>jar</packaging>

<name>LifeStealZ</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,25 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

if (!(sender instanceof Player)) return false;

int withdrawHearts = args != null && args.length > 0 ? Integer.parseInt(args[0]) : 1;
int withdrawHearts = 0;
try {
withdrawHearts = args != null && args.length > 0 ? Integer.parseInt(args[0]) : 1;
} catch (NumberFormatException e) {
sender.sendMessage(MessageUtils.getAndFormatMsg(false, "messages.usageError", "&cUsage: %usage%", new Replaceable("%usage%", "/withdrawheart <amount> [confirm]")));
return false;
}
String confirmOption = args != null && args.length > 1 ? args[1] : null;

Player player = (Player) sender;
PlayerData playerdata = LifeStealZ.getInstance().getPlayerDataStorage().load(player.getUniqueId());

boolean withdrawtoDeath = LifeStealZ.getInstance().getConfig().getBoolean("allowDyingFromWithdraw");

if (withdrawHearts < 1) {
sender.sendMessage(MessageUtils.getAndFormatMsg(false, "messages.withdrawMin", "&cYou can't withdraw less than 1 heart!"));
return false;
}

if (playerdata.getMaxhp() - ((double) withdrawHearts * 2) <= 0.0) {
if (confirmOption == null || !confirmOption.equals("confirm")) {
sender.sendMessage(MessageUtils.getAndFormatMsg(false, "messages.noWithdraw", "&cYou would be eliminated, if you withdraw a heart!"));
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,5 @@ messages:
heartconsume: "&7You got &c%amount% &7hearts!"
heartconsumeCooldown: "&cYou have to wait before using another heart!"
recipeNotCraftable: "&cThis item is not craftable!"
altKill: "&cPlease don't kill alts! This attempt has been logged!"
altKill: "&cPlease don't kill alts! This attempt has been logged!"
withdrawMin: "&cYou can't withdraw less than 1 heart!"

0 comments on commit af0a6a3

Please sign in to comment.