Changed to automatically sell/rent/lease as 'SERVER' for admin claims
This commit is contained in:
parent
2cff090309
commit
8c18e01cb4
@ -1,78 +1,78 @@
|
|||||||
package me.EtienneDx.RealEstate;
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.EtienneDx.RealEstate.Transactions.BoughtTransaction;
|
import me.EtienneDx.RealEstate.Transactions.BoughtTransaction;
|
||||||
import me.EtienneDx.RealEstate.Transactions.Transaction;
|
import me.EtienneDx.RealEstate.Transactions.Transaction;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
import me.ryanhamshire.GriefPrevention.IRealEstate;
|
import me.ryanhamshire.GriefPrevention.IRealEstate;
|
||||||
|
|
||||||
public class GP_RealEstateHook implements IRealEstate
|
public class GP_RealEstateHook implements IRealEstate
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public String allowEdit(Claim claim, Player player)
|
public String allowEdit(Claim claim, Player player)
|
||||||
{
|
{
|
||||||
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
||||||
if(b != null && b.getOwner().equals(player.getUniqueId()) && b instanceof BoughtTransaction)
|
if(b != null && player.getUniqueId().equals(b.getOwner()) && b instanceof BoughtTransaction)
|
||||||
{
|
{
|
||||||
if(((BoughtTransaction)b).getBuyer() != null)
|
if(((BoughtTransaction)b).getBuyer() != null)
|
||||||
return "This claim is currently involved in a transaction, you can't edit it!";
|
return "This claim is currently involved in a transaction, you can't edit it!";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String allowBuild(Claim claim, Player player, Material material)
|
public String allowBuild(Claim claim, Player player, Material material)
|
||||||
{
|
{
|
||||||
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
||||||
if(b != null && b.getOwner().equals(player.getUniqueId()) && b instanceof BoughtTransaction)
|
if(b != null && player.getUniqueId().equals(b.getOwner()) && b instanceof BoughtTransaction)// ??
|
||||||
{
|
{
|
||||||
if(((BoughtTransaction)b).getBuyer() != null)
|
if(((BoughtTransaction)b).getBuyer() != null)
|
||||||
return "This claim is currently involved in a transaction, you can't build on it!";
|
return "This claim is currently involved in a transaction, you can't build on it!";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String allowAccess(Claim claim, Player player)
|
public String allowAccess(Claim claim, Player player)
|
||||||
{
|
{
|
||||||
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
||||||
if(b != null && b.getOwner().equals(player.getUniqueId()) && b instanceof BoughtTransaction)
|
if(b != null && player.getUniqueId().equals(b.getOwner()) && b instanceof BoughtTransaction)
|
||||||
{
|
{
|
||||||
if(((BoughtTransaction)b).getBuyer() != null)
|
if(((BoughtTransaction)b).getBuyer() != null)
|
||||||
return "This claim is currently involved in a transaction, you can't access it!";
|
return "This claim is currently involved in a transaction, you can't access it!";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String allowContainers(Claim claim, Player player)
|
public String allowContainers(Claim claim, Player player)
|
||||||
{
|
{
|
||||||
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
||||||
if(b != null && b.getOwner().equals(player.getUniqueId()) && b instanceof BoughtTransaction)
|
if(b != null && player.getUniqueId().equals(b.getOwner()) && b instanceof BoughtTransaction)
|
||||||
{
|
{
|
||||||
if(((BoughtTransaction)b).getBuyer() != null)
|
if(((BoughtTransaction)b).getBuyer() != null)
|
||||||
return "This claim is currently involved in a transaction, you can't access it's containers!";
|
return "This claim is currently involved in a transaction, you can't access it's containers!";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String allowGrantPermission(Claim claim, Player player)
|
public String allowGrantPermission(Claim claim, Player player)
|
||||||
{
|
{
|
||||||
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
Transaction b = RealEstate.transactionsStore.getTransaction(claim);
|
||||||
if(b != null && b instanceof BoughtTransaction)
|
if(b != null && b instanceof BoughtTransaction)
|
||||||
{
|
{
|
||||||
if(((BoughtTransaction)b).getBuyer() != null)
|
if(((BoughtTransaction)b).getBuyer() != null)
|
||||||
return "This claim is currently involved in a transaction, you can't change any permission!";
|
return "This claim is currently involved in a transaction, you can't change any permission!";
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean anyTransaction(Claim claim)
|
public boolean anyTransaction(Claim claim)
|
||||||
{
|
{
|
||||||
return RealEstate.transactionsStore.anyTransaction(claim);
|
return RealEstate.transactionsStore.anyTransaction(claim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -87,7 +87,7 @@ public class RECommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subcommand("seller")
|
/*@Subcommand("seller")
|
||||||
@Description("Displays or changes the seller of a claim (admin only)")
|
@Description("Displays or changes the seller of a claim (admin only)")
|
||||||
@Conditions("inPendingTransactionClaim")
|
@Conditions("inPendingTransactionClaim")
|
||||||
public static void setSeller(Player player, @Optional String newSeller)
|
public static void setSeller(Player player, @Optional String newSeller)
|
||||||
@ -112,6 +112,7 @@ public class RECommand extends BaseCommand
|
|||||||
{
|
{
|
||||||
tr.setOwner(null);
|
tr.setOwner(null);
|
||||||
tr.update();
|
tr.update();
|
||||||
|
RealEstate.transactionsStore.saveData();
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to the server");
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to the server");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -130,11 +131,12 @@ public class RECommand extends BaseCommand
|
|||||||
{
|
{
|
||||||
tr.setOwner(newOwner.getUniqueId());
|
tr.setOwner(newOwner.getUniqueId());
|
||||||
tr.update();
|
tr.update();
|
||||||
|
RealEstate.transactionsStore.saveData();
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to " +
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to " +
|
||||||
ChatColor.GREEN + newOwner.getDisplayName());
|
ChatColor.GREEN + newOwner.getDisplayName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
@Subcommand("exitoffer")
|
@Subcommand("exitoffer")
|
||||||
@Conditions("partOfBoughtTransaction")
|
@Conditions("partOfBoughtTransaction")
|
||||||
|
|||||||
@ -114,13 +114,16 @@ public class REListener implements Listener
|
|||||||
event.getBlock().breakNaturally();
|
event.getBlock().breakNaturally();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
|
if(claim.isAdminClaim())
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to sell admin claims!");
|
if(!RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
|
||||||
event.setCancelled(true);
|
{
|
||||||
event.getBlock().breakNaturally();
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to sell admin claims!");
|
||||||
return;
|
event.setCancelled(true);
|
||||||
|
event.getBlock().breakNaturally();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
|
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
|
||||||
{
|
{
|
||||||
@ -132,7 +135,7 @@ public class REListener implements Listener
|
|||||||
|
|
||||||
// we should be good to sell it now
|
// we should be good to sell it now
|
||||||
event.setCancelled(true);// need to cancel the event, so we can update the sign elsewhere
|
event.setCancelled(true);// need to cancel the event, so we can update the sign elsewhere
|
||||||
RealEstate.transactionsStore.sell(claim, player, price, event.getBlock().getLocation());
|
RealEstate.transactionsStore.sell(claim, claim.isAdminClaim() ? null : player, price, event.getBlock().getLocation());
|
||||||
}
|
}
|
||||||
else if(RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
|
else if(RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
|
||||||
{
|
{
|
||||||
@ -216,12 +219,15 @@ public class REListener implements Listener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may rent admin claims
|
if(claim.isAdminClaim())
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to rent admin claims!");
|
if(!RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
|
||||||
event.setCancelled(true);
|
{
|
||||||
event.getBlock().breakNaturally();
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to rent admin claims!");
|
||||||
return;
|
event.setCancelled(true);
|
||||||
|
event.getBlock().breakNaturally();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
|
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
|
||||||
{
|
{
|
||||||
@ -307,12 +313,15 @@ public class REListener implements Listener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may rent admin claims
|
if(claim.isAdminClaim())
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to lease admin claims!");
|
if(!RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
|
||||||
event.setCancelled(true);
|
{
|
||||||
event.getBlock().breakNaturally();
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to lease admin claims!");
|
||||||
return;
|
event.setCancelled(true);
|
||||||
|
event.getBlock().breakNaturally();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
|
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,410 +1,413 @@
|
|||||||
package me.EtienneDx.RealEstate.Transactions;
|
package me.EtienneDx.RealEstate.Transactions;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
|
||||||
import me.EtienneDx.RealEstate.RealEstate;
|
import me.EtienneDx.RealEstate.RealEstate;
|
||||||
import me.EtienneDx.RealEstate.Utils;
|
import me.EtienneDx.RealEstate.Utils;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
||||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
public class ClaimLease extends BoughtTransaction
|
public class ClaimLease extends BoughtTransaction
|
||||||
{
|
{
|
||||||
public LocalDateTime lastPayment = null;
|
public LocalDateTime lastPayment = null;
|
||||||
public int frequency;
|
public int frequency;
|
||||||
public int paymentsLeft;
|
public int paymentsLeft;
|
||||||
|
|
||||||
public ClaimLease(Map<String, Object> map)
|
public ClaimLease(Map<String, Object> map)
|
||||||
{
|
{
|
||||||
super(map);
|
super(map);
|
||||||
if(map.get("lastPayment") != null)
|
if(map.get("lastPayment") != null)
|
||||||
lastPayment = LocalDateTime.parse((String) map.get("lastPayment"), DateTimeFormatter.ISO_DATE_TIME);
|
lastPayment = LocalDateTime.parse((String) map.get("lastPayment"), DateTimeFormatter.ISO_DATE_TIME);
|
||||||
frequency = (int)map.get("frequency");
|
frequency = (int)map.get("frequency");
|
||||||
paymentsLeft = (int)map.get("paymentsLeft");
|
paymentsLeft = (int)map.get("paymentsLeft");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClaimLease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsLeft)
|
public ClaimLease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsLeft)
|
||||||
{
|
{
|
||||||
super(claim, player, price, sign);
|
super(claim, player, price, sign);
|
||||||
this.frequency = frequency;
|
this.frequency = frequency;
|
||||||
this.paymentsLeft = paymentsLeft;
|
this.paymentsLeft = paymentsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> serialize() {
|
public Map<String, Object> serialize() {
|
||||||
Map<String, Object> map = super.serialize();
|
Map<String, Object> map = super.serialize();
|
||||||
|
|
||||||
if(lastPayment != null)
|
if(lastPayment != null)
|
||||||
map.put("lastPayment", lastPayment.format(DateTimeFormatter.ISO_DATE_TIME));
|
map.put("lastPayment", lastPayment.format(DateTimeFormatter.ISO_DATE_TIME));
|
||||||
map.put("frequency", frequency);
|
map.put("frequency", frequency);
|
||||||
map.put("paymentsLeft", paymentsLeft);
|
map.put("paymentsLeft", paymentsLeft);
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
if(buyer == null)// not yet leased
|
if(buyer == null)// not yet leased
|
||||||
{
|
{
|
||||||
if(destroyedSign)
|
if(destroyedSign)
|
||||||
{
|
{
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
RealEstate.transactionsStore.cancelTransaction(this);
|
||||||
}
|
}
|
||||||
else if(sign.getBlock().getState() instanceof Sign)
|
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);
|
||||||
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceLease);
|
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceLease);
|
||||||
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
|
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
|
||||||
//s.setLine(2, paymentsLeft + "x " + price + " " + RealEstate.econ.currencyNamePlural());
|
//s.setLine(2, paymentsLeft + "x " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
if(RealEstate.instance.config.cfgUseCurrencySymbol)
|
if(RealEstate.instance.config.cfgUseCurrencySymbol)
|
||||||
{
|
{
|
||||||
s.setLine(2, paymentsLeft + "x " + RealEstate.instance.config.cfgCurrencySymbol + " " + price);
|
s.setLine(2, paymentsLeft + "x " + RealEstate.instance.config.cfgCurrencySymbol + " " + price);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s.setLine(2, paymentsLeft + "x " + price + " " + RealEstate.econ.currencyNamePlural());
|
s.setLine(2, paymentsLeft + "x " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
}
|
||||||
s.setLine(3, Utils.getTime(frequency, null, false));
|
s.setLine(3, Utils.getTime(frequency, null, false));
|
||||||
s.update(true);
|
s.update(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int days = Period.between(lastPayment.toLocalDate(), LocalDate.now()).getDays();
|
int days = Period.between(lastPayment.toLocalDate(), LocalDate.now()).getDays();
|
||||||
Duration hours = Duration.between(lastPayment.toLocalTime(), LocalTime.now());
|
Duration hours = Duration.between(lastPayment.toLocalTime(), LocalTime.now());
|
||||||
if(hours.isNegative() && !hours.isZero())
|
if(hours.isNegative() && !hours.isZero())
|
||||||
{
|
{
|
||||||
hours = hours.plusHours(24);
|
hours = hours.plusHours(24);
|
||||||
days--;
|
days--;
|
||||||
}
|
}
|
||||||
if(days >= frequency)// we exceeded the time limit!
|
if(days >= frequency)// we exceeded the time limit!
|
||||||
{
|
{
|
||||||
payLease();
|
payLease();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void payLease()
|
private void payLease()
|
||||||
{
|
{
|
||||||
if(buyer == null) return;
|
if(buyer == null) return;
|
||||||
|
|
||||||
OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(buyer);
|
OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(buyer);
|
||||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
OfflinePlayer seller = owner == null ? null : Bukkit.getOfflinePlayer(owner);
|
||||||
|
|
||||||
String claimType = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null).parent == null ? "claim" : "subclaim";
|
String claimType = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null).parent == null ? "claim" : "subclaim";
|
||||||
|
|
||||||
if(Utils.makePayment(owner, buyer, price, false, false))
|
if(Utils.makePayment(owner, buyer, price, false, false))
|
||||||
{
|
{
|
||||||
lastPayment = LocalDateTime.now();
|
lastPayment = LocalDateTime.now();
|
||||||
paymentsLeft--;
|
paymentsLeft--;
|
||||||
if(paymentsLeft > 0)
|
if(paymentsLeft > 0)
|
||||||
{
|
{
|
||||||
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||||
{
|
{
|
||||||
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
"Paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
"Paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
||||||
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
}
|
}
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
{
|
{
|
||||||
User u = RealEstate.ess.getUser(this.buyer);
|
User u = RealEstate.ess.getUser(this.buyer);
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
"Paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
"Paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
||||||
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
if(owner != null)
|
||||||
{
|
{
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||||
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
{
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
ChatColor.AQUA + " at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
}
|
ChatColor.AQUA + " at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
{
|
}
|
||||||
User u = RealEstate.ess.getUser(this.owner);
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
{
|
||||||
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
User u = RealEstate.ess.getUser(this.owner);
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
ChatColor.AQUA + " at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
}
|
ChatColor.AQUA + " at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
}
|
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
}
|
||||||
{
|
else
|
||||||
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
{
|
||||||
"Paid final lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||||
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
{
|
||||||
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
ChatColor.AQUA + ", the " + claimType + " is now yours");
|
"Paid final lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
||||||
}
|
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
{
|
ChatColor.AQUA + ", the " + claimType + " is now yours");
|
||||||
User u = RealEstate.ess.getUser(this.buyer);
|
}
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
"Paid final lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
{
|
||||||
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
User u = RealEstate.ess.getUser(this.buyer);
|
||||||
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
ChatColor.AQUA + ", the " + claimType + " is now yours");
|
"Paid final lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
||||||
}
|
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
|
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
ChatColor.AQUA + ", the " + claimType + " is now yours");
|
||||||
{
|
}
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
|
||||||
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
{
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||||
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
ChatColor.AQUA + ", the " + claimType + " is now his property");
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
}
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
{
|
ChatColor.AQUA + ", the " + claimType + " is now his property");
|
||||||
User u = RealEstate.ess.getUser(this.owner);
|
}
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
{
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
User u = RealEstate.ess.getUser(this.owner);
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||||
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
ChatColor.AQUA + ", the " + claimType + " is now his property");
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
}
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
|
||||||
|
ChatColor.AQUA + ", the " + claimType + " is now his property");
|
||||||
Utils.transferClaim(claim, buyer, owner);
|
}
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);// the transaction is finished
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
||||||
}
|
|
||||||
}
|
Utils.transferClaim(claim, buyer, owner);
|
||||||
else
|
RealEstate.transactionsStore.cancelTransaction(this);// the transaction is finished
|
||||||
{
|
}
|
||||||
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
}
|
||||||
{
|
else
|
||||||
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
{
|
||||||
"Couldn't pay the lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||||
sign.getBlockX() + ", Y: " +
|
{
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
|
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
}
|
"Couldn't pay the lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
sign.getBlockX() + ", Y: " +
|
||||||
{
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
|
||||||
User u = RealEstate.ess.getUser(this.buyer);
|
}
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
"Couldn't pay the lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
{
|
||||||
sign.getBlockX() + ", Y: " +
|
User u = RealEstate.ess.getUser(this.buyer);
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
}
|
"Couldn't pay the lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
||||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
sign.getBlockX() + ", Y: " +
|
||||||
{
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
}
|
||||||
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
{
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||||
ChatColor.AQUA + ", the transaction has been cancelled");
|
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
}
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
{
|
ChatColor.AQUA + ", the transaction has been cancelled");
|
||||||
User u = RealEstate.ess.getUser(this.owner);
|
}
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
{
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
User u = RealEstate.ess.getUser(this.owner);
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||||
ChatColor.AQUA + ", the transaction has been cancelled");
|
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
}
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
}
|
ChatColor.AQUA + ", the transaction has been cancelled");
|
||||||
// no need to re update, since there's no sign
|
}
|
||||||
RealEstate.transactionsStore.saveData();
|
RealEstate.transactionsStore.cancelTransaction(this);
|
||||||
}
|
}
|
||||||
|
// no need to re update, since there's no sign
|
||||||
@Override
|
RealEstate.transactionsStore.saveData();
|
||||||
public boolean tryCancelTransaction(Player p)
|
}
|
||||||
{
|
|
||||||
if(buyer != null)
|
@Override
|
||||||
{
|
public boolean tryCancelTransaction(Player p)
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
{
|
||||||
if(p != null)
|
if(buyer != null)
|
||||||
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
|
{
|
||||||
" is currently rented, you can't cancel the transaction!");
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
||||||
return false;
|
if(p != null)
|
||||||
}
|
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
|
||||||
else
|
" is currently rented, you can't cancel the transaction!");
|
||||||
{
|
return false;
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
}
|
||||||
return true;
|
else
|
||||||
}
|
{
|
||||||
}
|
RealEstate.transactionsStore.cancelTransaction(this);
|
||||||
|
return true;
|
||||||
@Override
|
}
|
||||||
public void interact(Player player)
|
}
|
||||||
{
|
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
|
@Override
|
||||||
if(claim == null)
|
public void interact(Player player)
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
|
||||||
RealEstate.transactionsStore.cancelTransaction(claim);
|
if(claim == null)
|
||||||
return;
|
{
|
||||||
}
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
|
||||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
RealEstate.transactionsStore.cancelTransaction(claim);
|
||||||
|
return;
|
||||||
if (owner.equals(player.getUniqueId()))
|
}
|
||||||
{
|
String claimType = claim.parent == null ? "claim" : "subclaim";
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
|
||||||
return;
|
if (owner.equals(player.getUniqueId()))
|
||||||
}
|
{
|
||||||
if(claim.parent == null && !owner.equals(claim.ownerID))
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
||||||
{
|
return;
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
}
|
||||||
" does not have the right to put this " + claimType + " for lease!");
|
if(claim.parent == null && !owner.equals(claim.ownerID))
|
||||||
RealEstate.transactionsStore.cancelTransaction(claim);
|
{
|
||||||
return;
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
||||||
}
|
" does not have the right to put this " + claimType + " for lease!");
|
||||||
if(!player.hasPermission("realestate." + claimType + ".lease"))
|
RealEstate.transactionsStore.cancelTransaction(claim);
|
||||||
{
|
return;
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to lease " +
|
}
|
||||||
claimType + "s!");
|
if(!player.hasPermission("realestate." + claimType + ".lease"))
|
||||||
return;
|
{
|
||||||
}
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to lease " +
|
||||||
if(player.getUniqueId().equals(buyer))
|
claimType + "s!");
|
||||||
{
|
return;
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are already leasing this " +
|
}
|
||||||
claimType + "!");
|
if(player.getUniqueId().equals(buyer))
|
||||||
return;
|
{
|
||||||
}
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are already leasing this " +
|
||||||
if(buyer != null)
|
claimType + "!");
|
||||||
{
|
return;
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Someone already leases this " +
|
}
|
||||||
claimType + "!");
|
if(buyer != null)
|
||||||
return;
|
{
|
||||||
}
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Someone already leases this " +
|
||||||
|
claimType + "!");
|
||||||
if(Utils.makePayment(owner, player.getUniqueId(), price, false, true))// if payment succeed
|
return;
|
||||||
{
|
}
|
||||||
buyer = player.getUniqueId();
|
|
||||||
lastPayment = LocalDateTime.now();
|
if(Utils.makePayment(owner, player.getUniqueId(), price, false, true))// if payment succeed
|
||||||
paymentsLeft--;
|
{
|
||||||
claim.setPermission(buyer.toString(), ClaimPermission.Build);
|
buyer = player.getUniqueId();
|
||||||
GriefPrevention.instance.dataStore.saveClaim(claim);
|
lastPayment = LocalDateTime.now();
|
||||||
getHolder().breakNaturally();// leases don't have signs indicating the remaining time
|
paymentsLeft--;
|
||||||
update();
|
claim.setPermission(buyer.toString(), ClaimPermission.Build);
|
||||||
RealEstate.transactionsStore.saveData();
|
GriefPrevention.instance.dataStore.saveClaim(claim);
|
||||||
|
getHolder().breakNaturally();// leases don't have signs indicating the remaining time
|
||||||
RealEstate.instance.addLogEntry(
|
update();
|
||||||
"[" + RealEstate.transactionsStore.dateFormat.format(RealEstate.transactionsStore.date) + "] " + player.getName() +
|
RealEstate.transactionsStore.saveData();
|
||||||
" has started leasing a " + claimType + " at " +
|
|
||||||
"[" + player.getLocation().getWorld() + ", " +
|
RealEstate.instance.addLogEntry(
|
||||||
"X: " + player.getLocation().getBlockX() + ", " +
|
"[" + RealEstate.transactionsStore.dateFormat.format(RealEstate.transactionsStore.date) + "] " + player.getName() +
|
||||||
"Y: " + player.getLocation().getBlockY() + ", " +
|
" has started leasing a " + claimType + " at " +
|
||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
"[" + player.getLocation().getWorld() + ", " +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
"X: " + player.getLocation().getBlockX() + ", " +
|
||||||
|
"Y: " + player.getLocation().getBlockY() + ", " +
|
||||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
{
|
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||||
" has just paid for your lease for the " + claimType + " at " +
|
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
{
|
||||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
" has just paid for your lease for the " + claimType + " at " +
|
||||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||||
}
|
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
||||||
{
|
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
User u = RealEstate.ess.getUser(this.owner);
|
}
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
" has just paid for your lease for the " + claimType + " at " +
|
{
|
||||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
User u = RealEstate.ess.getUser(this.owner);
|
||||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
|
" has just paid for your lease for the " + claimType + " at " +
|
||||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
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 + ", " +
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully paid lease for this " + claimType +
|
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
" 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 + ", " +
|
||||||
|
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||||
@Override
|
}
|
||||||
public void preview(Player player)
|
}
|
||||||
{
|
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
@Override
|
||||||
String msg = "";
|
public void preview(Player player)
|
||||||
if(player.hasPermission("realestate.info"))
|
{
|
||||||
{
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
||||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
String msg = "";
|
||||||
msg = ChatColor.BLUE + "-----= " + ChatColor.WHITE + "[" + ChatColor.GOLD + "RealEstate Rent Info" + ChatColor.WHITE + "]" +
|
if(player.hasPermission("realestate.info"))
|
||||||
ChatColor.BLUE + " =-----\n";
|
{
|
||||||
if(buyer == null)
|
String claimType = claim.parent == null ? "claim" : "subclaim";
|
||||||
{
|
msg = ChatColor.BLUE + "-----= " + ChatColor.WHITE + "[" + ChatColor.GOLD + "RealEstate Rent Info" + ChatColor.WHITE + "]" +
|
||||||
msg += ChatColor.AQUA + "This " + claimType + " is for lease for " +
|
ChatColor.BLUE + " =-----\n";
|
||||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments of " +
|
if(buyer == null)
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " each.\nPayments are due every " +
|
{
|
||||||
ChatColor.GREEN + Utils.getTime(frequency, null, true) + "\n";
|
msg += ChatColor.AQUA + "This " + claimType + " is for lease for " +
|
||||||
|
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments of " +
|
||||||
if(claimType.equalsIgnoreCase("claim"))
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " each.\nPayments are due every " +
|
||||||
{
|
ChatColor.GREEN + Utils.getTime(frequency, null, true) + "\n";
|
||||||
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
|
||||||
}
|
if(claimType.equalsIgnoreCase("claim"))
|
||||||
else
|
{
|
||||||
{
|
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
||||||
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName() + "\n";
|
}
|
||||||
msg += ChatColor.LIGHT_PURPLE + "Note: " + ChatColor.AQUA + "You will only get access to this subclaim!";
|
else
|
||||||
}
|
{
|
||||||
}
|
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName() + "\n";
|
||||||
else
|
msg += ChatColor.LIGHT_PURPLE + "Note: " + ChatColor.AQUA + "You will only get access to this subclaim!";
|
||||||
{
|
}
|
||||||
int days = Period.between(lastPayment.toLocalDate(), LocalDate.now()).getDays();
|
}
|
||||||
Duration hours = Duration.between(lastPayment.toLocalTime(), LocalTime.now());
|
else
|
||||||
if(hours.isNegative() && !hours.isZero())
|
{
|
||||||
{
|
int days = Period.between(lastPayment.toLocalDate(), LocalDate.now()).getDays();
|
||||||
hours = hours.plusHours(24);
|
Duration hours = Duration.between(lastPayment.toLocalTime(), LocalTime.now());
|
||||||
days--;
|
if(hours.isNegative() && !hours.isZero())
|
||||||
}
|
{
|
||||||
int daysLeft = frequency - days - 1;// we need to remove the current day
|
hours = hours.plusHours(24);
|
||||||
Duration timeRemaining = Duration.ofHours(24).minus(hours);
|
days--;
|
||||||
|
}
|
||||||
msg += ChatColor.AQUA + "This " + claimType + " is currently leased by " +
|
int daysLeft = frequency - days - 1;// we need to remove the current day
|
||||||
ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " +
|
Duration timeRemaining = Duration.ofHours(24).minus(hours);
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ". There is " +
|
|
||||||
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left. Next payment is in " +
|
msg += ChatColor.AQUA + "This " + claimType + " is currently leased by " +
|
||||||
ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + ChatColor.AQUA + ".\n";
|
ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " +
|
||||||
if(claimType.equalsIgnoreCase("claim"))
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ". There is " +
|
||||||
{
|
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left. Next payment is in " +
|
||||||
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + ChatColor.AQUA + ".\n";
|
||||||
}
|
if(claimType.equalsIgnoreCase("claim"))
|
||||||
else
|
{
|
||||||
{
|
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
||||||
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
}
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
}
|
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
|
}
|
||||||
}
|
else
|
||||||
player.sendMessage(msg);
|
{
|
||||||
}
|
msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
|
||||||
|
}
|
||||||
}
|
player.sendMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -1,390 +1,392 @@
|
|||||||
package me.EtienneDx.RealEstate.Transactions;
|
package me.EtienneDx.RealEstate.Transactions;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.block.Sign;
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
|
||||||
import me.EtienneDx.RealEstate.RealEstate;
|
import me.EtienneDx.RealEstate.RealEstate;
|
||||||
import me.EtienneDx.RealEstate.Utils;
|
import me.EtienneDx.RealEstate.Utils;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
||||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
public class ClaimRent extends BoughtTransaction
|
public class ClaimRent extends BoughtTransaction
|
||||||
{
|
{
|
||||||
LocalDateTime startDate = null;
|
LocalDateTime startDate = null;
|
||||||
int duration;
|
int duration;
|
||||||
public boolean autoRenew = false;
|
public boolean autoRenew = false;
|
||||||
public int periodCount = 0;
|
public int periodCount = 0;
|
||||||
public int maxPeriod;
|
public int maxPeriod;
|
||||||
|
|
||||||
public ClaimRent(Map<String, Object> map)
|
public ClaimRent(Map<String, Object> map)
|
||||||
{
|
{
|
||||||
super(map);
|
super(map);
|
||||||
if(map.get("startDate") != null)
|
if(map.get("startDate") != null)
|
||||||
startDate = LocalDateTime.parse((String) map.get("startDate"), DateTimeFormatter.ISO_DATE_TIME);
|
startDate = LocalDateTime.parse((String) map.get("startDate"), DateTimeFormatter.ISO_DATE_TIME);
|
||||||
duration = (int)map.get("duration");
|
duration = (int)map.get("duration");
|
||||||
autoRenew = (boolean) map.get("autoRenew");
|
autoRenew = (boolean) map.get("autoRenew");
|
||||||
periodCount = (int) map.get("periodCount");
|
periodCount = (int) map.get("periodCount");
|
||||||
maxPeriod = (int) map.get("maxPeriod");
|
maxPeriod = (int) map.get("maxPeriod");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClaimRent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
|
public ClaimRent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
|
||||||
{
|
{
|
||||||
super(claim, player, price, sign);
|
super(claim, player, price, sign);
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1;
|
this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> serialize() {
|
public Map<String, Object> serialize() {
|
||||||
Map<String, Object> map = super.serialize();
|
Map<String, Object> map = super.serialize();
|
||||||
|
|
||||||
if(startDate != null)
|
if(startDate != null)
|
||||||
map.put("startDate", startDate.format(DateTimeFormatter.ISO_DATE_TIME));
|
map.put("startDate", startDate.format(DateTimeFormatter.ISO_DATE_TIME));
|
||||||
map.put("duration", duration);
|
map.put("duration", duration);
|
||||||
map.put("autoRenew", autoRenew);
|
map.put("autoRenew", autoRenew);
|
||||||
map.put("periodCount", periodCount);
|
map.put("periodCount", periodCount);
|
||||||
map.put("maxPeriod", maxPeriod);
|
map.put("maxPeriod", maxPeriod);
|
||||||
|
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
if(buyer == null)
|
if(buyer == null)
|
||||||
{
|
{
|
||||||
if(destroyedSign)
|
if(destroyedSign)
|
||||||
{
|
{
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
RealEstate.transactionsStore.cancelTransaction(this);
|
||||||
}
|
}
|
||||||
else if(sign.getBlock().getState() instanceof Sign)
|
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);
|
||||||
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceRent);
|
s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceRent);
|
||||||
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
|
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
|
||||||
if(RealEstate.instance.config.cfgUseCurrencySymbol)
|
if(RealEstate.instance.config.cfgUseCurrencySymbol)
|
||||||
{
|
{
|
||||||
s.setLine(2, RealEstate.instance.config.cfgCurrencySymbol + " " + price);
|
s.setLine(2, RealEstate.instance.config.cfgCurrencySymbol + " " + price);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
s.setLine(2, price + " " + RealEstate.econ.currencyNamePlural());
|
s.setLine(2, price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
}
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// we want to know how much time has gone by since startDate
|
// we want to know how much time has gone by since startDate
|
||||||
int days = Period.between(startDate.toLocalDate(), LocalDate.now()).getDays();
|
int days = Period.between(startDate.toLocalDate(), LocalDate.now()).getDays();
|
||||||
Duration hours = Duration.between(startDate.toLocalTime(), LocalTime.now());
|
Duration hours = Duration.between(startDate.toLocalTime(), LocalTime.now());
|
||||||
if(hours.isNegative() && !hours.isZero())
|
if(hours.isNegative() && !hours.isZero())
|
||||||
{
|
{
|
||||||
hours = hours.plusHours(24);
|
hours = hours.plusHours(24);
|
||||||
days--;
|
days--;
|
||||||
}
|
}
|
||||||
if(days >= duration)// we exceeded the time limit!
|
if(days >= duration)// we exceeded the time limit!
|
||||||
{
|
{
|
||||||
payRent();
|
payRent();
|
||||||
}
|
}
|
||||||
else if(sign.getBlock().getState() instanceof Sign)
|
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);
|
||||||
s.setLine(1, Utils.getSignString("Rented by " + Bukkit.getOfflinePlayer(buyer).getName()));
|
s.setLine(1, Utils.getSignString("Rented by " + Bukkit.getOfflinePlayer(buyer).getName()));
|
||||||
s.setLine(2, "Time remaining : ");
|
s.setLine(2, "Time remaining : ");
|
||||||
|
|
||||||
int daysLeft = duration - days - 1;// we need to remove the current day
|
int daysLeft = duration - days - 1;// we need to remove the current day
|
||||||
Duration timeRemaining = Duration.ofHours(24).minus(hours);
|
Duration timeRemaining = Duration.ofHours(24).minus(hours);
|
||||||
|
|
||||||
s.setLine(3, Utils.getTime(daysLeft, timeRemaining, false));
|
s.setLine(3, Utils.getTime(daysLeft, timeRemaining, false));
|
||||||
s.update(true);
|
s.update(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unRent(boolean msgBuyer)
|
private void unRent(boolean msgBuyer)
|
||||||
{
|
{
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
||||||
claim.dropPermission(buyer.toString());
|
claim.dropPermission(buyer.toString());
|
||||||
GriefPrevention.instance.dataStore.saveClaim(claim);
|
GriefPrevention.instance.dataStore.saveClaim(claim);
|
||||||
if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||||
{
|
{
|
||||||
Bukkit.getPlayer(buyer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
Bukkit.getPlayer(buyer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
"The rent for the " + (claim.parent == null ? "claim" : "subclaim") + " at " + ChatColor.BLUE + "[" +
|
"The rent for the " + (claim.parent == null ? "claim" : "subclaim") + " at " + ChatColor.BLUE + "[" +
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.AQUA + " is now over, your access has been revoked.");
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.AQUA + " is now over, your access has been revoked.");
|
||||||
}
|
}
|
||||||
buyer = null;
|
buyer = null;
|
||||||
RealEstate.transactionsStore.saveData();
|
RealEstate.transactionsStore.saveData();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void payRent()
|
private void payRent()
|
||||||
{
|
{
|
||||||
if(buyer == null) return;
|
if(buyer == null) return;
|
||||||
|
|
||||||
OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(this.buyer);
|
OfflinePlayer buyerPlayer = Bukkit.getOfflinePlayer(this.buyer);
|
||||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
OfflinePlayer seller = owner == null ? null : Bukkit.getOfflinePlayer(owner);
|
||||||
|
|
||||||
String claimType = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null).parent == null ? "claim" : "subclaim";
|
String claimType = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null).parent == null ? "claim" : "subclaim";
|
||||||
|
|
||||||
if((autoRenew || periodCount < maxPeriod) && Utils.makePayment(owner, this.buyer, price, false, false))
|
if((autoRenew || periodCount < maxPeriod) && Utils.makePayment(owner, this.buyer, price, false, false))
|
||||||
{
|
{
|
||||||
periodCount = (periodCount + 1) % maxPeriod;
|
periodCount = (periodCount + 1) % maxPeriod;
|
||||||
startDate = LocalDateTime.now();
|
startDate = LocalDateTime.now();
|
||||||
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||||
{
|
{
|
||||||
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
"Paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
"Paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
||||||
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
}
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
{
|
{
|
||||||
User u = RealEstate.ess.getUser(this.buyer);
|
User u = RealEstate.ess.getUser(this.buyer);
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
|
||||||
"Paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
"Paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() +
|
||||||
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
if(seller != null)
|
||||||
{
|
{
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
|
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||||
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
{
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
}
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
{
|
}
|
||||||
User u = RealEstate.ess.getUser(this.owner);
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
|
{
|
||||||
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
User u = RealEstate.ess.getUser(this.owner);
|
||||||
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
|
||||||
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
|
||||||
}
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||||
|
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (autoRenew)
|
|
||||||
{
|
}
|
||||||
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
else if (autoRenew)
|
||||||
{
|
{
|
||||||
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||||
"Couldn't pay the rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
{
|
||||||
sign.getBlockX() + ", Y: " +
|
((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", your access has been revoked.");
|
"Couldn't pay the rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
||||||
}
|
sign.getBlockX() + ", Y: " +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", your access has been revoked.");
|
||||||
{
|
}
|
||||||
User u = RealEstate.ess.getUser(this.buyer);
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
{
|
||||||
"Couldn't pay the rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
User u = RealEstate.ess.getUser(this.buyer);
|
||||||
sign.getBlockX() + ", Y: " +
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", your access has been revoked.");
|
"Couldn't pay the rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
|
||||||
}
|
sign.getBlockX() + ", Y: " +
|
||||||
unRent(false);
|
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", your access has been revoked.");
|
||||||
return;
|
}
|
||||||
}
|
unRent(false);
|
||||||
else
|
return;
|
||||||
{
|
}
|
||||||
unRent(true);
|
else
|
||||||
return;
|
{
|
||||||
}
|
unRent(true);
|
||||||
update();
|
return;
|
||||||
RealEstate.transactionsStore.saveData();
|
}
|
||||||
}
|
update();
|
||||||
|
RealEstate.transactionsStore.saveData();
|
||||||
@Override
|
}
|
||||||
public boolean tryCancelTransaction(Player p)
|
|
||||||
{
|
@Override
|
||||||
if(buyer != null)
|
public boolean tryCancelTransaction(Player p)
|
||||||
{
|
{
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
if(buyer != null)
|
||||||
if(p != null)
|
{
|
||||||
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
||||||
" is currently rented, you can't cancel the transaction!");
|
if(p != null)
|
||||||
return false;
|
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
|
||||||
}
|
" is currently rented, you can't cancel the transaction!");
|
||||||
else
|
return false;
|
||||||
{
|
}
|
||||||
RealEstate.transactionsStore.cancelTransaction(this);
|
else
|
||||||
return true;
|
{
|
||||||
}
|
RealEstate.transactionsStore.cancelTransaction(this);
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void interact(Player player)
|
|
||||||
{
|
@Override
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
|
public void interact(Player player)
|
||||||
if(claim == null)
|
{
|
||||||
{
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
|
if(claim == null)
|
||||||
RealEstate.transactionsStore.cancelTransaction(claim);
|
{
|
||||||
return;
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
|
||||||
}
|
RealEstate.transactionsStore.cancelTransaction(claim);
|
||||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
return;
|
||||||
|
}
|
||||||
if (owner.equals(player.getUniqueId()))
|
String claimType = claim.parent == null ? "claim" : "subclaim";
|
||||||
{
|
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
if (owner.equals(player.getUniqueId()))
|
||||||
return;
|
{
|
||||||
}
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
|
||||||
if(claim.parent == null && !owner.equals(claim.ownerID))
|
return;
|
||||||
{
|
}
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
if(claim.parent == null && !owner.equals(claim.ownerID))
|
||||||
" does not have the right to rent this " + claimType + "!");
|
{
|
||||||
RealEstate.transactionsStore.cancelTransaction(claim);
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
|
||||||
return;
|
" does not have the right to rent this " + claimType + "!");
|
||||||
}
|
RealEstate.transactionsStore.cancelTransaction(claim);
|
||||||
if(!player.hasPermission("realestate." + claimType + ".rent"))
|
return;
|
||||||
{
|
}
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to rent " +
|
if(!player.hasPermission("realestate." + claimType + ".rent"))
|
||||||
claimType + "s!");
|
{
|
||||||
return;
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to rent " +
|
||||||
}
|
claimType + "s!");
|
||||||
if(player.getUniqueId().equals(buyer))
|
return;
|
||||||
{
|
}
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are already renting this " +
|
if(player.getUniqueId().equals(buyer))
|
||||||
claimType + "!");
|
{
|
||||||
return;
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are already renting this " +
|
||||||
}
|
claimType + "!");
|
||||||
if(buyer != null)
|
return;
|
||||||
{
|
}
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Someone already rents this " +
|
if(buyer != null)
|
||||||
claimType + "!");
|
{
|
||||||
return;
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Someone already rents this " +
|
||||||
}
|
claimType + "!");
|
||||||
|
return;
|
||||||
if(Utils.makePayment(owner, player.getUniqueId(), price, false, true))// if payment succeed
|
}
|
||||||
{
|
|
||||||
buyer = player.getUniqueId();
|
if(Utils.makePayment(owner, player.getUniqueId(), price, false, true))// if payment succeed
|
||||||
startDate = LocalDateTime.now();
|
{
|
||||||
autoRenew = false;
|
buyer = player.getUniqueId();
|
||||||
claim.setPermission(buyer.toString(), ClaimPermission.Build);
|
startDate = LocalDateTime.now();
|
||||||
GriefPrevention.instance.dataStore.saveClaim(claim);
|
autoRenew = false;
|
||||||
update();
|
claim.setPermission(buyer.toString(), ClaimPermission.Build);
|
||||||
RealEstate.transactionsStore.saveData();
|
GriefPrevention.instance.dataStore.saveClaim(claim);
|
||||||
|
update();
|
||||||
RealEstate.instance.addLogEntry(
|
RealEstate.transactionsStore.saveData();
|
||||||
"[" + RealEstate.transactionsStore.dateFormat.format(RealEstate.transactionsStore.date) + "] " + player.getName() +
|
|
||||||
" has rented a " + claimType + " at " +
|
RealEstate.instance.addLogEntry(
|
||||||
"[" + player.getLocation().getWorld() + ", " +
|
"[" + RealEstate.transactionsStore.dateFormat.format(RealEstate.transactionsStore.date) + "] " + player.getName() +
|
||||||
"X: " + player.getLocation().getBlockX() + ", " +
|
" has rented a " + claimType + " at " +
|
||||||
"Y: " + player.getLocation().getBlockY() + ", " +
|
"[" + player.getLocation().getWorld() + ", " +
|
||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
"X: " + player.getLocation().getBlockX() + ", " +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
"Y: " + player.getLocation().getBlockY() + ", " +
|
||||||
|
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||||
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
|
||||||
{
|
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
|
||||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
|
||||||
" has just rented your " + claimType + " at " +
|
{
|
||||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
" has just rented your " + claimType + " at " +
|
||||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
||||||
}
|
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
||||||
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
{
|
}
|
||||||
User u = RealEstate.ess.getUser(this.owner);
|
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
|
||||||
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
{
|
||||||
" has just rented your " + claimType + " at " +
|
User u = RealEstate.ess.getUser(this.owner);
|
||||||
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
|
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
|
||||||
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
|
" has just rented your " + claimType + " at " +
|
||||||
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
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());
|
|
||||||
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully rented this " + claimType +
|
||||||
destroySign();
|
" for " + ChatColor.GREEN + price + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
|
||||||
}
|
destroySign();
|
||||||
|
}
|
||||||
@Override
|
}
|
||||||
public void preview(Player player)
|
|
||||||
{
|
@Override
|
||||||
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
public void preview(Player player)
|
||||||
String msg = "";
|
{
|
||||||
if(player.hasPermission("realestate.info"))
|
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
|
||||||
{
|
String msg = "";
|
||||||
String claimType = claim.parent == null ? "claim" : "subclaim";
|
if(player.hasPermission("realestate.info"))
|
||||||
msg = ChatColor.BLUE + "-----= " + ChatColor.WHITE + "[" + ChatColor.GOLD + "RealEstate Rent Info" + ChatColor.WHITE + "]" +
|
{
|
||||||
ChatColor.BLUE + " =-----\n";
|
String claimType = claim.parent == null ? "claim" : "subclaim";
|
||||||
if(buyer == null)
|
msg = ChatColor.BLUE + "-----= " + ChatColor.WHITE + "[" + ChatColor.GOLD + "RealEstate Rent Info" + ChatColor.WHITE + "]" +
|
||||||
{
|
ChatColor.BLUE + " =-----\n";
|
||||||
msg += ChatColor.AQUA + "This " + claimType + " is for rent for " +
|
if(buyer == null)
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " +
|
{
|
||||||
(maxPeriod > 1 ? "" + ChatColor.GREEN + maxPeriod + ChatColor.AQUA + " periods of " : "") +
|
msg += ChatColor.AQUA + "This " + claimType + " is for rent for " +
|
||||||
ChatColor.GREEN + Utils.getTime(duration, null, true) + "\n";
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " +
|
||||||
|
(maxPeriod > 1 ? "" + ChatColor.GREEN + maxPeriod + ChatColor.AQUA + " periods of " : "") +
|
||||||
if(claimType.equalsIgnoreCase("claim"))
|
ChatColor.GREEN + Utils.getTime(duration, null, true) + "\n";
|
||||||
{
|
|
||||||
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
if(claimType.equalsIgnoreCase("claim"))
|
||||||
}
|
{
|
||||||
else
|
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
||||||
{
|
}
|
||||||
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName() + "\n";
|
else
|
||||||
msg += ChatColor.LIGHT_PURPLE + "Note: " + ChatColor.AQUA + "You will only rent access to this subclaim!";
|
{
|
||||||
}
|
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName() + "\n";
|
||||||
}
|
msg += ChatColor.LIGHT_PURPLE + "Note: " + ChatColor.AQUA + "You will only rent access to this subclaim!";
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
int days = Period.between(startDate.toLocalDate(), LocalDate.now()).getDays();
|
else
|
||||||
Duration hours = Duration.between(startDate.toLocalTime(), LocalTime.now());
|
{
|
||||||
if(hours.isNegative() && !hours.isZero())
|
int days = Period.between(startDate.toLocalDate(), LocalDate.now()).getDays();
|
||||||
{
|
Duration hours = Duration.between(startDate.toLocalTime(), LocalTime.now());
|
||||||
hours = hours.plusHours(24);
|
if(hours.isNegative() && !hours.isZero())
|
||||||
days--;
|
{
|
||||||
}
|
hours = hours.plusHours(24);
|
||||||
int daysLeft = duration - days - 1;// we need to remove the current day
|
days--;
|
||||||
Duration timeRemaining = Duration.ofHours(24).minus(hours);
|
}
|
||||||
|
int daysLeft = duration - days - 1;// we need to remove the current day
|
||||||
msg += ChatColor.AQUA + "This " + claimType + " is currently rented by " +
|
Duration timeRemaining = Duration.ofHours(24).minus(hours);
|
||||||
ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " +
|
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " +
|
msg += ChatColor.AQUA + "This " + claimType + " is currently rented by " +
|
||||||
(maxPeriod - periodCount > 1 ? "" + ChatColor.GREEN + (maxPeriod - periodCount) + ChatColor.AQUA + " periods of " +
|
ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " +
|
||||||
ChatColor.GREEN + Utils.getTime(duration, null, false) + ChatColor.AQUA + ". The current period will end in " : "another ") +
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " +
|
||||||
ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n";
|
(maxPeriod - periodCount > 1 ? "" + ChatColor.GREEN + (maxPeriod - periodCount) + ChatColor.AQUA + " periods of " +
|
||||||
if((owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.config.cfgEnableAutoRenew)
|
ChatColor.GREEN + Utils.getTime(duration, null, false) + ChatColor.AQUA + ". The current period will end in " : "another ") +
|
||||||
{
|
ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n";
|
||||||
msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enabled" : "disabled") + "\n";
|
if((owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.config.cfgEnableAutoRenew)
|
||||||
}
|
{
|
||||||
if(claimType.equalsIgnoreCase("claim"))
|
msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enabled" : "disabled") + "\n";
|
||||||
{
|
}
|
||||||
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
if(claimType.equalsIgnoreCase("claim"))
|
||||||
}
|
{
|
||||||
else
|
msg += ChatColor.AQUA + "The current owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
||||||
{
|
}
|
||||||
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
else
|
||||||
}
|
{
|
||||||
}
|
msg += ChatColor.AQUA + "The main claim owner is: " + ChatColor.GREEN + claim.getOwnerName();
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
}
|
||||||
msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
|
else
|
||||||
}
|
{
|
||||||
player.sendMessage(msg);
|
msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
|
||||||
}
|
}
|
||||||
|
player.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -115,7 +115,7 @@ public class ClaimSell extends ClaimTransaction
|
|||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
"Z: " + player.getLocation().getBlockZ() + "] " +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
|
||||||
if(RealEstate.instance.config.cfgMessageOwner)
|
if(RealEstate.instance.config.cfgMessageOwner && owner != null)
|
||||||
{
|
{
|
||||||
OfflinePlayer oldOwner = Bukkit.getOfflinePlayer(owner);
|
OfflinePlayer oldOwner = Bukkit.getOfflinePlayer(owner);
|
||||||
if(oldOwner.isOnline())
|
if(oldOwner.isOnline())
|
||||||
|
|||||||
@ -1,273 +1,294 @@
|
|||||||
package me.EtienneDx.RealEstate.Transactions;
|
package me.EtienneDx.RealEstate.Transactions;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.DateFormat;
|
import java.nio.file.FileSystem;
|
||||||
import java.text.SimpleDateFormat;
|
import java.nio.file.FileSystems;
|
||||||
import java.util.Collection;
|
import java.nio.file.Files;
|
||||||
import java.util.Date;
|
import java.nio.file.Path;
|
||||||
import java.util.HashMap;
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import org.bukkit.Bukkit;
|
import java.util.Collection;
|
||||||
import org.bukkit.Location;
|
import java.util.Date;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import java.util.HashMap;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import me.EtienneDx.RealEstate.RealEstate;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
import org.bukkit.entity.Player;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.util.FileUtil;
|
||||||
public class TransactionsStore
|
|
||||||
{
|
import me.EtienneDx.RealEstate.RealEstate;
|
||||||
public final String dataFilePath = RealEstate.pluginDirPath + "transactions.data";
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
Date date = new Date();
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
public HashMap<String, ClaimSell> claimSell;
|
public class TransactionsStore
|
||||||
public HashMap<String, ClaimRent> claimRent;
|
{
|
||||||
public HashMap<String, ClaimLease> claimLease;
|
public final String dataFilePath = RealEstate.pluginDirPath + "transactions.data";
|
||||||
|
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||||
public TransactionsStore()
|
Date date = new Date();
|
||||||
{
|
|
||||||
loadData();
|
public HashMap<String, ClaimSell> claimSell;
|
||||||
new BukkitRunnable()
|
public HashMap<String, ClaimRent> claimRent;
|
||||||
{
|
public HashMap<String, ClaimLease> claimLease;
|
||||||
|
|
||||||
@Override
|
public TransactionsStore()
|
||||||
public void run()
|
{
|
||||||
{
|
loadData();
|
||||||
Collection<ClaimRent> col = claimRent.values();// need intermediate since some may get removed in the process
|
new BukkitRunnable()
|
||||||
for(ClaimRent cr : col)
|
{
|
||||||
{
|
|
||||||
cr.update();
|
@Override
|
||||||
}
|
public void run()
|
||||||
Collection<ClaimLease> co = claimLease.values();// need intermediate since some may get removed in the process
|
{
|
||||||
for(ClaimLease cl : co)
|
Collection<ClaimRent> col = claimRent.values();// need intermediate since some may get removed in the process
|
||||||
{
|
for(ClaimRent cr : col)
|
||||||
cl.update();
|
{
|
||||||
}
|
cr.update();
|
||||||
}
|
}
|
||||||
}.runTaskTimer(RealEstate.instance, 0, 1200L);// run every 60 seconds
|
Collection<ClaimLease> co = claimLease.values();// need intermediate since some may get removed in the process
|
||||||
}
|
for(ClaimLease cl : co)
|
||||||
|
{
|
||||||
public void loadData()
|
cl.update();
|
||||||
{
|
}
|
||||||
claimSell = new HashMap<>();
|
}
|
||||||
claimRent = new HashMap<>();
|
}.runTaskTimer(RealEstate.instance, 0, 1200L);// run every 60 seconds
|
||||||
claimLease = new HashMap<>();
|
}
|
||||||
|
|
||||||
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.dataFilePath));
|
public void loadData()
|
||||||
for(String key : config.getKeys(true))
|
{
|
||||||
{
|
claimSell = new HashMap<>();
|
||||||
if(key.startsWith("Sell."))
|
claimRent = new HashMap<>();
|
||||||
{
|
claimLease = new HashMap<>();
|
||||||
ClaimSell cs = (ClaimSell)config.get(key);
|
|
||||||
claimSell.put(key.substring(5), cs);
|
File file = new File(this.dataFilePath);
|
||||||
}
|
|
||||||
else if(key.startsWith("Rent."))
|
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
{
|
try {
|
||||||
ClaimRent cr = (ClaimRent)config.get(key);
|
RealEstate.instance.addLogEntry(new String(Files.readAllBytes(FileSystems.getDefault().getPath(this.dataFilePath))));
|
||||||
claimRent.put(key.substring(5), cr);
|
} catch (IOException e) {
|
||||||
}
|
// TODO Auto-generated catch block
|
||||||
else if(key.startsWith("Lease."))
|
e.printStackTrace();
|
||||||
{
|
}
|
||||||
ClaimLease cl = (ClaimLease)config.get(key);
|
ConfigurationSection sell = config.getConfigurationSection("Sell");
|
||||||
claimLease.put(key.substring(6), cl);
|
ConfigurationSection rent = config.getConfigurationSection("Rent");
|
||||||
}
|
ConfigurationSection lease = config.getConfigurationSection("Lease");
|
||||||
}
|
if(sell != null)
|
||||||
}
|
{
|
||||||
|
RealEstate.instance.addLogEntry(sell.toString());
|
||||||
public void saveData()
|
RealEstate.instance.addLogEntry(sell.getKeys(false).size() + "");
|
||||||
{
|
for(String key : sell.getKeys(false))
|
||||||
YamlConfiguration config = new YamlConfiguration();
|
{
|
||||||
for (ClaimSell cs : claimSell.values())
|
ClaimSell cs = (ClaimSell)sell.get(key);
|
||||||
config.set("Sell." + cs.claimId, cs);
|
claimSell.put(key, cs);
|
||||||
for (ClaimRent cr : claimRent.values())
|
}
|
||||||
config.set("Rent." + cr.claimId, cr);
|
}
|
||||||
for (ClaimLease cl : claimLease.values())
|
if(rent != null)
|
||||||
config.set("Lease." + cl.claimId, cl);
|
for(String key : rent.getKeys(false))
|
||||||
try
|
{
|
||||||
{
|
ClaimRent cr = (ClaimRent)rent.get(key);
|
||||||
config.save(new File(this.dataFilePath));
|
claimRent.put(key, cr);
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
if(lease != null)
|
||||||
{
|
for(String key : lease.getKeys(false))
|
||||||
RealEstate.instance.log.info("Unable to write to the data file at \"" + this.dataFilePath + "\"");
|
{
|
||||||
}
|
ClaimLease cl = (ClaimLease)lease.get(key);
|
||||||
}
|
claimLease.put(key, cl);
|
||||||
|
}
|
||||||
public boolean anyTransaction(Claim claim)
|
}
|
||||||
{
|
|
||||||
return claim != null &&
|
public void saveData()
|
||||||
(claimSell.containsKey(claim.getID().toString()) ||
|
{
|
||||||
claimRent.containsKey(claim.getID().toString()) ||
|
YamlConfiguration config = new YamlConfiguration();
|
||||||
claimLease.containsKey(claim.getID().toString()));
|
for (ClaimSell cs : claimSell.values())
|
||||||
}
|
config.set("Sell." + cs.claimId, cs);
|
||||||
|
for (ClaimRent cr : claimRent.values())
|
||||||
public Transaction getTransaction(Claim claim)
|
config.set("Rent." + cr.claimId, cr);
|
||||||
{
|
for (ClaimLease cl : claimLease.values())
|
||||||
if(claimSell.containsKey(claim.getID().toString()))
|
config.set("Lease." + cl.claimId, cl);
|
||||||
return claimSell.get(claim.getID().toString());
|
try
|
||||||
if(claimRent.containsKey(claim.getID().toString()))
|
{
|
||||||
return claimRent.get(claim.getID().toString());
|
config.save(new File(this.dataFilePath));
|
||||||
if(claimLease.containsKey(claim.getID().toString()))
|
}
|
||||||
return claimLease.get(claim.getID().toString());
|
catch (IOException e)
|
||||||
return null;
|
{
|
||||||
}
|
RealEstate.instance.log.info("Unable to write to the data file at \"" + this.dataFilePath + "\"");
|
||||||
|
}
|
||||||
public void cancelTransaction(Claim claim)
|
}
|
||||||
{
|
|
||||||
if(anyTransaction(claim))
|
public boolean anyTransaction(Claim claim)
|
||||||
{
|
{
|
||||||
Transaction tr = getTransaction(claim);
|
return claim != null &&
|
||||||
cancelTransaction(tr);
|
(claimSell.containsKey(claim.getID().toString()) ||
|
||||||
}
|
claimRent.containsKey(claim.getID().toString()) ||
|
||||||
saveData();
|
claimLease.containsKey(claim.getID().toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void cancelTransaction(Transaction tr)
|
public Transaction getTransaction(Claim claim)
|
||||||
{
|
{
|
||||||
if(tr.getHolder() != null)
|
if(claimSell.containsKey(claim.getID().toString()))
|
||||||
tr.getHolder().breakNaturally();
|
return claimSell.get(claim.getID().toString());
|
||||||
if(tr instanceof ClaimSell)
|
if(claimRent.containsKey(claim.getID().toString()))
|
||||||
{
|
return claimRent.get(claim.getID().toString());
|
||||||
claimSell.remove(String.valueOf(((ClaimSell) tr).claimId));
|
if(claimLease.containsKey(claim.getID().toString()))
|
||||||
}
|
return claimLease.get(claim.getID().toString());
|
||||||
if(tr instanceof ClaimRent)
|
return null;
|
||||||
{
|
}
|
||||||
claimRent.remove(String.valueOf(((ClaimRent) tr).claimId));
|
|
||||||
}
|
public void cancelTransaction(Claim claim)
|
||||||
if(tr instanceof ClaimLease)
|
{
|
||||||
{
|
if(anyTransaction(claim))
|
||||||
claimLease.remove(String.valueOf(((ClaimLease) tr).claimId));
|
{
|
||||||
}
|
Transaction tr = getTransaction(claim);
|
||||||
saveData();
|
cancelTransaction(tr);
|
||||||
}
|
}
|
||||||
|
saveData();
|
||||||
public boolean canCancelTransaction(Transaction tr)
|
}
|
||||||
{
|
|
||||||
return tr instanceof ClaimSell || (tr instanceof ClaimRent && ((ClaimRent)tr).buyer == null) ||
|
public void cancelTransaction(Transaction tr)
|
||||||
(tr instanceof ClaimLease && ((ClaimLease)tr).buyer == null);
|
{
|
||||||
}
|
if(tr.getHolder() != null)
|
||||||
|
tr.getHolder().breakNaturally();
|
||||||
public void sell(Claim claim, Player player, double price, Location sign)
|
if(tr instanceof ClaimSell)
|
||||||
{
|
{
|
||||||
ClaimSell cs = new ClaimSell(claim, player, price, sign);
|
claimSell.remove(String.valueOf(((ClaimSell) tr).claimId));
|
||||||
claimSell.put(claim.getID().toString(), cs);
|
}
|
||||||
cs.update();
|
if(tr instanceof ClaimRent)
|
||||||
saveData();
|
{
|
||||||
|
claimRent.remove(String.valueOf(((ClaimRent) tr).claimId));
|
||||||
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() +
|
}
|
||||||
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale at " +
|
if(tr instanceof ClaimLease)
|
||||||
"[" + player.getLocation().getWorld() + ", " +
|
{
|
||||||
"X: " + player.getLocation().getBlockX() + ", " +
|
claimLease.remove(String.valueOf(((ClaimLease) tr).claimId));
|
||||||
"Y: " + player.getLocation().getBlockY() + ", " +
|
}
|
||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
saveData();
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
}
|
||||||
|
|
||||||
if(player != null)
|
public boolean canCancelTransaction(Transaction tr)
|
||||||
{
|
{
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully created " +
|
return tr instanceof ClaimSell || (tr instanceof ClaimRent && ((ClaimRent)tr).buyer == null) ||
|
||||||
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " sale for " +
|
(tr instanceof ClaimLease && ((ClaimLease)tr).buyer == null);
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
}
|
||||||
}
|
|
||||||
if(RealEstate.instance.config.cfgBroadcastSell)
|
public void sell(Claim claim, Player player, double price, Location sign)
|
||||||
{
|
{
|
||||||
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
ClaimSell cs = new ClaimSell(claim, player, price, sign);
|
||||||
{
|
claimSell.put(claim.getID().toString(), cs);
|
||||||
if(p != player)
|
cs.update();
|
||||||
{
|
saveData();
|
||||||
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
|
|
||||||
ChatColor.AQUA + " has put " +
|
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
|
||||||
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale for " +
|
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale at " +
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
"[" + claim.getGreaterBoundaryCorner().getWorld() + ", " +
|
||||||
}
|
"X: " + claim.getGreaterBoundaryCorner().getBlockX() + ", " +
|
||||||
}
|
"Y: " + claim.getGreaterBoundaryCorner().getBlockY() + ", " +
|
||||||
}
|
"Z: " + claim.getGreaterBoundaryCorner().getBlockZ() + "] " +
|
||||||
}
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
|
||||||
public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
|
if(player != null)
|
||||||
{
|
{
|
||||||
ClaimRent cr = new ClaimRent(claim, player, price, sign, duration, rentPeriods);
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully created " +
|
||||||
claimRent.put(claim.getID().toString(), cr);
|
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " sale for " +
|
||||||
cr.update();
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
saveData();
|
}
|
||||||
|
if(RealEstate.instance.config.cfgBroadcastSell)
|
||||||
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() +
|
{
|
||||||
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent at " +
|
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
||||||
"[" + player.getLocation().getWorld() + ", " +
|
{
|
||||||
"X: " + player.getLocation().getBlockX() + ", " +
|
if(p != player)
|
||||||
"Y: " + player.getLocation().getBlockY() + ", " +
|
{
|
||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + (player == null ? "The Server" : player.getDisplayName()) +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
ChatColor.AQUA + " has put " +
|
||||||
|
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale for " +
|
||||||
if(player != null)
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
{
|
}
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully put " +
|
}
|
||||||
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent for " +
|
}
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
}
|
||||||
}
|
|
||||||
if(RealEstate.instance.config.cfgBroadcastSell)
|
public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
|
||||||
{
|
{
|
||||||
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
ClaimRent cr = new ClaimRent(claim, player, price, sign, duration, rentPeriods);
|
||||||
{
|
claimRent.put(claim.getID().toString(), cr);
|
||||||
if(p != player)
|
cr.update();
|
||||||
{
|
saveData();
|
||||||
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
|
|
||||||
ChatColor.AQUA + " has put " +
|
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
|
||||||
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent for " +
|
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent at " +
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
"[" + claim.getLesserBoundaryCorner().getWorld() + ", " +
|
||||||
}
|
"X: " + claim.getLesserBoundaryCorner().getBlockX() + ", " +
|
||||||
}
|
"Y: " + claim.getLesserBoundaryCorner().getBlockY() + ", " +
|
||||||
}
|
"Z: " + claim.getLesserBoundaryCorner().getBlockZ() + "] " +
|
||||||
}
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
|
||||||
public void lease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsCount)
|
if(player != null)
|
||||||
{
|
{
|
||||||
ClaimLease cl = new ClaimLease(claim, player, price, sign, frequency, paymentsCount);
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully put " +
|
||||||
claimLease.put(claim.getID().toString(), cl);
|
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent for " +
|
||||||
cl.update();
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
saveData();
|
}
|
||||||
|
if(RealEstate.instance.config.cfgBroadcastSell)
|
||||||
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() +
|
{
|
||||||
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease at " +
|
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
||||||
"[" + player.getLocation().getWorld() + ", " +
|
{
|
||||||
"X: " + player.getLocation().getBlockX() + ", " +
|
if(p != player)
|
||||||
"Y: " + player.getLocation().getBlockY() + ", " +
|
{
|
||||||
"Z: " + player.getLocation().getBlockZ() + "] " +
|
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + (player == null ? "The Server" : player.getDisplayName()) +
|
||||||
"Payments Count : " + paymentsCount + " " +
|
ChatColor.AQUA + " has put " +
|
||||||
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent for " +
|
||||||
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
if(player != null)
|
}
|
||||||
{
|
}
|
||||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully put " +
|
}
|
||||||
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease for " +
|
}
|
||||||
ChatColor.GREEN + paymentsCount + ChatColor.AQUA + " payments of " +
|
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
public void lease(Claim claim, Player player, double price, Location sign, int frequency, int paymentsCount)
|
||||||
}
|
{
|
||||||
if(RealEstate.instance.config.cfgBroadcastSell)
|
ClaimLease cl = new ClaimLease(claim, player, price, sign, frequency, paymentsCount);
|
||||||
{
|
claimLease.put(claim.getID().toString(), cl);
|
||||||
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
cl.update();
|
||||||
{
|
saveData();
|
||||||
if(p != player)
|
|
||||||
{
|
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
|
||||||
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
|
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease at " +
|
||||||
ChatColor.AQUA + " has put " +
|
"[" + claim.getLesserBoundaryCorner().getWorld() + ", " +
|
||||||
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease for " +
|
"X: " + claim.getLesserBoundaryCorner().getBlockX() + ", " +
|
||||||
ChatColor.GREEN + paymentsCount + ChatColor.AQUA + " payments of " +
|
"Y: " + claim.getLesserBoundaryCorner().getBlockY() + ", " +
|
||||||
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
"Z: " + claim.getLesserBoundaryCorner().getBlockZ() + "] " +
|
||||||
}
|
"Payments Count : " + paymentsCount + " " +
|
||||||
}
|
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
}
|
|
||||||
}
|
if(player != null)
|
||||||
|
{
|
||||||
public Transaction getTransaction(Player player)
|
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully put " +
|
||||||
{
|
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease for " +
|
||||||
if(player == null) return null;
|
ChatColor.GREEN + paymentsCount + ChatColor.AQUA + " payments of " +
|
||||||
Claim c = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), false, null);
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
return getTransaction(c);
|
}
|
||||||
}
|
if(RealEstate.instance.config.cfgBroadcastSell)
|
||||||
}
|
{
|
||||||
|
for(Player p : Bukkit.getServer().getOnlinePlayers())
|
||||||
|
{
|
||||||
|
if(p != player)
|
||||||
|
{
|
||||||
|
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + (player == null ? "The Server" : player.getDisplayName()) +
|
||||||
|
ChatColor.AQUA + " has put " +
|
||||||
|
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease for " +
|
||||||
|
ChatColor.GREEN + paymentsCount + ChatColor.AQUA + " payments of " +
|
||||||
|
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Transaction getTransaction(Player player)
|
||||||
|
{
|
||||||
|
if(player == null) return null;
|
||||||
|
Claim c = GriefPrevention.instance.dataStore.getClaimAt(player.getLocation(), false, null);
|
||||||
|
return getTransaction(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -1,154 +1,157 @@
|
|||||||
package me.EtienneDx.RealEstate;
|
package me.EtienneDx.RealEstate;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import me.ryanhamshire.GriefPrevention.Claim;
|
import me.ryanhamshire.GriefPrevention.Claim;
|
||||||
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
import me.ryanhamshire.GriefPrevention.ClaimPermission;
|
||||||
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
import me.ryanhamshire.GriefPrevention.GriefPrevention;
|
||||||
import me.ryanhamshire.GriefPrevention.PlayerData;
|
import me.ryanhamshire.GriefPrevention.PlayerData;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
|
||||||
public class Utils
|
public class Utils
|
||||||
{
|
{
|
||||||
public static boolean makePayment(UUID receiver, UUID giver, double amount, boolean msgSeller, boolean msgBuyer)
|
public static boolean makePayment(UUID receiver, UUID giver, double amount, boolean msgSeller, boolean msgBuyer)
|
||||||
{
|
{
|
||||||
// seller might be null if it is the server
|
// seller might be null if it is the server
|
||||||
OfflinePlayer s = receiver != null ? Bukkit.getOfflinePlayer(receiver) : null, b = Bukkit.getOfflinePlayer(giver);
|
OfflinePlayer s = receiver != null ? Bukkit.getOfflinePlayer(receiver) : null, b = Bukkit.getOfflinePlayer(giver);
|
||||||
if(!RealEstate.econ.has(b, amount))
|
if(!RealEstate.econ.has(b, amount))
|
||||||
{
|
{
|
||||||
if(b.isOnline() && msgBuyer)
|
if(b.isOnline() && msgBuyer)
|
||||||
{
|
{
|
||||||
((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
"You don't have enough money to make this transaction!");
|
"You don't have enough money to make this transaction!");
|
||||||
}
|
}
|
||||||
if(s != null && s.isOnline() && msgSeller)
|
if(s != null && s.isOnline() && msgSeller)
|
||||||
{
|
{
|
||||||
((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
b.getName() + " doesn't have enough money to make this transaction!");
|
b.getName() + " doesn't have enough money to make this transaction!");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
EconomyResponse resp = RealEstate.econ.withdrawPlayer(b, amount);
|
EconomyResponse resp = RealEstate.econ.withdrawPlayer(b, amount);
|
||||||
if(!resp.transactionSuccess())
|
if(!resp.transactionSuccess())
|
||||||
{
|
{
|
||||||
if(b.isOnline() && msgBuyer)
|
if(b.isOnline() && msgBuyer)
|
||||||
{
|
{
|
||||||
((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
"Could not withdraw the money!");
|
"Could not withdraw the money!");
|
||||||
}
|
}
|
||||||
if(s != null && s.isOnline() && msgSeller)
|
if(s != null && s.isOnline() && msgSeller)
|
||||||
{
|
{
|
||||||
((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
"Could not withdraw the money!");
|
"Could not withdraw the money!");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(s != null)
|
if(s != null)
|
||||||
{
|
{
|
||||||
resp = RealEstate.econ.depositPlayer(s, amount);
|
resp = RealEstate.econ.depositPlayer(s, amount);
|
||||||
if(!resp.transactionSuccess())
|
if(!resp.transactionSuccess())
|
||||||
{
|
{
|
||||||
if(b.isOnline() && msgBuyer)
|
if(b.isOnline() && msgBuyer)
|
||||||
{
|
{
|
||||||
((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
"Could not deposit to " + s.getName() + ", refunding Player!");
|
"Could not deposit to " + s.getName() + ", refunding Player!");
|
||||||
}
|
}
|
||||||
if(s != null && s.isOnline() && msgSeller)
|
if(s != null && s.isOnline() && msgSeller)
|
||||||
{
|
{
|
||||||
((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
|
||||||
"Could not deposit to you, refunding" + b.getName() + "!");
|
"Could not deposit to you, refunding" + b.getName() + "!");
|
||||||
}
|
}
|
||||||
RealEstate.econ.depositPlayer(b, amount);
|
RealEstate.econ.depositPlayer(b, amount);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getTime(int days, Duration hours, boolean details)
|
public static String getTime(int days, Duration hours, boolean details)
|
||||||
{
|
{
|
||||||
String time = "";
|
String time = "";
|
||||||
if(days >= 7)
|
if(days >= 7)
|
||||||
{
|
{
|
||||||
time += (days / 7) + " week" + (days >= 14 ? "s" : "");
|
time += (days / 7) + " week" + (days >= 14 ? "s" : "");
|
||||||
}
|
}
|
||||||
if(days % 7 > 0)
|
if(days % 7 > 0)
|
||||||
{
|
{
|
||||||
time += (time.isEmpty() ? "" : " ") + (days % 7) + " day" + (days % 7 > 1 ? "s" : "");
|
time += (time.isEmpty() ? "" : " ") + (days % 7) + " day" + (days % 7 > 1 ? "s" : "");
|
||||||
}
|
}
|
||||||
if((details || days < 7) && hours != null && hours.toHours() > 0)
|
if((details || days < 7) && hours != null && hours.toHours() > 0)
|
||||||
{
|
{
|
||||||
time += (time.isEmpty() ? "" : " ") + hours.toHours() + " hour" + (hours.toHours() > 1 ? "s" : "");
|
time += (time.isEmpty() ? "" : " ") + hours.toHours() + " hour" + (hours.toHours() > 1 ? "s" : "");
|
||||||
}
|
}
|
||||||
if((details || days == 0) && hours != null && (time.isEmpty() || hours.toMinutes() % 60 > 0))
|
if((details || days == 0) && hours != null && (time.isEmpty() || hours.toMinutes() % 60 > 0))
|
||||||
{
|
{
|
||||||
time += (time.isEmpty() ? "" : " ") + (hours.toMinutes() % 60) + " min" + (hours.toMinutes() % 60 > 1 ? "s" : "");
|
time += (time.isEmpty() ? "" : " ") + (hours.toMinutes() % 60) + " min" + (hours.toMinutes() % 60 > 1 ? "s" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void transferClaim(Claim claim, UUID buyer, UUID seller)
|
public static void transferClaim(Claim claim, UUID buyer, UUID seller)
|
||||||
{
|
{
|
||||||
// blocks transfer :
|
// blocks transfer :
|
||||||
// if transfert is true, the seller will lose the blocks he had
|
// if transfert is true, the seller will lose the blocks he had
|
||||||
// and the buyer will get them
|
// and the buyer will get them
|
||||||
// (that means the buyer will keep the same amount of remaining blocks after the transaction)
|
// (that means the buyer will keep the same amount of remaining blocks after the transaction)
|
||||||
if(claim.parent == null && RealEstate.instance.config.cfgTransferClaimBlocks)
|
if(claim.parent == null && RealEstate.instance.config.cfgTransferClaimBlocks)
|
||||||
{
|
{
|
||||||
PlayerData buyerData = GriefPrevention.instance.dataStore.getPlayerData(buyer);
|
PlayerData buyerData = GriefPrevention.instance.dataStore.getPlayerData(buyer);
|
||||||
PlayerData sellerData = GriefPrevention.instance.dataStore.getPlayerData(seller);
|
if(seller != null)
|
||||||
|
{
|
||||||
// the seller has to provide the blocks
|
PlayerData sellerData = GriefPrevention.instance.dataStore.getPlayerData(seller);
|
||||||
sellerData.setBonusClaimBlocks(sellerData.getBonusClaimBlocks() - claim.getArea());
|
|
||||||
if (sellerData.getBonusClaimBlocks() < 0)// can't have negative bonus claim blocks, so if need be, we take into the accrued
|
// the seller has to provide the blocks
|
||||||
{
|
sellerData.setBonusClaimBlocks(sellerData.getBonusClaimBlocks() - claim.getArea());
|
||||||
sellerData.setAccruedClaimBlocks(sellerData.getAccruedClaimBlocks() + sellerData.getBonusClaimBlocks());
|
if (sellerData.getBonusClaimBlocks() < 0)// can't have negative bonus claim blocks, so if need be, we take into the accrued
|
||||||
sellerData.setBonusClaimBlocks(0);
|
{
|
||||||
}
|
sellerData.setAccruedClaimBlocks(sellerData.getAccruedClaimBlocks() + sellerData.getBonusClaimBlocks());
|
||||||
|
sellerData.setBonusClaimBlocks(0);
|
||||||
// the buyer receive them
|
}
|
||||||
buyerData.setBonusClaimBlocks(buyerData.getBonusClaimBlocks() + claim.getArea());
|
}
|
||||||
}
|
|
||||||
|
// the buyer receive them
|
||||||
// start to change owner
|
buyerData.setBonusClaimBlocks(buyerData.getBonusClaimBlocks() + claim.getArea());
|
||||||
if(claim.parent == null)
|
}
|
||||||
for(Claim child : claim.children)
|
|
||||||
{
|
// start to change owner
|
||||||
child.clearPermissions();
|
if(claim.parent == null)
|
||||||
child.managers.clear();
|
for(Claim child : claim.children)
|
||||||
}
|
{
|
||||||
claim.clearPermissions();
|
child.clearPermissions();
|
||||||
|
child.managers.clear();
|
||||||
try
|
}
|
||||||
{
|
claim.clearPermissions();
|
||||||
if(claim.parent == null)
|
|
||||||
GriefPrevention.instance.dataStore.changeClaimOwner(claim, buyer);
|
try
|
||||||
else
|
{
|
||||||
{
|
if(claim.parent == null)
|
||||||
claim.setPermission(buyer.toString(), ClaimPermission.Build);
|
GriefPrevention.instance.dataStore.changeClaimOwner(claim, buyer);
|
||||||
}
|
else
|
||||||
}
|
{
|
||||||
catch (Exception e)// error occurs when trying to change subclaim owner
|
claim.setPermission(buyer.toString(), ClaimPermission.Build);
|
||||||
{
|
}
|
||||||
e.printStackTrace();
|
}
|
||||||
return;
|
catch (Exception e)// error occurs when trying to change subclaim owner
|
||||||
}
|
{
|
||||||
GriefPrevention.instance.dataStore.saveClaim(claim);
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
GriefPrevention.instance.dataStore.saveClaim(claim);
|
||||||
public static String getSignString(String str)
|
|
||||||
{
|
}
|
||||||
if(str.length() > 16)
|
|
||||||
str = str.substring(0, 16);
|
public static String getSignString(String str)
|
||||||
return str;
|
{
|
||||||
}
|
if(str.length() > 16)
|
||||||
}
|
str = str.substring(0, 16);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user