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()
|
public void destroySign()
|
||||||
{
|
{
|
||||||
if((this instanceof ClaimRent &&RealEstate.instance.config.cfgDestroyRentSigns) ||
|
if((this instanceof ClaimRent && RealEstate.instance.config.cfgDestroyRentSigns) ||
|
||||||
(this instanceof ClaimLease &&RealEstate.instance.config.cfgDestroyLeaseSigns))
|
(this instanceof ClaimLease && RealEstate.instance.config.cfgDestroyLeaseSigns))
|
||||||
{
|
{
|
||||||
if(!destroyedSign && getHolder().getState() instanceof Sign)
|
if(!destroyedSign && getHolder().getState() instanceof Sign)
|
||||||
getHolder().breakNaturally();
|
getHolder().breakNaturally();
|
||||||
|
|||||||
@ -57,15 +57,11 @@ public class ClaimLease extends BoughtTransaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public boolean update()
|
||||||
{
|
{
|
||||||
if(buyer == null)// not yet leased
|
if(buyer == null)// not yet leased
|
||||||
{
|
{
|
||||||
if(destroyedSign)
|
if(sign.getBlock().getState() instanceof Sign)
|
||||||
{
|
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
|
||||||
}
|
|
||||||
else if(sign.getBlock().getState() instanceof Sign)
|
|
||||||
{
|
{
|
||||||
Sign s = (Sign)sign.getBlock().getState();
|
Sign s = (Sign)sign.getBlock().getState();
|
||||||
s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
|
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.setLine(3, Utils.getTime(frequency, null, false));
|
||||||
s.update(true);
|
s.update(true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -98,6 +99,7 @@ public class ClaimLease extends BoughtTransaction
|
|||||||
payLease();
|
payLease();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void payLease()
|
private void payLease()
|
||||||
@ -271,12 +273,12 @@ public class ClaimLease extends BoughtTransaction
|
|||||||
}
|
}
|
||||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
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 + "!");
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
||||||
return;
|
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() +
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
||||||
" does not have the right to put this " + claimType + " for lease!");
|
" does not have the right to put this " + claimType + " for lease!");
|
||||||
@ -323,6 +325,8 @@ public class ClaimLease extends BoughtTransaction
|
|||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
|
||||||
|
if(owner != null)
|
||||||
|
{
|
||||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||||
{
|
{
|
||||||
@ -343,6 +347,7 @@ public class ClaimLease extends BoughtTransaction
|
|||||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully paid lease for this " + claimType +
|
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 + ", " +
|
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||||
|
|||||||
@ -63,15 +63,11 @@ public class ClaimRent extends BoughtTransaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public boolean update()
|
||||||
{
|
{
|
||||||
if(buyer == null)
|
if(buyer == null)
|
||||||
{
|
{
|
||||||
if(destroyedSign)
|
if(sign.getBlock().getState() instanceof Sign)
|
||||||
{
|
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
|
||||||
}
|
|
||||||
else if(sign.getBlock().getState() instanceof Sign)
|
|
||||||
{
|
{
|
||||||
Sign s = (Sign) sign.getBlock().getState();
|
Sign s = (Sign) sign.getBlock().getState();
|
||||||
s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
|
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.setLine(3, (maxPeriod > 1 ? maxPeriod + "x " : "") + Utils.getTime(duration, null, false));
|
||||||
s.update(true);
|
s.update(true);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -117,6 +117,7 @@ public class ClaimRent extends BoughtTransaction
|
|||||||
s.update(true);
|
s.update(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,12 +248,12 @@ public class ClaimRent extends BoughtTransaction
|
|||||||
}
|
}
|
||||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
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 + "!");
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
||||||
return;
|
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() +
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
||||||
" does not have the right to rent this " + claimType + "!");
|
" does not have the right to rent this " + claimType + "!");
|
||||||
@ -298,7 +299,10 @@ public class ClaimRent extends BoughtTransaction
|
|||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
|
||||||
|
if(owner != null)
|
||||||
|
{
|
||||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||||
|
|
||||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||||
{
|
{
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||||
@ -316,6 +320,7 @@ public class ClaimRent extends BoughtTransaction
|
|||||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully rented this " + claimType +
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully rented this " + claimType +
|
||||||
" for " + ChatColor.GREEN + price + RealEstate.econ.currencyNamePlural());
|
" 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 " +
|
(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(duration, null, false) + ChatColor.AQUA + ". The current period will end in " : "another ") +
|
||||||
ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n";
|
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";
|
msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enabled" : "disabled") + "\n";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ public class ClaimSell extends ClaimTransaction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public boolean update()
|
||||||
{
|
{
|
||||||
if(sign.getBlock().getState() instanceof Sign)
|
if(sign.getBlock().getState() instanceof Sign)
|
||||||
{
|
{
|
||||||
@ -53,6 +53,7 @@ public class ClaimSell extends ClaimTransaction
|
|||||||
{
|
{
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
RealEstate.transactionsStore.cancelTransaction(this);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -12,7 +12,7 @@ public interface Transaction
|
|||||||
public void setOwner(UUID newOwner);
|
public void setOwner(UUID newOwner);
|
||||||
public void interact(Player player);
|
public void interact(Player player);
|
||||||
public void preview(Player player);
|
public void preview(Player player);
|
||||||
public void update();
|
public boolean update();
|
||||||
public boolean tryCancelTransaction(Player p);
|
public boolean tryCancelTransaction(Player p);
|
||||||
public void msgInfo(Player player);
|
public void msgInfo(Player player);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,15 +2,13 @@ package me.EtienneDx.RealEstate.Transactions;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileSystem;
|
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -19,8 +17,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.FileUtil;
|
|
||||||
|
|
||||||
import me.EtienneDx.RealEstate.RealEstate;
|
import me.EtienneDx.RealEstate.RealEstate;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
@ -45,16 +41,30 @@ public class TransactionsStore
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Collection<ClaimRent> col = claimRent.values();// need intermediate since some may get removed in the process
|
//Collection<ClaimRent> col = claimRent.values();// need intermediate since some may get removed in the process
|
||||||
for(ClaimRent cr : col)
|
Iterator<ClaimRent> ite = claimRent.values().iterator();
|
||||||
|
int i = 0;
|
||||||
|
while(ite.hasNext())
|
||||||
|
{
|
||||||
|
if(ite.next().update())
|
||||||
|
ite.remove();
|
||||||
|
}
|
||||||
|
/*for(ClaimRent cr : col)
|
||||||
{
|
{
|
||||||
cr.update();
|
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)
|
for(ClaimLease cl : co)
|
||||||
{
|
{
|
||||||
cl.update();
|
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
|
}.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)
|
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);
|
claimSell.put(claim.getID().toString(), cs);
|
||||||
cs.update();
|
cs.update();
|
||||||
saveData();
|
saveData();
|
||||||
@ -212,7 +222,7 @@ public class TransactionsStore
|
|||||||
|
|
||||||
public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
|
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);
|
claimRent.put(claim.getID().toString(), cr);
|
||||||
cr.update();
|
cr.update();
|
||||||
saveData();
|
saveData();
|
||||||
@ -248,7 +258,7 @@ public class TransactionsStore
|
|||||||
|
|
||||||
public void lease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsCount)
|
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);
|
claimLease.put(claim.getID().toString(), cl);
|
||||||
cl.update();
|
cl.update();
|
||||||
saveData();
|
saveData();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user