Тема: Grind Team
Показать сообщение отдельно

  #11  
Старый 07.08.2015, 20:21
L2CCCP
Постоянный
Регистрация: 07.07.2015
Сообщений: 486
С нами: 5710893

Репутация: 0
По умолчанию

[QUOTE="kick"]

Реализация автоанонсов просто нечто, уровень 2007 года.
[QUOTE="Спойлер"]
[COLOR="#363940"]
package core.gameserver.instancemanager;

import java.io.File;

import java.util.ArrayList;

import java.util.HashMap;

import javax.xml.parsers.DocumentBuilderFactory;

import core.gameserver.Announcements;

import core.gameserver.Config;

import core.gameserver.model.AutoAnnounces;

import org.w3c.dom.Document;

import org.w3c.dom.NamedNodeMap;

import org.w3c.dom.Node;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

public class AutoAnnounce implements Runnable

{

private static final Logger _log = LoggerFactory.getLogger(AutoAnnounce.class);

private static AutoAnnounce _instance;

static HashMap _lists;

public static AutoAnnounce getInstance()

{

if(_instance == null)

_instance = new AutoAnnounce();

return _instance;

}

public static void reload()

{

_instance = new AutoAnnounce();

}

public AutoAnnounce()

{

_lists = new HashMap();

_log.info("AutoAnnounce: Initializing");

load();

_log.info("AutoAnnounce: Loaded " + _lists.size() + " announce.");

}

private void load()

{

try

{

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setValidating(false);

factory.setIgnoringComments(true);

File file = new File("./config/autoannounce.xml");

if(!file.exists())

{

_log.warn("AutoAnnounce: NO FILE (./config/autoannounce.xml)");

return;

}

Document doc = factory.newDocumentBuilder().parse(file);

int counterAnnounce = 0;

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("announce".equalsIgnoreCase(d.getNodeName()))

{

ArrayList msg = new ArrayList();

NamedNodeMap attrs = d.getAttributes();

int delay = Integer.parseInt(attrs.getNamedItem("delay").getNo deValue());

int repeat = Integer.parseInt(attrs.getNamedItem("repeat").getN odeValue());

AutoAnnounces aa = new AutoAnnounces(counterAnnounce);

for(Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())

{

if("message".equalsIgnoreCase(cd.getNodeName()))

msg.add(String.valueOf(cd.getAttributes().getNamed Item("text").getNodeValue()));

}

aa.setAnnounce(delay, repeat, msg);

_lists.put(counterAnnounce, aa);

counterAnnounce++;

}

}

}

_log.info("AutoAnnounce: Load OK");

}

catch(Exception e)

{

_log.warn("AutoAnnounce: Error parsing autoannounce.xml file. " + e);

}

}

public void run()

{

if(_lists.size() msg = _lists.get(i).getMessage();

for(int c = 0; c
 
Ответить с цитированием