Skip to content

Commit

Permalink
added container rent
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDx committed May 26, 2021
1 parent d7fa646 commit a145048
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/me/EtienneDx/RealEstate/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Config extends AnnotationConfig
public List<String> cfgSellKeywords = Arrays.asList("[sell]", "[sell claim]", "[sc]", "[re]", "[realestate]");
@ConfigField(name="RealEstate.Keywords.Rent", comment = "List of all possible possible signs headers to rent a claim")
public List<String> cfgRentKeywords = Arrays.asList("[rent]", "[rent claim]", "[rc]");
@ConfigField(name="RealEstate.Keywords.ContainerRent", comment = "List of all possible possible signs headers to rent a claim")
public List<String> cfgContainerRentKeywords = Arrays.asList("[container rent]", "[crent]");
@ConfigField(name="RealEstate.Keywords.Lease", comment = "List of all possible possible signs headers to lease a claim")
public List<String> cfgLeaseKeywords = Arrays.asList("[lease]", "[lease claim]", "[lc]");

Expand All @@ -39,6 +41,8 @@ public class Config extends AnnotationConfig
public String cfgReplaceLease = "FOR LEASE";
@ConfigField(name="RealEstate.Keywords.Replace.Ongoing.Rent", comment = "What is displayed on the first line of the sign once someone rents a claim.")
public String cfgReplaceOngoingRent = "[Rented]";
@ConfigField(name="RealEstate.Keywords.Replace.ContainerRent", comment = "What is displayed on the third line of the sign when renting container access only.")
public String cfgContainerRentLine = ChatColor.BLUE + "Containers only";

@ConfigField(name="RealEstate.Rules.Sell", comment = "Is selling claims enabled?")
public boolean cfgEnableSell = true;
Expand Down
9 changes: 6 additions & 3 deletions src/me/EtienneDx/RealEstate/REListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public void onSignChange(SignChangeEvent event)
{
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()))
RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()) ||
RealEstate.instance.config.cfgContainerRentKeywords.contains(event.getLine(0).toLowerCase()))
{
Player player = event.getPlayer();
Location loc = event.getBlock().getLocation();
Expand Down Expand Up @@ -144,7 +145,8 @@ else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// o
event.setCancelled(true);// need to cancel the event, so we can update the sign elsewhere
RealEstate.transactionsStore.sell(claim, claim.isAdminClaim() ? null : player, price, event.getBlock().getLocation());
}
else if(RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
else if(RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()) ||
RealEstate.instance.config.cfgContainerRentKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
{
if(!RealEstate.instance.config.cfgEnableRent)
{
Expand Down Expand Up @@ -253,7 +255,8 @@ else if(type.equals("claim") && !player.getUniqueId().equals(claim.ownerID))// o

// all should be good, we can create the rent
event.setCancelled(true);
RealEstate.transactionsStore.rent(claim, player, price, event.getBlock().getLocation(), duration, rentPeriods);
RealEstate.transactionsStore.rent(claim, player, price, event.getBlock().getLocation(), duration, rentPeriods,
RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toLowerCase()));
}
else if(RealEstate.instance.config.cfgLeaseKeywords.contains(event.getLine(0).toLowerCase()))// we want to rent it
{
Expand Down
31 changes: 24 additions & 7 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ClaimRent extends BoughtTransaction
LocalDateTime startDate = null;
int duration;
public boolean autoRenew = false;
public boolean buildTrust = true;
public int periodCount = 0;
public int maxPeriod;

Expand All @@ -40,13 +41,20 @@ public ClaimRent(Map<String, Object> map)
autoRenew = (boolean) map.get("autoRenew");
periodCount = (int) map.get("periodCount");
maxPeriod = (int) map.get("maxPeriod");
try {
buildTrust = (boolean) map.get("buildTrust");
}
catch (Exception e) {
buildTrust = true;
}
}

public ClaimRent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
public ClaimRent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods, boolean buildTrust)
{
super(claim, player, price, sign);
this.duration = duration;
this.maxPeriod = RealEstate.instance.config.cfgEnableRentPeriod ? rentPeriods : 1;
this.buildTrust = buildTrust;
}

@Override
Expand All @@ -59,6 +67,7 @@ public Map<String, Object> serialize() {
map.put("autoRenew", autoRenew);
map.put("periodCount", periodCount);
map.put("maxPeriod", maxPeriod);
map.put("buildTrust", buildTrust);

return map;
}
Expand All @@ -74,30 +83,38 @@ public boolean update()
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");
String price_line = "";
if(RealEstate.instance.config.cfgUseCurrencySymbol)
{
if(RealEstate.instance.config.cfgUseDecimalCurrency == false)
{
s.setLine(2, RealEstate.instance.config.cfgCurrencySymbol + " " + (int)Math.round(price));
price_line = RealEstate.instance.config.cfgCurrencySymbol + " " + (int)Math.round(price);
}
else
{
s.setLine(2, RealEstate.instance.config.cfgCurrencySymbol + " " + price);
price_line = RealEstate.instance.config.cfgCurrencySymbol + " " + price;
}

}
else
{
if(RealEstate.instance.config.cfgUseDecimalCurrency == false)
{
s.setLine(2, (int)Math.round(price) + " " + RealEstate.econ.currencyNamePlural());
price_line = (int)Math.round(price) + " " + RealEstate.econ.currencyNamePlural();
}
else
{
s.setLine(2, price + " " + RealEstate.econ.currencyNamePlural());
price_line = price + " " + RealEstate.econ.currencyNamePlural();
}
}
s.setLine(3, (maxPeriod > 1 ? maxPeriod + "x " : "") + Utils.getTime(duration, null, false));
String period = (maxPeriod > 1 ? maxPeriod + "x " : "") + Utils.getTime(duration, null, false);
if(this.buildTrust) {
s.setLine(2, price_line);
s.setLine(3, period);
} else {
s.setLine(2, RealEstate.instance.config.cfgContainerRentLine);
s.setLine(3, price_line + " - " + period);
}
s.update(true);
}
else
Expand Down Expand Up @@ -311,7 +328,7 @@ public void interact(Player player)
buyer = player.getUniqueId();
startDate = LocalDateTime.now();
autoRenew = false;
claim.setPermission(buyer.toString(), ClaimPermission.Build);
claim.setPermission(buyer.toString(), buildTrust ? ClaimPermission.Build : ClaimPermission.Inventory);
claim.allowGrantPermission(player);
claim.managers.add(player.getUniqueId().toString());
claim.setSubclaimRestrictions(true);
Expand Down
10 changes: 5 additions & 5 deletions src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ public void sell(Claim claim, Player player, double price, Location sign)
}
}

public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods)
public void rent(Claim claim, Player player, double price, Location sign, int duration, int rentPeriods, boolean buildTrust)
{
ClaimRent cr = new ClaimRent(claim, claim.isAdminClaim() ? null : player, price, sign, duration, rentPeriods);
ClaimRent cr = new ClaimRent(claim, claim.isAdminClaim() ? null : player, price, sign, duration, rentPeriods, buildTrust);
claimRent.put(claim.getID().toString(), cr);
cr.update();
saveData();

RealEstate.instance.addLogEntry("[" + this.dateFormat.format(this.date) + "] " + (player == null ? "The Server" : player.getName()) +
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent at " +
" has made " + (claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for" + (buildTrust ? "" : " container") + " rent at " +
"[" + claim.getLesserBoundaryCorner().getWorld() + ", " +
"X: " + claim.getLesserBoundaryCorner().getBlockX() + ", " +
"Y: " + claim.getLesserBoundaryCorner().getBlockY() + ", " +
Expand All @@ -236,7 +236,7 @@ public void rent(Claim claim, Player player, double price, Location sign, int du
if(player != null)
{
player.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.AQUA + "You have successfully put " +
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent for " +
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for" + (buildTrust ? "" : " container") + " rent for " +
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
}
if(RealEstate.instance.config.cfgBroadcastSell)
Expand All @@ -247,7 +247,7 @@ public void rent(Claim claim, Player player, double price, Location sign, int du
{
p.sendMessage(RealEstate.instance.config.chatPrefix + ChatColor.DARK_GREEN + (player == null ? "The Server" : player.getDisplayName()) +
ChatColor.AQUA + " has put " +
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for rent for " +
(claim.isAdminClaim() ? "an admin" : "a") + " " + (claim.parent == null ? "claim" : "subclaim") + " for" + (buildTrust ? "" : " container") + " rent for " +
ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural());
}
}
Expand Down

0 comments on commit a145048

Please sign in to comment.