From a14504861f14be5ab742464bafc5dcce4ccbd502 Mon Sep 17 00:00:00 2001 From: EtienneDx Date: Wed, 26 May 2021 11:31:33 +0200 Subject: [PATCH] added container rent --- src/me/EtienneDx/RealEstate/Config.java | 4 +++ src/me/EtienneDx/RealEstate/REListener.java | 9 ++++-- .../RealEstate/Transactions/ClaimRent.java | 31 ++++++++++++++----- .../Transactions/TransactionsStore.java | 10 +++--- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/me/EtienneDx/RealEstate/Config.java b/src/me/EtienneDx/RealEstate/Config.java index e1c5a9b..b6f0e35 100644 --- a/src/me/EtienneDx/RealEstate/Config.java +++ b/src/me/EtienneDx/RealEstate/Config.java @@ -28,6 +28,8 @@ public class Config extends AnnotationConfig public List 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 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 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 cfgLeaseKeywords = Arrays.asList("[lease]", "[lease claim]", "[lc]"); @@ -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; diff --git a/src/me/EtienneDx/RealEstate/REListener.java b/src/me/EtienneDx/RealEstate/REListener.java index 4c73959..9c1675f 100644 --- a/src/me/EtienneDx/RealEstate/REListener.java +++ b/src/me/EtienneDx/RealEstate/REListener.java @@ -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(); @@ -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) { @@ -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 { diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java index e57cfeb..92be5ad 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java @@ -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; @@ -40,13 +41,20 @@ public ClaimRent(Map 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 @@ -59,6 +67,7 @@ public Map serialize() { map.put("autoRenew", autoRenew); map.put("periodCount", periodCount); map.put("maxPeriod", maxPeriod); + map.put("buildTrust", buildTrust); return map; } @@ -74,15 +83,16 @@ 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; } } @@ -90,14 +100,21 @@ public boolean update() { 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 @@ -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); diff --git a/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java b/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java index e03c992..1cf30ba 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java +++ b/src/me/EtienneDx/RealEstate/Transactions/TransactionsStore.java @@ -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() + ", " + @@ -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) @@ -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()); } }