All pastes #962222 Raw Edit

Mine

public java v1 · immutable
#962222 ·published 2008-03-29 16:32 UTC
rendered paste body
/* * This program 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. *  * This program 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/>. *//** * @author Forsaiken */package net.sf.l2j.gameserver.handler;import java.io.File;import java.util.logging.Logger;import javax.xml.parsers.DocumentBuilderFactory;import net.sf.l2j.Config;import net.sf.l2j.gameserver.model.L2Skill;import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;import net.sf.l2j.util.L2FastList;import net.sf.l2j.util.L2FastMap;import org.w3c.dom.Document;import org.w3c.dom.NamedNodeMap;import org.w3c.dom.Node;public final class SkillLearnModTable{    private static final Logger _log = Logger.getLogger(SkillLearnModTable.class.getName());        private static SkillLearnModTable _instance;        public static SkillLearnModTable getInstance()    {        if (_instance == null)            _instance = new SkillLearnModTable();        return _instance;    }        private SkillLearnModTable()    {        load();    }        private L2FastMap<Integer, L2FastList<Integer>> _stackingSkills;        public void load()    {        _stackingSkills = new L2FastMap<Integer, L2FastList<Integer>>();                        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();        factory.setValidating(false);        factory.setIgnoringComments(true);                File file = new File(Config.DATAPACK_ROOT + "/data/mods/skillstacking.xml");        if (!file.exists())        {            _log.info("The skillstacking.xml file is missing.");            return;        }                try        {            Document doc = factory.newDocumentBuilder().parse(file);            for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())            {                if ("list".equalsIgnoreCase(n.getNodeName()))                {                    for (Node na = n.getFirstChild(); na != null; na = na.getNextSibling())                    {                        if ("skillgroup".equalsIgnoreCase(na.getNodeName()))                        {                            L2FastList<Integer> stackingSkills = new L2FastList<Integer>();                            for (Node nb = na.getFirstChild(); nb != null; nb = nb.getNextSibling())                            {                                if ("skill".equalsIgnoreCase(nb.getNodeName()))                                {                                    NamedNodeMap attrs = nb.getAttributes();                                    final int skill_id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());                                    stackingSkills.add(skill_id);                                }                            }                            _log.info("SKILL MOD LEARN: NEW SKILL STACK GROUP");                            for (final int skill_id : stackingSkills)                            {                                _log.info("ID "+skill_id);                                _stackingSkills.put(skill_id, stackingSkills);                            }                        }                    }                }            }        }        catch (Exception e)        {            e.printStackTrace();        }    }        /**     * Check if the skill_id stack with the players current skills.     * @param player who wants to learn the skill     * @param skill_id of the skill the player wants to learn     * @return true if stacking     */    public final boolean isStacking(L2PcInstance player, final int skill_id)    {        if (_stackingSkills.containsKey(skill_id))        {            System.out.println("Player want to learn a skill wich is marked to be stackable" + skill_id);                        L2FastList<Integer> tempList = _stackingSkills.get(skill_id);                        L2Skill[] skills = player.getAllSkills();            System.out.println("1");            if (skills != null && tempList != null)            {                System.out.println("2");                for (L2Skill skill : skills)                {                    if (skill != null)                    {                        System.out.println("3");                                                final int temp = skill.getId();                                                if (temp == skill_id)                        {                            System.out.println("Loop over skill wich player allready have...continue" + skill_id);                            continue;                        }                                                if (tempList.contains(temp))                        {                            System.out.println("player have allready: "+temp+" and is not allowed to learn "+skill_id);                            return true;                        }                    }                }            }        }        return false;    }}