Skip to content

Commit

Permalink
Added mail support and optionnal sign removal
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDx committed Apr 30, 2019
1 parent 53597d7 commit f603b07
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 23 deletions.
13 changes: 12 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>Me.EtienneDx</groupId>
<artifactId>RealEstate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.1.1-SNAPSHOT</version>
<name>RealEstate</name>
<description>A spigot plugin for selling, renting and leasing GriefPrevention claims</description>
<build>
Expand Down Expand Up @@ -74,6 +74,11 @@
<id>aikar</id>
<url>https://repo.aikar.co/content/groups/aikar/</url>
</repository>
<!-- EssentialsX repo -->
<repository>
<id>ess-repo</id>
<url>https://ci.ender.zone/plugin/repository/everything/</url>
</repository>
</repositories>
<dependencies>
<dependency>
Expand All @@ -99,5 +104,11 @@
<artifactId>acf-bukkit</artifactId>
<version>0.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.ess3</groupId>
<artifactId>EssentialsX</artifactId>
<version>2.16.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
9 changes: 9 additions & 0 deletions src/me/EtienneDx/RealEstate/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ public class Config

public boolean cfgEnableAutoRenew;
public boolean cfgEnableRentPeriod;
public boolean cfgDestroyRentSigns;
public boolean cfgDestroyLeaseSigns;

public boolean cfgTransferClaimBlocks;

public boolean cfgMessageOwner;
public boolean cfgMessageBuyer;
public boolean cfgBroadcastSell;
public boolean cfgMailOffline;

public double cfgPriceSellPerBlock;
public double cfgPriceRentPerBlock;
Expand Down Expand Up @@ -93,11 +96,14 @@ public void loadConfig(YamlConfiguration config)

this.cfgEnableAutoRenew = config.getBoolean("RealEstate.Rules.AutomaticRenew", true);
this.cfgEnableRentPeriod = config.getBoolean("RealEstate.Rules.RentPeriods", true);
this.cfgDestroyRentSigns = config.getBoolean("RealEstate.Rules.DestroySigns.Rent", false);
this.cfgDestroyLeaseSigns = config.getBoolean("RealEstate.Rules.DestroySigns.Lease", false);

this.cfgTransferClaimBlocks = config.getBoolean("RealEstate.Rules.TransferClaimBlocks", true);

this.cfgMessageOwner = config.getBoolean("RealEstate.Messaging.MessageOwner", true);
this.cfgMessageBuyer = config.getBoolean("RealEstate.Messaging.MessageBuyer", true);
this.cfgMailOffline = config.getBoolean("RealEstate.Messaging.MailOffline", true);
this.cfgBroadcastSell = config.getBoolean("RealEstate.Messaging.BroadcastSell", true);

this.cfgPriceSellPerBlock = config.getDouble("RealEstate.Default.PricesPerBlock.Sell", 5.0);
Expand Down Expand Up @@ -136,11 +142,14 @@ public void saveConfig()

outConfig.set("RealEstate.Rules.AutomaticRenew", this.cfgEnableAutoRenew);
outConfig.set("RealEstate.Rules.RentPeriods", this.cfgEnableRentPeriod);
outConfig.set("RealEstate.Rules.DestroySigns.Rent", this.cfgDestroyRentSigns);
outConfig.set("RealEstate.Rules.DestroySigns.Lease", this.cfgDestroyLeaseSigns);

outConfig.set("RealEstate.Rules.TransferClaimBlocks", this.cfgTransferClaimBlocks);

outConfig.set("RealEstate.Messaging.MessageOwner", this.cfgMessageOwner);
outConfig.set("RealEstate.Messaging.MessageBuyer", this.cfgMessageBuyer);
outConfig.set("RealEstate.Messaging.MailOffline", this.cfgMailOffline);
outConfig.set("RealEstate.Messaging.BroadcastSell", this.cfgBroadcastSell);

outConfig.set("RealEstate.Default.PricePerBlock.Sell", this.cfgPriceSellPerBlock);
Expand Down
38 changes: 36 additions & 2 deletions src/me/EtienneDx/RealEstate/RECommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import com.earth2me.essentials.User;

import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandHelp;
import co.aikar.commands.annotation.CommandAlias;
Expand Down Expand Up @@ -141,15 +143,23 @@ public void create(Player player, @Conditions("positiveDouble") Double price)
"The proposition has been successfully created!");
UUID other = player.getUniqueId().equals(bt.owner) ? bt.buyer : bt.owner;
OfflinePlayer otherP = Bukkit.getOfflinePlayer(other);
Location loc = player.getLocation();
String claimType = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null).parent == null ? "claim" : "subclaim";
if(otherP.isOnline())
{
Location loc = player.getLocation();
String claimType = GriefPrevention.instance.dataStore.getClaimAt(loc, false, null).parent == null ? "claim" : "subclaim";
((Player)otherP).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() +
ChatColor.AQUA + " has 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(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(other);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() +
ChatColor.AQUA + " has 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());
}
}

@Subcommand("accept")
Expand Down Expand Up @@ -183,6 +193,14 @@ else if(Utils.makePayment(player.getUniqueId(), bt.exitOffer.offerBy, bt.exitOff
ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() +
", Z: " + loc.getBlockZ() + "]. It is no longer rented or leased.");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(other);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() +
ChatColor.AQUA + " has 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.");
}
bt.exitOffer = null;
claim.dropPermission(bt.buyer.toString());
bt.buyer = null;
Expand Down Expand Up @@ -223,6 +241,14 @@ else if(bt.exitOffer.offerBy.equals(player.getUniqueId()))
ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() +
", Z: " + loc.getBlockZ() + "]");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(other);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() +
ChatColor.AQUA + " has 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() + "]");
}
}
}

Expand All @@ -248,6 +274,14 @@ public void cancel(Player player)
ChatColor.BLUE + "[" + loc.getWorld().getName() + ", X: " + loc.getBlockX() + ", Y: " + loc.getBlockY() + ", Z: "
+ loc.getBlockZ() + "]");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(other);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() +
ChatColor.AQUA + " has 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
{
Expand Down
7 changes: 7 additions & 0 deletions src/me/EtienneDx/RealEstate/RealEstate.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import com.earth2me.essentials.Essentials;

import co.aikar.commands.BukkitCommandManager;
import co.aikar.commands.ConditionFailedException;
import me.EtienneDx.RealEstate.Transactions.BoughtTransaction;
Expand All @@ -33,6 +35,7 @@ public class RealEstate extends JavaPlugin
public static boolean vaultPresent = false;
public static Economy econ = null;
public static Permission perms = null;
public static Essentials ess = null;

public static RealEstate instance = null;

Expand Down Expand Up @@ -70,6 +73,10 @@ public void onEnable()
return;
}
}
if((ess = (Essentials)getServer().getPluginManager().getPlugin("Essentials")) != null)
{
this.log.info("Found Essentials, using version " + ess.getDescription().getVersion());
}
this.config = new Config();
this.config.loadConfig();// loads config or default
this.config.saveConfig();// save eventual default
Expand Down
17 changes: 17 additions & 0 deletions src/me/EtienneDx/RealEstate/Transactions/BoughtTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
import java.util.UUID;

import org.bukkit.Location;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;

import me.EtienneDx.RealEstate.RealEstate;
import me.ryanhamshire.GriefPrevention.Claim;

public abstract class BoughtTransaction extends ClaimTransaction
{
public UUID buyer = null;
public ExitOffer exitOffer = null;
public boolean destroyedSign = false;

public BoughtTransaction(Map<String, Object> map)
{
Expand All @@ -20,6 +23,8 @@ public BoughtTransaction(Map<String, Object> map)
buyer = UUID.fromString((String)map.get("buyer"));
if(map.get("exitOffer") != null)
exitOffer = (ExitOffer) map.get("exitOffer");
if(map.get("destroyedSign") != null)// may be the case on upgrading from 0.0.1-SNAPSHOT
destroyedSign = (boolean) map.get("destroyedSign");
}

public BoughtTransaction(Claim claim, Player player, double price, Location sign)
Expand All @@ -35,10 +40,22 @@ public Map<String, Object> serialize()
map.put("buyer", buyer.toString());
if(exitOffer != null)
map.put("exitOffer", exitOffer);
map.put("destroyedSign", destroyedSign);

return map;
}

public void destroySign()
{
if((this instanceof ClaimRent &&RealEstate.instance.config.cfgDestroyRentSigns) ||
(this instanceof ClaimLease &&RealEstate.instance.config.cfgDestroyLeaseSigns))
{
if(!destroyedSign && getHolder().getState() instanceof Sign)
getHolder().breakNaturally();
destroyedSign = true;
}
}

public UUID getBuyer()
{
return buyer;
Expand Down
85 changes: 76 additions & 9 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimLease.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;

import com.earth2me.essentials.User;

import me.EtienneDx.RealEstate.RealEstate;
import me.EtienneDx.RealEstate.Utils;
import me.ryanhamshire.GriefPrevention.Claim;
Expand Down Expand Up @@ -59,7 +61,11 @@ public void update()
{
if(buyer == null)// not yet leased
{
if(sign.getBlock().getState() instanceof Sign)
if(destroyedSign)
{
RealEstate.transactionsStore.cancelTransaction(this);
}
else if(sign.getBlock().getState() instanceof Sign)
{
Sign s = (Sign)sign.getBlock().getState();
s.setLine(0, RealEstate.instance.config.cfgSignsHeader);
Expand All @@ -69,10 +75,6 @@ public void update()
s.setLine(3, Utils.getTime(frequency, null, false));
s.update(true);
}
else
{
RealEstate.transactionsStore.cancelTransaction(this);
}
}
else
{
Expand Down Expand Up @@ -113,6 +115,15 @@ private void payLease()
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.buyer);
u.addMail(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.config.cfgMessageOwner)
{
Expand All @@ -123,6 +134,16 @@ private void payLease()
ChatColor.AQUA + " at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + " at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", " + ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
}
else
{
Expand All @@ -134,6 +155,15 @@ private void payLease()
ChatColor.AQUA + " for the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", the " + claimType + " is now yours");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.buyer);
u.addMail(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.config.cfgMessageOwner)
{
Expand All @@ -144,6 +174,16 @@ private void payLease()
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", the " + claimType + " is now his property");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " has paid lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + "at the price of " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() +
ChatColor.AQUA + ", the " + claimType + " is now his property");
}
Claim claim = GriefPrevention.instance.dataStore.getClaimAt(sign, false, null);

Utils.transferClaim(claim, buyer, owner);
Expand All @@ -159,6 +199,14 @@ private void payLease()
sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" + ChatColor.RED + ", the transaction has been cancelled.");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.buyer);
u.addMail(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.config.cfgMessageOwner)
{
((Player)seller).sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
Expand All @@ -167,6 +215,15 @@ private void payLease()
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + ", the transaction has been cancelled");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + buyerPlayer.getName() +
ChatColor.AQUA + " couldn't pay lease for the " + claimType + " at " + ChatColor.BLUE + "[" +
sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " +
sign.getBlockY() + ", Z: " + sign.getBlockZ() + "]" +
ChatColor.AQUA + ", the transaction has been cancelled");
}
RealEstate.transactionsStore.cancelTransaction(this);
}
// no need to re update, since there's no sign
Expand Down Expand Up @@ -258,17 +315,27 @@ public void interact(Player player)
{
((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() + ", " +
"Y: " + sign.getBlockY() + ", " +
"Z: " + sign.getBlockZ() + "] " +
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}
else if(RealEstate.instance.config.cfgMailOffline && RealEstate.ess != null)
{
User u = RealEstate.ess.getUser(this.owner);
u.addMail(RealEstate.instance.config.chatPrefix + ChatColor.GREEN + player.getName() + ChatColor.AQUA +
" has just paid for your lease for the " + claimType + " at " +
ChatColor.BLUE + "[" + sign.getWorld().getName() + ", X: " + sign.getBlockX() + ", Y: " + sign.getBlockY() + ", Z: "
+ sign.getBlockZ() + "]" + ChatColor.AQUA +
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");
}

player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully paid lease for this " + claimType +
" for " + ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + ", " +
ChatColor.GREEN + paymentsLeft + ChatColor.AQUA + " payments left");

destroySign();
}
}

Expand Down
Loading

0 comments on commit f603b07

Please sign in to comment.