Здравствуйте ув. пользователи (кроме Deazer'a наркошки). Выкладываю свой парсер-конвертер спавна инстанс зон l2j форках в Over форки.
P.S. Mangol дядька прювейт!!!!
ConvSpawnL2jToOver.java
Для тех кто не умеет генерировать конструктор для инсерта в коллекцию по заданым критериям.
SpawnInfo.java
П.С. писалось под структуру:
Parse:
<location heading="39048" npcId="19212" respawn="60" x="116743" y="-183026" z="-1608"/>
Include:
<spawn npcId="19212" respawn="60">
<location x="116743" y="-183026" z="-1608" heading="39048"/>
</spawn>
П.П.С. фреймы - jdom2, dom4j
P.S. Mangol дядька прювейт!!!!
ConvSpawnL2jToOver.java
Код:
/**
* User: GenCloud
* Date: 02.07.2015
* Team: La2Era Team
*/
public class ConvSpawnL2jToOver
{
private static final List<SpawnInfo> spawn = new ArrayList<>();
private static ConvSpawnL2jToOver instance;
public ConvSpawnL2jToOver()
{
parse();
insert();
}
public static ConvSpawnL2jToOver getInstance()
{
return instance == null ? instance = new ConvSpawnL2jToOver() : null;
}
private void parse()
{
try
{
File file = new File("./data/spawn/data/spawn.xml");
SAXBuilder builder = new SAXBuilder();
builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
Document doc = builder.build(file);
for(final Element element : doc.getRootElement().getChildren())
{
String name = element.getName();
if (name.equalsIgnoreCase("location"))
{
final int npcId = Integer.parseInt(element.getAttributeValue("npcId"));
final int respawn = Integer.parseInt(element.getAttributeValue("respawn"));
final int x = Integer.parseInt(element.getAttributeValue("x"));
final int y = Integer.parseInt(element.getAttributeValue("y"));
final int z = Integer.parseInt(element.getAttributeValue("z"));
final int h = Integer.parseInt(element.getAttributeValue("respawn"));
SpawnInfo spawnInfo = new SpawnInfo(npcId, respawn, x, y, z, h);
spawn.add(spawnInfo);
}
}
}
catch (JDOMException | IOException e)
{
e.printStackTrace();
}
}
private void insert()
{
try
{
org.dom4j.Document doc = DocumentHelper.createDocument();
org.dom4j.Element element = doc.getRootElement();
spawn.forEach(s -> {
org.dom4j.Element spawnInfo = element.addElement("spawn");
spawnInfo.addAttribute("npcId", String.valueOf(s.getNpcId()));
spawnInfo.addAttribute("respawn", String.valueOf(s.getRespawnTime()));
org.dom4j.Element loc = spawnInfo.addElement("location");
loc.addAttribute("x", String.valueOf(s.getX()));
loc.addAttribute("y", String.valueOf(s.getY()));
loc.addAttribute("z", String.valueOf(s.getZ()));
loc.addAttribute("heading", String.valueOf(s.getH()));
});
org.dom4j.Document doc1 = doc.getDocument();
OutputFormat of = new OutputFormat("\t", true);
of.setOmitEncoding(false);
of.setEncoding("UTF-8");
XMLWriter writer = null;
File file = new File("./data/spawn/finish/spawn.xml");
try
{
writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF8"), of);
writer.write(doc1);
}
finally
{
if(writer != null)
{
writer.flush();
writer.close();
}
}
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
SpawnInfo.java
Код:
/**
* User: GenCloud
* Date: 02.07.2015
* Team: La2Era Team
*/
public class SpawnInfo
{
private final int npcId;
private final int respawnTime;
private final int x;
private final int y;
private final int z;
private final int h;
public SpawnInfo(int npcId, int respawnTime, int x, int y, int z, int h) {
this.npcId = npcId;
this.respawnTime = respawnTime;
this.x = x;
this.y = y;
this.z = z;
this.h = h;
}
public int getNpcId() {
return npcId;
}
public int getRespawnTime() {
return respawnTime;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public int getH() {
return h;
}
public int getZ() {
return z;
}
}
П.С. писалось под структуру:
Parse:
<location heading="39048" npcId="19212" respawn="60" x="116743" y="-183026" z="-1608"/>
Include:
<spawn npcId="19212" respawn="60">
<location x="116743" y="-183026" z="-1608" heading="39048"/>
</spawn>
П.П.С. фреймы - jdom2, dom4j
Последнее редактирование: