Support for builder messages through SendMessageLocalisationData.
This commit is contained in:
@ -28,6 +28,7 @@ import org.w3c.dom.Document;
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.commons.util.IXmlReader;
|
||||
import org.l2jmobius.gameserver.model.StatsSet;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
|
||||
/**
|
||||
* @author Mobius
|
||||
@ -86,52 +87,55 @@ public class SendMessageLocalisationData implements IXmlReader
|
||||
}));
|
||||
}
|
||||
|
||||
public String getLocalisation(String lang, String message)
|
||||
public static String getLocalisation(PlayerInstance player, String message)
|
||||
{
|
||||
final Map<String[], String[]> localisations = SEND_MESSAGE_LOCALISATIONS.get(lang);
|
||||
if (localisations != null)
|
||||
if (Config.MULTILANG_ENABLE)
|
||||
{
|
||||
// No pretty way of doing something like this.
|
||||
// Consider using proper SystemMessages where possible.
|
||||
String[] searchMessage;
|
||||
String[] replacementMessage;
|
||||
boolean found;
|
||||
for (Entry<String[], String[]> entry : localisations.entrySet())
|
||||
final Map<String[], String[]> localisations = SEND_MESSAGE_LOCALISATIONS.get(player.getLang());
|
||||
if (localisations != null)
|
||||
{
|
||||
searchMessage = entry.getKey();
|
||||
replacementMessage = entry.getValue();
|
||||
|
||||
// Exact match.
|
||||
if (searchMessage.length == 1)
|
||||
// No pretty way of doing something like this.
|
||||
// Consider using proper SystemMessages where possible.
|
||||
String[] searchMessage;
|
||||
String[] replacementMessage;
|
||||
boolean found;
|
||||
for (Entry<String[], String[]> entry : localisations.entrySet())
|
||||
{
|
||||
if (searchMessage[0].equals(message))
|
||||
searchMessage = entry.getKey();
|
||||
replacementMessage = entry.getValue();
|
||||
|
||||
// Exact match.
|
||||
if (searchMessage.length == 1)
|
||||
{
|
||||
return replacementMessage[0];
|
||||
}
|
||||
}
|
||||
else // Split match.
|
||||
{
|
||||
found = true;
|
||||
for (String part : searchMessage)
|
||||
{
|
||||
if (!message.contains(part))
|
||||
if (searchMessage[0].equals(message))
|
||||
{
|
||||
found = false;
|
||||
return replacementMessage[0];
|
||||
}
|
||||
}
|
||||
else // Split match.
|
||||
{
|
||||
found = true;
|
||||
for (String part : searchMessage)
|
||||
{
|
||||
if (!message.contains(part))
|
||||
{
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
for (int i = 0; i < searchMessage.length; i++)
|
||||
{
|
||||
message = message.replace(searchMessage[i], replacementMessage[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
{
|
||||
for (int i = 0; i < searchMessage.length; i++)
|
||||
{
|
||||
message = message.replace(searchMessage[i], replacementMessage[i]);
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return message;
|
||||
}
|
||||
|
||||
public static SendMessageLocalisationData getInstance()
|
||||
|
@ -8937,16 +8937,7 @@ public class PlayerInstance extends Playable
|
||||
@Override
|
||||
public void sendMessage(String message)
|
||||
{
|
||||
if (Config.MULTILANG_ENABLE)
|
||||
{
|
||||
final String localisation = SendMessageLocalisationData.getInstance().getLocalisation(_lang, message);
|
||||
if (localisation != null)
|
||||
{
|
||||
sendPacket(new SystemMessage(localisation));
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendPacket(new SystemMessage(message));
|
||||
sendPacket(new SystemMessage(SendMessageLocalisationData.getLocalisation(this, message)));
|
||||
}
|
||||
|
||||
public void setObserving(boolean state)
|
||||
|
@ -17,6 +17,7 @@
|
||||
package org.l2jmobius.gameserver.util;
|
||||
|
||||
import org.l2jmobius.Config;
|
||||
import org.l2jmobius.gameserver.data.xml.impl.SendMessageLocalisationData;
|
||||
import org.l2jmobius.gameserver.enums.ChatType;
|
||||
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
|
||||
import org.l2jmobius.gameserver.network.serverpackets.CreatureSay;
|
||||
@ -41,7 +42,7 @@ public class BuilderUtil
|
||||
{
|
||||
if (Config.GM_STARTUP_BUILDER_HIDE)
|
||||
{
|
||||
player.sendPacket(new CreatureSay(null, ChatType.GENERAL, "SYS", message));
|
||||
player.sendPacket(new CreatureSay(null, ChatType.GENERAL, "SYS", SendMessageLocalisationData.getLocalisation(player, message)));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Reference in New Issue
Block a user