diff --git a/src/me/EtienneDx/RealEstate/BoughtTransaction.java b/src/me/EtienneDx/RealEstate/BoughtTransaction.java new file mode 100644 index 0000000..037864c --- /dev/null +++ b/src/me/EtienneDx/RealEstate/BoughtTransaction.java @@ -0,0 +1,46 @@ +package me.EtienneDx.RealEstate; + +import java.util.Map; +import java.util.UUID; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import me.ryanhamshire.GriefPrevention.Claim; + +public abstract class BoughtTransaction extends ClaimTransaction +{ + UUID buyer = null; + ExitOffer exitOffer = null; + + public BoughtTransaction(Map map) + { + super(map); + if(map.get("buyer") != null) + buyer = UUID.fromString((String)map.get("buyer")); + if(map.get("exitOffer") != null) + exitOffer = (ExitOffer) map.get("exitOffer"); + } + + public BoughtTransaction(Claim claim, Player player, double price, Location sign) + { + super(claim, player, price, sign); + } + + @Override + public Map serialize() + { + Map map = super.serialize(); + if(buyer != null) + map.put("buyer", buyer.toString()); + if(exitOffer != null) + map.put("exitOffer", exitOffer); + + return map; + } + + public UUID getBuyer() + { + return buyer; + } +} diff --git a/src/me/EtienneDx/RealEstate/ClaimLease.java b/src/me/EtienneDx/RealEstate/ClaimLease.java index fca4f09..b999395 100644 --- a/src/me/EtienneDx/RealEstate/ClaimLease.java +++ b/src/me/EtienneDx/RealEstate/ClaimLease.java @@ -7,8 +7,6 @@ import java.time.Period; import java.time.format.DateTimeFormatter; import java.util.Map; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -20,12 +18,11 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention; import net.md_5.bungee.api.ChatColor; -public class ClaimLease extends ClaimTransaction +public class ClaimLease extends BoughtTransaction { LocalDateTime lastPayment = null; int frequency; int paymentsLeft; - UUID buyer = null; public ClaimLease(Map map) { @@ -34,8 +31,6 @@ public ClaimLease(Map map) lastPayment = LocalDateTime.parse((String) map.get("lastPayment"), DateTimeFormatter.ISO_DATE_TIME); frequency = (int)map.get("frequency"); paymentsLeft = (int)map.get("paymentsLeft"); - if(map.get("buyer") != null) - buyer = UUID.fromString((String)map.get("buyer")); } public ClaimLease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsLeft) @@ -53,8 +48,6 @@ public Map serialize() { map.put("lastPayment", lastPayment.format(DateTimeFormatter.ISO_DATE_TIME)); map.put("frequency", frequency); map.put("paymentsLeft", paymentsLeft); - if(buyer != null) - map.put("buyer", buyer.toString()); return map; } @@ -74,6 +67,10 @@ public void update() s.setLine(3, Utils.getTime(frequency, null, false)); s.update(true); } + else + { + RealEstate.transactionsStore.cancelTransaction(this); + } } else { diff --git a/src/me/EtienneDx/RealEstate/ClaimRent.java b/src/me/EtienneDx/RealEstate/ClaimRent.java index 7e8c155..8d2dc50 100644 --- a/src/me/EtienneDx/RealEstate/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/ClaimRent.java @@ -7,8 +7,6 @@ import java.time.Period; import java.time.format.DateTimeFormatter; import java.util.Map; -import java.util.UUID; - import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; @@ -20,11 +18,10 @@ import me.ryanhamshire.GriefPrevention.GriefPrevention; import net.md_5.bungee.api.ChatColor; -public class ClaimRent extends ClaimTransaction +public class ClaimRent extends BoughtTransaction { LocalDateTime startDate = null; int duration; - UUID rentedBy = null; boolean autoRenew = false; public ClaimRent(Map map) @@ -33,8 +30,6 @@ public ClaimRent(Map map) if(map.get("startDate") != null) startDate = LocalDateTime.parse((String) map.get("startDate"), DateTimeFormatter.ISO_DATE_TIME); duration = (int)map.get("duration"); - if(map.get("rentedBy") != null) - rentedBy = UUID.fromString((String)map.get("rentedBy")); autoRenew = (boolean) map.get("autoRenew"); } @@ -51,8 +46,6 @@ public Map serialize() { if(startDate != null) map.put("startDate", startDate.format(DateTimeFormatter.ISO_DATE_TIME)); map.put("duration", duration); - if(rentedBy != null) - map.put("rentedBy", rentedBy.toString()); map.put("autoRenew", autoRenew); return map; @@ -64,7 +57,7 @@ public void update() if(sign.getBlock().getState() instanceof Sign) { Sign s = (Sign) sign.getBlock().getState(); - if(rentedBy == null) + if(buyer == null) { s.setLine(0, RealEstate.instance.dataStore.cfgSignsHeader); s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.dataStore.cfgReplaceRent); @@ -94,7 +87,7 @@ public void update() else { s.setLine(0, RealEstate.instance.dataStore.cfgSignsHeader); - s.setLine(1, ("Rented by " + Bukkit.getOfflinePlayer(rentedBy).getName()).substring(0, 16)); + s.setLine(1, ("Rented by " + Bukkit.getOfflinePlayer(buyer).getName()).substring(0, 16)); s.setLine(2, "Time remaining : "); int daysLeft = duration - days - 1;// we need to remove the current day @@ -106,7 +99,7 @@ public void update() } } - else + else if(buyer == null)// if no one is renting it, we can delete it (no sign indicating it's rentable) { RealEstate.transactionsStore.cancelTransaction(this); } @@ -115,34 +108,34 @@ public void update() private void unRent(boolean msgBuyer) { Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null); - claim.dropPermission(rentedBy.toString()); - if(msgBuyer && Bukkit.getOfflinePlayer(rentedBy).isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer) + claim.dropPermission(buyer.toString()); + if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer) { - Bukkit.getPlayer(rentedBy).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + + Bukkit.getPlayer(buyer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "The rent for the " + (claim.parent == null ? "claim" : "subclaim") + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.AQUA + " is now over, your access has been revoked."); } - rentedBy = null; + buyer = null; RealEstate.transactionsStore.saveData(); update(); } private void payRent() { - if(rentedBy == null) return; + if(buyer == null) return; - OfflinePlayer buyer = Bukkit.getOfflinePlayer(rentedBy); + OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(this.buyer); OfflinePlayer seller = Bukkit.getOfflinePlayer(owner); String claimType = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null).parent == null ? "claim" : "subclaim"; - if(Utils.makePayment(owner, rentedBy, price, false, false)) + if(Utils.makePayment(owner, this.buyer, price, false, false)) { startDate = LocalDateTime.now(); - if(buyer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer) + if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer) { - ((Player)buyer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + + ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "Paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural()); @@ -150,7 +143,7 @@ private void payRent() if(seller.isOnline() && RealEstate.instance.dataStore.cfgMessageOwner) { - ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + buyer.getName() + + ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() + " has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + @@ -159,9 +152,9 @@ private void payRent() } else { - if(buyer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer) + if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer) { - ((Player)buyer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Couldn't pay the rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", your access has been revoked."); @@ -175,7 +168,7 @@ private void payRent() @Override public boolean tryCancelTransaction(Player p) { - if(rentedBy != null) + if(buyer != null) { Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null); if(p != null) @@ -220,13 +213,13 @@ public void interact(Player player) claimType + "s!"); return; } - if(player.getUniqueId().equals(rentedBy)) + if(player.getUniqueId().equals(buyer)) { player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are already renting this " + claimType + "!"); return; } - if(rentedBy != null) + if(buyer != null) { player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Someone already rents this " + claimType + "!"); @@ -235,10 +228,10 @@ public void interact(Player player) if(Utils.makePayment(owner, player.getUniqueId(), price, false, true))// if payment succeed { - rentedBy = player.getUniqueId(); + buyer = player.getUniqueId(); startDate = LocalDateTime.now(); autoRenew = false; - claim.setPermission(rentedBy.toString(), ClaimPermission.Build); + claim.setPermission(buyer.toString(), ClaimPermission.Build); update(); RealEstate.transactionsStore.saveData(); @@ -278,15 +271,12 @@ public void preview(Player player) String claimType = claim.parent == null ? "claim" : "subclaim"; msg = ChatColor.BLUE + "-----= " + ChatColor.WHITE + "[" + ChatColor.GOLD + "RealEstate Rent Info" + ChatColor.WHITE + "]" + ChatColor.BLUE + " =-----\n"; - if(rentedBy == null) + if(buyer == null) { msg += ChatColor.AQUA + "This " + claimType + " is for rent for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for a duration of " + ChatColor.GREEN + Utils.getTime(duration, null, true) + "\n"; - if(rentedBy.equals(player.getUniqueId()) && RealEstate.instance.dataStore.cfgEnableAutoRenew) - { - msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enable" : "disable") + "\n"; - } + if(claimType.equalsIgnoreCase("claim")) { msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName(); @@ -310,9 +300,13 @@ public void preview(Player player) Duration timeRemaining = Duration.ofHours(24).minus(hours); msg += ChatColor.AQUA + "This " + claimType + " is currently rented by " + - ChatColor.GREEN + Bukkit.getOfflinePlayer(rentedBy).getName() + ChatColor.AQUA + " for " + + ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for another " + ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n"; + if((owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.dataStore.cfgEnableAutoRenew) + { + msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enable" : "disable") + "\n"; + } if(claimType.equalsIgnoreCase("claim")) { msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName(); diff --git a/src/me/EtienneDx/RealEstate/DataStore.java b/src/me/EtienneDx/RealEstate/DataStore.java index 007f80b..a2f8184 100644 --- a/src/me/EtienneDx/RealEstate/DataStore.java +++ b/src/me/EtienneDx/RealEstate/DataStore.java @@ -78,7 +78,7 @@ public void loadConfig(YamlConfiguration config) this.cfgSignsHeader = config.getString("RealEstate.Keywords.SignsHeader", ChatColor.GOLD + "[RealEstate]"); //this.cfgSigns = getConfigList(config, "RealEstate.Keywords.Signs", Arrays.asList("[re]", "[realestate]")); - this.cfgSellKeywords = getConfigList(config, "RealEstate.Keywords.Sell", Arrays.asList("[sell]", "[sellclaim]", "[sc]", "[re]", "[realestate]")); + this.cfgSellKeywords = getConfigList(config, "RealEstate.Keywords.Sell", Arrays.asList("[sell]", "[sell claim]", "[sc]", "[re]", "[realestate]")); this.cfgRentKeywords = getConfigList(config, "RealEstate.Keywords.Rent", Arrays.asList("[rent]", "[rent claim]", "[rc]")); this.cfgLeaseKeywords = getConfigList(config, "RealEstate.Keywords.Lease", Arrays.asList("[lease]", "[lease claim]", "[lc]")); diff --git a/src/me/EtienneDx/RealEstate/ExitOffer.java b/src/me/EtienneDx/RealEstate/ExitOffer.java new file mode 100644 index 0000000..49d7acc --- /dev/null +++ b/src/me/EtienneDx/RealEstate/ExitOffer.java @@ -0,0 +1,34 @@ +package me.EtienneDx.RealEstate; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.configuration.serialization.ConfigurationSerializable; + +public class ExitOffer implements ConfigurationSerializable +{ + UUID offerBy; + double price; + + public ExitOffer(UUID offerBy, double price) + { + this.offerBy = offerBy; + this.price = price; + } + + public ExitOffer(Map map) + { + offerBy = UUID.fromString((String)map.get("offerBy")); + price = (double)map.get("price"); + } + + @Override + public Map serialize() + { + HashMap map = new HashMap<>(); + map.put("offerBy", offerBy.toString()); + map.put("price", price); + return map; + } +} diff --git a/src/me/EtienneDx/RealEstate/REListener.java b/src/me/EtienneDx/RealEstate/REListener.java index 3c28cf8..26fcb2d 100644 --- a/src/me/EtienneDx/RealEstate/REListener.java +++ b/src/me/EtienneDx/RealEstate/REListener.java @@ -1,8 +1,10 @@ package me.EtienneDx.RealEstate; +import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.block.Sign; @@ -331,10 +333,12 @@ private double getDouble(SignChangeEvent event, int line, double defaultValue) t @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - if(event.getHand().equals(EquipmentSlot.HAND) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && event.getClickedBlock().getState() instanceof Sign) + if(event.getHand().equals(EquipmentSlot.HAND) && event.getAction().equals(Action.RIGHT_CLICK_BLOCK) && + event.getClickedBlock().getState() instanceof Sign) { Sign sign = (Sign)event.getClickedBlock().getState(); - if(ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(ChatColor.stripColor(RealEstate.instance.dataStore.cfgSignsHeader)))// it is a real estate sign + // it is a real estate sign + if(ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(ChatColor.stripColor(RealEstate.instance.dataStore.cfgSignsHeader))) { Player player = event.getPlayer(); Claim claim = GriefPrevention.instance.dataStore.getClaimAt(event.getClickedBlock().getLocation(), false, null); @@ -421,7 +425,10 @@ else if(args[0].equalsIgnoreCase("renewRent")) return true; } if(!(sender instanceof Player)) - return false; + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Only players can use this command!"); + return true; + } Claim claim = GriefPrevention.instance.dataStore.getClaimAt(((Player)sender).getLocation(), false, null); if(claim == null) { @@ -436,7 +443,7 @@ else if(args[0].equalsIgnoreCase("renewRent")) return true; } ClaimRent cr = (ClaimRent)tr; - if(!((Player)sender).getUniqueId().equals(cr.rentedBy) && !((Player)sender).getUniqueId().equals(cr.owner)) + if(!((Player)sender).getUniqueId().equals(cr.buyer) && !((Player)sender).getUniqueId().equals(cr.owner)) { sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are not the person renting this " + claimType + "!"); @@ -450,7 +457,7 @@ else if(args[0].equalsIgnoreCase("renewRent")) } else if(args.length > 2 || (!args[1].equalsIgnoreCase("enable") && !args[1].equalsIgnoreCase("disable"))) { - sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Usage : /" + label + " renewRent [enable|disable]!"); + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Usage : /" + label + " renewrent [enable|disable]!"); return true; } cr.autoRenew = args[1].equalsIgnoreCase("enable"); @@ -459,10 +466,159 @@ else if(args.length > 2 || (!args[1].equalsIgnoreCase("enable") && !args[1].equa ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!"); return true; } + else if(args[0].equalsIgnoreCase("exitoffer")) + { + if(!(sender instanceof Player)) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Only players can use this command!"); + return true; + } + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(((Player)sender).getLocation(), false, null); + if(claim == null) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are not standing inside of a claim!"); + return true; + } + String claimType = claim.parent == null ? "claim" : "subclaim"; + Transaction tr = RealEstate.transactionsStore.getTransaction(claim); + if(!(tr instanceof BoughtTransaction)) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim is not for rent or lease!"); + return true; + } + BoughtTransaction bt = (BoughtTransaction)tr; + if(!((Player)sender).getUniqueId().equals(bt.getBuyer()) && !((Player)sender).getUniqueId().equals(tr.getOwner())) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "You are not the person renting or leasing this " + claimType + "!"); + return true; + } + if(args.length == 1 || args[1].equalsIgnoreCase("info")) + { + if(bt.exitOffer == null) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "There is currently no exit offer for this claim!"); + } + else if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId())) + { + String msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You offered to exit the contract for " + + ChatColor.GREEN + bt.exitOffer.price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + + ", but your offer hasn't been accepted or denied yet...\n"; + msg += ChatColor.AQUA + "To cancel your offer, just type " + ChatColor.LIGHT_PURPLE + "/" + label + " exitoffer cancel"; + sender.sendMessage(msg); + } + else// it is the other person + { + String msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + Bukkit.getOfflinePlayer(bt.exitOffer.offerBy).getName() + + ChatColor.AQUA + " offered to exit the contract for " + + ChatColor.GREEN + bt.exitOffer.price + " " + RealEstate.econ.currencyNamePlural() + "\n"; + msg += ChatColor.AQUA + "To accept the offer, just type " + ChatColor.LIGHT_PURPLE + "/" + label + " exitoffer accept\n"; + msg += ChatColor.AQUA + "To refuse the offer, just type " + ChatColor.LIGHT_PURPLE + "/" + label + " exitoffer refuse\n"; + sender.sendMessage(msg); + } + return true; + } + else if(!Arrays.asList("cancel", "accept", "refuse", "create").contains(args[1].toLowerCase())) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Usage : /" + label + + " exitoffer [cancel|accept|refuse|info|create]"); + return true; + } + if(args[1].equalsIgnoreCase("create")) + { + if(bt.exitOffer != null) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "There is already an exit proposition for this transaction!"); + return true; + } + if(args.length != 3) + { + + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "Usage : /" + label + " exitoffer create "); + return true; + } + double price; + try + { + price = Double.parseDouble(args[2]); + } + catch(Exception e) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "The price isn't a valid number!"); + return true; + } + if(price < 0) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "The price must be a positive number!"); + return true; + } + bt.exitOffer = new ExitOffer(((Player)sender).getUniqueId(), price); + + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + + "The proposition has been successfully created!"); + } + else + { + if(bt.exitOffer == null) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "There has been no exit propositions for this transaction!"); + return true; + } + if(args[1].equalsIgnoreCase("cancel")) + { + if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId())) + { + bt.exitOffer = null; + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + + "This exit offer has been cancelled"); + } + else + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "Only the player who created this exit proposition may cancel it"); + } + } + else if(args[1].equalsIgnoreCase("accept") || args[1].equalsIgnoreCase("refuse")) + { + if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId())) + { + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + + "You can't accept or refuse an offer you made!"); + } + else + { + if(args[1].equalsIgnoreCase("refuse"))// easy part + { + bt.exitOffer = null; + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + + "This exit offer has been refused"); + } + else if(Utils.makePayment(((Player)sender).getUniqueId(), bt.exitOffer.offerBy, bt.exitOffer.price, true, false)) + { + bt.exitOffer = null; + claim.dropPermission(bt.buyer.toString()); + bt.buyer = null; + bt.update();// eventual cancel is contained in here + sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + + "This exit offer has been accepted, the " + claimType + " is no longer rented or leased!"); + } + // in case of payment failure, a msg has been sent by the utils function + } + } + } + + RealEstate.transactionsStore.saveData(); + return true; + } } else// plugin infos { - String msg = ChatColor.BLUE + "---------= [" + ChatColor.GOLD + RealEstate.instance.getDescription().getName() + ChatColor.BLUE + "] =---------\n"; + String msg = ChatColor.BLUE + "-------= [" + ChatColor.GOLD + RealEstate.instance.getDescription().getName() + ChatColor.BLUE + "] =-------\n"; msg += ChatColor.AQUA + "/" + label + ChatColor.LIGHT_PURPLE + " info" + ChatColor.AQUA + " : Gets the informations about the transactions going on in the claim you're standing in.\n"; diff --git a/src/me/EtienneDx/RealEstate/RealEstate.java b/src/me/EtienneDx/RealEstate/RealEstate.java index c80d95b..6e12493 100644 --- a/src/me/EtienneDx/RealEstate/RealEstate.java +++ b/src/me/EtienneDx/RealEstate/RealEstate.java @@ -64,6 +64,7 @@ public void onEnable() ConfigurationSerialization.registerClass(ClaimSell.class); ConfigurationSerialization.registerClass(ClaimRent.class); ConfigurationSerialization.registerClass(ClaimLease.class); + ConfigurationSerialization.registerClass(ExitOffer.class); RealEstate.transactionsStore = new TransactionsStore(); diff --git a/src/me/EtienneDx/RealEstate/TransactionsStore.java b/src/me/EtienneDx/RealEstate/TransactionsStore.java index 350603a..55d984a 100644 --- a/src/me/EtienneDx/RealEstate/TransactionsStore.java +++ b/src/me/EtienneDx/RealEstate/TransactionsStore.java @@ -147,7 +147,7 @@ public void cancelTransaction(Transaction tr) public boolean canCancelTransaction(Transaction tr) { - return tr instanceof ClaimSell || (tr instanceof ClaimRent && ((ClaimRent)tr).rentedBy == null) || + return tr instanceof ClaimSell || (tr instanceof ClaimRent && ((ClaimRent)tr).buyer == null) || (tr instanceof ClaimLease && ((ClaimLease)tr).buyer == null); } diff --git a/src/me/EtienneDx/RealEstate/Utils.java b/src/me/EtienneDx/RealEstate/Utils.java index e89b0ca..15b9aee 100644 --- a/src/me/EtienneDx/RealEstate/Utils.java +++ b/src/me/EtienneDx/RealEstate/Utils.java @@ -16,10 +16,10 @@ public class Utils { - public static boolean makePayment(UUID seller, UUID buyer, double amount, boolean msgSeller, boolean msgBuyer) + public static boolean makePayment(UUID receiver, UUID giver, double amount, boolean msgSeller, boolean msgBuyer) { // seller might be null if it is the server - OfflinePlayer s = seller != null ? Bukkit.getOfflinePlayer(seller) : null, b = Bukkit.getOfflinePlayer(buyer); + OfflinePlayer s = receiver != null ? Bukkit.getOfflinePlayer(receiver) : null, b = Bukkit.getOfflinePlayer(giver); if(!RealEstate.econ.has(b, amount)) { if(b.isOnline() && msgBuyer)