This is my idea but not tested and not fully completed..
Cuz i got lazy to do Enums and i did it like Zoey76 began with ids xD
Core:
[diff]Index: java/com/l2jserver/gameserver/instancemanager/CustomMessages.java===================================================================--- java/com/l2jserver/gameserver/instancemanager/CustomMessages.java (revision 0)+++ java/com/l2jserver/gameserver/instancemanager/CustomMessages.java (revision 0)@@ -0,0 +1,121 @@+/*+ * 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 com.l2jserver.gameserver.instancemanager;++import java.io.File;+import java.util.List;+import java.util.Map;+import java.util.logging.Level;+import java.util.logging.Logger;++import javolution.util.FastList;+import javolution.util.FastMap;++import com.l2jserver.Config;+import com.l2jserver.gameserver.model.CustomLanguage;+++/**+ * @author UnAfraid+ *+ */+public class CustomMessages+{+ private final Logger _log = Logger.getLogger(getClass().getName());+ private Map<String, CustomLanguage> _languages;+ + public CustomMessages()+ {+ _languages = new FastMap<String, CustomLanguage>();+ load();+ }+ + public void load()+ {+ List<File> files = new FastList<File>();+ hashFiles("lang", files);+ for (File file : files)+ {+ try+ {+ String name = file.getName().replaceAll(".xml", "");+ _languages.put(name, new CustomLanguage(file));+ _log.log(Level.INFO, getClass().getSimpleName() + ": Loading Custom language file: " + name);+ }+ catch (Exception e)+ {+ _log.log(Level.SEVERE, "Error loading file " + file, e);+ continue;+ }+ }+ + _log.log(Level.SEVERE, getClass().getSimpleName() + ": Loaded " + _languages.size() + " Custom languages");+ }+ + public String getMessage(int id, String language)+ {+ String msg = null;+ if (_languages.containsKey(language))+ {+ CustomLanguage lang = _languages.get(language);+ msg = lang.getMessage(id);+ if (msg == null)+ {+ _log.log(Level.SEVERE, getClass().getSimpleName() + ": Missing custom language id: " + id + " for language: " + language);+ if (Config.DEBUG)+ new Throwable().printStackTrace();+ + if (_languages.containsKey(Config.L2JMOD_MULTILANG_DEFAULT))+ msg = _languages.get(Config.L2JMOD_MULTILANG_DEFAULT).getMessage(id);+ }+ }+ else+ {+ _log.log(Level.SEVERE, getClass().getSimpleName() + ": Missing custom language: " + language);+ if (Config.DEBUG)+ new Throwable().printStackTrace();+ msg = "";+ }+ return msg;+ }+ + private final void hashFiles(String dirname, List<File> hash)+ {+ File dir = new File(Config.DATAPACK_ROOT, "data/" + dirname);+ if (!dir.exists())+ {+ _log.config("Dir " + dir.getAbsolutePath() + " not exists");+ return;+ }+ + File[] files = dir.listFiles();+ for (File f : files)+ {+ if (f.getName().endsWith(".xml"))+ hash.add(f);+ }+ }+ + public static CustomMessages getInstance()+ {+ return SingletonHolder._instance;+ }+ + @SuppressWarnings("synthetic-access")+ private static class SingletonHolder+ {+ protected static final CustomMessages _instance = new CustomMessages();+ }+}Index: java/com/l2jserver/gameserver/GameServer.java===================================================================--- java/com/l2jserver/gameserver/GameServer.java (revision 4488)+++ java/com/l2jserver/gameserver/GameServer.java (working copy)@@ -92,6 +92,7 @@ import com.l2jserver.gameserver.instancemanager.ClanHallManager; import com.l2jserver.gameserver.instancemanager.CoupleManager; import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;+import com.l2jserver.gameserver.instancemanager.CustomMessages; import com.l2jserver.gameserver.instancemanager.DayNightSpawnManager; import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager; import com.l2jserver.gameserver.instancemanager.FortManager;@@ -307,6 +308,7 @@ HelperBuffTable.getInstance(); AugmentationData.getInstance(); CursedWeaponsManager.getInstance();+ CustomMessages.getInstance(); printSection("Scripts"); QuestManager.getInstance();Index: java/com/l2jserver/gameserver/model/CustomLanguage.java===================================================================--- java/com/l2jserver/gameserver/model/CustomLanguage.java (revision 0)+++ java/com/l2jserver/gameserver/model/CustomLanguage.java (revision 0)@@ -0,0 +1,108 @@+/*+ * 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 com.l2jserver.gameserver.model;++import java.io.File;+import java.util.Map;+import java.util.logging.Level;+import java.util.logging.Logger;++import javax.xml.parsers.DocumentBuilderFactory;++import javolution.util.FastMap;++import org.w3c.dom.Document;+import org.w3c.dom.NamedNodeMap;+import org.w3c.dom.Node;++/**+ * @author UnAfraid+ *+ */+public class CustomLanguage+{+ private final Logger _log = Logger.getLogger(getClass().getName());+ Map<Integer, String> _messages;+ + public CustomLanguage(File file)+ {+ _messages = new FastMap<Integer, String>();+ load(file);+ }+ + public String getMessage(int id)+ {+ if (_messages.containsKey(id))+ return _messages.get(id);+ else+ return null;+ }+ + public void load(File file)+ {+ _messages.clear();+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();+ factory.setValidating(false);+ factory.setIgnoringComments(true);+ Document doc = null;+ if (file.exists())+ {+ try+ {+ doc = factory.newDocumentBuilder().parse(file);+ }+ catch (Exception e)+ {+ _log.log(Level.WARNING, "Could not parse " + file.getName() + " file: " + e.getMessage(), e);+ }+ + for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())+ {+ if ("list".equalsIgnoreCase(n.getNodeName()))+ {+ for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())+ {+ if ("msg".equalsIgnoreCase(d.getNodeName()))+ {+ NamedNodeMap attrs = d.getAttributes();+ Node att;+ int id = 0;+ String text = null;+ + att = attrs.getNamedItem("id");+ if (att == null)+ {+ _log.severe(getClass().getSimpleName() + " Missing id, skipping");+ continue;+ }+ id = Integer.parseInt(att.getNodeValue());+ + att = attrs.getNamedItem("text");+ if (att == null)+ {+ _log.severe(getClass().getSimpleName() + " Missing text, skipping");+ continue;+ }+ text = att.getNodeValue();+ + _messages.put(id, text);+ }+ }+ }+ }+ }+ _log.log(Level.SEVERE, getClass().getSimpleName() + ": Loaded: [" + file.getName().replaceAll(".xml", "") + "] " + _messages.size() + " Custom Messages");+ }+}Index: java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java===================================================================--- java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java (revision 4488)+++ java/com/l2jserver/gameserver/model/actor/instance/L2PcInstance.java (working copy)@@ -79,6 +79,7 @@ import com.l2jserver.gameserver.instancemanager.CastleManager; import com.l2jserver.gameserver.instancemanager.CoupleManager; import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;+import com.l2jserver.gameserver.instancemanager.CustomMessages; import com.l2jserver.gameserver.instancemanager.DimensionalRiftManager; import com.l2jserver.gameserver.instancemanager.DuelManager; import com.l2jserver.gameserver.instancemanager.FortManager;@@ -5263,10 +5264,10 @@ if (answer == 1) { CoupleManager.getInstance().createCouple(ptarget, L2PcInstance.this);- ptarget.sendMessage("Request to Engage has been >ACCEPTED<");+ ptarget.sendMessage(CustomMessages.getInstance().getMessage(5, ptarget.getHtmlPrefix())); // Request to Engage has been >ACCEPTED< } else- ptarget.sendMessage("Request to Engage has been >DENIED<!");+ ptarget.sendMessage(CustomMessages.getInstance().getMessage(6, ptarget.getHtmlPrefix())); // Request to Engage has been >DENIED<! } } }Index: java/com/l2jserver/gameserver/communitybbs/Manager/RegionBBSManager.java===================================================================--- java/com/l2jserver/gameserver/communitybbs/Manager/RegionBBSManager.java (revision 4488)+++ java/com/l2jserver/gameserver/communitybbs/Manager/RegionBBSManager.java (working copy)@@ -26,6 +26,7 @@ import com.l2jserver.Config; import com.l2jserver.gameserver.GameServer;+import com.l2jserver.gameserver.instancemanager.CustomMessages; import com.l2jserver.gameserver.model.BlockList; import com.l2jserver.gameserver.model.L2World; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;@@ -192,7 +193,7 @@ try {- + CustomMessages msgs = CustomMessages.getInstance(); L2PcInstance receiver = L2World.getInstance().getPlayer(ar2); if (receiver == null) {@@ -203,7 +204,7 @@ } if (Config.JAIL_DISABLE_CHAT && receiver.isInJail()) {- activeChar.sendMessage("Player is in jail.");+ activeChar.sendMessage(msgs.getMessage(1, activeChar.getHtmlPrefix())); // Player is in jail. return; } if (receiver.isChatBanned())@@ -208,7 +209,7 @@ } if (receiver.isChatBanned()) {- activeChar.sendMessage("Player is chat banned.");+ activeChar.sendMessage(msgs.getMessage(2, activeChar.getHtmlPrefix())); // Player is chat banned. return; } if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT)@@ -213,7 +214,7 @@ } if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT) {- activeChar.sendMessage("You can not chat while in jail.");+ activeChar.sendMessage(msgs.getMessage(3, activeChar.getHtmlPrefix())); // You can not chat while in jail. return; } if (activeChar.isChatBanned())@@ -218,7 +219,7 @@ } if (activeChar.isChatBanned()) {- activeChar.sendMessage("You are banned from using chat");+ activeChar.sendMessage(msgs.getMessage(4, activeChar.getHtmlPrefix())); // You are banned from using chat return; } [/diff]
DP:
[diff]Index: data/lang/en.xml===================================================================--- data/lang/en.xml (revision 0)+++ data/lang/en.xml (revision 0)@@ -0,0 +1,7 @@+<?xml version="1.0" encoding="UTF-8"?>+<list>+ <msg id="1" text="Player is in jail." />+ <msg id="2" text="Player is chat banned." />+ <msg id="3" text="You can not chat while in jail." />+ <msg id="4" text="You are banned from using chat." />+</list>\ No newline at end of fileIndex: data/lang/ru.xml===================================================================--- data/lang/ru.xml (revision 0)+++ data/lang/ru.xml (revision 0)@@ -0,0 +1,9 @@+<?xml version="1.0" encoding="UTF-8"?>+<list>+ <msg id="1" text="Игрок находится в тюрьме." />+ <msg id="2" text="Чат игрока заблокирован." />+ <msg id="3" text="Вы не можете общаться, когда находитесь в тюрьме." />+ <msg id="4" text="Использование чата запрещено." />+ <msg id="5" text="Запрос на помолвку принят!" />+ <msg id="6" text="Запрос на помолвку отклонен!" />+</list>\ No newline at end of file [/diff]