From 2b6b0ae13e30359588d1a1586ca5cc064f4de4b2 Mon Sep 17 00:00:00 2001 From: EtienneDx Date: Mon, 29 Apr 2019 14:56:57 +0200 Subject: [PATCH] Switched commands to ACF --- pom.xml | 31 ++ src/me/EtienneDx/RealEstate/RECommand.java | 265 ++++++++++++++++ src/me/EtienneDx/RealEstate/REListener.java | 296 +----------------- src/me/EtienneDx/RealEstate/RealEstate.java | 99 +++++- .../RealEstate/Transactions/ClaimRent.java | 9 +- .../Transactions/TransactionsStore.java | 8 + 6 files changed, 410 insertions(+), 298 deletions(-) create mode 100644 src/me/EtienneDx/RealEstate/RECommand.java diff --git a/pom.xml b/pom.xml index c76523b..74f9d19 100644 --- a/pom.xml +++ b/pom.xml @@ -29,6 +29,28 @@ 1.8 + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + ${project.build.directory}/dependency-reduced-pom.xml + + + co.aikar.commands + me.EtienneDx.RealEstate.acf + + + + + + package + + shade + + + + @@ -48,6 +70,10 @@ vault-repo http://nexus.hc.to/content/repositories/pub_releases + + aikar + https://repo.aikar.co/content/groups/aikar/ + @@ -66,5 +92,10 @@ GriefPrevention 16.11.6 + + co.aikar + acf-bukkit + 0.5.0-SNAPSHOT + \ No newline at end of file diff --git a/src/me/EtienneDx/RealEstate/RECommand.java b/src/me/EtienneDx/RealEstate/RECommand.java new file mode 100644 index 0000000..2ceec0d --- /dev/null +++ b/src/me/EtienneDx/RealEstate/RECommand.java @@ -0,0 +1,265 @@ +package me.EtienneDx.RealEstate; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import co.aikar.commands.BaseCommand; +import co.aikar.commands.CommandHelp; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Conditions; +import co.aikar.commands.annotation.Default; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.HelpCommand; +import co.aikar.commands.annotation.Optional; +import co.aikar.commands.annotation.Subcommand; +import me.EtienneDx.RealEstate.Transactions.BoughtTransaction; +import me.EtienneDx.RealEstate.Transactions.ClaimRent; +import me.EtienneDx.RealEstate.Transactions.ExitOffer; +import me.EtienneDx.RealEstate.Transactions.Transaction; +import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.GriefPrevention; + +@CommandAlias("re|realestate") +public class RECommand extends BaseCommand +{ + @Subcommand("info") + @Description("Gives the player informations about the claim he is standing in") + @CommandPermission("realestate.info") + public static void info(Player player) + { + if(RealEstate.transactionsStore.anyTransaction( + GriefPrevention.instance.dataStore.getClaimAt(((Player)player).getLocation(), false, null))) + { + Transaction tr = RealEstate.transactionsStore.getTransaction( + GriefPrevention.instance.dataStore.getClaimAt(((Player)player).getLocation(), false, null)); + tr.preview((Player)player); + } + else + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction found at your location!"); + } + } + + @Subcommand("renewrent") + @Description("Allows the player renting a claim or subclaim to enable or disable the automatic renew of his rent") + @Conditions("partOfRent") + @CommandCompletion("enable|disable") + public static void renewRent(Player player, @Optional String newStatus) + { + Location loc = player.getLocation(); + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null); + ClaimRent cr = (ClaimRent)RealEstate.transactionsStore.getTransaction(claim); + String claimType = claim.parent == null ? "claim" : "subclaim"; + if(!RealEstate.instance.config.cfgEnableAutoRenew) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Automatic renew is disabled!"); + return; + } + if(newStatus == null) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is currently " + + ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!"); + } + else if(!newStatus.equalsIgnoreCase("enable") && !newStatus.equalsIgnoreCase("disable")) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Usage : /re renewrent [enable|disable]!"); + } + else if(cr.buyer.equals(player.getUniqueId())) + { + cr.autoRenew = newStatus.equalsIgnoreCase("enable"); + RealEstate.transactionsStore.saveData(); + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is now " + + ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!"); + } + else + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Only the buyer may change this setting!"); + } + } + + @Subcommand("exitoffer") + @Conditions("partOfBoughtTransaction") + public class ExitOfferCommand extends BaseCommand + { + @Subcommand("info") + @Default + @Description("View informations about the exit offer") + public void info(Player player) + { + BoughtTransaction bt = (BoughtTransaction)RealEstate.transactionsStore.getTransaction(player); + if(bt.exitOffer == null) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "There is currently no exit offer for this claim!"); + } + else if(bt.exitOffer.offerBy.equals(player.getUniqueId())) + { + String msg = RealEstate.instance.config.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 + "/re exitoffer cancel"; + player.sendMessage(msg); + } + else// it is the other person + { + String msg = RealEstate.instance.config.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 + "/re exitoffer accept\n"; + msg += ChatColor.AQUA + "To refuse the offer, just type " + ChatColor.LIGHT_PURPLE + "/re exitoffer refuse\n"; + player.sendMessage(msg); + } + } + + @Subcommand("create") + @Description("Creates an offer to break an ongoing transaction") + public void create(Player player, @Conditions("positiveDouble") Double price) + { + BoughtTransaction bt = (BoughtTransaction)RealEstate.transactionsStore.getTransaction(player); + if(bt.exitOffer != null) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "There is already an exit proposition for this transaction!"); + return; + } + if(bt.buyer == null) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "No one is engaged by this transaction yet!"); + return; + } + bt.exitOffer = new ExitOffer(player.getUniqueId(), price); + + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + + "The proposition has been successfully created!"); + UUID other = player.getUniqueId().equals(bt.owner) ? bt.buyer : bt.owner; + OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); + if(otherP.isOnline()) + { + Location loc = player.getLocation(); + String claimType = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null).parent == null ? "claim" : "subclaim"; + ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + + ChatColor.AQUA + " has created an offer to exit the rent/lease contract for the " + claimType + " at " + + ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: " + + loc.getBlockZ() + "]" + ChatColor.AQUA + " for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural()); + } + } + + @Subcommand("accept") + @Description("Accepts an offer to break an ongoing transaction") + public void accept(Player player) + { + Location loc = player.getLocation(); + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null); + BoughtTransaction bt = (BoughtTransaction)RealEstate.transactionsStore.getTransaction(claim); + String claimType = claim.parent == null ? "claim" : "subclaim"; + if(bt.exitOffer == null) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "There has been no exit propositions for this transaction!"); + } + else if(bt.exitOffer.offerBy.equals(player.getUniqueId())) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "You can't accept or refuse an offer you made!"); + } + else if(Utils.makePayment(player.getUniqueId(), bt.exitOffer.offerBy, bt.exitOffer.price, true, false)) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + + "This exit offer has been accepted, the " + claimType + " is no longer rented or leased!"); + UUID other = player.getUniqueId().equals(bt.owner) ? bt.buyer : bt.owner; + OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); + if(otherP.isOnline()) + { + ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + + ChatColor.AQUA + " has accepted your offer to exit the rent/lease contract for the " + claimType + " at " + + ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + + ", Z: " + loc.getBlockZ() + "]. It is no longer rented or leased."); + } + bt.exitOffer = null; + claim.dropPermission(bt.buyer.toString()); + bt.buyer = null; + bt.update();// eventual cancel is contained in here + } + // the make payment takes care of sending error if need be + } + + @Subcommand("refuse") + @Description("Refuses an offer to break an ongoing transaction") + public void refuse(Player player) + { + Location loc = player.getLocation(); + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null); + BoughtTransaction bt = (BoughtTransaction)RealEstate.transactionsStore.getTransaction(claim); + String claimType = claim.parent == null ? "claim" : "subclaim"; + if(bt.exitOffer == null) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "There has been no exit propositions for this transaction!"); + } + else if(bt.exitOffer.offerBy.equals(player.getUniqueId())) + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "You can't accept or refuse an offer you made!"); + } + else + { + bt.exitOffer = null; + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + + "This exit offer has been refused"); + UUID other = player.getUniqueId().equals(bt.owner) ? bt.buyer : bt.owner; + OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); + if(otherP.isOnline()) + { + ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + + ChatColor.AQUA + " has refused your offer to exit the rent/lease contract for the " + claimType + " at " + + ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + + ", Z: " + loc.getBlockZ() + "]"); + } + } + } + + @Subcommand("cancel") + @Description("Cancels an offer to break an ongoing transaction") + public void cancel(Player player) + { + Location loc = player.getLocation(); + Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null); + BoughtTransaction bt = (BoughtTransaction)RealEstate.transactionsStore.getTransaction(claim); + String claimType = claim.parent == null ? "claim" : "subclaim"; + if(bt.exitOffer.offerBy.equals(player.getUniqueId())) + { + bt.exitOffer = null; + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + + "This exit offer has been cancelled"); + UUID other = player.getUniqueId().equals(bt.owner) ? bt.buyer : bt.owner; + OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); + if(otherP.isOnline()) + { + ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + + ChatColor.AQUA + " has cancelled his offer to exit the rent/lease contract for the " + claimType + " at " + + ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: " + + loc.getBlockZ() + "]"); + } + } + else + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + + "Only the player who created this exit proposition may cancel it"); + } + } + } + + @HelpCommand + public static void onHelp(CommandSender sender, CommandHelp help) + { + help.showHelp(); + } +} diff --git a/src/me/EtienneDx/RealEstate/REListener.java b/src/me/EtienneDx/RealEstate/REListener.java index be04a7a..f7f5815 100644 --- a/src/me/EtienneDx/RealEstate/REListener.java +++ b/src/me/EtienneDx/RealEstate/REListener.java @@ -1,18 +1,11 @@ package me.EtienneDx.RealEstate; -import java.util.Arrays; -import java.util.UUID; 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.OfflinePlayer; import org.bukkit.block.Sign; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -23,21 +16,18 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.plugin.PluginManager; -import me.EtienneDx.RealEstate.Transactions.BoughtTransaction; -import me.EtienneDx.RealEstate.Transactions.ClaimRent; -import me.EtienneDx.RealEstate.Transactions.ExitOffer; import me.EtienneDx.RealEstate.Transactions.Transaction; import me.ryanhamshire.GriefPrevention.Claim; import me.ryanhamshire.GriefPrevention.GriefPrevention; -public class REListener implements Listener, CommandExecutor +public class REListener implements Listener { void registerEvents() { PluginManager pm = RealEstate.instance.getServer().getPluginManager(); pm.registerEvents(this, RealEstate.instance); - RealEstate.instance.getCommand("re").setExecutor(this); + //RealEstate.instance.getCommand("re").setExecutor(this); } @EventHandler @@ -423,286 +413,4 @@ public void onBreakBlock(BlockBreakEvent event) } } } - - @Override - public boolean onCommand(CommandSender sender, Command command, String label, String[] args) - { - if(args.length >= 1 && !args[0].equalsIgnoreCase("help")) - { - if(args[0].equalsIgnoreCase("info")) - { - if(sender.hasPermission("realestate.info")) - { - if(sender instanceof Player && RealEstate.transactionsStore.anyTransaction( - GriefPrevention.instance.dataStore.getClaimAt(((Player)sender).getLocation(), false, null))) - { - Transaction tr = RealEstate.transactionsStore.getTransaction( - GriefPrevention.instance.dataStore.getClaimAt(((Player)sender).getLocation(), false, null)); - tr.preview((Player)sender); - } - else - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction found at your location!"); - } - } - else - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to view claim infos!"); - } - return true; - } - else if(args[0].equalsIgnoreCase("renewRent")) - { - if(!RealEstate.instance.config.cfgEnableAutoRenew) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Automatic renew is disabled!"); - return true; - } - if(!(sender instanceof Player)) - { - sender.sendMessage(RealEstate.instance.config.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.config.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 ClaimRent)) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim is not for rent!"); - return true; - } - ClaimRent cr = (ClaimRent)tr; - if(!((Player)sender).getUniqueId().equals(cr.buyer) && !((Player)sender).getUniqueId().equals(cr.owner)) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + - "You are not the person renting this " + claimType + "!"); - return true; - } - if(args.length == 1 || ((Player)sender).getUniqueId().equals(cr.owner)) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is currently " + - ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!"); - return true; - } - else if(args.length > 2 || (!args[1].equalsIgnoreCase("enable") && !args[1].equalsIgnoreCase("disable"))) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Usage : /" + label + " renewrent [enable|disable]!"); - return true; - } - cr.autoRenew = args[1].equalsIgnoreCase("enable"); - RealEstate.transactionsStore.saveData(); - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is now " + - 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.config.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.config.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.config.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.config.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.config.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.config.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.config.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.config.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.config.chatPrefix + ChatColor.RED + - "There is already an exit proposition for this transaction!"); - return true; - } - if(args.length != 3) - { - - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + - "Usage : /" + label + " exitoffer create "); - return true; - } - double price; - try - { - price = Double.parseDouble(args[2]); - } - catch(Exception e) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + - "The price isn't a valid number!"); - return true; - } - if(price < 0) - { - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + - "The price must be a positive number!"); - return true; - } - bt.exitOffer = new ExitOffer(((Player)sender).getUniqueId(), price); - - sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + - "The proposition has been successfully created!"); - UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner; - OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); - if(otherP.isOnline()) - { - Location loc = ((Player)sender).getLocation(); - ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() + - ChatColor.AQUA + " as created an offer to exit the rent/lease contract for the " + claimType + " at " + - ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: " - + loc.getBlockZ() + "]" + ChatColor.AQUA + " for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural()); - } - } - else - { - if(bt.exitOffer == null) - { - sender.sendMessage(RealEstate.instance.config.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.config.chatPrefix + ChatColor.AQUA + - "This exit offer has been cancelled"); - UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner; - OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); - if(otherP.isOnline()) - { - Location loc = ((Player)sender).getLocation(); - ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() + - ChatColor.AQUA + " as cancelled his offer to exit the rent/lease contract for the " + claimType + " at " + - ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: " - + loc.getBlockZ() + "]"); - } - } - else - { - sender.sendMessage(RealEstate.instance.config.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.config.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.config.chatPrefix + ChatColor.AQUA + - "This exit offer has been refused"); - UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner; - OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); - if(otherP.isOnline()) - { - Location loc = ((Player)sender).getLocation(); - ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() + - ChatColor.AQUA + " as refused your offer to exit the rent/lease contract for the " + claimType + " at " + - ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + - ", Z: " + loc.getBlockZ() + "]"); - } - } - 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.config.chatPrefix + ChatColor.AQUA + - "This exit offer has been accepted, the " + claimType + " is no longer rented or leased!"); - UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner; - OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); - if(otherP.isOnline()) - { - Location loc = ((Player)sender).getLocation(); - ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() + - ChatColor.AQUA + " as accepted your offer to exit the rent/lease contract for the " + claimType + " at " + - ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + - ", Z: " + loc.getBlockZ() + "]. It 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"; - - 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"; - if(sender.hasPermission("realestate.autorenew") && RealEstate.instance.config.cfgEnableAutoRenew) - msg += ChatColor.AQUA + "/" + label + ChatColor.LIGHT_PURPLE + " renewRent" + ChatColor.AQUA + - " : Allow you to enable or disable the automatic renewal of rents\n"; - - sender.sendMessage(msg); - return true; - } - return false; - } } diff --git a/src/me/EtienneDx/RealEstate/RealEstate.java b/src/me/EtienneDx/RealEstate/RealEstate.java index 30f4be6..589b644 100644 --- a/src/me/EtienneDx/RealEstate/RealEstate.java +++ b/src/me/EtienneDx/RealEstate/RealEstate.java @@ -10,11 +10,17 @@ import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import co.aikar.commands.BukkitCommandManager; +import co.aikar.commands.ConditionFailedException; +import me.EtienneDx.RealEstate.Transactions.BoughtTransaction; import me.EtienneDx.RealEstate.Transactions.ClaimLease; import me.EtienneDx.RealEstate.Transactions.ClaimRent; import me.EtienneDx.RealEstate.Transactions.ClaimSell; import me.EtienneDx.RealEstate.Transactions.ExitOffer; +import me.EtienneDx.RealEstate.Transactions.Transaction; import me.EtienneDx.RealEstate.Transactions.TransactionsStore; +import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.GriefPrevention; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; @@ -22,6 +28,7 @@ public class RealEstate extends JavaPlugin { public Logger log; public Config config; + BukkitCommandManager manager; public final static String pluginDirPath = "plugins" + File.separator + "RealEstate" + File.separator; public static boolean vaultPresent = false; public static Economy econ = null; @@ -31,6 +38,7 @@ public class RealEstate extends JavaPlugin public static TransactionsStore transactionsStore = null; + @SuppressWarnings("deprecation") public void onEnable() { RealEstate.instance = this; @@ -74,9 +82,98 @@ public void onEnable() RealEstate.transactionsStore = new TransactionsStore(); new REListener().registerEvents(); + + manager = new BukkitCommandManager(this); + manager.enableUnstableAPI("help"); + registerConditions(); + manager.registerCommand(new RECommand()); + } + + private void registerConditions() + { + manager.getCommandConditions().addCondition("inClaim", (context) -> { + if(context.getIssuer().isPlayer() && + GriefPrevention.instance.dataStore.getClaimAt(context.getIssuer().getPlayer().getLocation(), false, null) != null) + { + return; + } + throw new ConditionFailedException("You must stand inside of a claim to use this command!"); + }); + manager.getCommandConditions().addCondition("inBoughtClaim", (context) -> { + if(!context.getIssuer().isPlayer()) + { + throw new ConditionFailedException("Only Players can perform this command!"); + } + Claim c = GriefPrevention.instance.dataStore.getClaimAt(context.getIssuer().getPlayer().getLocation(), false, null); + if(c == null) + { + throw new ConditionFailedException("You must stand inside of a claim to use this command!"); + } + Transaction tr = transactionsStore.getTransaction(c); + if(tr == null || !(tr instanceof BoughtTransaction)) + { + throw new ConditionFailedException("This claim is neither to rent or to lease!"); + } + }); + manager.getCommandConditions().addCondition("partOfBoughtTransaction", context -> { + if(!context.getIssuer().isPlayer()) + { + throw new ConditionFailedException("Only Players can perform this command!"); + } + Claim c = GriefPrevention.instance.dataStore.getClaimAt(context.getIssuer().getPlayer().getLocation(), false, null); + if(c == null) + { + throw new ConditionFailedException("You must stand inside of a claim to use this command!"); + } + Transaction tr = transactionsStore.getTransaction(c); + if(tr == null) + { + throw new ConditionFailedException("This claim is neither to sell, rent or lease!"); + } + if(!(tr instanceof BoughtTransaction)) + { + throw new ConditionFailedException("This command only applies to rented or leased claims!"); + } + if((((BoughtTransaction)tr).buyer != null&& ((BoughtTransaction)tr).buyer.equals(context.getIssuer().getPlayer().getUniqueId())) || + tr.getOwner().equals(context.getIssuer().getPlayer().getUniqueId())) + { + return; + } + throw new ConditionFailedException("You are not part of this transaction!"); + }); + manager.getCommandConditions().addCondition("partOfRent", context -> { + if(!context.getIssuer().isPlayer()) + { + throw new ConditionFailedException("Only Players can perform this command!"); + } + Claim c = GriefPrevention.instance.dataStore.getClaimAt(context.getIssuer().getPlayer().getLocation(), false, null); + if(c == null) + { + throw new ConditionFailedException("You must stand inside of a claim to use this command!"); + } + Transaction tr = transactionsStore.getTransaction(c); + if(tr == null) + { + throw new ConditionFailedException("This claim is neither to sell, rent or lease!"); + } + if(!(tr instanceof ClaimRent)) + { + throw new ConditionFailedException("This command only applies to rented claims!"); + } + if((((ClaimRent)tr).buyer != null && ((ClaimRent)tr).buyer.equals(context.getIssuer().getPlayer().getUniqueId())) || + tr.getOwner().equals(context.getIssuer().getPlayer().getUniqueId())) + { + return; + } + throw new ConditionFailedException("You are not part of this transaction!"); + }); + manager.getCommandConditions().addCondition(Double.class, "positiveDouble", (c, exec, value) -> { + if(value > 0) return; + throw new ConditionFailedException("The value must be greater than zero!"); + }); } - public void addLogEntry(String entry) + public void addLogEntry(String entry) { try { diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java index 7349c77..eab0c98 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java @@ -287,7 +287,8 @@ public void preview(Player player) 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 + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " + + (maxPeriod > 1 ? "" + ChatColor.GREEN + maxPeriod + ChatColor.AQUA + " periods of " : "") + ChatColor.GREEN + Utils.getTime(duration, null, true) + "\n"; if(claimType.equalsIgnoreCase("claim")) @@ -314,11 +315,13 @@ public void preview(Player player) msg += ChatColor.AQUA + "This " + claimType + " is currently rented by " + ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " + - ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for another " + + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " + + (maxPeriod - periodCount > 1 ? "" + ChatColor.GREEN + (maxPeriod - periodCount) + ChatColor.AQUA + " periods of " + + ChatColor.GREEN + Utils.getTime(duration, null, false) + ChatColor.AQUA + ". The current period will end in " : "another ") + ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n"; if((owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.config.cfgEnableAutoRenew) { - msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enable" : "disable") + "\n"; + msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enabled" : "disabled") + "\n"; } if(claimType.equalsIgnoreCase("claim")) { diff --git a/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java b/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java index 2f0b323..64f9af7 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java +++ b/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java @@ -17,6 +17,7 @@ import me.EtienneDx.RealEstate.RealEstate; import me.ryanhamshire.GriefPrevention.Claim; +import me.ryanhamshire.GriefPrevention.GriefPrevention; import net.md_5.bungee.api.ChatColor; public class TransactionsStore @@ -262,4 +263,11 @@ public void lease(Claim claim, Player player, double price, Location sign, int f } } } + + public Transaction getTransaction(Player player) + { + if(player == null) return null; + Claim c = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), false, null); + return getTransaction(c); + } }