Changed to automatically sell/rent/lease as 'SERVER' for admin claims
This commit is contained in:
parent
2cff090309
commit
8c18e01cb4
@ -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!";
|
||||
|
||||
@ -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")
|
||||
|
||||
@ -115,13 +115,16 @@ public class REListener implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
|
||||
if(claim.isAdminClaim())
|
||||
{
|
||||
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
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You can only sell claims you own!");
|
||||
@ -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,13 +219,16 @@ public class REListener implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may rent admin claims
|
||||
if(claim.isAdminClaim())
|
||||
{
|
||||
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
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You can only rent claims you own!");
|
||||
@ -307,13 +313,16 @@ public class REListener implements Listener
|
||||
return;
|
||||
}
|
||||
|
||||
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may rent admin claims
|
||||
if(claim.isAdminClaim())
|
||||
{
|
||||
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
|
||||
{
|
||||
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You can only lease claims you own!");
|
||||
|
||||
@ -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,6 +133,8 @@ public class ClaimLease extends BoughtTransaction
|
||||
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||
}
|
||||
|
||||
if(owner != null)
|
||||
{
|
||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
|
||||
@ -153,6 +155,7 @@ public class ClaimLease extends BoughtTransaction
|
||||
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
|
||||
|
||||
@ -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,6 +166,8 @@ public class ClaimRent extends BoughtTransaction
|
||||
ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
}
|
||||
|
||||
if(seller != null)
|
||||
{
|
||||
if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
|
||||
{
|
||||
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
|
||||
@ -183,7 +185,7 @@ public class ClaimRent extends BoughtTransaction
|
||||
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
|
||||
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if (autoRenew)
|
||||
|
||||
@ -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())
|
||||
|
||||
@ -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))
|
||||
{
|
||||
if(key.startsWith("Sell."))
|
||||
{
|
||||
ClaimSell cs = (ClaimSell)config.get(key);
|
||||
claimSell.put(key.substring(5), cs);
|
||||
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();
|
||||
}
|
||||
else if(key.startsWith("Rent."))
|
||||
ConfigurationSection sell = config.getConfigurationSection("Sell");
|
||||
ConfigurationSection rent = config.getConfigurationSection("Rent");
|
||||
ConfigurationSection lease = config.getConfigurationSection("Lease");
|
||||
if(sell != null)
|
||||
{
|
||||
ClaimRent cr = (ClaimRent)config.get(key);
|
||||
claimRent.put(key.substring(5), cr);
|
||||
}
|
||||
else if(key.startsWith("Lease."))
|
||||
RealEstate.instance.addLogEntry(sell.toString());
|
||||
RealEstate.instance.addLogEntry(sell.getKeys(false).size() + "");
|
||||
for(String key : sell.getKeys(false))
|
||||
{
|
||||
ClaimLease cl = (ClaimLease)config.get(key);
|
||||
claimLease.put(key.substring(6), cl);
|
||||
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 " +
|
||||
|
||||
@ -104,6 +104,8 @@ public class Utils
|
||||
if(claim.parent == null && RealEstate.instance.config.cfgTransferClaimBlocks)
|
||||
{
|
||||
PlayerData buyerData = GriefPrevention.instance.dataStore.getPlayerData(buyer);
|
||||
if(seller != null)
|
||||
{
|
||||
PlayerData sellerData = GriefPrevention.instance.dataStore.getPlayerData(seller);
|
||||
|
||||
// the seller has to provide the blocks
|
||||
@ -113,6 +115,7 @@ public class Utils
|
||||
sellerData.setAccruedClaimBlocks(sellerData.getAccruedClaimBlocks() + sellerData.getBonusClaimBlocks());
|
||||
sellerData.setBonusClaimBlocks(0);
|
||||
}
|
||||
}
|
||||
|
||||
// the buyer receive them
|
||||
buyerData.setBonusClaimBlocks(buyerData.getBonusClaimBlocks() + claim.getArea());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user