public class BBSTeleportParser extends AbstractFileParser<BBSTeleportHolder>
{
private static final BBSTeleportParser INSTANCE = new BBSTeleportParser();
public static BBSTeleportParser getInstance()
{
return INSTANCE;
}
protected BBSTeleportParser()
{
super(BBSTeleportHolder.getInstance());
}
@Override
public File getXMLFile()
{
return new File(Config.DATAPACK_ROOT, "data/teleports.xml");
}
@Override
public String getDTDFileName()
{
return "teleports.dtd";
}
@Override
protected void readData(final BBSTeleportHolder holder, final Element rootElement) throws Exception
{
for(final Element pointElement : rootElement.getChildren())
{
final int id = Integer.parseInt(pointElement.getAttributeValue("id"));
final String name = pointElement.getAttributeValue("name");
final int min = Integer.parseInt(pointElement.getAttributeValue("min"));
final int max = Integer.parseInt(pointElement.getAttributeValue("max"));
final boolean pk = Boolean.parseBoolean(pointElement.getAttributeValue("pk"));
final boolean isPremiumPoint = Boolean.parseBoolean(pointElement.getAttributeValue("isPremiumPoint"));
final TeleportPoint teleport = new TeleportPoint(id, name, min, max, pk, isPremiumPoint);
for(final Element staticInfo : pointElement.getChildren())
{
final String nameInfo = staticInfo.getName();
if(nameInfo.equalsIgnoreCase("cost"))
{
final int item = Integer.parseInt(staticInfo.getAttributeValue("Item"));
final int count = Integer.parseInt(staticInfo.getAttributeValue("Count"));
final int premium_item = Integer.parseInt(staticInfo.getAttributeValue("PremiumItem"));
final int premium_count = Integer.parseInt(staticInfo.getAttributeValue("PremiumCount"));
teleport.setCost(item, count, premium_item, premium_count);
}
else if(nameInfo.equalsIgnoreCase("coordinates"))
{
final int x = Integer.parseInt(staticInfo.getAttributeValue("x"));
final int y = Integer.parseInt(staticInfo.getAttributeValue("y"));
final int z = Integer.parseInt(staticInfo.getAttributeValue("z"));
teleport.setCoordinate(x, y, z);
}
}
holder.addToBuyList(id, teleport);
}
}