Drop messageFormat for simple string replace, remove duped ' marks.

This commit is contained in:
KHobbits 2013-06-27 09:31:29 +01:00
parent 3e519f95d5
commit 0292cb59cd
3 changed files with 18 additions and 21 deletions

View File

@ -27,7 +27,7 @@ public interface ISettings extends IConf
long getBackupInterval();
MessageFormat getChatFormat(String group);
String getChatFormat(String group);
int getChatRadius();

View File

@ -402,26 +402,23 @@ public class Settings implements ISettings
{
return config.getString("backup.command", null);
}
private Map<String, MessageFormat> chatFormats = Collections.synchronizedMap(new HashMap<String, MessageFormat>());
private Map<String, String> chatFormats = Collections.synchronizedMap(new HashMap<String, String>());
@Override
public MessageFormat getChatFormat(String group)
public String getChatFormat(String group)
{
MessageFormat mFormat = chatFormats.get(group);
String mFormat = chatFormats.get(group);
if (mFormat == null)
{
String format = config.getString("chat.group-formats." + (group == null ? "Default" : group),
mFormat = config.getString("chat.group-formats." + (group == null ? "Default" : group),
config.getString("chat.format", "&7[{GROUP}]&r {DISPLAYNAME}&7:&r {MESSAGE}"));
format = FormatUtil.replaceFormat(format);
format = format.replace("'", "''");
format = format.replace("{DISPLAYNAME}", "%1$s");
format = format.replace("{GROUP}", "{0}");
format = format.replace("{MESSAGE}", "%2$s");
format = format.replace("{WORLDNAME}", "{1}");
format = format.replace("{SHORTWORLDNAME}", "{2}");
format = format.replaceAll("\\{(\\D*?)\\}", "'\\{$1\\}'");
format = "§r".concat(format);
mFormat = new MessageFormat(format);
mFormat = FormatUtil.replaceFormat(mFormat);
mFormat = mFormat.replace("{DISPLAYNAME}", "%1$s");
mFormat = mFormat.replace("{MESSAGE}", "%2$s");
mFormat = mFormat.replace("{GROUP}", "{0}");
mFormat = mFormat.replace("{WORLDNAME}", "{1}");
mFormat = mFormat.replace("{SHORTWORLDNAME}", "{2}");
mFormat = "§r".concat(mFormat);
chatFormats.put(group, mFormat);
}
return mFormat;

View File

@ -48,13 +48,13 @@ public class EssentialsChatPlayerListenerLowest extends EssentialsChatPlayer
event.setMessage(FormatUtil.formatMessage(user, "essentials.chat", event.getMessage()));
String group = user.getGroup();
String world = user.getWorld().getName();
MessageFormat format = ess.getSettings().getChatFormat(group);
String format = ess.getSettings().getChatFormat(group);
format = format.replace("{0}", group);
format = format.replace("{1}", world);
format = format.replace("{2}", world.substring(0, 1).toUpperCase(Locale.ENGLISH));
synchronized (format)
{
event.setFormat(format.format(new Object[]
{
group, world, world.substring(0, 1).toUpperCase(Locale.ENGLISH)
}));
{
event.setFormat(format);
}
}
}