Skip to content

Commit

Permalink
Take needed balance for /setwarp from village and allow refunding of …
Browse files Browse the repository at this point in the history
…deleted warps
  • Loading branch information
zavdav committed Jan 29, 2025
1 parent a6cc0d8 commit 59d3a26
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
return true;
}

if (settings.getConfigBoolean("settings.warp.refund-deleted.enabled")) {
village.addBalance(settings.getConfigDouble("settings.warp.price.amount"));
}
village.removeWarp(warpName);
village.broadcastToTown(language.getMessage("command_village_delwarp_del_broadcast")
.replace("%player%", player.getName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.johnymuffin.jvillage.beta.commands.village;

import com.johnymuffin.beta.fundamentals.api.EconomyAPI;
import com.johnymuffin.beta.fundamentals.api.FundamentalsAPI;
import com.johnymuffin.jvillage.beta.JVillage;
import com.johnymuffin.jvillage.beta.commands.JVBaseCommand;
import com.johnymuffin.jvillage.beta.models.VSpawnCords;
Expand Down Expand Up @@ -80,24 +78,11 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}

double creationCost = settings.getConfigDouble("settings.warp.price.amount");
if (creationCost > 0 && plugin.isFundamentalsEnabled()) {
EconomyAPI.EconomyResult result = FundamentalsAPI.getEconomy().subtractBalance(player.getUniqueId(), creationCost, player.getWorld().getName());
String message;
switch (result) {
case successful:
commandSender.sendMessage(language.getMessage("command_village_setwarp_payment")
.replace("%amount%", settings.getConfigDouble("settings.warp.price.amount").toString())
.replace("%warp%", warpName));
break;
case notEnoughFunds:
commandSender.sendMessage(language.getMessage("command_village_setwarp_insufficient_funds")
.replace("%cost%", String.valueOf(creationCost)));
return true;
default:
message = language.getMessage("unknown_economy_error");
commandSender.sendMessage(message);
return true;
}
if (creationCost > 0 && !village.hasEnough(creationCost)) {
String message = language.getMessage("command_village_setwarp_insufficient_funds")
.replace("%cost%", String.valueOf(creationCost));
commandSender.sendMessage(message);
return true;
}
VSpawnCords cords = new VSpawnCords(player.getLocation());
village.addWarp(warpName, cords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ private void write() {

generateConfigOption("settings.warp.max-name-length.value", 20);
generateConfigOption("settings.warp.max-name-length.info", "This is the maximum length of a town warp name.");

generateConfigOption("settings.warp.refund-deleted.enabled", true);
generateConfigOption("settings.warp.refund-deleted.info", "If true, the price to set a warp will be refunded when deleting a warp.");

generateConfigOption("settings.resident.maximum-towns-owned.value", 10);
generateConfigOption("settings.resident.maximum-towns-owned.info", "This is the maximum number of towns a resident can own. Set to 0 to disable.");
Expand Down

0 comments on commit 59d3a26

Please sign in to comment.