Skip to content

Commit

Permalink
Multiple bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDx committed Feb 27, 2020
1 parent 44f64dd commit 5570e8b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 96 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Me.EtienneDx</groupId>
<artifactId>RealEstate</artifactId>
<version>1.0.0</version>
<version>1.1.1</version>
<name>RealEstate</name>
<description>A spigot plugin for selling, renting and leasing GriefPrevention claims</description>
<build>
Expand Down Expand Up @@ -88,7 +88,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14-R0.1-SNAPSHOT</version>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
198 changes: 114 additions & 84 deletions src/me/EtienneDx/RealEstate/RECommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void info(Player player)
@Description("Displays the list of all real estate offers currently existing")
@CommandCompletion("all|sell|rent|lease")
@Syntax("[all|sell|rent|lease] <page>")
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)
{
Expand Down Expand Up @@ -94,34 +94,52 @@ else if(type.equalsIgnoreCase("lease"))
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<Transaction> transactions = new ArrayList<Transaction>(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"))
{
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++)
else
{
RealEstate.instance.log.info("transaction " + i);
transactions.get(i).msgInfo(player);
ArrayList<Transaction> transactions = new ArrayList<Transaction>(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!");
}
}
}

Expand Down Expand Up @@ -270,24 +288,27 @@ public void create(Player player, @Conditions("positiveDouble") Double 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);
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")
Expand All @@ -313,22 +334,25 @@ else if(Utils.makePayment(player.getUniqueId(), bt.exitOffer.offerBy, bt.exitOff
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);
Expand Down Expand Up @@ -362,22 +386,25 @@ else if(bt.exitOffer.offerBy.equals(player.getUniqueId()))
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() + "]");
}
}
}

Expand All @@ -395,22 +422,25 @@ public void cancel(Player player)
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
{
Expand Down
4 changes: 2 additions & 2 deletions src/me/EtienneDx/RealEstate/RealEstate.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ else if(tr instanceof BoughtTransaction && ((BoughtTransaction)tr).getBuyer() !=
{
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;
}
Expand Down
5 changes: 3 additions & 2 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -417,9 +418,9 @@ public void preview(Player player)
}

@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() + ", " +
Expand Down
7 changes: 4 additions & 3 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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;
Expand Down Expand Up @@ -255,7 +256,7 @@ public void interact(Player player)
}
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;
Expand Down Expand Up @@ -396,9 +397,9 @@ public void preview(Player player)
}

@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() + ", " +
Expand Down
5 changes: 3 additions & 2 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.block.Sign;
import org.bukkit.command.CommandSender;

public class ClaimSell extends ClaimTransaction
{
Expand Down Expand Up @@ -193,9 +194,9 @@ public void setOwner(UUID newOwner)
}

@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() + ", " +
Expand Down
3 changes: 2 additions & 1 deletion src/me/EtienneDx/RealEstate/Transactions/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.UUID;

import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public interface Transaction
Expand All @@ -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);
}

0 comments on commit 5570e8b

Please sign in to comment.