Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add village chunk claim refunds (collaboration with zavdav) and fix README.md typo #6

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# JVillage
An alterative for Towny in Beta 1.7.3
An alternative for Towny in Beta 1.7.3
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
Loading