Skip to content

Commit

Permalink
feat: fixed missing checks for auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDx committed Apr 20, 2022
1 parent d420ac5 commit 098a1f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/me/EtienneDx/RealEstate/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ public class Messages extends AnnotationConfig
@ConfigField(name="RealEstate.Info.Claim.Info.Auction.Ended", comment = "0: claim type")
public String msgInfoClaimInfoAuctionEnded = "$bThe auction for the {0} has ended.";

@ConfigField(name="RealEstate.Info.Claim.Info.Auction.Cancelled", comment = "0: claim type")
public String msgInfoClaimInfoAuctionCancelled = "$bThe auction for the {0} has been cancelled. You have been reimbursed.";

@ConfigField(name="RealEstate.Info.Claim.Info.Owner", comment = "0: owner name")
public String msgInfoClaimInfoOwner = "$bThe current owner is $a{0}";

Expand Down
22 changes: 21 additions & 1 deletion src/me/EtienneDx/RealEstate/Transactions/ClaimAuction.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ else if(!Utils.makePayment(owner, null, price, false, false))
if(buyerPlayer.isOnline())
{
Messages.sendMessage(buyerPlayer.getPlayer(), RealEstate.instance.messages.msgErrorAuctionCouldntPayOwner);
if(!Utils.makePayment(buyer, null, price, false, false))
{
RealEstate.instance.log.warning("Couldn't reimburse " + price + " to " + buyerPlayer.getName() + " for the cancellation of an auction");
}
if(buyerPlayer.isOnline())
{
Messages.sendMessage(buyerPlayer.getPlayer(), RealEstate.instance.messages.msgInfoClaimInfoAuctionCancelled);
}
}
if(owner != null && ownerPlayer.isOnline())
{
Expand Down Expand Up @@ -153,8 +161,20 @@ else if(!Utils.makePayment(owner, null, price, false, false))

@Override
public boolean tryCancelTransaction(Player p, boolean force) {
if(buyer == null || force || p.hasPermission("realestate.admin"))
if(buyer == null || RealEstate.instance.config.cfgCancelAuction || force || p.hasPermission("realestate.admin"))
{
if(buyer != null)
{
OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(buyer);
if(!Utils.makePayment(buyer, null, price, false, false))
{
RealEstate.instance.log.warning("Couldn't reimburse " + price + " to " + buyerPlayer.getName() + " for the cancellation of an auction");
}
if(buyerPlayer.isOnline())
{
Messages.sendMessage(buyerPlayer.getPlayer(), RealEstate.instance.messages.msgInfoClaimInfoAuctionCancelled);
}
}
RealEstate.transactionsStore.cancelTransaction(this);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ public void cancelTransaction(Transaction tr)

public boolean canCancelTransaction(Transaction tr)
{
return tr instanceof ClaimSell || tr instanceof ClaimAuction || (tr instanceof ClaimRent && ((ClaimRent)tr).buyer == null) ||
return tr instanceof ClaimSell ||
(tr instanceof ClaimAuction && ((ClaimRent)tr).buyer == null || RealEstate.instance.config.cfgCancelAuction) ||
(tr instanceof ClaimRent && ((ClaimRent)tr).buyer == null) ||
(tr instanceof ClaimLease && ((ClaimLease)tr).buyer == null);
}

Expand Down

0 comments on commit 098a1f7

Please sign in to comment.