fixes for admin claims renting and leasing
This commit is contained in:
parent
f25693ce6b
commit
44f64dd400
@ -47,8 +47,8 @@ public abstract class BoughtTransaction extends ClaimTransaction
|
||||
|
||||
public void destroySign()
|
||||
{
|
||||
if((this instanceof ClaimRent &&RealEstate.instance.config.cfgDestroyRentSigns) ||
|
||||
(this instanceof ClaimLease &&RealEstate.instance.config.cfgDestroyLeaseSigns))
|
||||
if((this instanceof ClaimRent && RealEstate.instance.config.cfgDestroyRentSigns) ||
|
||||
(this instanceof ClaimLease && RealEstate.instance.config.cfgDestroyLeaseSigns))
|
||||
{
|
||||
if(!destroyedSign && getHolder().getState() instanceof Sign)
|
||||
getHolder().breakNaturally();
|
||||
|
||||
@ -57,15 +57,11 @@ public class ClaimLease extends BoughtTransaction
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
public boolean update()
|
||||
{
|
||||
if(buyer == null)// not yet leased
|
||||
{
|
||||
if(destroyedSign)
|
||||
{
|
||||
RealEstate.transactionsStore.cancelTransaction(this);
|
||||
}
|
||||
else if(sign.getBlock().getState() instanceof Sign)
|
||||
if(sign.getBlock().getState() instanceof Sign)
|
||||
{
|
||||
Sign s = (Sign)sign.getBlock().getState();
|
||||
s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
|
||||
@ -83,6 +79,11 @@ public class ClaimLease extends BoughtTransaction
|
||||
s.setLine(3, Utils.getTime(frequency, null, false));
|
||||
s.update(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -98,6 +99,7 @@ public class ClaimLease extends BoughtTransaction
|
||||
payLease();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void payLease()
|
||||
@ -271,12 +273,12 @@ public class ClaimLease extends BoughtTransaction
|
||||
}
|
||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
||||
|
||||
if (owner.equals(player.getUniqueId()))
|
||||
if (owner != null && owner.equals(player.getUniqueId()))
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
||||
return;
|
||||
}
|
||||
if(claim.parent == null && !owner.equals(claim.ownerID))
|
||||
if(claim.parent == null && owner != null && !owner.equals(claim.ownerID))
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
||||
" does not have the right to put this " + claimType + " for lease!");
|
||||
@ -323,26 +325,29 @@ public class ClaimLease extends BoughtTransaction
|
||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
|
||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||
if(owner != null)
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just paid for your lease for the " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just paid for your lease for the " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||
}
|
||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.owner);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just paid for your lease for the " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||
}
|
||||
}
|
||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.owner);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just paid for your lease for the " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||
}
|
||||
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully paid lease for this " + claimType +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||
|
||||
@ -63,15 +63,11 @@ public class ClaimRent extends BoughtTransaction
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
public boolean update()
|
||||
{
|
||||
if(buyer == null)
|
||||
{
|
||||
if(destroyedSign)
|
||||
{
|
||||
RealEstate.transactionsStore.cancelTransaction(this);
|
||||
}
|
||||
else if(sign.getBlock().getState() instanceof Sign)
|
||||
if(sign.getBlock().getState() instanceof Sign)
|
||||
{
|
||||
Sign s = (Sign) sign.getBlock().getState();
|
||||
s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
|
||||
@ -88,6 +84,10 @@ public class ClaimRent extends BoughtTransaction
|
||||
s.setLine(3, (maxPeriod > 1 ? maxPeriod + "x " : "") + Utils.getTime(duration, null, false));
|
||||
s.update(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -117,6 +117,7 @@ public class ClaimRent extends BoughtTransaction
|
||||
s.update(true);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@ -247,12 +248,12 @@ public class ClaimRent extends BoughtTransaction
|
||||
}
|
||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
||||
|
||||
if (owner.equals(player.getUniqueId()))
|
||||
if (owner != null && owner.equals(player.getUniqueId()))
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
||||
return;
|
||||
}
|
||||
if(claim.parent == null && !owner.equals(claim.ownerID))
|
||||
if(claim.parent == null && owner != null && !owner.equals(claim.ownerID))
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
||||
" does not have the right to rent this " + claimType + "!");
|
||||
@ -298,24 +299,28 @@ public class ClaimRent extends BoughtTransaction
|
||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
|
||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||
if(owner != null)
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just rented your " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||
|
||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just rented your " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
}
|
||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.owner);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just rented your " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
}
|
||||
}
|
||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||
{
|
||||
User u = RealEstate.ess.getUser(this.owner);
|
||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||
" has just rented your " + claimType + " at " +
|
||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
}
|
||||
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully rented this " + claimType +
|
||||
" for " + ChatColor.GREEN + price + RealEstate.econ.currencyNamePlural());
|
||||
@ -369,7 +374,7 @@ public class ClaimRent extends BoughtTransaction
|
||||
(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)
|
||||
if((owner != null && owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.config.cfgEnableAutoRenew)
|
||||
{
|
||||
msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enabled" : "disabled") + "\n";
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ public class ClaimSell extends ClaimTransaction
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update()
|
||||
public boolean update()
|
||||
{
|
||||
if(sign.getBlock().getState() instanceof Sign)
|
||||
{
|
||||
@ -53,6 +53,7 @@ public class ClaimSell extends ClaimTransaction
|
||||
{
|
||||
RealEstate.transactionsStore.cancelTransaction(this);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -12,7 +12,7 @@ public interface Transaction
|
||||
public void setOwner(UUID newOwner);
|
||||
public void interact(Player player);
|
||||
public void preview(Player player);
|
||||
public void update();
|
||||
public boolean update();
|
||||
public boolean tryCancelTransaction(Player p);
|
||||
public void msgInfo(Player player);
|
||||
}
|
||||
|
||||
@ -2,15 +2,13 @@ package me.EtienneDx.RealEstate.Transactions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -19,8 +17,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.FileUtil;
|
||||
|
||||
import me.EtienneDx.RealEstate.RealEstate;
|
||||
import me.ryanhamshire.GriefPrevention.Claim;
|
||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||
@ -45,16 +41,30 @@ public class TransactionsStore
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Collection<ClaimRent> col = claimRent.values();// need intermediate since some may get removed in the process
|
||||
for(ClaimRent cr : col)
|
||||
//Collection<ClaimRent> col = claimRent.values();// need intermediate since some may get removed in the process
|
||||
Iterator<ClaimRent> ite = claimRent.values().iterator();
|
||||
int i = 0;
|
||||
while(ite.hasNext())
|
||||
{
|
||||
if(ite.next().update())
|
||||
ite.remove();
|
||||
}
|
||||
/*for(ClaimRent cr : col)
|
||||
{
|
||||
cr.update();
|
||||
}
|
||||
Collection<ClaimLease> co = claimLease.values();// need intermediate since some may get removed in the process
|
||||
}*/
|
||||
/*Collection<ClaimLease> co = claimLease.values();// need intermediate since some may get removed in the process
|
||||
for(ClaimLease cl : co)
|
||||
{
|
||||
cl.update();
|
||||
}*/
|
||||
Iterator<ClaimLease> it = claimLease.values().iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
if(it.next().update())
|
||||
it.remove();
|
||||
}
|
||||
saveData();
|
||||
}
|
||||
}.runTaskTimer(RealEstate.instance, 0, 1200L);// run every 60 seconds
|
||||
}
|
||||
@ -176,7 +186,7 @@ public class TransactionsStore
|
||||
|
||||
public void sell(Claim claim, Player player, double price, Location sign)
|
||||
{
|
||||
ClaimSell cs = new ClaimSell(claim, player, price, sign);
|
||||
ClaimSell cs = new ClaimSell(claim, claim.isAdminClaim() ? null : player, price, sign);
|
||||
claimSell.put(claim.getID().toString(), cs);
|
||||
cs.update();
|
||||
saveData();
|
||||
@ -212,7 +222,7 @@ public class TransactionsStore
|
||||
|
||||
public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
|
||||
{
|
||||
ClaimRent cr = new ClaimRent(claim, player, price, sign, duration, rentPeriods);
|
||||
ClaimRent cr = new ClaimRent(claim, claim.isAdminClaim() ? null : player, price, sign, duration, rentPeriods);
|
||||
claimRent.put(claim.getID().toString(), cr);
|
||||
cr.update();
|
||||
saveData();
|
||||
@ -248,7 +258,7 @@ public class TransactionsStore
|
||||
|
||||
public void lease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsCount)
|
||||
{
|
||||
ClaimLease cl = new ClaimLease(claim, player, price, sign, frequency, paymentsCount);
|
||||
ClaimLease cl = new ClaimLease(claim, claim.isAdminClaim() ? null : player, price, sign, frequency, paymentsCount);
|
||||
claimLease.put(claim.getID().toString(), cl);
|
||||
cl.update();
|
||||
saveData();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user