From 868f4d6b5835323db800c6090c4b359e8a0af10b Mon Sep 17 00:00:00 2001 From: Thijs Wiefferink Date: Sat, 28 May 2016 17:00:52 +0200 Subject: [PATCH] Events: Add refunded money to UnrentedRegionEvent and SoldRegionEvent Closes #147 --- .../areashop/events/notify/SoldRegionEvent.java | 12 +++++++++++- .../areashop/events/notify/UnrentedRegionEvent.java | 12 +++++++++++- .../evolutioncoding/areashop/regions/BuyRegion.java | 2 +- .../evolutioncoding/areashop/regions/RentRegion.java | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/SoldRegionEvent.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/SoldRegionEvent.java index 6a84504..0fb37ae 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/SoldRegionEvent.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/SoldRegionEvent.java @@ -12,15 +12,17 @@ public class SoldRegionEvent extends NotifyAreaShopEvent { private BuyRegion region; private UUID oldBuyer; + private double refundedMoney; /** * Constructor * @param region The region that has been sold * @param oldBuyer The player for which the region has been sold */ - public SoldRegionEvent(BuyRegion region, UUID oldBuyer) { + public SoldRegionEvent(BuyRegion region, UUID oldBuyer, double refundedMoney) { this.region = region; this.oldBuyer = oldBuyer; + this.refundedMoney = refundedMoney; } /** @@ -38,4 +40,12 @@ public class SoldRegionEvent extends NotifyAreaShopEvent { public UUID getOldBuyer() { return oldBuyer; } + + /** + * Get the amount that is paid back to the player + * @return The amount of money paid back to the player + */ + public double getRefundedMoney() { + return refundedMoney; + } } diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/UnrentedRegionEvent.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/UnrentedRegionEvent.java index 6264d0b..88999f7 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/UnrentedRegionEvent.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/events/notify/UnrentedRegionEvent.java @@ -12,15 +12,17 @@ public class UnrentedRegionEvent extends NotifyAreaShopEvent { private RentRegion region; private UUID oldRenter; + private double refundedMoney; /** * Constructor * @param region The region that has been unrented * @param oldRenter The player that rented the region before it was unrented */ - public UnrentedRegionEvent(RentRegion region, UUID oldRenter) { + public UnrentedRegionEvent(RentRegion region, UUID oldRenter, double refundedMoney) { this.region = region; this.oldRenter = oldRenter; + this.refundedMoney = refundedMoney; } /** @@ -38,4 +40,12 @@ public class UnrentedRegionEvent extends NotifyAreaShopEvent { public UUID getOldRenter() { return oldRenter; } + + /** + * Get the amount that is paid back to the player + * @return The amount of money paid back to the player + */ + public double getRefundedMoney() { + return refundedMoney; + } } diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java index 13a0df6..2028202 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/BuyRegion.java @@ -521,7 +521,7 @@ public class BuyRegion extends GeneralRegion { removeLastActiveTime(); // Notify about updates - this.notifyAndUpdate(new SoldRegionEvent(this, oldBuyer)); + this.notifyAndUpdate(new SoldRegionEvent(this, oldBuyer, Math.max(moneyBack, 0))); // Update everything handleSchematicEvent(RegionEvent.SOLD); diff --git a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java index 6c236f8..72173f0 100644 --- a/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java +++ b/AreaShop/src/main/java/nl/evolutioncoding/areashop/regions/RentRegion.java @@ -680,7 +680,7 @@ public class RentRegion extends GeneralRegion { removeLastActiveTime(); // Notify about updates - this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter)); + this.notifyAndUpdate(new UnrentedRegionEvent(this, oldRenter, Math.max(0, moneyBack))); // Run commands this.runEventCommands(RegionEvent.UNRENTED, false);