fix: fixed #42 and removeed a duplicated message

This commit is contained in:
Etienne Dx 2022-03-04 19:02:31 +01:00
parent 757de574be
commit 2e92305aec
4 changed files with 18 additions and 16 deletions

View File

@ -17,3 +17,4 @@
### Fixed ### Fixed
* Sign header color formatting being lost on server restart * Sign header color formatting being lost on server restart
* Fixed issue preventing to buy claims due to currencies using $ character

View File

@ -1,5 +1,8 @@
package me.EtienneDx.RealEstate; package me.EtienneDx.RealEstate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.plugin.PluginDescriptionFile; import org.bukkit.plugin.PluginDescriptionFile;
@ -122,7 +125,7 @@ public class Messages extends AnnotationConfig
public String msgErrorNonIntegerPrice = "$cThe price must be an integer!"; 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") @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") @ConfigField(name="RealEstate.Errors.NoMoneySelf")
public String msgErrorNoMoneySelf = "$cYou don't have enough money to make this transaction!"; public String msgErrorNoMoneySelf = "$cYou don't have enough money to make this transaction!";
@ -444,12 +447,16 @@ public class Messages extends AnnotationConfig
if (withPrefix) { if (withPrefix) {
msgTemplate = RealEstate.instance.config.chatPrefix + msgTemplate; msgTemplate = RealEstate.instance.config.chatPrefix + msgTemplate;
} }
msgTemplate = msgTemplate.replace('$', ChatColor.COLOR_CHAR);
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
String param = args[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 //sends a color-coded message to a player
public static void sendMessage(CommandSender player, String msgTemplate, String... args) { public static void sendMessage(CommandSender player, String msgTemplate, String... args) {

View File

@ -203,9 +203,9 @@ public class REListener implements Listener
if(duration == 0) if(duration == 0)
{ {
Messages.sendMessage(player, RealEstate.instance.messages.msgErrorInvalidDuration, event.getLine(2), Messages.sendMessage(player, RealEstate.instance.messages.msgErrorInvalidDuration, event.getLine(2),
ChatColor.GREEN + "10 weeks", "10 weeks",
ChatColor.GREEN + "3 days", "3 days",
ChatColor.GREEN + "1 week 3 days"); "1 week 3 days");
event.setCancelled(true); event.setCancelled(true);
event.getBlock().breakNaturally(); event.getBlock().breakNaturally();
return; return;
@ -334,9 +334,9 @@ public class REListener implements Listener
if(frequency == 0) if(frequency == 0)
{ {
Messages.sendMessage(player, RealEstate.instance.messages.msgErrorInvalidDuration, event.getLine(3), Messages.sendMessage(player, RealEstate.instance.messages.msgErrorInvalidDuration, event.getLine(3),
ChatColor.GREEN + "10 weeks", "10 weeks",
ChatColor.GREEN + "3 days", "3 days",
ChatColor.GREEN + "1 week 3 days"); "1 week 3 days");
event.setCancelled(true); event.setCancelled(true);
event.getBlock().breakNaturally(); event.getBlock().breakNaturally();
return; return;

View File

@ -441,12 +441,6 @@ public class ClaimRent extends BoughtTransaction
RealEstate.econ.format(price), RealEstate.econ.format(price),
Utils.getTime(daysLeft, timeRemaining, true), Utils.getTime(daysLeft, timeRemaining, true),
Utils.getTime(duration, null, true)) + "\n"; 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) if(maxPeriod > 1 && maxPeriod - periodCount > 0)
{ {