Skip to content

Commit

Permalink
fix: fixed EtienneDx#42 and removeed a duplicated message
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneDx committed Mar 4, 2022
1 parent 757de57 commit 2e92305
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
* Removed requirement for custom GP jar file

### 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
13 changes: 10 additions & 3 deletions src/me/EtienneDx/RealEstate/Messages.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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!";
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/me/EtienneDx/RealEstate/REListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 0 additions & 6 deletions src/me/EtienneDx/RealEstate/Transactions/ClaimRent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 2e92305

Please sign in to comment.