From 2e92305aec69641b62351ccc217a5e90982a23a3 Mon Sep 17 00:00:00 2001 From: Etienne Dx Date: Fri, 4 Mar 2022 19:02:31 +0100 Subject: [PATCH] fix: fixed #42 and removeed a duplicated message --- CHANGELOG.md | 3 ++- src/me/EtienneDx/RealEstate/Messages.java | 13 ++++++++++--- src/me/EtienneDx/RealEstate/REListener.java | 12 ++++++------ .../RealEstate/Transactions/ClaimRent.java | 6 ------ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebc205c..c24f545 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,4 +16,5 @@ * Removed requirement for custom GP jar file ### Fixed -* Sign header color formatting being lost on server restart \ No newline at end of file +* Sign header color formatting being lost on server restart +* Fixed issue preventing to buy claims due to currencies using $ character \ No newline at end of file diff --git a/src/me/EtienneDx/RealEstate/Messages.java b/src/me/EtienneDx/RealEstate/Messages.java index 7166b28..bc78635 100644 --- a/src/me/EtienneDx/RealEstate/Messages.java +++ b/src/me/EtienneDx/RealEstate/Messages.java @@ -1,5 +1,8 @@ package me.EtienneDx.RealEstate; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.bukkit.command.CommandSender; import org.bukkit.plugin.PluginDescriptionFile; @@ -122,7 +125,7 @@ public class Messages extends AnnotationConfig public String msgErrorNonIntegerPrice = "$cThe price must be an integer!"; @ConfigField(name="RealEstate.Errors.InvalidDuration", comment = "0: duration, 1: example of duration format, 2: example, 3: example") - public String msgErrorInvalidDuration = "$c{0} is not a valid duration! Durations must be in the format {1} or {2} or {3}!"; + public String msgErrorInvalidDuration = "$c{0} is not a valid duration! Durations must be in the format $a{1}$c or $a{2}$c or $a{3}$c!"; @ConfigField(name="RealEstate.Errors.NoMoneySelf") public String msgErrorNoMoneySelf = "$cYou don't have enough money to make this transaction!"; @@ -444,12 +447,16 @@ public static String getMessage(String msgTemplate, boolean withPrefix, String.. if (withPrefix) { msgTemplate = RealEstate.instance.config.chatPrefix + msgTemplate; } + + msgTemplate = msgTemplate.replace('$', ChatColor.COLOR_CHAR); + for (int i = 0; i < args.length; i++) { String param = args[i]; - msgTemplate = msgTemplate.replaceAll("\\{" + i + "\\}", param); + Matcher matcher = Pattern.compile("\\{" + i + "\\}").matcher(msgTemplate); + msgTemplate = matcher.replaceAll(Matcher.quoteReplacement(param)); } - return msgTemplate.replace('$', ChatColor.COLOR_CHAR); + return msgTemplate; } //sends a color-coded message to a player public static void sendMessage(CommandSender player, String msgTemplate, String... args) { diff --git a/src/me/EtienneDx/RealEstate/REListener.java b/src/me/EtienneDx/RealEstate/REListener.java index 717bbf0..decec38 100644 --- a/src/me/EtienneDx/RealEstate/REListener.java +++ b/src/me/EtienneDx/RealEstate/REListener.java @@ -203,9 +203,9 @@ else if(RealEstate.instance.config.cfgRentKeywords.contains(event.getLine(0).toL if(duration == 0) { Messages.sendMessage(player, RealEstate.instance.messages.msgErrorInvalidDuration, event.getLine(2), - ChatColor.GREEN + "10 weeks", - ChatColor.GREEN + "3 days", - ChatColor.GREEN + "1 week 3 days"); + "10 weeks", + "3 days", + "1 week 3 days"); event.setCancelled(true); event.getBlock().breakNaturally(); return; @@ -334,9 +334,9 @@ else if(RealEstate.instance.config.cfgLeaseKeywords.contains(event.getLine(0).to if(frequency == 0) { Messages.sendMessage(player, RealEstate.instance.messages.msgErrorInvalidDuration, event.getLine(3), - ChatColor.GREEN + "10 weeks", - ChatColor.GREEN + "3 days", - ChatColor.GREEN + "1 week 3 days"); + "10 weeks", + "3 days", + "1 week 3 days"); event.setCancelled(true); event.getBlock().breakNaturally(); return; diff --git a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java index 37046a8..91a2bf1 100644 --- a/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java +++ b/src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java @@ -441,12 +441,6 @@ public void preview(Player player) RealEstate.econ.format(price), Utils.getTime(daysLeft, timeRemaining, true), Utils.getTime(duration, null, true)) + "\n"; - msg += ChatColor.AQUA + "This " + claimType + " is currently rented by " + - ChatColor.GREEN + Bukkit.getOfflinePlayer(buyer).getName() + ChatColor.AQUA + " for " + - ChatColor.GREEN + price + " " + RealEstate.econ.currencyNamePlural() + ChatColor.AQUA + " for " + - (maxPeriod - periodCount > 1 ? "" + ChatColor.GREEN + (maxPeriod - periodCount) + ChatColor.AQUA + " periods of " + - ChatColor.GREEN + Utils.getTime(duration, null, false) + ChatColor.AQUA + ". The current period will end in " : "another ") + - ChatColor.GREEN + Utils.getTime(daysLeft, timeRemaining, true) + "\n"; if(maxPeriod > 1 && maxPeriod - periodCount > 0) {