diff --git a/plugin.yml b/plugin.yml index e2a18a1..cdf415d 100644 --- a/plugin.yml +++ b/plugin.yml @@ -19,6 +19,7 @@ permissions: children: realestate.info: true realestate.admin: true + realestate.destroysigns: true realestate.claim.buy: true realestate.claim.sell: true realestate.claim.rent: true @@ -77,4 +78,6 @@ permissions: realestate.ignore.limit: description: Allows the player to buy bigger claims than his available claim size default: false - \ No newline at end of file + realestate.destroysigns: + description: Allows the player to destroy any sign representing a transaction + default: op \ No newline at end of file diff --git a/src/me/EtienneDx/RealEstate/ClaimSell.java b/src/me/EtienneDx/RealEstate/ClaimSell.java index 938b79b..bd5f372 100644 --- a/src/me/EtienneDx/RealEstate/ClaimSell.java +++ b/src/me/EtienneDx/RealEstate/ClaimSell.java @@ -12,14 +12,15 @@ import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.block.Block; import org.bukkit.block.Sign; -public class ClaimSell implements ConfigurationSerializable +public class ClaimSell implements ConfigurationSerializable, Transaction { - public long claimId; + long claimId; private UUID owner = null; private double price; - private Sign sign = null; + Sign sign = null; public ClaimSell(Map map) { @@ -34,7 +35,7 @@ public ClaimSell(Map map) public ClaimSell(Claim claim, Player player, double price, Sign sign) { this.claimId = claim.getID(); - this.owner = player.getUniqueId(); + this.owner = player != null ? player.getUniqueId() : null; this.price = price; this.sign = sign; } @@ -64,4 +65,16 @@ public Map serialize() return map; } + + @Override + public Block getHolder() + { + return (Block) sign; + } + + @Override + public UUID getOwner() + { + return owner; + } } diff --git a/src/me/EtienneDx/RealEstate/REListener.java b/src/me/EtienneDx/RealEstate/REListener.java index 6b15f3d..4f1dc14 100644 --- a/src/me/EtienneDx/RealEstate/REListener.java +++ b/src/me/EtienneDx/RealEstate/REListener.java @@ -6,6 +6,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.SignChangeEvent; import org.bukkit.plugin.PluginManager; @@ -95,4 +96,24 @@ else if(type.equals("claim") && !player.getName().equalsIgnoreCase(claim.getOwne } } } + + @EventHandler + public void onBreakBlock(BlockBreakEvent event) + { + if(event.getBlock() instanceof Sign) + { + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(event.getBlock().getLocation(), false, null); + Transaction tr = RealEstate.transactionsStore.getTransaction(claim); + if(tr.getHolder() == event.getBlock() && !tr.getOwner().equals(event.getPlayer().getUniqueId()) && + !RealEstate.perms.has(event.getPlayer(), "realestate.destroysigns")) + { + event.getPlayer().sendMessage(RealEstate.instance.dataStore.chatPrefix + + ChatColor.RED + "Only the author of the sell/rent sign is allowed to destroy it"); + event.setCancelled(true); + return; + } + // the sign has been destroy, we can remove the transaction + RealEstate.transactionsStore.cancelTransaction(claim); + } + } } diff --git a/src/me/EtienneDx/RealEstate/Transaction.java b/src/me/EtienneDx/RealEstate/Transaction.java new file mode 100644 index 0000000..1b1da3a --- /dev/null +++ b/src/me/EtienneDx/RealEstate/Transaction.java @@ -0,0 +1,11 @@ +package me.EtienneDx.RealEstate; + +import java.util.UUID; + +import org.bukkit.block.Block; + +public interface Transaction +{ + public Block getHolder(); + public UUID getOwner(); +} diff --git a/src/me/EtienneDx/RealEstate/TransactionsStore.java b/src/me/EtienneDx/RealEstate/TransactionsStore.java index cab6da5..f53b185 100644 --- a/src/me/EtienneDx/RealEstate/TransactionsStore.java +++ b/src/me/EtienneDx/RealEstate/TransactionsStore.java @@ -2,18 +2,25 @@ import java.io.File; import java.io.IOException; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; +import org.bukkit.Bukkit; import org.bukkit.block.Sign; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import me.ryanhamshire.GriefPrevention.Claim; +import net.md_5.bungee.api.ChatColor; public class TransactionsStore { public final String dataFilePath = RealEstate.pluginDirPath + "transactions.data"; + DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + Date date = new Date(); public HashMap claimSell; @@ -53,10 +60,52 @@ public void sell(Claim claim, Player player, double price, Sign sign) claimSell.put(claim.getID().toString(), cs); cs.updateSign(); saveData(); + + RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() + + " has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale at " + + "[" + player.getLocation().getWorld() + ", " + + "X: " + player.getLocation().getBlockX() + ", " + + "Y: " + player.getLocation().getBlockY() + ", " + + "Z: " + player.getLocation().getBlockZ() + "] " + + "Price: " + price + " " + RealEstate.econ.currencyNamePlural()); + + if(player != null) + { + player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully created " + + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " sale for " + + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural()); + } + if(RealEstate.instance.dataStore.cfgBroadcastSell) + { + for(Player p : Bukkit.getServer().getOnlinePlayers()) + { + if(p != player) + { + p.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() + + ChatColor.AQUA + " has put " + + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale for " + + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural()); + } + } + } } public boolean anyTransaction(Claim claim) { return claimSell.containsKey(claim.getID().toString()); } + + public Transaction getTransaction(Claim claim) + { + if(claimSell.containsKey(claim.getID().toString())) + return claimSell.get(claim.getID().toString()); + return null; + } + + public void cancelTransaction(Claim claim) + { + if(claimSell.containsKey(claim.getID().toString())) + claimSell.remove(claim.getID().toString()); + saveData(); + } }