diff --git a/pom.xml b/pom.xml index 7c537c2..0ad019b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 Me.EtienneDx RealEstate - 1.0.0 + 1.1.1 RealEstate A spigot plugin for selling, renting and leasing GriefPrevention claims @@ -88,7 +88,7 @@ org.spigotmc spigot-api - 1.14-R0.1-SNAPSHOT + 1.15.2-R0.1-SNAPSHOT provided diff --git a/src/me/EtienneDx/RealEstate/RECommand.java b/src/me/EtienneDx/RealEstate/RECommand.java index a6518d2..4af2f6b 100644 --- a/src/me/EtienneDx/RealEstate/RECommand.java +++ b/src/me/EtienneDx/RealEstate/RECommand.java @@ -58,7 +58,7 @@ public class RECommand extends BaseCommand @Description("Displays the list of all real estate offers currently existing") @CommandCompletion("all|sell|rent|lease") @Syntax("[all|sell|rent|lease] ") - public static void list(Player player, @Optional String type, @Default("1") int page) + public static void list(CommandSender player, @Optional String type, @Default("1") int page) { if(page <= 0) { @@ -94,34 +94,52 @@ public class RECommand extends BaseCommand player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Invalid option provided!"); return; } - player.sendMessage(ChatColor.DARK_BLUE + "----= " + ChatColor.WHITE + "[ " + ChatColor.GOLD + typeMsg + ChatColor.DARK_GREEN + " " + - page + ChatColor.GOLD + " / " + ChatColor.DARK_GREEN + (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize) + - ChatColor.WHITE + " ]" + ChatColor.DARK_BLUE + " =----"); - ArrayList transactions = new ArrayList(count); - if(type == null || type.equalsIgnoreCase("all")) + if(count == 0) { - transactions.addAll(RealEstate.transactionsStore.claimSell.values()); - transactions.addAll(RealEstate.transactionsStore.claimRent.values()); - transactions.addAll(RealEstate.transactionsStore.claimLease.values()); + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction have been found!"); } - else if(type.equalsIgnoreCase("sell")) + else { - transactions.addAll(RealEstate.transactionsStore.claimSell.values()); - } - else if(type.equalsIgnoreCase("rent")) - { - transactions.addAll(RealEstate.transactionsStore.claimRent.values()); - } - else if(type.equalsIgnoreCase("lease")) - { - transactions.addAll(RealEstate.transactionsStore.claimLease.values()); - } - - int max = Math.min(start + RealEstate.instance.config.cfgPageSize, count); - for(int i = start; i < max; i++) - { - RealEstate.instance.log.info("transaction " + i); - transactions.get(i).msgInfo(player); + ArrayList transactions = new ArrayList(count); + if(type == null || type.equalsIgnoreCase("all")) + { + transactions.addAll(RealEstate.transactionsStore.claimSell.values()); + transactions.addAll(RealEstate.transactionsStore.claimRent.values()); + transactions.addAll(RealEstate.transactionsStore.claimLease.values()); + } + else if(type.equalsIgnoreCase("sell")) + { + transactions.addAll(RealEstate.transactionsStore.claimSell.values()); + } + else if(type.equalsIgnoreCase("rent")) + { + transactions.addAll(RealEstate.transactionsStore.claimRent.values()); + } + else if(type.equalsIgnoreCase("lease")) + { + transactions.addAll(RealEstate.transactionsStore.claimLease.values()); + } + + int max = Math.min(start + RealEstate.instance.config.cfgPageSize, count); + if(start <= max) + { + player.sendMessage(ChatColor.DARK_BLUE + "----= " + ChatColor.WHITE + "[ " + ChatColor.GOLD + typeMsg + " page " + ChatColor.DARK_GREEN + " " + + page + ChatColor.GOLD + " / " + ChatColor.DARK_GREEN + (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize) + + ChatColor.WHITE + " ]" + ChatColor.DARK_BLUE + " =----"); + for(int i = start; i < max; i++) + { + RealEstate.instance.log.info("transaction " + i); + transactions.get(i).msgInfo(player); + } + if(page < (int)Math.ceil(count / (double)RealEstate.instance.config.cfgPageSize)) + { + player.sendMessage(ChatColor.GOLD + "To see the next page, type " + ChatColor.GREEN + "/re list " + (type != null ? type : "all") + " " + (page + 1)); + } + } + else + { + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This page does not exist!"); + } } } @@ -270,24 +288,27 @@ public class RECommand extends BaseCommand 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); - Location loc = player.getLocation(); - String claimType = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null).parent == null ? "claim" : "subclaim"; - if(otherP.isOnline()) + if(other != null)// not an admin claim { - ((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()); + OfflinePlayer otherP = Bukkit.getOfflinePlayer(other); + Location loc = player.getLocation(); + String claimType = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null).parent == null ? "claim" : "subclaim"; + if(otherP.isOnline()) + { + ((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()); + } + else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) + { + User u = RealEstate.ess.getUser(other); + u.addMail(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()); + } } - else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) - { - User u = RealEstate.ess.getUser(other); - u.addMail(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") @@ -313,22 +334,25 @@ public class RECommand extends BaseCommand 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()) + if(other != null) { - ((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."); + 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."); + } + else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) + { + User u = RealEstate.ess.getUser(other); + u.addMail(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."); + } } - else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) - { - User u = RealEstate.ess.getUser(other); - u.addMail(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()); GriefPrevention.instance.dataStore.saveClaim(claim); @@ -362,22 +386,25 @@ public class RECommand extends BaseCommand 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()) + if(other != null) { - ((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() + "]"); + 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() + "]"); + } + else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) + { + User u = RealEstate.ess.getUser(other); + u.addMail(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() + "]"); + } } - else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) - { - User u = RealEstate.ess.getUser(other); - u.addMail(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() + "]"); - } } } @@ -395,22 +422,25 @@ public class RECommand extends BaseCommand 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()) + if(other != null) { - ((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() + "]"); + 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 if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) + { + User u = RealEstate.ess.getUser(other); + u.addMail(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 if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null) - { - User u = RealEstate.ess.getUser(other); - u.addMail(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 { diff --git a/src/me/EtienneDx/RealEstate/RealEstate.java b/src/me/EtienneDx/RealEstate/RealEstate.java index a4081a1..50c504d 100644 --- a/src/me/EtienneDx/RealEstate/RealEstate.java +++ b/src/me/EtienneDx/RealEstate/RealEstate.java @@ -163,8 +163,8 @@ public class RealEstate extends JavaPlugin { 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())) + if((((BoughtTransaction)tr).buyer != null && ((BoughtTransaction)tr).buyer.equals(context.getIssuer().getPlayer().getUniqueId())) || + (tr.getOwner() != null && tr.getOwner().equals(context.getIssuer().getPlayer().getUniqueId()))) { return; } diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java index aa1669d..1f357ab 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java @@ -11,6 +11,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.block.Sign; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.earth2me.essentials.User; @@ -417,9 +418,9 @@ public class ClaimLease extends BoughtTransaction } @Override - public void msgInfo(Player player) + public void msgInfo(CommandSender cs) { - player.sendMessage(ChatColor.DARK_GREEN + "" + GriefPrevention.instance.dataStore.getClaim(claimId).getArea() + + cs.sendMessage(ChatColor.DARK_GREEN + "" + GriefPrevention.instance.dataStore.getClaim(claimId).getArea() + ChatColor.AQUA + " blocks to " + ChatColor.DARK_GREEN + "Lease " + ChatColor.AQUA + "at " + ChatColor.DARK_GREEN + "[" + GriefPrevention.instance.dataStore.getClaim(claimId).getLesserBoundaryCorner().getWorld().getName() + ", " + "X: " + GriefPrevention.instance.dataStore.getClaim(claimId).getLesserBoundaryCorner().getBlockX() + ", " + diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java index fd8b6a6..1254030 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java @@ -11,6 +11,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.block.Sign; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import com.earth2me.essentials.User; @@ -255,7 +256,7 @@ public class ClaimRent extends BoughtTransaction } if(claim.parent == null && owner != null && !owner.equals(claim.ownerID)) { - player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() + + player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getOfflinePlayer(owner).getName() + " does not have the right to rent this " + claimType + "!"); RealEstate.transactionsStore.cancelTransaction(claim); return; @@ -396,9 +397,9 @@ public class ClaimRent extends BoughtTransaction } @Override - public void msgInfo(Player player) + public void msgInfo(CommandSender cs) { - player.sendMessage(ChatColor.DARK_GREEN + "" + GriefPrevention.instance.dataStore.getClaim(claimId).getArea() + + cs.sendMessage(ChatColor.DARK_GREEN + "" + GriefPrevention.instance.dataStore.getClaim(claimId).getArea() + ChatColor.AQUA + " blocks to " + ChatColor.DARK_GREEN + "Rent " + ChatColor.AQUA + "at " + ChatColor.DARK_GREEN + "[" + GriefPrevention.instance.dataStore.getClaim(claimId).getLesserBoundaryCorner().getWorld().getName() + ", " + "X: " + GriefPrevention.instance.dataStore.getClaim(claimId).getLesserBoundaryCorner().getBlockX() + ", " + diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java index 458571e..ea0d9f5 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java @@ -17,6 +17,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.block.Sign; +import org.bukkit.command.CommandSender; public class ClaimSell extends ClaimTransaction { @@ -193,9 +194,9 @@ public class ClaimSell extends ClaimTransaction } @Override - public void msgInfo(Player player) + public void msgInfo(CommandSender cs) { - player.sendMessage(ChatColor.DARK_GREEN + "" + GriefPrevention.instance.dataStore.getClaim(claimId).getArea() + + cs.sendMessage(ChatColor.DARK_GREEN + "" + GriefPrevention.instance.dataStore.getClaim(claimId).getArea() + ChatColor.AQUA + " blocks to " + ChatColor.DARK_GREEN + "Sell " + ChatColor.AQUA + "at " + ChatColor.DARK_GREEN + "[" + GriefPrevention.instance.dataStore.getClaim(claimId).getLesserBoundaryCorner().getWorld().getName() + ", " + "X: " + GriefPrevention.instance.dataStore.getClaim(claimId).getLesserBoundaryCorner().getBlockX() + ", " + diff --git a/src/me/EtienneDx/RealEstate/Transactions/Transaction.java b/src/me/EtienneDx/RealEstate/Transactions/Transaction.java index efb4064..87530cd 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/Transaction.java +++ b/src/me/EtienneDx/RealEstate/Transactions/Transaction.java @@ -3,6 +3,7 @@ package me.EtienneDx.RealEstate.Transactions; import java.util.UUID; import org.bukkit.block.Block; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; public interface Transaction @@ -14,5 +15,5 @@ public interface Transaction public void preview(Player player); public boolean update(); public boolean tryCancelTransaction(Player p); - public void msgInfo(Player player); + public void msgInfo(CommandSender cs); }