Changed to automatically sell/rent/lease as 'SERVER' for admin claims

This commit is contained in:
EtienneDx 2019-08-06 14:34:13 +02:00
parent 2cff090309
commit 8c18e01cb4
8 changed files with 1365 additions and 1325 deletions

View File

@ -14,7 +14,7 @@ public class GP_RealEstateHook implements IRealEstate
public String allowEdit(Claim claim, Player player)
{
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)
return "This claim is currently involved in a transaction, you can't edit it!";
@ -26,7 +26,7 @@ public class GP_RealEstateHook implements IRealEstate
public String allowBuild(Claim claim, Player player, Material material)
{
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)
return "This claim is currently involved in a transaction, you can't build on it!";
@ -38,7 +38,7 @@ public class GP_RealEstateHook implements IRealEstate
public String allowAccess(Claim claim, Player player)
{
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)
return "This claim is currently involved in a transaction, you can't access it!";
@ -50,7 +50,7 @@ public class GP_RealEstateHook implements IRealEstate
public String allowContainers(Claim claim, Player player)
{
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)
return "This claim is currently involved in a transaction, you can't access it's containers!";

View File

@ -87,7 +87,7 @@ public class RECommand extends BaseCommand
}
}
@Subcommand("seller")
/*@Subcommand("seller")
@Description("Displays or changes the seller of a claim (admin only)")
@Conditions("inPendingTransactionClaim")
public static void setSeller(Player player, @Optional String newSeller)
@ -112,6 +112,7 @@ public class RECommand extends BaseCommand
{
tr.setOwner(null);
tr.update();
RealEstate.transactionsStore.saveData();
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to the server");
}
else
@ -130,11 +131,12 @@ public class RECommand extends BaseCommand
{
tr.setOwner(newOwner.getUniqueId());
tr.update();
RealEstate.transactionsStore.saveData();
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Changed the seller to " +
ChatColor.GREEN + newOwner.getDisplayName());
}
}
}
}*/
@Subcommand("exitoffer")
@Conditions("partOfBoughtTransaction")

View File

@ -115,12 +115,15 @@ public class REListener implements Listener
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!");
event.setCancelled(true);
event.getBlock().breakNaturally();
return;
if(!RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to sell admin claims!");
event.setCancelled(true);
event.getBlock().breakNaturally();
return;
}
}
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
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
{
@ -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!");
event.setCancelled(true);
event.getBlock().breakNaturally();
return;
if(!RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to rent admin claims!");
event.setCancelled(true);
event.getBlock().breakNaturally();
return;
}
}
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;
}
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!");
event.setCancelled(true);
event.getBlock().breakNaturally();
return;
if(!RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to lease admin claims!");
event.setCancelled(true);
event.getBlock().breakNaturally();
return;
}
}
else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// only the owner may sell his claim
{

View File

@ -105,7 +105,7 @@ public class ClaimLease extends BoughtTransaction
if(buyer == null) return;
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";
@ -133,25 +133,28 @@ public class ClaimLease extends BoughtTransaction
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() +
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
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");
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
{
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
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(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
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(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
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
{

View File

@ -142,7 +142,7 @@ public class ClaimRent extends BoughtTransaction
if(buyer == null) return;
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";
@ -166,24 +166,26 @@ public class ClaimRent extends BoughtTransaction
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() +
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
{
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
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(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
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(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
" has paid rent for the " + claimType + " at " + ChatColor.BLUE + "[" +
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)

View File

@ -115,7 +115,7 @@ public class ClaimSell extends ClaimTransaction
"Z: " + player.getLocation().getBlockZ() + "] " +
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
if(RealEstate.instance.config.cfgMessageOwner)
if(RealEstate.instance.config.cfgMessageOwner && owner != null)
{
OfflinePlayer oldOwner = Bukkit.getOfflinePlayer(owner);
if(oldOwner.isOnline())

View File

@ -2,6 +2,10 @@ package me.EtienneDx.RealEstate.Transactions;
import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
@ -10,10 +14,12 @@ import java.util.HashMap;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.FileUtil;
import me.EtienneDx.RealEstate.RealEstate;
import me.ryanhamshire.GriefPrevention.Claim;
@ -59,25 +65,40 @@ public class TransactionsStore
claimRent = new HashMap<>();
claimLease = new HashMap<>();
FileConfiguration config = YamlConfiguration.loadConfiguration(new File(this.dataFilePath));
for(String key : config.getKeys(true))
File file = new File(this.dataFilePath);
FileConfiguration config = YamlConfiguration.loadConfiguration(file);
try {
RealEstate.instance.addLogEntry(new String(Files.readAllBytes(FileSystems.getDefault().getPath(this.dataFilePath))));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ConfigurationSection sell = config.getConfigurationSection("Sell");
ConfigurationSection rent = config.getConfigurationSection("Rent");
ConfigurationSection lease = config.getConfigurationSection("Lease");
if(sell != null)
{
if(key.startsWith("Sell."))
{
ClaimSell cs = (ClaimSell)config.get(key);
claimSell.put(key.substring(5), cs);
}
else if(key.startsWith("Rent."))
{
ClaimRent cr = (ClaimRent)config.get(key);
claimRent.put(key.substring(5), cr);
}
else if(key.startsWith("Lease."))
{
ClaimLease cl = (ClaimLease)config.get(key);
claimLease.put(key.substring(6), cl);
}
RealEstate.instance.addLogEntry(sell.toString());
RealEstate.instance.addLogEntry(sell.getKeys(false).size() + "");
for(String key : sell.getKeys(false))
{
ClaimSell cs = (ClaimSell)sell.get(key);
claimSell.put(key, cs);
}
}
if(rent != null)
for(String key : rent.getKeys(false))
{
ClaimRent cr = (ClaimRent)rent.get(key);
claimRent.put(key, cr);
}
if(lease != null)
for(String key : lease.getKeys(false))
{
ClaimLease cl = (ClaimLease)lease.get(key);
claimLease.put(key, cl);
}
}
public void saveData()
@ -160,12 +181,12 @@ public class TransactionsStore
cs.update();
saveData();
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() +
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for sale at " +
"[" + player.getLocation().getWorld() + ", " +
"X: " + player.getLocation().getBlockX() + ", " +
"Y: " + player.getLocation().getBlockY() + ", " +
"Z: " + player.getLocation().getBlockZ() + "] " +
"[" + claim.getGreaterBoundaryCorner().getWorld() + ", " +
"X: " + claim.getGreaterBoundaryCorner().getBlockX() + ", " +
"Y: " + claim.getGreaterBoundaryCorner().getBlockY() + ", " +
"Z: " + claim.getGreaterBoundaryCorner().getBlockZ() + "] " +
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
if(player != null)
@ -180,7 +201,7 @@ public class TransactionsStore
{
if(p != player)
{
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
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 sale for " +
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
@ -196,12 +217,12 @@ public class TransactionsStore
cr.update();
saveData();
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() +
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent at " +
"[" + player.getLocation().getWorld() + ", " +
"X: " + player.getLocation().getBlockX() + ", " +
"Y: " + player.getLocation().getBlockY() + ", " +
"Z: " + player.getLocation().getBlockZ() + "] " +
"[" + claim.getLesserBoundaryCorner().getWorld() + ", " +
"X: " + claim.getLesserBoundaryCorner().getBlockX() + ", " +
"Y: " + claim.getLesserBoundaryCorner().getBlockY() + ", " +
"Z: " + claim.getLesserBoundaryCorner().getBlockZ() + "] " +
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
if(player != null)
@ -216,7 +237,7 @@ public class TransactionsStore
{
if(p != player)
{
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
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 rent for " +
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
@ -232,12 +253,12 @@ public class TransactionsStore
cl.update();
saveData();
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + player.getName() +
RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for lease at " +
"[" + player.getLocation().getWorld() + ", " +
"X: " + player.getLocation().getBlockX() + ", " +
"Y: " + player.getLocation().getBlockY() + ", " +
"Z: " + player.getLocation().getBlockZ() + "] " +
"[" + claim.getLesserBoundaryCorner().getWorld() + ", " +
"X: " + claim.getLesserBoundaryCorner().getBlockX() + ", " +
"Y: " + claim.getLesserBoundaryCorner().getBlockY() + ", " +
"Z: " + claim.getLesserBoundaryCorner().getBlockZ() + "] " +
"Payments Count : " + paymentsCount + " " +
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
@ -254,7 +275,7 @@ public class TransactionsStore
{
if(p != player)
{
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
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 " +

View File

@ -104,15 +104,18 @@ public class Utils
if(claim.parent == null && RealEstate.instance.config.cfgTransferClaimBlocks)
{
PlayerData buyerData = GriefPrevention.instance.dataStore.getPlayerData(buyer);
PlayerData sellerData = GriefPrevention.instance.dataStore.getPlayerData(seller);
if(seller != null)
{
PlayerData sellerData = GriefPrevention.instance.dataStore.getPlayerData(seller);
// the seller has to provide the blocks
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
{
sellerData.setAccruedClaimBlocks(sellerData.getAccruedClaimBlocks() + sellerData.getBonusClaimBlocks());
sellerData.setBonusClaimBlocks(0);
}
// the seller has to provide the blocks
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
{
sellerData.setAccruedClaimBlocks(sellerData.getAccruedClaimBlocks() + sellerData.getBonusClaimBlocks());
sellerData.setBonusClaimBlocks(0);
}
}
// the buyer receive them
buyerData.setBonusClaimBlocks(buyerData.getBonusClaimBlocks() + claim.getArea());