Skip to content

Commit

Permalink
add refund for village claim cost (with help of zavdav)
Browse files Browse the repository at this point in the history
  • Loading branch information
svgaming234 committed Aug 25, 2024
1 parent 5419f67 commit ee1fd5e
Showing 1 changed file with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
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.VCords;
import com.johnymuffin.jvillage.beta.models.Village;
import com.johnymuffin.jvillage.beta.models.chunk.ChunkClaimSettings;
import com.johnymuffin.jvillage.beta.models.chunk.VClaim;
import com.johnymuffin.jvillage.beta.player.VPlayer;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
Expand All @@ -14,6 +17,8 @@

import java.util.logging.Level;

import static com.johnymuffin.jvillage.beta.JVUtility.cordsInChunk;

public class JDeleteCommand extends JVBaseCommand implements CommandExecutor {

public JDeleteCommand(JVillage plugin) {
Expand Down Expand Up @@ -58,17 +63,28 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
}

// Refund the player the balance
double townBalance = village.getBalance();
double refundAmount = village.getBalance();

// Refund the player the cost of the claims
VCords spawnCords = village.getTownSpawn();

for (VClaim vClaim : plugin.getVillageClaimsArray(village)) {
ChunkClaimSettings chunkClaimSettings = village.getChunkClaimSettings(vClaim);

if (!cordsInChunk(spawnCords, vClaim)) {
refundAmount += chunkClaimSettings.getPrice();
}
}

if (townBalance > 0 && plugin.isFundamentalsEnabled()) {
EconomyAPI.EconomyResult result = FundamentalsAPI.getEconomy().additionBalance(player.getUniqueId(), townBalance);
if (refundAmount > 0 && plugin.isFundamentalsEnabled()) {
EconomyAPI.EconomyResult result = FundamentalsAPI.getEconomy().additionBalance(player.getUniqueId(), refundAmount);
String message;
switch (result) {
case successful:
this.plugin.logger(Level.INFO, "Successfully refunded $" + townBalance + " to " + player.getName() + " for deleting village " + village.getTownName());
this.plugin.logger(Level.INFO, "Successfully refunded $" + refundAmount + " to " + player.getName() + " for deleting village " + village.getTownName());
break;
default:
this.plugin.logger(Level.WARNING, "Failed to refund $" + townBalance + " to " + player.getName() + " for deleting village " + village.getTownName());
this.plugin.logger(Level.WARNING, "Failed to refund $" + refundAmount + " to " + player.getName() + " for deleting village " + village.getTownName());
message = language.getMessage("generic_error");
commandSender.sendMessage(message);
return true;
Expand Down

0 comments on commit ee1fd5e

Please sign in to comment.