[HELP] Custom XML Buffer

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
sponer
Posts: 86
Joined: Sat Jul 02, 2011 6:02 am

[HELP] Custom XML Buffer

Post by sponer »

Hello guys.

I want to create an xml buffer that gets the buff id and level from an xml file and store it in memory..
Sorry for my double post but the previous one was kinda unrelated with this...

I have got the NpcBufferTable from datatables and i tried to make it work and read from xml... here:

Code: Select all

/* * Copyright (C) 2004-2014 L2J Server *  * This file is part of L2J Server. *  * L2J Server 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. *  * L2J Server 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.datatables; import java.util.ArrayList;import java.util.List;import java.util.logging.Logger; import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node; import com.l2jserver.gameserver.engines.DocumentParser;import com.l2jserver.gameserver.model.StatsSet;import com.l2jserver.gameserver.model.holders.SkillHolder; public class CustomNpcBufferData extends DocumentParser{    private static final Logger _log = Logger.getLogger(CustomNpcBufferData.class.getName());        private final List<NpcBufferSkills> _buffers = new ArrayList<>();        int skillCount = 0;        protected CustomNpcBufferData()    {        load();    }        public static class NpcBufferData    {        private final SkillHolder _skill;                protected NpcBufferData(int skillId, int skillLevel)        {            _skill = new SkillHolder(skillId, skillLevel);        }                public SkillHolder getSkill()        {            return _skill;        }    }        private static class NpcBufferSkills    {        private final List<NpcBufferData> _skills = new ArrayList<>();                protected NpcBufferSkills(int npcId)        {        }                public void addSkill(int skillId, int skillLevel)        {            _skills.add(new NpcBufferData(skillId, skillLevel));        }    }        @Override    public synchronized void load()    {        parseDatapackDirectory("data/stats/buffs", false);        _log.info(getClass().getSimpleName() + ": Loaded " + _buffers.size() + " buffs");    }        @Override    protected void parseDocument()    {        NpcBufferSkills skills = null;        int lastNpcId = 0;        int getSkillId = 0;        int getSkillLevel = 0;                for (Node node = getCurrentDocument().getFirstChild(); node != null; node = node.getNextSibling())        {            for (Node list_node = node.getFirstChild(); list_node != null; list_node = list_node.getNextSibling())            {                if ("npc".equalsIgnoreCase(list_node.getNodeName()))                {                    NamedNodeMap attrs = list_node.getAttributes();                    final StatsSet set = new StatsSet();                    final int npcId = parseInteger(attrs, "id");                    set.set("id", npcId);                    for (Node npc_node = list_node.getFirstChild(); npc_node != null; npc_node = npc_node.getNextSibling())                    {                        attrs = npc_node.getAttributes();                        switch (npc_node.getNodeName().toLowerCase())                        {                            case "skill":                            {                                for (Node skill_node = npc_node.getFirstChild(); skill_node != null; skill_node = skill_node.getNextSibling())                                {                                    if ("skill".equalsIgnoreCase(skill_node.getNodeName()))                                    {                                        attrs = skill_node.getAttributes();                                        final int skillId = parseInteger(attrs, "id");                                        final int skillLevel = parseInteger(attrs, "level");                                        if (npcId != lastNpcId)                                        {                                            if (lastNpcId != 0)                                            {                                                _buffers.add(lastNpcId, skills);                                            }                                                                                        skills = new NpcBufferSkills(npcId);                                            skills.addSkill(skillId, skillLevel);                                        }                                        else if (skills != null)                                        {                                            skills.addSkill(skillId, skillLevel);                                        }                                                                                lastNpcId = npcId;                                        skillCount++;                                        getSkillId = skillId;                                        getSkillLevel = skillLevel;                                    }                                    else                                    {                                        _log.warning("[" + getCurrentFile().getName() + "] skill not found. NPC ID: " + npcId + " Skill ID:" + getSkillId + " Skill Level: " + getSkillLevel);                                    }                                }                            }                                break;                        }                    }                }            }        }    }        public static CustomNpcBufferData getInstance()    {        return SingletonHolder._instance;    }        private static class SingletonHolder    {        protected static final CustomNpcBufferData _instance = new CustomNpcBufferData();    }}
now the problem is that the buffs doesn't loading in startup.. (btw i placed the instance into GameServer.java)
the code is running but in this part:

Code: Select all

parseDatapackDirectory("data/stats/buffs", false);
it's like it doesn't do nothing... with the result of:

Code: Select all

CustomNpcBufferData: Loaded 0 buffs.
I already have an xml file with some buffs in the location
and i already have a java buffer that i want to read the buffs i want from memory...
Actually i did the most part of the code but my brain doesn't roll to find how to save the buffs into a map or list and get them as skills in game... :P
User avatar
sponer
Posts: 86
Joined: Sat Jul 02, 2011 6:02 am

Re: [HELP] Custom XML Buffer

Post by sponer »

bump
Post Reply