diff --git a/.gitignore b/.gitignore
index a98b458..79177a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.classpath
.project
.settings/*
-bin/*
\ No newline at end of file
+bin/*
+target/*
\ No newline at end of file
diff --git a/plugin.yml b/plugin.yml
index 0573c89..f504e27 100644
--- a/plugin.yml
+++ b/plugin.yml
@@ -1,6 +1,6 @@
name: RealEstate
main: me.EtienneDx.RealEstate.RealEstate
-version: beta0.1
+version: ${project.version}
authors: [EtienneDx]
depend: [GriefPrevention, Vault]
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..2b4904e
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,69 @@
+
+ 4.0.0
+ Me.EtienneDx
+ RealEstate
+ 0.0.1-SNAPSHOT
+ RealEstate
+ A spigot plugin for selling, renting and leasing GriefPrevention claims
+
+ src
+
+
+ .
+ true
+ .
+
+ plugin.yml
+
+
+
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ 1.8
+
+
+
+
+
+
+ spigot-repo
+ https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+
+
+ bungeecord-repo
+ https://()oss.sonatype.org/content/repositories/snapshots
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+ vault-repo
+ http://nexus.hc.to/content/repositories/pub_releases
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.13.2-R0.1-SNAPSHOT
+ provided
+
+
+ net.milkbowl.vault
+ VaultAPI
+ 1.7
+
+
+ com.github.TechFortress
+ GriefPrevention
+ 16.11.6
+
+
+
\ No newline at end of file
diff --git a/src/me/EtienneDx/RealEstate/DataStore.java b/src/me/EtienneDx/RealEstate/Config.java
similarity index 96%
rename from src/me/EtienneDx/RealEstate/DataStore.java
rename to src/me/EtienneDx/RealEstate/Config.java
index a2f8184..148edf9 100644
--- a/src/me/EtienneDx/RealEstate/DataStore.java
+++ b/src/me/EtienneDx/RealEstate/Config.java
@@ -10,7 +10,7 @@
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.PluginDescriptionFile;
-public class DataStore
+public class Config
{
public PluginDescriptionFile pdf;
@@ -34,6 +34,7 @@ public class DataStore
public boolean cfgEnableLease;
public boolean cfgEnableAutoRenew;
+ public boolean cfgEnableRentPeriod;
public boolean cfgTransferClaimBlocks;
@@ -50,7 +51,7 @@ public class DataStore
public int cfgLeasePayments;
- public DataStore()
+ public Config()
{
this.pdf = RealEstate.instance.getDescription();
}
@@ -91,6 +92,7 @@ public void loadConfig(YamlConfiguration config)
this.cfgEnableLease = config.getBoolean("RealEstate.Rules.Lease", true);
this.cfgEnableAutoRenew = config.getBoolean("RealEstate.Rules.AutomaticRenew", true);
+ this.cfgEnableRentPeriod = config.getBoolean("RealEstate.Rules.RentPeriods", true);
this.cfgTransferClaimBlocks = config.getBoolean("RealEstate.Rules.TransferClaimBlocks", true);
@@ -133,6 +135,7 @@ public void saveConfig()
outConfig.set("RealEstate.Rules.Lease", this.cfgEnableLease);
outConfig.set("RealEstate.Rules.AutomaticRenew", this.cfgEnableAutoRenew);
+ outConfig.set("RealEstate.Rules.RentPeriods", this.cfgEnableRentPeriod);
outConfig.set("RealEstate.Rules.TransferClaimBlocks", this.cfgTransferClaimBlocks);
diff --git a/src/me/EtienneDx/RealEstate/REListener.java b/src/me/EtienneDx/RealEstate/REListener.java
index 26fcb2d..be04a7a 100644
--- a/src/me/EtienneDx/RealEstate/REListener.java
+++ b/src/me/EtienneDx/RealEstate/REListener.java
@@ -1,12 +1,14 @@
package me.EtienneDx.RealEstate;
import java.util.Arrays;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
+import org.bukkit.OfflinePlayer;
import org.bukkit.block.Sign;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -21,6 +23,10 @@
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.plugin.PluginManager;
+import me.EtienneDx.RealEstate.Transactions.BoughtTransaction;
+import me.EtienneDx.RealEstate.Transactions.ClaimRent;
+import me.EtienneDx.RealEstate.Transactions.ExitOffer;
+import me.EtienneDx.RealEstate.Transactions.Transaction;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
@@ -29,230 +35,258 @@ public class REListener implements Listener, CommandExecutor
void registerEvents()
{
PluginManager pm = RealEstate.instance.getServer().getPluginManager();
-
+
pm.registerEvents(this, RealEstate.instance);
RealEstate.instance.getCommand("re").setExecutor(this);
}
-
+
@EventHandler
public void onSignChange(SignChangeEvent event)
{
- if(RealEstate.instance.dataStore.cfgSellKeywords.contains(event.getLine(0).toLowerCase()) ||
- RealEstate.instance.dataStore.cfgLeaseKeywords.contains(event.getLine(0).toLowerCase()) ||
- RealEstate.instance.dataStore.cfgRentKeywords.contains(event.getLine(0).toLowerCase()))
+ if(RealEstate.instance.config.cfgSellKeywords.contains(event.getLine(0).toLowerCase()) ||
+ RealEstate.instance.config.cfgLeaseKeywords.contains(event.getLine(0).toLowerCase()) ||
+ RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()))
{
Player player = event.getPlayer();
Location loc = event.getBlock().getLocation();
-
+
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null);
if(claim == null)// must have something to sell
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The sign you placed is not inside a claim!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The sign you placed is not inside a claim!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
if(RealEstate.transactionsStore.anyTransaction(claim))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim already has an ongoing transaction!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim already has an ongoing transaction!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
if(RealEstate.transactionsStore.anyTransaction(claim.parent))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The parent claim already has an ongoing transaction!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The parent claim already has an ongoing transaction!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
for(Claim c : claim.children)
{
if(RealEstate.transactionsStore.anyTransaction(c))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
- "A subclaim of this claim already has an ongoing transaction!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
+ "A subclaim of this claim already has an ongoing transaction!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
}
-
+
// empty is considered a wish to sell
- if(RealEstate.instance.dataStore.cfgSellKeywords.contains(event.getLine(0).toLowerCase()))
+ if(RealEstate.instance.config.cfgSellKeywords.contains(event.getLine(0).toLowerCase()))
{
- if(!RealEstate.instance.dataStore.cfgEnableSell)
+ if(!RealEstate.instance.config.cfgEnableSell)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Selling is disabled!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Selling is disabled!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
String type = claim.parent == null ? "claim" : "subclaim";
if(!RealEstate.perms.has(player, "realestate." + type + ".sell"))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to sell " + type + "s!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to sell " + type + "s!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
// check for a valid price
double price;
try
{
- price = getDouble(event, 1, RealEstate.instance.dataStore.cfgPriceSellPerBlock * claim.getArea());
+ price = getDouble(event, 1, RealEstate.instance.config.cfgPriceSellPerBlock * claim.getArea());
}
catch (NumberFormatException e)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The price you entered is not a valid number!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The price you entered is not a valid number!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
if(price <= 0)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The price must be greater than 0!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The price must be greater than 0!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may sell admin claims
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to sell admin claims!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ 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.dataStore.chatPrefix + ChatColor.RED + "You can only sell claims you own!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You can only sell claims you own!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
// 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());
}
- else if(RealEstate.instance.dataStore.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
{
- if(!RealEstate.instance.dataStore.cfgEnableRent)
+ if(!RealEstate.instance.config.cfgEnableRent)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Renting is disabled!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Renting is disabled!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
String type = claim.parent == null ? "claim" : "subclaim";
if(!RealEstate.perms.has(player, "realestate." + type + ".rent"))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to rent " + type + "s!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to rent " + type + "s!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
// check for a valid price
double price;
try
{
- price = getDouble(event, 1, RealEstate.instance.dataStore.cfgPriceRentPerBlock * claim.getArea());
+ price = getDouble(event, 1, RealEstate.instance.config.cfgPriceRentPerBlock * claim.getArea());
}
catch (NumberFormatException e)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The price you entered is not a valid number!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The price you entered is not a valid number!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
if(price <= 0)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The price must be greater than 0!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The price must be greater than 0!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
if(event.getLine(2).isEmpty())
{
- event.setLine(2, RealEstate.instance.dataStore.cfgRentTime);
+ event.setLine(2, RealEstate.instance.config.cfgRentTime);
}
int duration = parseDuration(event.getLine(2));
if(duration == 0)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Couldn't read the date!\n" +
- "Date must be formatted as follow" + ChatColor.GREEN + "10 weeks" + ChatColor.RED + " or " +
- ChatColor.GREEN + "3 days" + ChatColor.RED + " or " + ChatColor.GREEN + "1 week 3 days");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Couldn't read the date!\n" +
+ "Date must be formatted as follow" + ChatColor.GREEN + "10 weeks" + ChatColor.RED + " or " +
+ ChatColor.GREEN + "3 days" + ChatColor.RED + " or " + ChatColor.GREEN + "1 week 3 days");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
+ }
+ int rentPeriods = 1;
+ if(RealEstate.instance.config.cfgEnableRentPeriod)
+ {
+ if(event.getLine(3).isEmpty())
+ {
+ event.setLine(3, "1");
+ }
+ try
+ {
+ rentPeriods = Integer.parseInt(event.getLine(3));
+ }
+ catch (NumberFormatException e)
+ {
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
+ "The number of rent periods you entered is not a valid number!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
+ }
+ if(rentPeriods <= 0)
+ {
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
+ "The number of rent periods must be greater than 0!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
+ }
}
-
+
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may rent admin claims
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to rent admin claims!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ 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.dataStore.chatPrefix + ChatColor.RED + "You can only rent claims you own!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You can only rent claims you own!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
// all should be good, we can create the rent
event.setCancelled(true);
- RealEstate.transactionsStore.rent(claim, player, price, event.getBlock().getLocation(), duration);
+ RealEstate.transactionsStore.rent(claim, player, price, event.getBlock().getLocation(), duration, rentPeriods);
}
- else if(RealEstate.instance.dataStore.cfgLeaseKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
+ else if(RealEstate.instance.config.cfgLeaseKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
{
- if(!RealEstate.instance.dataStore.cfgEnableLease)
+ if(!RealEstate.instance.config.cfgEnableLease)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Leasing is disabled!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Leasing is disabled!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
String type = claim.parent == null ? "claim" : "subclaim";
if(!RealEstate.perms.has(player, "realestate." + type + ".lease"))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to lease " + type + "s!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to lease " + type + "s!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
// check for a valid price
double price;
try
{
- price = getDouble(event, 1, RealEstate.instance.dataStore.cfgPriceLeasePerBlock * claim.getArea());
+ price = getDouble(event, 1, RealEstate.instance.config.cfgPriceLeasePerBlock * claim.getArea());
}
catch (NumberFormatException e)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The price you entered is not a valid number!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The price you entered is not a valid number!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
if(price <= 0)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "The price must be greater than 0!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "The price must be greater than 0!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
if(event.getLine(2).isEmpty())
{
- event.setLine(2, "" + RealEstate.instance.dataStore.cfgLeasePayments);
+ event.setLine(2, "" + RealEstate.instance.config.cfgLeasePayments);
}
int paymentsCount;
try
@@ -261,50 +295,50 @@ else if(RealEstate.instance.dataStore.cfgLeaseKeywords.contains(event.getLine(0)
}
catch(Exception e)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
- "The number of payments you enterred is not a valid number!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
+ "The number of payments you enterred is not a valid number!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
if(event.getLine(3).isEmpty())
{
- event.setLine(3, RealEstate.instance.dataStore.cfgLeaseTime);
+ event.setLine(3, RealEstate.instance.config.cfgLeaseTime);
}
int frequency = parseDuration(event.getLine(3));
if(frequency == 0)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Couldn't read the date!\n" +
- "Date must be formatted as follow" + ChatColor.GREEN + "10 weeks" + ChatColor.RED + " or " +
- ChatColor.GREEN + "3 days" + ChatColor.RED + " or " + ChatColor.GREEN + "1 week 3 days");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Couldn't read the date!\n" +
+ "Date must be formatted as follow" + ChatColor.GREEN + "10 weeks" + ChatColor.RED + " or " +
+ ChatColor.GREEN + "3 days" + ChatColor.RED + " or " + ChatColor.GREEN + "1 week 3 days");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
if(claim.isAdminClaim() && !RealEstate.perms.has(player, "realestate.admin"))// admin may rent admin claims
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to lease admin claims!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ 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.dataStore.chatPrefix + ChatColor.RED + "You can only lease claims you own!");
- event.setCancelled(true);
- event.getBlock().breakNaturally();
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You can only lease claims you own!");
+ event.setCancelled(true);
+ event.getBlock().breakNaturally();
+ return;
}
-
+
// all should be good, we can create the rent
event.setCancelled(true);
RealEstate.transactionsStore.lease(claim, player, price, event.getBlock().getLocation(), frequency, paymentsCount);
}
}
}
-
+
private int parseDuration(String line)
{
Pattern p = Pattern.compile("^(?:(?\\d{1,2}) ?w(?:eeks?)?)? ?(?:(?\\d{1,2}) ?d(?:ays?)?)?$", Pattern.CASE_INSENSITIVE);
@@ -329,7 +363,7 @@ private double getDouble(SignChangeEvent event, int line, double defaultValue) t
}
return Double.parseDouble(event.getLine(line));
}
-
+
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
@@ -338,20 +372,20 @@ public void onPlayerInteract(PlayerInteractEvent event)
{
Sign sign = (Sign)event.getClickedBlock().getState();
// it is a real estate sign
- if(ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(ChatColor.stripColor(RealEstate.instance.dataStore.cfgSignsHeader)))
+ if(ChatColor.stripColor(sign.getLine(0)).equalsIgnoreCase(ChatColor.stripColor(RealEstate.instance.config.cfgSignsHeader)))
{
Player player = event.getPlayer();
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(event.getClickedBlock().getLocation(), false, null);
-
+
if(!RealEstate.transactionsStore.anyTransaction(claim))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
- "This claim is no longer for rent or for sell, sorry...");
- event.getClickedBlock().breakNaturally();
- event.setCancelled(true);
- return;
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
+ "This claim is no longer for rent or for sell, sorry...");
+ event.getClickedBlock().breakNaturally();
+ event.setCancelled(true);
+ return;
}
-
+
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
if(player.isSneaking())
tr.preview(player);
@@ -360,7 +394,7 @@ public void onPlayerInteract(PlayerInteractEvent event)
}
}
}
-
+
@EventHandler
public void onBreakBlock(BlockBreakEvent event)
{
@@ -375,7 +409,7 @@ public void onBreakBlock(BlockBreakEvent event)
if(event.getPlayer() != null && !tr.getOwner().equals(event.getPlayer().getUniqueId()) &&
!RealEstate.perms.has(event.getPlayer(), "realestate.destroysigns"))
{
- event.getPlayer().sendMessage(RealEstate.instance.dataStore.chatPrefix +
+ event.getPlayer().sendMessage(RealEstate.instance.config.chatPrefix +
ChatColor.RED + "Only the author of the sell/rent sign is allowed to destroy it");
event.setCancelled(true);
return;
@@ -389,7 +423,7 @@ public void onBreakBlock(BlockBreakEvent event)
}
}
}
-
+
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
@@ -408,61 +442,61 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
else
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "No transaction found at your location!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "No transaction found at your location!");
}
}
else
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You do not have the permission to view claim infos!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to view claim infos!");
}
return true;
}
else if(args[0].equalsIgnoreCase("renewRent"))
{
- if(!RealEstate.instance.dataStore.cfgEnableAutoRenew)
+ if(!RealEstate.instance.config.cfgEnableAutoRenew)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Automatic renew is disabled!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Automatic renew is disabled!");
return true;
}
if(!(sender instanceof Player))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Only players can use this command!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Only players can use this command!");
return true;
}
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(((Player)sender).getLocation(), false, null);
if(claim == null)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are not standing inside of a claim!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are not standing inside of a claim!");
return true;
}
String claimType = claim.parent == null ? "claim" : "subclaim";
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
if(!(tr instanceof ClaimRent))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim is not for rent!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim is not for rent!");
return true;
}
ClaimRent cr = (ClaimRent)tr;
if(!((Player)sender).getUniqueId().equals(cr.buyer) && !((Player)sender).getUniqueId().equals(cr.owner))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"You are not the person renting this " + claimType + "!");
return true;
}
if(args.length == 1 || ((Player)sender).getUniqueId().equals(cr.owner))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "Automatic renew is currently " +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is currently " +
ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!");
return true;
}
else if(args.length > 2 || (!args[1].equalsIgnoreCase("enable") && !args[1].equalsIgnoreCase("disable")))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Usage : /" + label + " renewrent [enable|disable]!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Usage : /" + label + " renewrent [enable|disable]!");
return true;
}
cr.autoRenew = args[1].equalsIgnoreCase("enable");
RealEstate.transactionsStore.saveData();
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "Automatic renew is now " +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "Automatic renew is now " +
ChatColor.GREEN + (cr.autoRenew ? "enabled" : "disabled") + ChatColor.AQUA + " for this " + claimType + "!");
return true;
}
@@ -470,26 +504,26 @@ else if(args[0].equalsIgnoreCase("exitoffer"))
{
if(!(sender instanceof Player))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Only players can use this command!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Only players can use this command!");
return true;
}
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(((Player)sender).getLocation(), false, null);
if(claim == null)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are not standing inside of a claim!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are not standing inside of a claim!");
return true;
}
String claimType = claim.parent == null ? "claim" : "subclaim";
Transaction tr = RealEstate.transactionsStore.getTransaction(claim);
if(!(tr instanceof BoughtTransaction))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim is not for rent or lease!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim is not for rent or lease!");
return true;
}
BoughtTransaction bt = (BoughtTransaction)tr;
if(!((Player)sender).getUniqueId().equals(bt.getBuyer()) && !((Player)sender).getUniqueId().equals(tr.getOwner()))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"You are not the person renting or leasing this " + claimType + "!");
return true;
}
@@ -497,11 +531,11 @@ else if(args[0].equalsIgnoreCase("exitoffer"))
{
if(bt.exitOffer == null)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "There is currently no exit offer for this claim!");
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "There is currently no exit offer for this claim!");
}
else if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId()))
{
- String msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You offered to exit the contract for " +
+ String msg = RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You offered to exit the contract for " +
ChatColor.GREEN + bt.exitOffer.price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA +
", but your offer hasn't been accepted or denied yet...\n";
msg += ChatColor.AQUA + "To cancel your offer, just type " + ChatColor.LIGHT_PURPLE + "/" + label + " exitoffer cancel";
@@ -509,7 +543,7 @@ else if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId()))
}
else// it is the other person
{
- String msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + Bukkit.getOfflinePlayer(bt.exitOffer.offerBy).getName() +
+ String msg = RealEstate.instance.config.chatPrefix + ChatColor.GREEN + Bukkit.getOfflinePlayer(bt.exitOffer.offerBy).getName() +
ChatColor.AQUA + " offered to exit the contract for " +
ChatColor.GREEN + bt.exitOffer.price + " " + RealEstate.econ.currencyNamePlural() + "\n";
msg += ChatColor.AQUA + "To accept the offer, just type " + ChatColor.LIGHT_PURPLE + "/" + label + " exitoffer accept\n";
@@ -520,7 +554,7 @@ else if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId()))
}
else if(!Arrays.asList("cancel", "accept", "refuse", "create").contains(args[1].toLowerCase()))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Usage : /" + label +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Usage : /" + label +
" exitoffer [cancel|accept|refuse|info|create]");
return true;
}
@@ -528,14 +562,14 @@ else if(!Arrays.asList("cancel", "accept", "refuse", "create").contains(args[1].
{
if(bt.exitOffer != null)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"There is already an exit proposition for this transaction!");
return true;
}
if(args.length != 3)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Usage : /" + label + " exitoffer create ");
return true;
}
@@ -546,26 +580,36 @@ else if(!Arrays.asList("cancel", "accept", "refuse", "create").contains(args[1].
}
catch(Exception e)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"The price isn't a valid number!");
return true;
}
if(price < 0)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"The price must be a positive number!");
return true;
}
bt.exitOffer = new ExitOffer(((Player)sender).getUniqueId(), price);
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
"The proposition has been successfully created!");
+ UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner;
+ OfflinePlayer otherP = Bukkit.getOfflinePlayer(other);
+ if(otherP.isOnline())
+ {
+ Location loc = ((Player)sender).getLocation();
+ ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() +
+ ChatColor.AQUA + " as created an offer to exit the rent/lease contract for the " + claimType + " at " +
+ ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: "
+ + loc.getBlockZ() + "]" + ChatColor.AQUA + " for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
+ }
}
else
{
if(bt.exitOffer == null)
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"There has been no exit propositions for this transaction!");
return true;
}
@@ -574,12 +618,22 @@ else if(!Arrays.asList("cancel", "accept", "refuse", "create").contains(args[1].
if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId()))
{
bt.exitOffer = null;
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
"This exit offer has been cancelled");
+ UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner;
+ OfflinePlayer otherP = Bukkit.getOfflinePlayer(other);
+ if(otherP.isOnline())
+ {
+ Location loc = ((Player)sender).getLocation();
+ ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() +
+ ChatColor.AQUA + " as cancelled his offer to exit the rent/lease contract for the " + claimType + " at " +
+ ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: "
+ + loc.getBlockZ() + "]");
+ }
}
else
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Only the player who created this exit proposition may cancel it");
}
}
@@ -587,7 +641,7 @@ else if(args[1].equalsIgnoreCase("accept") || args[1].equalsIgnoreCase("refuse")
{
if(bt.exitOffer.offerBy.equals(((Player)sender).getUniqueId()))
{
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"You can't accept or refuse an offer you made!");
}
else
@@ -595,8 +649,18 @@ else if(args[1].equalsIgnoreCase("accept") || args[1].equalsIgnoreCase("refuse")
if(args[1].equalsIgnoreCase("refuse"))// easy part
{
bt.exitOffer = null;
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
"This exit offer has been refused");
+ UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner;
+ OfflinePlayer otherP = Bukkit.getOfflinePlayer(other);
+ if(otherP.isOnline())
+ {
+ Location loc = ((Player)sender).getLocation();
+ ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() +
+ ChatColor.AQUA + " as refused your offer to exit the rent/lease contract for the " + claimType + " at " +
+ ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() +
+ ", Z: " + loc.getBlockZ() + "]");
+ }
}
else if(Utils.makePayment(((Player)sender).getUniqueId(), bt.exitOffer.offerBy, bt.exitOffer.price, true, false))
{
@@ -604,14 +668,24 @@ else if(Utils.makePayment(((Player)sender).getUniqueId(), bt.exitOffer.offerBy,
claim.dropPermission(bt.buyer.toString());
bt.buyer = null;
bt.update();// eventual cancel is contained in here
- sender.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA +
+ sender.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
"This exit offer has been accepted, the " + claimType + " is no longer rented or leased!");
+ UUID other = bt.exitOffer.offerBy == bt.owner ? bt.buyer : bt.owner;
+ OfflinePlayer otherP = Bukkit.getOfflinePlayer(other);
+ if(otherP.isOnline())
+ {
+ Location loc = ((Player)sender).getLocation();
+ ((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + ((Player)sender).getName() +
+ ChatColor.AQUA + " as accepted your offer to exit the rent/lease contract for the " + claimType + " at " +
+ ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() +
+ ", Z: " + loc.getBlockZ() + "]. It is no longer rented or leased.");
+ }
}
// in case of payment failure, a msg has been sent by the utils function
}
}
}
-
+
RealEstate.transactionsStore.saveData();
return true;
}
@@ -622,10 +696,10 @@ else if(Utils.makePayment(((Player)sender).getUniqueId(), bt.exitOffer.offerBy,
msg += ChatColor.AQUA + "/" + label + ChatColor.LIGHT_PURPLE + " info" + ChatColor.AQUA +
" : Gets the informations about the transactions going on in the claim you're standing in.\n";
- if(sender.hasPermission("realestate.autorenew") && RealEstate.instance.dataStore.cfgEnableAutoRenew)
+ if(sender.hasPermission("realestate.autorenew") && RealEstate.instance.config.cfgEnableAutoRenew)
msg += ChatColor.AQUA + "/" + label + ChatColor.LIGHT_PURPLE + " renewRent" + ChatColor.AQUA +
- " : Allow you to enable or disable the automatic renewal of rents\n";
-
+ " : Allow you to enable or disable the automatic renewal of rents\n";
+
sender.sendMessage(msg);
return true;
}
diff --git a/src/me/EtienneDx/RealEstate/RealEstate.java b/src/me/EtienneDx/RealEstate/RealEstate.java
index 6e12493..30f4be6 100644
--- a/src/me/EtienneDx/RealEstate/RealEstate.java
+++ b/src/me/EtienneDx/RealEstate/RealEstate.java
@@ -10,13 +10,18 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
+import me.EtienneDx.RealEstate.Transactions.ClaimLease;
+import me.EtienneDx.RealEstate.Transactions.ClaimRent;
+import me.EtienneDx.RealEstate.Transactions.ClaimSell;
+import me.EtienneDx.RealEstate.Transactions.ExitOffer;
+import me.EtienneDx.RealEstate.Transactions.TransactionsStore;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;
public class RealEstate extends JavaPlugin
{
- Logger log;
- DataStore dataStore;
+ public Logger log;
+ public Config config;
public final static String pluginDirPath = "plugins" + File.separator + "RealEstate" + File.separator;
public static boolean vaultPresent = false;
public static Economy econ = null;
@@ -57,9 +62,9 @@ public void onEnable()
return;
}
}
- this.dataStore = new DataStore();
- this.dataStore.loadConfig();// loads config or default
- this.dataStore.saveConfig();// save eventual default
+ this.config = new Config();
+ this.config.loadConfig();// loads config or default
+ this.config.saveConfig();// save eventual default
ConfigurationSerialization.registerClass(ClaimSell.class);
ConfigurationSerialization.registerClass(ClaimRent.class);
@@ -75,7 +80,7 @@ public void addLogEntry(String entry)
{
try
{
- File logFile = new File(this.dataStore.logFilePath);
+ File logFile = new File(this.config.logFilePath);
if (!logFile.exists()) {
logFile.createNewFile();
}
diff --git a/src/me/EtienneDx/RealEstate/BoughtTransaction.java b/src/me/EtienneDx/RealEstate/Transactions/BoughtTransaction.java
similarity index 89%
rename from src/me/EtienneDx/RealEstate/BoughtTransaction.java
rename to src/me/EtienneDx/RealEstate/Transactions/BoughtTransaction.java
index 037864c..93e30eb 100644
--- a/src/me/EtienneDx/RealEstate/BoughtTransaction.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/BoughtTransaction.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.util.Map;
import java.util.UUID;
@@ -10,8 +10,8 @@
public abstract class BoughtTransaction extends ClaimTransaction
{
- UUID buyer = null;
- ExitOffer exitOffer = null;
+ public UUID buyer = null;
+ public ExitOffer exitOffer = null;
public BoughtTransaction(Map map)
{
diff --git a/src/me/EtienneDx/RealEstate/ClaimLease.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java
similarity index 80%
rename from src/me/EtienneDx/RealEstate/ClaimLease.java
rename to src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java
index b999395..9a7332e 100644
--- a/src/me/EtienneDx/RealEstate/ClaimLease.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.time.Duration;
import java.time.LocalDate;
@@ -13,6 +13,8 @@
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
+import me.EtienneDx.RealEstate.RealEstate;
+import me.EtienneDx.RealEstate.Utils;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.ClaimPermission;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
@@ -20,9 +22,9 @@
public class ClaimLease extends BoughtTransaction
{
- LocalDateTime lastPayment = null;
- int frequency;
- int paymentsLeft;
+ public LocalDateTime lastPayment = null;
+ public int frequency;
+ public int paymentsLeft;
public ClaimLease(Map map)
{
@@ -60,8 +62,8 @@ public void update()
if(sign.getBlock().getState() instanceof Sign)
{
Sign s = (Sign)sign.getBlock().getState();
- s.setLine(0, RealEstate.instance.dataStore.cfgSignsHeader);
- s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.dataStore.cfgReplaceLease);
+ s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
+ s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceLease);
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
s.setLine(2, paymentsLeft + "x " + price + " " + RealEstate.econ.currencyNamePlural());
s.setLine(3, Utils.getTime(frequency, null, false));
@@ -103,18 +105,18 @@ private void payLease()
paymentsLeft--;
if(paymentsLeft > 0)
{
- if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer)
+ if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
- ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.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() +
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
- if(seller.isOnline() && RealEstate.instance.dataStore.cfgMessageOwner)
+ if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
{
- ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
+ ((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() + "]" +
@@ -124,18 +126,18 @@ private void payLease()
}
else
{
- if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer)
+ if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
- ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA +
+ ((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA +
"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() +
ChatColor.AQUA + ", the " + claimType + " is now yours");
}
- if(seller.isOnline() && RealEstate.instance.dataStore.cfgMessageOwner)
+ if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
{
- ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
+ ((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() + "]" +
@@ -150,16 +152,16 @@ private void payLease()
}
else
{
- if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer)
+ if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
- ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Couldn't pay the lease for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
}
- if(seller.isOnline() && RealEstate.instance.dataStore.cfgMessageOwner)
+ if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
{
- ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
+ ((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
@@ -178,7 +180,7 @@ public boolean tryCancelTransaction(Player p)
{
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
if(p != null)
- p.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
+ p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
" is currently rented, you can't cancel the transaction!");
return false;
}
@@ -195,7 +197,7 @@ public void interact(Player player)
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
if(claim == null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim does not exist!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
RealEstate.transactionsStore.cancelTransaction(claim);
return;
}
@@ -203,31 +205,31 @@ public void interact(Player player)
if (owner.equals(player.getUniqueId()))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
return;
}
if(claim.parent == null && !owner.equals(claim.ownerID))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
" does not have the right to put this " + claimType + " for lease!");
RealEstate.transactionsStore.cancelTransaction(claim);
return;
}
if(!player.hasPermission("realestate." + claimType + ".lease"))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You do not have the permission to lease " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to lease " +
claimType + "s!");
return;
}
if(player.getUniqueId().equals(buyer))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are already leasing this " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are already leasing this " +
claimType + "!");
return;
}
if(buyer != null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Someone already leases this " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Someone already leases this " +
claimType + "!");
return;
}
@@ -252,9 +254,9 @@ public void interact(Player player)
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
- if(RealEstate.instance.dataStore.cfgMessageOwner && seller.isOnline())
+ if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
{
- ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
+ ((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
" has just paid for your lease for the " + claimType + " at " +
"[" + sign.getWorld().getName() + ", " +
"X: " + sign.getBlockX() + ", " +
@@ -264,7 +266,7 @@ public void interact(Player player)
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully paid lease for this " + claimType +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully paid lease for this " + claimType +
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
@@ -326,7 +328,7 @@ public void preview(Player player)
}
else
{
- msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
+ msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
}
player.sendMessage(msg);
}
diff --git a/src/me/EtienneDx/RealEstate/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
similarity index 67%
rename from src/me/EtienneDx/RealEstate/ClaimRent.java
rename to src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
index 8d2dc50..7349c77 100644
--- a/src/me/EtienneDx/RealEstate/ClaimRent.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.time.Duration;
import java.time.LocalDate;
@@ -13,6 +13,8 @@
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
+import me.EtienneDx.RealEstate.RealEstate;
+import me.EtienneDx.RealEstate.Utils;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.ClaimPermission;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
@@ -22,7 +24,9 @@ public class ClaimRent extends BoughtTransaction
{
LocalDateTime startDate = null;
int duration;
- boolean autoRenew = false;
+ public boolean autoRenew = false;
+ public int periodCount = 0;
+ public int maxPeriod;
public ClaimRent(Map map)
{
@@ -31,12 +35,15 @@ public ClaimRent(Map map)
startDate = LocalDateTime.parse((String) map.get("startDate"), DateTimeFormatter.ISO_DATE_TIME);
duration = (int)map.get("duration");
autoRenew = (boolean) map.get("autoRenew");
+ periodCount = (int) map.get("periodCount");
+ maxPeriod = (int) map.get("maxPeriod");
}
- public ClaimRent(Claim claim, Player player, double price, Location sign, int duration)
+ public ClaimRent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
{
super(claim, player, price, sign);
this.duration = duration;
+ this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1;
}
@Override
@@ -47,6 +54,8 @@ public Map serialize() {
map.put("startDate", startDate.format(DateTimeFormatter.ISO_DATE_TIME));
map.put("duration", duration);
map.put("autoRenew", autoRenew);
+ map.put("periodCount", periodCount);
+ map.put("maxPeriod", maxPeriod);
return map;
}
@@ -54,64 +63,61 @@ public Map serialize() {
@Override
public void update()
{
- if(sign.getBlock().getState() instanceof Sign)
+ if(buyer == null)
{
- Sign s = (Sign) sign.getBlock().getState();
- if(buyer == null)
+ if(sign.getBlock().getState() instanceof Sign)
{
- s.setLine(0, RealEstate.instance.dataStore.cfgSignsHeader);
- s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.dataStore.cfgReplaceRent);
+ Sign s = (Sign) sign.getBlock().getState();
+ s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
+ s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceRent);
//s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
s.setLine(2, price + " " + RealEstate.econ.currencyNamePlural());
- s.setLine(3, Utils.getTime(duration, null, false));
+ s.setLine(3, (maxPeriod > 1 ? maxPeriod + "x " : "") + Utils.getTime(duration, null, false));
s.update(true);
}
- else
+ else// if no one is renting it, we can delete it (no sign indicating it's rentable)
{
- // we want to know how much time has gone by since startDate
- int days = Period.between(startDate.toLocalDate(), LocalDate.now()).getDays();
- Duration hours = Duration.between(startDate.toLocalTime(), LocalTime.now());
- if(hours.isNegative() && !hours.isZero())
- {
- hours = hours.plusHours(24);
- days--;
- }
- if(days >= duration)// we exceeded the time limit!
- {
- // both functions will call update again to update the sign
- if(autoRenew)
- payRent();
- else
- unRent(true);
- }
- else
- {
- s.setLine(0, RealEstate.instance.dataStore.cfgSignsHeader);
- s.setLine(1, ("Rented by " + Bukkit.getOfflinePlayer(buyer).getName()).substring(0, 16));
- s.setLine(2, "Time remaining : ");
-
- int daysLeft = duration - days - 1;// we need to remove the current day
- Duration timeRemaining = Duration.ofHours(24).minus(hours);
-
- s.setLine(3, Utils.getTime(daysLeft, timeRemaining, false));
- s.update(true);
- }
-
+ RealEstate.transactionsStore.cancelTransaction(this);
}
}
- else if(buyer == null)// if no one is renting it, we can delete it (no sign indicating it's rentable)
+ else
{
- RealEstate.transactionsStore.cancelTransaction(this);
+ // we want to know how much time has gone by since startDate
+ int days = Period.between(startDate.toLocalDate(), LocalDate.now()).getDays();
+ Duration hours = Duration.between(startDate.toLocalTime(), LocalTime.now());
+ if(hours.isNegative() && !hours.isZero())
+ {
+ hours = hours.plusHours(24);
+ days--;
+ }
+ if(days >= duration)// we exceeded the time limit!
+ {
+ payRent();
+ }
+ else if(sign.getBlock().getState() instanceof Sign)
+ {
+ Sign s = (Sign) sign.getBlock().getState();
+ s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
+ s.setLine(1, ("Rented by " + Bukkit.getOfflinePlayer(buyer).getName()).substring(0, 16));
+ s.setLine(2, "Time remaining : ");
+
+ int daysLeft = duration - days - 1;// we need to remove the current day
+ Duration timeRemaining = Duration.ofHours(24).minus(hours);
+
+ s.setLine(3, Utils.getTime(daysLeft, timeRemaining, false));
+ s.update(true);
+ }
}
+
}
private void unRent(boolean msgBuyer)
{
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
claim.dropPermission(buyer.toString());
- if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer)
+ if(msgBuyer && Bukkit.getOfflinePlayer(buyer).isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
- Bukkit.getPlayer(buyer).sendMessage(RealEstate.instance.dataStore.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 + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.AQUA + " is now over, your access has been revoked.");
@@ -130,36 +136,43 @@ private void payRent()
String claimType = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null).parent == null ? "claim" : "subclaim";
- if(Utils.makePayment(owner, this.buyer, price, false, false))
+ if((autoRenew || periodCount < maxPeriod) && Utils.makePayment(owner, this.buyer, price, false, false))
{
+ periodCount = (periodCount + 1) % maxPeriod;
startDate = LocalDateTime.now();
- if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer)
+ if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
- ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.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() +
", Y: " + sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + "for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
}
- if(seller.isOnline() && RealEstate.instance.dataStore.cfgMessageOwner)
+ if(seller.isOnline() && RealEstate.instance.config.cfgMessageOwner)
{
- ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + buyerPlayer.getName() +
+ ((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
+ else if (autoRenew)
{
- if(buyerPlayer.isOnline() && RealEstate.instance.dataStore.cfgMessageBuyer)
+ if(buyerPlayer.isOnline() && RealEstate.instance.config.cfgMessageBuyer)
{
- ((Player)buyerPlayer).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)buyerPlayer).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Couldn't pay the rent for the " + claimType + " at " + ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " +
sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", your access has been revoked.");
}
unRent(false);
+ return;
+ }
+ else
+ {
+ unRent(true);
+ return;
}
update();
RealEstate.transactionsStore.saveData();
@@ -172,7 +185,7 @@ public boolean tryCancelTransaction(Player p)
{
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);
if(p != null)
- p.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
+ p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This " + (claim.parent == null ? "claim" : "subclaim") +
" is currently rented, you can't cancel the transaction!");
return false;
}
@@ -189,7 +202,7 @@ public void interact(Player player)
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
if(claim == null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim does not exist!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
RealEstate.transactionsStore.cancelTransaction(claim);
return;
}
@@ -197,31 +210,31 @@ public void interact(Player player)
if (owner.equals(player.getUniqueId()))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
return;
}
if(claim.parent == null && !owner.equals(claim.ownerID))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
" does not have the right to rent this " + claimType + "!");
RealEstate.transactionsStore.cancelTransaction(claim);
return;
}
if(!player.hasPermission("realestate." + claimType + ".rent"))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You do not have the permission to rent " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to rent " +
claimType + "s!");
return;
}
if(player.getUniqueId().equals(buyer))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You are already renting this " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You are already renting this " +
claimType + "!");
return;
}
if(buyer != null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Someone already rents this " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Someone already rents this " +
claimType + "!");
return;
}
@@ -245,9 +258,9 @@ public void interact(Player player)
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
OfflinePlayer seller = Bukkit.getOfflinePlayer(owner);
- if(RealEstate.instance.dataStore.cfgMessageOwner && seller.isOnline())
+ if(RealEstate.instance.config.cfgMessageOwner && seller.isOnline())
{
- ((Player)seller).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
+ ((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
" has just rented your " + claimType + " at " +
"[" + sign.getWorld().getName() + ", " +
"X: " + sign.getBlockX() + ", " +
@@ -256,7 +269,7 @@ public void interact(Player player)
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
}
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully rented this " + claimType +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully rented this " + claimType +
" for " + ChatColor.GREEN + price + RealEstate.econ.currencyNamePlural());
}
}
@@ -303,7 +316,7 @@ public void preview(Player player)
ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " +
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for another " +
ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n";
- if((owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.dataStore.cfgEnableAutoRenew)
+ if((owner.equals(player.getUniqueId()) || buyer.equals(player.getUniqueId())) && RealEstate.instance.config.cfgEnableAutoRenew)
{
msg += ChatColor.AQUA + "Automatic renew is currently " + ChatColor.LIGHT_PURPLE + (autoRenew ? "enable" : "disable") + "\n";
}
@@ -319,7 +332,7 @@ public void preview(Player player)
}
else
{
- msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
+ msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
}
player.sendMessage(msg);
}
diff --git a/src/me/EtienneDx/RealEstate/ClaimSell.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java
similarity index 79%
rename from src/me/EtienneDx/RealEstate/ClaimSell.java
rename to src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java
index 0346788..a662923 100644
--- a/src/me/EtienneDx/RealEstate/ClaimSell.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimSell.java
@@ -1,7 +1,9 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import org.bukkit.entity.Player;
+import me.EtienneDx.RealEstate.RealEstate;
+import me.EtienneDx.RealEstate.Utils;
import me.ryanhamshire.GriefPrevention.Claim;
import me.ryanhamshire.GriefPrevention.GriefPrevention;
import net.md_5.bungee.api.ChatColor;
@@ -24,8 +26,8 @@ public void update()
if(sign.getBlock().getState() instanceof Sign)
{
Sign s = (Sign) sign.getBlock().getState();
- s.setLine(0, RealEstate.instance.dataStore.cfgSignsHeader);
- s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.dataStore.cfgReplaceSell);
+ s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
+ s.setLine(1, ChatColor.DARK_GREEN + RealEstate.instance.config.cfgReplaceSell);
s.setLine(2, owner != null ? Bukkit.getOfflinePlayer(owner).getName() : "SERVER");
s.setLine(3, price + " " + RealEstate.econ.currencyNamePlural());
s.update(true);
@@ -49,7 +51,7 @@ public void interact(Player player)
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);// getting by id creates errors for subclaims
if(claim == null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "This claim does not exist!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "This claim does not exist!");
RealEstate.transactionsStore.cancelTransaction(claim);
return;
}
@@ -57,27 +59,27 @@ public void interact(Player player)
if (owner.equals(player.getUniqueId()))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You already own this " + claimType + "!");
return;
}
if(claim.parent == null && !owner.equals(claim.ownerID))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + Bukkit.getPlayer(owner).getDisplayName() +
" does not have the right to sell this " + claimType + "!");
RealEstate.transactionsStore.cancelTransaction(claim);
return;
}
if(!player.hasPermission("realestate." + claimType + ".buy"))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You do not have the permission to purchase " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "You do not have the permission to purchase " +
claimType + "s!");
return;
}
// for real claims, you may need to have enough claim blocks in reserve to purchase it (if transferClaimBlocks is false)
- if(claimType.equalsIgnoreCase("claim") && !RealEstate.instance.dataStore.cfgTransferClaimBlocks &&
+ if(claimType.equalsIgnoreCase("claim") && !RealEstate.instance.config.cfgTransferClaimBlocks &&
GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).getRemainingClaimBlocks() < claim.getArea())
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"You don't have enough claim blocks to purchase this claim, you need to get " + ChatColor.DARK_GREEN +
(claim.getArea() - GriefPrevention.instance.dataStore.getPlayerData(player.getUniqueId()).getRemainingClaimBlocks()) +
ChatColor.RED + " more blocks!");
@@ -91,7 +93,7 @@ public void interact(Player player)
// normally, this is always the case, so it's not necessary, but until I proven my point, here
if(claim.parent != null || claim.ownerID.equals(player.getUniqueId()))
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully purchased this " + claimType +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully purchased this " + claimType +
" for " + ChatColor.GREEN + price + RealEstate.econ.currencyNamePlural());
RealEstate.instance.addLogEntry(
"[" + RealEstate.transactionsStore.dateFormat.format(RealEstate.transactionsStore.date) + "] " + player.getName() +
@@ -102,12 +104,12 @@ public void interact(Player player)
"Z: " + player.getLocation().getBlockZ() + "] " +
"Price: " + price + " " + RealEstate.econ.currencyNamePlural());
- if(RealEstate.instance.dataStore.cfgMessageOwner)
+ if(RealEstate.instance.config.cfgMessageOwner)
{
OfflinePlayer oldOwner = Bukkit.getOfflinePlayer(owner);
if(oldOwner.isOnline())
{
- ((Player) oldOwner).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + player.getDisplayName() +
+ ((Player) oldOwner).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + player.getDisplayName() +
" has purchased your " + claimType + " at " +
"[" + player.getLocation().getWorld().getName() + ", " +
"X: " + player.getLocation().getBlockX() + ", " +
@@ -119,7 +121,7 @@ public void interact(Player player)
}
else
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "Cannot purchase claim!");
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED + "Cannot purchase claim!");
return;
}
RealEstate.transactionsStore.cancelTransaction(claim);
@@ -150,7 +152,7 @@ public void preview(Player player)
}
else
{
- msg = RealEstate.instance.dataStore.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
+ msg = RealEstate.instance.config.chatPrefix + ChatColor.RED + "You don't have the permission to view real estate informations!";
}
player.sendMessage(msg);
}
diff --git a/src/me/EtienneDx/RealEstate/ClaimTransaction.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimTransaction.java
similarity index 91%
rename from src/me/EtienneDx/RealEstate/ClaimTransaction.java
rename to src/me/EtienneDx/RealEstate/Transactions/ClaimTransaction.java
index 02f64b7..8c463d2 100644
--- a/src/me/EtienneDx/RealEstate/ClaimTransaction.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimTransaction.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.util.HashMap;
import java.util.Map;
@@ -14,10 +14,10 @@
public abstract class ClaimTransaction implements ConfigurationSerializable, Transaction
{
- protected long claimId;
- protected UUID owner = null;
- protected double price;
- protected Location sign = null;
+ public long claimId;
+ public UUID owner = null;
+ public double price;
+ public Location sign = null;
public ClaimTransaction(Claim claim, Player player, double price, Location sign)
{
diff --git a/src/me/EtienneDx/RealEstate/ExitOffer.java b/src/me/EtienneDx/RealEstate/Transactions/ExitOffer.java
similarity index 87%
rename from src/me/EtienneDx/RealEstate/ExitOffer.java
rename to src/me/EtienneDx/RealEstate/Transactions/ExitOffer.java
index 49d7acc..5bcd65b 100644
--- a/src/me/EtienneDx/RealEstate/ExitOffer.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/ExitOffer.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.util.HashMap;
import java.util.Map;
@@ -8,8 +8,8 @@
public class ExitOffer implements ConfigurationSerializable
{
- UUID offerBy;
- double price;
+ public UUID offerBy;
+ public double price;
public ExitOffer(UUID offerBy, double price)
{
diff --git a/src/me/EtienneDx/RealEstate/Transaction.java b/src/me/EtienneDx/RealEstate/Transactions/Transaction.java
similarity index 87%
rename from src/me/EtienneDx/RealEstate/Transaction.java
rename to src/me/EtienneDx/RealEstate/Transactions/Transaction.java
index caf25a0..e381982 100644
--- a/src/me/EtienneDx/RealEstate/Transaction.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/Transaction.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.util.UUID;
diff --git a/src/me/EtienneDx/RealEstate/TransactionsStore.java b/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java
similarity index 90%
rename from src/me/EtienneDx/RealEstate/TransactionsStore.java
rename to src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java
index 55d984a..2f0b323 100644
--- a/src/me/EtienneDx/RealEstate/TransactionsStore.java
+++ b/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java
@@ -1,4 +1,4 @@
-package me.EtienneDx.RealEstate;
+package me.EtienneDx.RealEstate.Transactions;
import java.io.File;
import java.io.IOException;
@@ -15,6 +15,7 @@
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
+import me.EtienneDx.RealEstate.RealEstate;
import me.ryanhamshire.GriefPrevention.Claim;
import net.md_5.bungee.api.ChatColor;
@@ -168,17 +169,17 @@ public void sell(Claim claim, Player player, double price, Location sign)
if(player != null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully created " +
+ player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully created " +
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " sale for " +
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
}
- if(RealEstate.instance.dataStore.cfgBroadcastSell)
+ if(RealEstate.instance.config.cfgBroadcastSell)
{
for(Player p : Bukkit.getServer().getOnlinePlayers())
{
if(p != player)
{
- p.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
+ p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + 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());
@@ -187,9 +188,9 @@ public void sell(Claim claim, Player player, double price, Location sign)
}
}
- public void rent(Claim claim, Player player, double price, Location sign, int duration)
+ public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
{
- ClaimRent cr = new ClaimRent(claim, player, price, sign, duration);
+ ClaimRent cr = new ClaimRent(claim, player, price, sign, duration, rentPeriods);
claimRent.put(claim.getID().toString(), cr);
cr.update();
saveData();
@@ -204,17 +205,17 @@ public void rent(Claim claim, Player player, double price, Location sign, int du
if(player != null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully put " +
+ 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.dataStore.cfgBroadcastSell)
+ if(RealEstate.instance.config.cfgBroadcastSell)
{
for(Player p : Bukkit.getServer().getOnlinePlayers())
{
if(p != player)
{
- p.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
+ p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + 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());
@@ -241,18 +242,18 @@ public void lease(Claim claim, Player player, double price, Location sign, int f
if(player != null)
{
- player.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.AQUA + "You have successfully put " +
+ 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());
}
- if(RealEstate.instance.dataStore.cfgBroadcastSell)
+ if(RealEstate.instance.config.cfgBroadcastSell)
{
for(Player p : Bukkit.getServer().getOnlinePlayers())
{
if(p != player)
{
- p.sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.DARK_GREEN + player.getDisplayName() +
+ p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + 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 " +
diff --git a/src/me/EtienneDx/RealEstate/Utils.java b/src/me/EtienneDx/RealEstate/Utils.java
index 15b9aee..4238986 100644
--- a/src/me/EtienneDx/RealEstate/Utils.java
+++ b/src/me/EtienneDx/RealEstate/Utils.java
@@ -24,12 +24,12 @@ public static boolean makePayment(UUID receiver, UUID giver, double amount, bool
{
if(b.isOnline() && msgBuyer)
{
- ((Player)b).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"You don't have enough money to make this transaction!");
}
if(s != null && s.isOnline() && msgSeller)
{
- ((Player)s).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
b.getName() + " doesn't have enough money to make this transaction!");
}
return false;
@@ -39,12 +39,12 @@ public static boolean makePayment(UUID receiver, UUID giver, double amount, bool
{
if(b.isOnline() && msgBuyer)
{
- ((Player)b).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Could not withdraw the money!");
}
if(s != null && s.isOnline() && msgSeller)
{
- ((Player)s).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Could not withdraw the money!");
}
return false;
@@ -56,12 +56,12 @@ public static boolean makePayment(UUID receiver, UUID giver, double amount, bool
{
if(b.isOnline() && msgBuyer)
{
- ((Player)b).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)b).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Could not deposit to " + s.getName() + ", refunding Player!");
}
if(s != null && s.isOnline() && msgSeller)
{
- ((Player)s).sendMessage(RealEstate.instance.dataStore.chatPrefix + ChatColor.RED +
+ ((Player)s).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.RED +
"Could not deposit to you, refunding" + b.getName() + "!");
}
RealEstate.econ.depositPlayer(b, amount);
@@ -101,7 +101,7 @@ public static void transferClaim(Claim claim, UUID buyer, UUID seller)
// if transfert is true, the seller will lose the blocks he had
// and the buyer will get them
// (that means the buyer will keep the same amount of remaining blocks after the transaction)
- if(claim.parent == null && RealEstate.instance.dataStore.cfgTransferClaimBlocks)
+ if(claim.parent == null && RealEstate.instance.config.cfgTransferClaimBlocks)
{
PlayerData buyerData = GriefPrevention.instance.dataStore.getPlayerData(buyer);
PlayerData sellerData = GriefPrevention.instance.dataStore.getPlayerData(seller);