Addition of localisations for custom player messages.

This commit is contained in:
MobiusDevelopment
2019-07-13 10:26:43 +00:00
parent 6d4d57cf6c
commit 95ba581cf5
78 changed files with 2457 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Replaces PlayerInstance sendMessage method messages with translated text. -->
<!-- No pretty way of doing something like this. Consider using proper SystemMessages where possible. Keep this list short. -->
<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../xsd/SendMessageLocalisation.xsd">
<localisation message="Entering world in Invulnerable mode." translation="Είσοδος στον κόσμο σε Άτρωτη κατάσταση." />
<localisation message="Entering world in Invisible mode." translation="Είσοδος στον κόσμο σε Αόρατη κατάσταση." />
<localisation message="Entering world in Silence mode." translation="Είσοδος στον κόσμο σε Σιωπηλή κατάσταση." />
<localisation message="You have learned XXX new skills." translation="Έμαθες XXX νέες ικανότητες." />
</list>

View File

@@ -40,6 +40,7 @@ import org.l2jmobius.gameserver.data.xml.impl.NpcData;
import org.l2jmobius.gameserver.data.xml.impl.OptionData;
import org.l2jmobius.gameserver.data.xml.impl.PrimeShopData;
import org.l2jmobius.gameserver.data.xml.impl.SayuneData;
import org.l2jmobius.gameserver.data.xml.impl.SendMessageLocalisationData;
import org.l2jmobius.gameserver.data.xml.impl.SkillData;
import org.l2jmobius.gameserver.data.xml.impl.TeleportersData;
import org.l2jmobius.gameserver.data.xml.impl.TransformData;
@@ -331,6 +332,7 @@ public class AdminReload implements IAdminCommandHandler
{
SystemMessageId.loadLocalisations();
NpcStringId.loadLocalisations();
SendMessageLocalisationData.getInstance().load();
AdminData.getInstance().broadcastMessageToGMs(activeChar.getName() + ": Reloaded Localisation data.");
break;
}

View File

@@ -0,0 +1,18 @@
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="list">
<xs:complexType>
<xs:sequence>
<xs:element name="localisation" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="message" use="required"/>
<xs:attribute type="xs:string" name="translation" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View File

@@ -86,6 +86,7 @@ import org.l2jmobius.gameserver.data.xml.impl.RecipeData;
import org.l2jmobius.gameserver.data.xml.impl.ResidenceFunctionsData;
import org.l2jmobius.gameserver.data.xml.impl.SayuneData;
import org.l2jmobius.gameserver.data.xml.impl.SecondaryAuthData;
import org.l2jmobius.gameserver.data.xml.impl.SendMessageLocalisationData;
import org.l2jmobius.gameserver.data.xml.impl.ShuttleData;
import org.l2jmobius.gameserver.data.xml.impl.SiegeScheduleData;
import org.l2jmobius.gameserver.data.xml.impl.SkillData;
@@ -341,6 +342,10 @@ public class GameServer
{
SellBuffsManager.getInstance();
}
if (Config.MULTILANG_ENABLE)
{
SendMessageLocalisationData.getInstance();
}
printSection("Scripts");
QuestManager.getInstance();

View File

@@ -0,0 +1,145 @@
/*
* This file is part of the L2J Mobius project.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.data.xml.impl;
import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import org.w3c.dom.Document;
import org.l2jmobius.Config;
import org.l2jmobius.commons.util.IXmlReader;
import org.l2jmobius.gameserver.model.StatsSet;
/**
* @author Mobius
*/
public class SendMessageLocalisationData implements IXmlReader
{
private final static Logger LOGGER = Logger.getLogger(SendMessageLocalisationData.class.getName());
private final static String SPLIT_STRING = "XXX";
private final static Map<String, Map<String[], String[]>> SEND_MESSAGE_LOCALISATIONS = new ConcurrentHashMap<>();
private static String _lang;
protected SendMessageLocalisationData()
{
load();
}
@Override
public void load()
{
SEND_MESSAGE_LOCALISATIONS.clear();
if (Config.MULTILANG_ENABLE)
{
for (String lang : Config.MULTILANG_ALLOWED)
{
final File file = new File("data/lang/" + lang + "/SendMessageLocalisation.xml");
if (!file.isFile())
{
continue;
}
SEND_MESSAGE_LOCALISATIONS.put(lang, new ConcurrentHashMap<String[], String[]>());
_lang = lang;
parseDatapackFile("data/lang/" + lang + "/SendMessageLocalisation.xml");
final int count = SEND_MESSAGE_LOCALISATIONS.get(lang).values().size();
if (count == 0)
{
SEND_MESSAGE_LOCALISATIONS.remove(lang);
}
else
{
LOGGER.info(getClass().getSimpleName() + ": Loaded localisations for '" + lang + "'");
}
}
}
}
@Override
public void parseDocument(Document doc, File f)
{
forEach(doc, "list", listNode -> forEach(listNode, "localisation", localisationNode ->
{
final StatsSet set = new StatsSet(parseAttributes(localisationNode));
SEND_MESSAGE_LOCALISATIONS.get(_lang).put(set.getString("message").split(SPLIT_STRING), set.getString("translation").split(SPLIT_STRING));
}));
}
public String getLocalisation(String lang, String message)
{
final Map<String[], String[]> localisations = SEND_MESSAGE_LOCALISATIONS.get(lang);
if (localisations != null)
{
// 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())
{
searchMessage = entry.getKey();
replacementMessage = entry.getValue();
// Exact match.
if (searchMessage.length == 1)
{
if (searchMessage[0].equals(message))
{
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]);
}
return message;
}
}
}
}
return null;
}
public static SendMessageLocalisationData getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final SendMessageLocalisationData INSTANCE = new SendMessageLocalisationData();
}
}

View File

@@ -72,6 +72,7 @@ import org.l2jmobius.gameserver.data.xml.impl.PetDataTable;
import org.l2jmobius.gameserver.data.xml.impl.PlayerTemplateData;
import org.l2jmobius.gameserver.data.xml.impl.PlayerXpPercentLostData;
import org.l2jmobius.gameserver.data.xml.impl.RecipeData;
import org.l2jmobius.gameserver.data.xml.impl.SendMessageLocalisationData;
import org.l2jmobius.gameserver.data.xml.impl.SkillData;
import org.l2jmobius.gameserver.data.xml.impl.SkillTreesData;
import org.l2jmobius.gameserver.datatables.ItemTable;
@@ -8986,6 +8987,15 @@ public final 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));
}