package org.mmocore.gameserver;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.mmocore.gameserver.data.xml.holder.ItemHolder;
import org.mmocore.gameserver.data.xml.parser.ItemParser;
import org.mmocore.gameserver.data.xml.parser.OptionDataParser;
import org.mmocore.gameserver.tables.SkillTable;
import org.mmocore.gameserver.templates.item.ItemTemplate;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Collection;
/**
* @[member='Authority'] Mangol
*/
public final class RemoveNpcDrop {
public static void main(String[] args) throws IOException, DocumentException {
SkillTable.getInstance().load();
OptionDataParser.getInstance().load();
ItemParser.getInstance().load();
final Collection<File> files = FileUtils.listFiles(new File("./data/npc/"), FileFilterUtils.suffixFileFilter(".xml"), FileFilterUtils.directoryFileFilter());
for(File f : files) {
if(!f.isHidden()) {
final SAXReader reader = new SAXReader();
reader.setValidation(false);
Document document = reader.read(f);
for(final Element element : document.getRootElement().elements()) {
final int npcId = Integer.parseInt(element.attributeValue("id"));
element.elements().stream().filter(block -> block.getName().equalsIgnoreCase("rewardlist")).forEach(block -> {
for(Element e : block.elements()) {
if(e.getName().equalsIgnoreCase("group")) {
for(Element r : e.elements()) {
int itemId = Integer.parseInt(r.attributeValue("item_id"));
if(itemId != 57)
e.detach();
/* ItemTemplate template = ItemHolder.getInstance().getTemplate(itemId);
if(template == null)
continue;
if(template.isHerb() || template.isCommonItem() || template.isRecipe() || template.getItemClass() == ItemTemplate.ItemClass.MATHERIALS || template.getItemClass() == ItemTemplate.ItemClass.SPELLBOOKS)
r.detach();*/
if(e.elements().isEmpty())
e.detach();
}
}
else if(e.getName().equalsIgnoreCase("reward")) {
int itemId = Integer.parseInt(e.attributeValue("item_id"));
if(itemId != 57)
e.detach();
/* ItemTemplate template = ItemHolder.getInstance().getTemplate(itemId);
if(template == null)
continue;
if(template.isHerb() || template.isCommonItem() || template.isRecipe() || template.getItemClass() == ItemTemplate.ItemClass.MATHERIALS || template.getItemClass() == ItemTemplate.ItemClass.SPELLBOOKS)
e.detach();*/
}
}
if(block.elements().isEmpty())
block.detach();
});
}
OutputFormat of = new OutputFormat("\t", true);
of.setOmitEncoding(false);
of.setEncoding("UTF-8");
XMLWriter writer = null;
try {
String name = "/".split(document.getName())["/".split(document.getName()).length - 1];
writer = new XMLWriter(new OutputStreamWriter(new FileOutputStream("./data/new_npc/" + name), "UTF8"), of);
writer.write(document);
}
finally {
if(writer != null) {
writer.flush();
writer.close();
}
}
}
}
}
}
finally {
if(writer != null) {
writer.flush();
writer.close();
вот зачем этот слушатель?
мы будем юзать каждым игроком его по 80 раз?
что это за бред?
объясни как оно работает?