YANBuffer - Import problem?

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
DrGonzo
Posts: 16
Joined: Sun Sep 29, 2013 4:20 pm

YANBuffer - Import problem?

Post by DrGonzo »

L2J Revision: 6663
L2J DP: 10464

Java VM version: 1.8

Hi again guys, when I try to load YANBuffer on my server, i got this error in gs log:

Code: Select all

1. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 53)    import com.l2jserver.gameserver.model.effects.L2Effect;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.model.effects.L2Effect cannot be resolved----------2. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 142)    return YANBufferData.getInstance().getBufferNpc(npc.getNpcId());                                                        ^^^^^^^^The method getNpcId() is undefined for the type L2Npc----------3. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 162)    activeChar.clearBypass();               ^^^^^^^^^^^The method clearBypass() is undefined for the type L2PcInstance----------4. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 186)    activeChar.addBypass2(html.substring(start, finish2).trim());               ^^^^^^^^^^The method addBypass2(String) is undefined for the type L2PcInstance----------5. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 190)    activeChar.addBypass(html.substring(start, finish).trim());               ^^^^^^^^^The method addBypass(String) is undefined for the type L2PcInstance----------6. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 234)    Long amount = items.get(item.getValue().item.getItemId());                                                 ^^^^^^^^^The method getItemId() is undefined for the type L2Item----------7. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 239)    items.put(item.getValue().item.getItemId(), amount + item.getValue().amount);                                   ^^^^^^^^^The method getItemId() is undefined for the type L2Item----------8. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 245)    buff.skill.getEffects(playable, playable);    ^^^^^^^^^^L2Skill cannot be resolved to a type----------9. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 717)    final L2Effect[] effects = player.getAllEffects();          ^^^^^^^^L2Effect cannot be resolved to a type----------10. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 717)    final L2Effect[] effects = player.getAllEffects();                                      ^^^^^^^^^^^^^The method getAllEffects() is undefined for the type L2PcInstance----------11. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 718)    for (final L2Effect effect : effects)               ^^^^^^^^L2Effect cannot be resolved to a type----------12. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 728)    if (buff.skill.getId() == effect.getSkill().getId())        ^^^^^^^^^^L2Skill cannot be resolved to a type--------------------13. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 44)    import com.l2jserver.gameserver.datatables.NpcTable;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.datatables.NpcTable cannot be resolved----------14. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 45)    import com.l2jserver.gameserver.datatables.SkillTable;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.datatables.SkillTable cannot be resolved----------15. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 49)    import com.l2jserver.gameserver.model.skills.L2Skill;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.model.skills.L2Skill cannot be resolved----------16. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 71)    protected final L2Skill skill;                    ^^^^^^^L2Skill cannot be resolved to a type----------17. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 77)    protected Buff(String ident, L2Skill skill, BuffType type, Element elem)                                 ^^^^^^^L2Skill cannot be resolved to a type----------18. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 80)    this.skill = skill;    ^^^^^^^^^^L2Skill cannot be resolved to a type----------19. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 450)    L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel);    ^^^^^^^L2Skill cannot be resolved to a type----------20. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 450)    L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel);                    ^^^^^^^^^^SkillTable cannot be resolved----------21. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 495)    L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);                        ^^^^^^^^NpcTable cannot be resolved----------22. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 502)    _bufferNpcs.put(npc.getNpcId(), new BufferNpc(npc, curElem));                        ^^^^^^^^The method getNpcId() is undefined for the type L2NpcTemplate--------------------23. ERROR in D:\L2J\game\data\scripts\YANModPack\util\ItemRequirement.java (at line 38)    this.placeholder.addChild("id", String.valueOf(item.getItemId())).addChild("icon", item.getIcon()).addChild("name", item.getName()).addChild("amount", String.valueOf(amount));                                                        ^^^^^^^^^The method getItemId() is undefined for the type L2Item--------------------24. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferNpcBypassHandler.java (at line 55)    if (!activeChar.validateBypass(command))                    ^^^^^^^^^^^^^^The method validateBypass(String) is undefined for the type L2PcInstance----------24 problems (24 errors)L2Skill cannot be resolved to a typeThe import com.l2jserver.gameserver.model.effects.L2Effect cannot be resolvedThe import com.l2jserver.gameserver.datatables.NpcTable cannot be resolvedThe import com.l2jserver.gameserver.datatables.SkillTable cannot be resolvedThe import com.l2jserver.gameserver.model.skills.L2Skill cannot be resolvedThe method getNpcId() is undefined for the type com.l2jserver.gameserver.model.actor.L2NpcThe method clearBypass() is undefined for the type com.l2jserver.gameserver.model.actor.instance.L2PcInstanceThe method addBypass2(java.lang.String) is undefined for the type com.l2jserver.gameserver.model.actor.instance.L2PcInstanceThe method addBypass(java.lang.String) is undefined for the type com.l2jserver.gameserver.model.actor.instance.L2PcInstanceThe method getItemId() is undefined for the type com.l2jserver.gameserver.model.items.L2ItemThe method getItemId() is undefined for the type com.l2jserver.gameserver.model.items.L2ItemL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeL2Effect cannot be resolved to a typeThe method getAllEffects() is undefined for the type com.l2jserver.gameserver.model.actor.instance.L2PcInstanceL2Effect cannot be resolved to a typeL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeSkillTable cannot be resolvedNpcTable cannot be resolvedThe method getNpcId() is undefined for the type com.l2jserver.gameserver.model.actor.templates.L2NpcTemplateThe method getItemId() is undefined for the type com.l2jserver.gameserver.model.items.L2ItemThe method validateBypass(java.lang.String) is undefined for the type com.l2jserver.gameserver.model.actor.instance.L2PcInstance[14/10 00:39:44] Failed executing script: D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBuffer.java. See YANBuffer.java.error.log for details.
My problem is really similar to this post: viewtopic.php?f=81&t=29540


- Actually I use latest trunk version of L2j server and datapack.
- Used HighFive/stable pack of YANBuffer
- scripts.cfg is ok.
- custom NPC in stats/npcs/custom/custom.xml is ok.
- custom tables are set all to true in General properties.
- I have run the SQL on l2jgs DB.

It seems there are importing problems? What do I need to change?
Thanks vm again


P.S.
When I used YANBuffer on my old server (version 6445 and DP 9641) I had NO problems with it. Currently Im on a Windows L2J sandbox, dedicated server runs Centos.
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: YANBuffer - Import problem?

Post by Zoey76 »

Trunk and beta has been recently merged, you may need to use the "beta" version that should work fine for new methods and imports. :wink:
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
DrGonzo
Posts: 16
Joined: Sun Sep 29, 2013 4:20 pm

Re: YANBuffer - Import problem?

Post by DrGonzo »

Thanks Zoey, I just tried what you said.

Same configuration, but now I used unstable version of YANBuffer instead of stable.
Few errors, 11 instead of 24, but 3 imports failed and script still doesn't work.. :?

Here's the log..

Code: Select all

1. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 165)    buff.skill.applyEffects(playable, playable);    ^^^^^^^^^^L2Skill cannot be resolved to a type----------2. ERROR in \YANModPack\YANBuffer\YANBuffer.java (at line 648)    if (buff.skill.getId() == effect.getSkill().getId())        ^^^^^^^^^^L2Skill cannot be resolved to a type--------------------3. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 44)    import com.l2jserver.gameserver.datatables.NpcTable;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.datatables.NpcTable cannot be resolved----------4. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 45)    import com.l2jserver.gameserver.datatables.SkillTable;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.datatables.SkillTable cannot be resolved----------5. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 49)    import com.l2jserver.gameserver.model.skills.L2Skill;           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^The import com.l2jserver.gameserver.model.skills.L2Skill cannot be resolved----------6. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 71)    protected final L2Skill skill;                    ^^^^^^^L2Skill cannot be resolved to a type----------7. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 77)    protected Buff(String ident, L2Skill skill, BuffType type, Element elem)                                 ^^^^^^^L2Skill cannot be resolved to a type----------8. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 80)    this.skill = skill;    ^^^^^^^^^^L2Skill cannot be resolved to a type----------9. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 450)    L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel);    ^^^^^^^L2Skill cannot be resolved to a type----------10. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 450)    L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel);                    ^^^^^^^^^^SkillTable cannot be resolved----------11. ERROR in D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBufferData.java (at line 495)    L2NpcTemplate npc = NpcTable.getInstance().getTemplate(npcId);                        ^^^^^^^^NpcTable cannot be resolved----------11 problems (11 errors)L2Skill cannot be resolved to a typeThe import com.l2jserver.gameserver.datatables.NpcTable cannot be resolvedThe import com.l2jserver.gameserver.datatables.SkillTable cannot be resolvedThe import com.l2jserver.gameserver.model.skills.L2Skill cannot be resolvedL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeL2Skill cannot be resolved to a typeSkillTable cannot be resolvedNpcTable cannot be resolved[14/10 03:26:56] Failed executing script: D:\L2J\game\data\scripts\YANModPack\YANBuffer\YANBuffer.java. See YANBuffer.java.error.log for details.
elitovec
Posts: 23
Joined: Tue Aug 19, 2014 8:04 pm

Re: YANBuffer - Import problem?

Post by elitovec »

i have got same error with
Core: 6652
Datapack: 10464
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: YANBuffer - Import problem?

Post by UnAfraid »

L2Skill -> Skill
Image
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7008
Joined: Tue Aug 11, 2009 3:36 am

Re: YANBuffer - Import problem?

Post by Zoey76 »

UnAfraid wrote:L2Skill -> Skill
NpcTable -> NpcData :D
Powered by Eclipse 4.34 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Stalitsa
Initiates
Initiates
Posts: 88
Joined: Fri Jul 26, 2013 10:16 am

Re: YANBuffer - Import problem?

Post by Stalitsa »

Zoey76 wrote:
UnAfraid wrote:L2Skill -> Skill
NpcTable -> NpcData :D
SkillTable -> SkillData :D
Image
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: YANBuffer - Import problem?

Post by UnAfraid »

SouLakoS wrote:
Zoey76 wrote:
UnAfraid wrote:L2Skill -> Skill
NpcTable -> NpcData :D
SkillTable -> SkillData :D
SkillTable.getInstance().getInfo -> SkillData.getInstance().getSkill :mrgreen:
Image
Stalitsa
Initiates
Initiates
Posts: 88
Joined: Fri Jul 26, 2013 10:16 am

Re: YANBuffer - Import problem?

Post by Stalitsa »

UnAfraid wrote: SkillTable.getInstance().getInfo -> SkillData.getInstance().getSkill :mrgreen:
:lol:
Image
elitovec
Posts: 23
Joined: Tue Aug 19, 2014 8:04 pm

Re: YANBuffer - Import problem?

Post by elitovec »

can anybody edit YANBuffer.java and upload to hosting for download? I can't see it where is it....
elitovec
Posts: 23
Joined: Tue Aug 19, 2014 8:04 pm

Re: YANBuffer - Import problem?

Post by elitovec »

can any body help me?
the0ffspring
Posts: 12
Joined: Wed Nov 26, 2014 12:25 am

Re: YANBuffer - Import problem?

Post by the0ffspring »

i've edit the complete java files like shown above

l2skill -> skill
npctale -> npcdata
skilltable -> slilldata
getinfo -> getskill

nothing really works since they have changed the way the server core works.
I'd like to ask for edit on these files pls anyone.

I am currently using latest release Hi5 server files.
yanbuffer.java

Code: Select all

/* * 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/>. */package YANModPack.YANBuffer; import java.nio.file.Path;import java.nio.file.Paths;import java.util.Collection;import java.util.HashMap;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Map.Entry;import java.util.concurrent.ConcurrentHashMap;import java.util.logging.Level;import java.util.logging.Logger; import YANModPack.YANBuffer.YANBufferData.Buff;import YANModPack.YANBuffer.YANBufferData.BuffCategory;import YANModPack.YANBuffer.YANBufferData.Buffer;import YANModPack.YANBuffer.YANBufferData.BufferNpc;import YANModPack.YANBuffer.YANBufferData.HtmlType;import YANModPack.YANBuffer.YANBufferData.VoicedBuffer;import YANModPack.util.ItemRequirement;import YANModPack.util.htmltmpls.HTMLTemplateParser;import YANModPack.util.htmltmpls.HTMLTemplatePlaceholder;import YANModPack.util.htmltmpls.funcs.ChildsCountFunc;import YANModPack.util.htmltmpls.funcs.ExistsFunc;import YANModPack.util.htmltmpls.funcs.ForeachFunc;import YANModPack.util.htmltmpls.funcs.IfChildsFunc;import YANModPack.util.htmltmpls.funcs.IfFunc;import YANModPack.util.htmltmpls.funcs.IncludeFunc;import ai.npc.AbstractNpcAI; import com.l2jserver.gameserver.handler.BypassHandler;import com.l2jserver.gameserver.handler.ItemHandler;import com.l2jserver.gameserver.handler.VoicedCommandHandler;import com.l2jserver.gameserver.model.actor.L2Character;import com.l2jserver.gameserver.model.actor.L2Npc;import com.l2jserver.gameserver.model.actor.L2Playable;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;import com.l2jserver.gameserver.model.effects.L2Effect;import com.l2jserver.gameserver.model.zone.ZoneId;import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;import com.l2jserver.gameserver.network.serverpackets.ShowBoard;import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager; /** * @author FBIagent */public final class YANBuffer extends AbstractNpcAI{    private static final class SingletonHolder    {        protected static final YANBuffer INSTANCE = new YANBuffer();    }        private static final Logger _LOGGER = Logger.getLogger(YANBuffer.class.getName());    public static final Path SCRIPTS_SUBFOLDER = Paths.get("YANModPack");    public static final Path SCRIPT_TOP_FOLDER = Paths.get("YANBuffer");    public static final Path SCRIPT_SUBFOLDER = Paths.get(SCRIPTS_SUBFOLDER.toString(), SCRIPT_TOP_FOLDER.toString());        static YANBuffer getInstance()    {        return SingletonHolder.INSTANCE;    }        public static void main(String[] args)    {        try        {            YANBufferData.initInstance();        }        catch (Exception ex)        {            _LOGGER.log(Level.WARNING, "YanBuffer - Data: Exception while loading npc buffer data, not registering mod!", ex);            return;        }                YANBuffer instance = getInstance();                for (Entry<Integer, BufferNpc> npc : YANBufferData.getInstance().getBufferNpcs().entrySet())        {            instance.addFirstTalkId(npc.getKey());            instance.addStartNpc(npc.getKey());            instance.addTalkId(npc.getKey());        }    }        private static final ConcurrentHashMap<Integer, Long> _LAST_PLAYABLES_HEAL_TIME = new ConcurrentHashMap<>();    private static final ConcurrentHashMap<Integer, String> _LAST_PLAYER_HTMLS = new ConcurrentHashMap<>();    private static final ConcurrentHashMap<Integer, String> _ACTIVE_PLAYER_BUFFLISTS = new ConcurrentHashMap<>();        YANBuffer()    {        super(SCRIPT_TOP_FOLDER.toString(), SCRIPTS_SUBFOLDER.toString());                BypassHandler.getInstance().registerHandler(YANBufferNpcBypassHandler.getInstance());                if (YANBufferData.getInstance().getVoicedBuffer().enabled)        {            VoicedCommandHandler.getInstance().registerHandler(YANBufferVoicedCommandHandler.getInstance());            ItemHandler.getInstance().registerHandler(YANBufferItemHandler.getInstance());        }    }        // ////////////////////////////////////    // AI METHOD OVERRIDES    // ////////////////////////////////////    @Override    public String onFirstTalk(L2Npc npc, L2PcInstance player)    {        executeCommand(player, npc, null);        return null;    }        // ///////////////////////////////////    // UTILITY METHODS    // ///////////////////////////////////    private Buffer _determineBuffer(L2Npc npc, L2PcInstance player)    {        if (npc == null)        {            VoicedBuffer buffer = YANBufferData.getInstance().getVoicedBuffer();            if (!buffer.enabled || ((buffer.requiredItem > 0) && (player.getInventory().getItemByItemId(buffer.requiredItem) == null)))            {                return null;            }            return buffer;        }        return YANBufferData.getInstance().getBufferNpc(npc.getNpcId());    }        private String _generateAdvancedHtml(L2PcInstance player, String path, Map<String, HTMLTemplatePlaceholder> placeholders, HtmlType dialogType)    {        return HTMLTemplateParser.fromCache("/data/scripts/" + SCRIPT_SUBFOLDER + "/data/html/" + dialogType.toString().toLowerCase(Locale.ENGLISH) + "/" + path, player, placeholders, IncludeFunc.INSTANCE, IfFunc.INSTANCE, ForeachFunc.INSTANCE, ExistsFunc.INSTANCE, IfChildsFunc.INSTANCE, ChildsCountFunc.INSTANCE);    }        /**     * Copy from {@link NpcHtmlMessage}     * @param activeChar     * @param html     */    private void _buildBypassCache(L2PcInstance activeChar, String html)    {        if (activeChar == null)        {            return;        }                activeChar.clearBypass();        int len = html.length();        for (int i = 0; i < len; i++)        {            int start = html.indexOf("\"bypass ", i);            int finish = html.indexOf("\"", start + 1);            if ((start < 0) || (finish < 0))            {                break;            }                        if (html.substring(start + 8, start + 10).equals("-h"))            {                start += 11;            }            else            {                start += 8;            }                        i = finish;            int finish2 = html.indexOf("$", start);            if ((finish2 < finish) && (finish2 > 0))            {                activeChar.addBypass2(html.substring(start, finish2).trim());            }            else            {                activeChar.addBypass(html.substring(start, finish).trim());            }        }    }        /**     * Copy from {@link com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager}. Modified to allow larger community board htmls.     * @param player     * @param html     */    private void _sendBBSHtml(L2PcInstance player, String html)    {        _buildBypassCache(player, html);                if (html.length() < 16250)        {            player.sendPacket(new ShowBoard(html, "101"));            player.sendPacket(new ShowBoard(null, "102"));            player.sendPacket(new ShowBoard(null, "103"));        }        else if (html.length() < (16250 * 2))        {            player.sendPacket(new ShowBoard(html.substring(0, 16250), "101"));            player.sendPacket(new ShowBoard(html.substring(16250), "102"));            player.sendPacket(new ShowBoard(null, "103"));        }        else if (html.length() < (16250 * 3))        {            player.sendPacket(new ShowBoard(html.substring(0, 16250), "101"));            player.sendPacket(new ShowBoard(html.substring(16250, 16250 * 2), "102"));            player.sendPacket(new ShowBoard(html.substring(16250 * 2), "103"));        }        else        {            player.sendPacket(new ShowBoard("<html><body><br><center>Error: HTML was too long!</center></body></html>", "101"));            player.sendPacket(new ShowBoard(null, "102"));            player.sendPacket(new ShowBoard(null, "103"));        }    }        private void _fillItemAmountMap(Map<Integer, Long> items, Buff buff)    {        for (Entry<String, ItemRequirement> item : buff.items.entrySet())        {            Long amount = items.get(item.getValue().item.getItemId());            if (amount == null)            {                amount = 0L;            }            items.put(item.getValue().item.getItemId(), amount + item.getValue().amount);        }    }        private void _castBuff(L2Playable playable, Buff buff)    {        buff.skill.getEffects(playable, playable);    }        // //////////////////////////////////    // HTML COMMANDS    // //////////////////////////////////    private void _showAdvancedHtml(L2PcInstance player, Buffer buffer, L2Npc npc, String htmlPath, Map<String, HTMLTemplatePlaceholder> placeholders)    {        placeholders.put(buffer.placeholder.getName(), buffer.placeholder);                HTMLTemplatePlaceholder ulistsPlaceholder = YANBufferData.getInstance().getPlayersUListsPlaceholder(player.getObjectId());        if (ulistsPlaceholder != null)        {            placeholders.put(ulistsPlaceholder.getName(), ulistsPlaceholder);        }                String activeUniqueName = _ACTIVE_PLAYER_BUFFLISTS.get(player.getObjectId());        if (activeUniqueName != null)        {            HTMLTemplatePlaceholder ulistPlaceholder = YANBufferData.getInstance().getPlayersUListPlaceholder(player.getObjectId(), activeUniqueName);            if (ulistPlaceholder != null)            {                placeholders.put("active_unique", ulistPlaceholder);            }        }                HtmlType dialogType = YANBufferData.getInstance().getHtmlType();                String html = _generateAdvancedHtml(player, htmlPath, placeholders, dialogType);        switch (dialogType)        {            case NPC:                player.sendPacket(new NpcHtmlMessage(npc == null ? 0 : npc.getObjectId(), html));                break;            case COMMUNITY:                _sendBBSHtml(player, html);                break;        }    }        private void _htmlShowMain(L2PcInstance player, Buffer buffer, L2Npc npc)    {        _showAdvancedHtml(player, buffer, npc, "main.html", new HashMap<String, HTMLTemplatePlaceholder>());    }        private void _htmlShowCategory(L2PcInstance player, Buffer buffer, L2Npc npc, String categoryIdent)    {        BuffCategory buffCat = buffer.getBuffCat(categoryIdent);        if (buffCat == null)        {            return;        }                HashMap<String, HTMLTemplatePlaceholder> placeholders = new HashMap<>();                placeholders.put("category", buffCat.placeholder);                _showAdvancedHtml(player, buffer, npc, "category.html", placeholders);    }        private void _htmlShowBuff(L2PcInstance player, Buffer buffer, L2Npc npc, String categoryIdent, String buffIdent)    {        BuffCategory buffCat = buffer.getBuffCat(categoryIdent);        if (buffCat == null)        {            return;        }        Buff buff = buffCat.getBuff(buffIdent);        if (buff == null)        {            return;        }                HashMap<String, HTMLTemplatePlaceholder> placeholders = new HashMap<>();                placeholders.put("category", buffCat.placeholder);        placeholders.put("buff", buff.placeholder);                _showAdvancedHtml(player, buffer, npc, "buff.html", placeholders);    }        private void _htmlShowPreset(L2PcInstance player, Buffer buffer, L2Npc npc, String presetBufflistIdent)    {        BuffCategory presetBufflist = buffer.getPresetBufflist(presetBufflistIdent);        if (presetBufflist == null)        {            return;        }                HashMap<String, HTMLTemplatePlaceholder> placeholders = new HashMap<>();                placeholders.put("preset", presetBufflist.placeholder);                _showAdvancedHtml(player, buffer, npc, "preset.html", placeholders);    }        private void _htmlShowUnique(L2PcInstance player, Buffer buffer, L2Npc npc, String uniqueName)    {        HTMLTemplatePlaceholder uniquePlaceholder = YANBufferData.getInstance().getPlayersUListPlaceholder(player.getObjectId(), uniqueName);        if (uniquePlaceholder == null)        {            // redirect to main html if uniqueName is not valid, will most likely happen when the player deletes a unique bufflist he is currently viewing            _executeHtmlCommand(player, buffer, npc, "main");            return;        }                HashMap<String, HTMLTemplatePlaceholder> placeholders = new HashMap<>();                placeholders.put(uniquePlaceholder.getName(), uniquePlaceholder);                _showAdvancedHtml(player, buffer, npc, "unique.html", placeholders);    }        private void _executeHtmlCommand(L2PcInstance player, Buffer buffer, L2Npc npc, String command)    {        _LAST_PLAYER_HTMLS.put(player.getObjectId(), command);                if ("main".equals(command))        {            _htmlShowMain(player, buffer, npc);        }        else if (command.startsWith("category "))        {            _htmlShowCategory(player, buffer, npc, command.substring(9));        }        else if (command.startsWith("preset "))        {            _htmlShowPreset(player, buffer, npc, command.substring(7));        }        else if (command.startsWith("buff "))        {            String[] argsSplit = command.substring(5).split(" ", 2);            if (argsSplit.length != 2)            {                return;            }            _htmlShowBuff(player, buffer, npc, argsSplit[0], argsSplit[1]);        }        else if (command.startsWith("unique "))        {            _htmlShowUnique(player, buffer, npc, command.substring(7));        }        else        {            // all other malformed bypasses            _htmlShowMain(player, buffer, npc);        }    }        //    // ////////////////////////////////        // /////////////////////////////////////////////    // TARGET COMMANDS    // /////////////////////////////////////////////    private void _targetBuffBuff(L2PcInstance player, L2Playable target, Buffer buffer, String categoryIdent, String buffIdent)    {        BuffCategory bCat = buffer.getBuffCat(categoryIdent);        if (bCat == null)        {            return;        }        Buff buff = bCat.getBuff(buffIdent);        if (buff == null)        {            return;        }                if (!buff.items.isEmpty())        {            HashMap<Integer, Long> items = new HashMap<>();            _fillItemAmountMap(items, buff);                        for (Entry<Integer, Long> item : items.entrySet())            {                if (player.getInventory().getInventoryItemCount(item.getKey(), 0, true) < item.getValue())                {                    player.sendMessage("Not enough items!");                    return;                }            }                        for (Entry<Integer, Long> item : items.entrySet())            {                player.destroyItemByItemId("YANBuffer", item.getKey(), item.getValue(), player, true);            }        }                _castBuff(target, buff);    }        private void _targetBuffUnique(L2PcInstance player, L2Playable target, Buffer buffer, String uniqueName)    {        List<Buff> buffs = YANBufferData.getInstance().getUniqueBufflist(player.getObjectId(), uniqueName);                if (buffs != null)        {            HashMap<Integer, Long> items = null;            for (Buff buff : buffs)            {                if (!buff.items.isEmpty())                {                    if (items == null)                    {                        items = new HashMap<>();                    }                    _fillItemAmountMap(items, buff);                }            }                        if (items != null)            {                for (Entry<Integer, Long> item : items.entrySet())                {                    if (player.getInventory().getInventoryItemCount(item.getKey(), 0, true) < item.getValue())                    {                        player.sendMessage("Not enough items!");                        return;                    }                }                                for (Entry<Integer, Long> item : items.entrySet())                {                    player.destroyItemByItemId("YANBuffer", item.getKey(), item.getValue(), player, true);                }            }                        for (Buff buff : buffs)            {                _castBuff(target, buff);            }        }    }        private void _targetBuffPreset(L2PcInstance player, L2Playable target, Buffer buffer, String presetBufflistIdent)    {        BuffCategory presetBufflist = buffer.getPresetBufflist(presetBufflistIdent);        if (presetBufflist == null)        {            return;        }                Collection<Buff> buffs = presetBufflist.buffs.values();                if (buffs != null)        {            HashMap<Integer, Long> items = null;            for (Buff buff : buffs)            {                if (!buff.items.isEmpty())                {                    if (items == null)                    {                        items = new HashMap<>();                    }                    _fillItemAmountMap(items, buff);                }            }                        if (items != null)            {                for (Entry<Integer, Long> item : items.entrySet())                {                    if (player.getInventory().getInventoryItemCount(item.getKey(), 0, true) < item.getValue())                    {                        player.sendMessage("Not enough items!");                        return;                    }                }                                for (Entry<Integer, Long> item : items.entrySet())                {                    player.destroyItemByItemId("YANBuffer", item.getKey(), item.getValue(), player, true);                }            }                        for (Buff buff : buffs)            {                _castBuff(target, buff);            }        }    }        private void _targetHeal(L2PcInstance player, L2Playable target, Buffer buffer)    {        if (!buffer.canHeal)        {            return;        }                // prevent heal spamming, process cooldown on heal target        Long lastPlayableHealTime = _LAST_PLAYABLES_HEAL_TIME.get(target.getObjectId());        if (lastPlayableHealTime != null)        {            Long elapsedTime = System.currentTimeMillis() - lastPlayableHealTime;            Long healCooldown = YANBufferData.getInstance().getHealCooldown();            if (elapsedTime < healCooldown)            {                Long remainingTime = healCooldown - elapsedTime;                if (target == player)                {                    player.sendMessage("You can heal yourself again in " + (remainingTime / 1000) + " seconds.");                }                else                {                    player.sendMessage("You can heal your pet again in " + (remainingTime / 1000) + " seconds.");                }                return;            }        }                _LAST_PLAYABLES_HEAL_TIME.put(target.getObjectId(), System.currentTimeMillis());                if (player == target)        {            player.setCurrentCp(player.getMaxCp());        }        target.setCurrentHp(target.getMaxHp());        target.setCurrentMp(target.getMaxMp());        target.broadcastStatusUpdate();    }        private void _targetCancel(L2PcInstance player, L2Playable target, Buffer buffer)    {        if (!buffer.canCancel)        {            return;        }        target.stopAllEffectsExceptThoseThatLastThroughDeath();    }        private void _executeTargetCommand(L2PcInstance player, Buffer buffer, String command)    {        // /////////////////////////////////        // first determine the target        L2Playable target;        if (command.startsWith("player "))        {            target = player;            command = command.substring(7);        }        else if (command.startsWith("summon "))        {            target = player.getSummon();            if (target == null)            {                return;            }            command = command.substring(7);        }        else        {            return;        }                // //////////////////////////////////////////        // run the choosen action on the target        if (command.startsWith("buff "))        {            String[] argsSplit = command.substring(5).split(" ", 2);            if (argsSplit.length != 2)            {                return;            }            _targetBuffBuff(player, target, buffer, argsSplit[0], argsSplit[1]);        }        else if (command.startsWith("unique "))        {            _targetBuffUnique(player, target, buffer, command.substring(7));        }        else if (command.startsWith("preset "))        {            _targetBuffPreset(player, target, buffer, command.substring(7));        }        else if ("heal".equals(command))        {            _targetHeal(player, target, buffer);        }        else if ("cancel".equals(command))        {            _targetCancel(player, target, buffer);        }    }        //    // ////////////////////////////////        // ////////////////////////////////    // UNIQUE COMMANDS    // ////////////////////////////////    private boolean _uniqueCreate(L2PcInstance player, String uniqueName)    {        if (!YANBufferData.getInstance().canHaveMoreBufflists(player))        {            player.sendMessage("Maximum number of unique bufflists reached!");            return false;        }                // only allow alpha numeric names because we use this name on the htmls        if (!uniqueName.matches("[A-Za-z0-9]+"))        {            return false;        }                return YANBufferData.getInstance().createUniqueBufflist(player.getObjectId(), uniqueName);    }        private void _uniqueDelete(L2PcInstance player, String uniqueName)    {        YANBufferData.getInstance().deleteUniqueBufflist(player.getObjectId(), uniqueName);        // also remove from active bufflist when it's the deleted        String activeUniqueName = _ACTIVE_PLAYER_BUFFLISTS.get(player.getObjectId());        if ((activeUniqueName != null) && activeUniqueName.equals(uniqueName))        {            _ACTIVE_PLAYER_BUFFLISTS.remove(player.getObjectId());        }    }        private void _uniqueAdd(L2PcInstance player, Buffer buffer, String uniqueName, String categoryIdent, String buffIdent)    {        BuffCategory bCat = buffer.getBuffCat(categoryIdent);        if (bCat == null)        {            return;        }        Buff buff = bCat.getBuff(buffIdent);        if (buff == null)        {            return;        }                YANBufferData.getInstance().addToUniqueBufflist(player.getObjectId(), uniqueName, buff);    }        private void _uniqueRemove(L2PcInstance player, String uniqueName, String buffIdent)    {        Buff buff = YANBufferData.getInstance().getBuff(buffIdent);        if (buff == null)        {            return;        }                YANBufferData.getInstance().removeFromUniqueBufflist(player.getObjectId(), uniqueName, buff);    }        private void _uniqueSelect(L2PcInstance player, String uniqueName)    {        if (YANBufferData.getInstance().hasUniqueBufflist(player.getObjectId(), uniqueName))        {            _ACTIVE_PLAYER_BUFFLISTS.put(player.getObjectId(), uniqueName);        }    }        private void _uniqueDeselect(L2PcInstance player)    {        _ACTIVE_PLAYER_BUFFLISTS.remove(player.getObjectId());    }        private void _executeUniqueCommand(L2PcInstance player, Buffer buffer, String command)    {        if (command.startsWith("create "))        {            _uniqueCreate(player, command.substring(7));        }        else if (command.startsWith("create_from_effects "))        {            String uniqueName = command.substring(20);            if (!_uniqueCreate(player, uniqueName))            {                return;            }                        final L2Effect[] effects = player.getAllEffects();            for (final L2Effect effect : effects)            {                for (Entry<String, BuffCategory> buffCatEntry : buffer.buffCats.entrySet())                {                    boolean added = false;                                        for (Entry<String, Buff> buffEntry : buffCatEntry.getValue().buffs.entrySet())                    {                        final Buff buff = buffEntry.getValue();                                                if (buff.skill.getId() == effect.getSkill().getId())                        {                            _uniqueAdd(player, buffer, uniqueName, buffCatEntry.getKey(), buff.ident);                            added = true;                            break;                        }                    }                                        if (added)                    {                        break;                    }                }            }        }        else if (command.startsWith("delete "))        {            _uniqueDelete(player, command.substring(7));        }        else if (command.startsWith("add "))        {            String[] argsSplit = command.substring(4).split(" ", 3);            if (argsSplit.length != 3)            {                return;            }            _uniqueAdd(player, buffer, argsSplit[0], argsSplit[1], argsSplit[2]);        }        else if (command.startsWith("remove "))        {            String[] argsSplit = command.substring(7).split(" ", 2);            if (argsSplit.length != 2)            {                return;            }            _uniqueRemove(player, argsSplit[0], argsSplit[1]);        }        else if (command.startsWith("select "))        {            _uniqueSelect(player, command.substring(7));        }        else if (command.startsWith("deselect"))        {            _uniqueDeselect(player);        }    }        //    // ////////////////////////////////        private static boolean _isInsideAnyZoneOf(L2Character character, ZoneId first, ZoneId... more)    {        if (character.isInsideZone(first))        {            return true;        }                if (more != null)        {            for (ZoneId zone : more)            {                if (character.isInsideZone(zone))                {                    return true;                }            }        }                return false;    }        void executeCommand(L2PcInstance player, L2Npc npc, String command)    {        if (_isInsideAnyZoneOf(player, ZoneId.PVP, ZoneId.SIEGE, ZoneId.WATER, ZoneId.JAIL, ZoneId.DANGER_AREA))        {            player.sendMessage("The buffer cannot be used here.");            return;        }        else if ((player.getEventStatus() != null) || (player.getBlockCheckerArena() != -1) || player.isOnEvent() || player.isInOlympiadMode())        {            player.sendMessage("The buffer cannot be used in events.");            return;        }                else if (player.isInDuel() || (player.getPvpFlag() == 1))        {            player.sendMessage("The buffer cannot be used in duells or pvp.");            return;        }                else if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))        {            player.sendMessage("The buffer cannot be used while in combat.");            return;        }                Buffer buffer = _determineBuffer(npc, player);        if (buffer == null)        {            // not an authorized npc or npc is null and voiced buffer is disabled            return;        }                if ((command == null) || command.isEmpty())        {            command = "html main";        }                if (command.startsWith("html "))        {            _executeHtmlCommand(player, buffer, npc, command.substring(5));        }        else        {            if (command.startsWith("target "))            {                _executeTargetCommand(player, buffer, command.substring(7));            }            else if (command.startsWith("unique "))            {                _executeUniqueCommand(player, buffer, command.substring(7));            }                        // display last html again            // since somebody could use the chat as a command line(eg.: .yanbuffer target player heal), we check if the player has opened a html before            String lastHtmlCommand = _LAST_PLAYER_HTMLS.get(player.getObjectId());            if (lastHtmlCommand != null)            {                _executeHtmlCommand(player, buffer, npc, _LAST_PLAYER_HTMLS.get(player.getObjectId()));            }        }    }}
the0ffspring
Posts: 12
Joined: Wed Nov 26, 2014 12:25 am

Re: YANBuffer - Import problem?

Post by the0ffspring »

yanbufferdata.java

Code: Select all

/* * 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/>. */package YANModPack.YANBuffer; import java.nio.file.Path;import java.nio.file.Paths;import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;import java.util.Collections;import java.util.HashMap;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;import java.util.Map.Entry;import java.util.concurrent.ConcurrentHashMap;import java.util.logging.Level;import java.util.logging.Logger; import org.w3c.dom.Element;import org.w3c.dom.Node; import YANModPack.util.ItemRequirement;import YANModPack.util.XMLUtils;import YANModPack.util.htmltmpls.HTMLTemplatePlaceholder; import com.l2jserver.Config;import com.l2jserver.L2DatabaseFactory;import com.l2jserver.gameserver.datatables.ItemTable;import com.l2jserver.gameserver.datatables.NpcData;import com.l2jserver.gameserver.datatables.SkillData;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;import com.l2jserver.gameserver.model.items.L2Item;import com.l2jserver.gameserver.model.skills.Skill; /** * @author FBIagent */final class YANBufferData{    public static enum BuffType    {        BUFF,        SONG_DANCE    }        public static enum HtmlType    {        NPC,        COMMUNITY    }        public final class Buff    {        protected final String ident;        protected final Skill skill;        protected final BuffType type;        protected final Map<String, ItemRequirement> items;        /** HTMLTemplatePlaceholder */        protected final HTMLTemplatePlaceholder placeholder;                protected Buff(String ident, Skill skill, BuffType type, Element elem)        {            this.ident = ident;            this.skill = skill;            this.type = type;            this.items = _parseItems(elem);                        this.placeholder = new HTMLTemplatePlaceholder("buff", null);            this.placeholder.addChild("ident", ident).addChild("skill_id", String.valueOf(skill.getId())).addChild("skill_name", skill.getName()).addChild("skill_icon", _getClientSkillIconSource(skill.getId())).addChild("type", type.toString());            if (!this.items.isEmpty())            {                HTMLTemplatePlaceholder itemsPlaceholder = this.placeholder.addChild("items", null).getChild("items");                for (Entry<String, ItemRequirement> item : this.items.entrySet())                {                    itemsPlaceholder.addAliasChild(String.valueOf(itemsPlaceholder.getChildsSize()), item.getValue().placeholder);                }            }        }                private Map<String, ItemRequirement> _parseItems(Element elem)        {            Map<String, ItemRequirement> items = new LinkedHashMap<>();            Node curNode = elem.getFirstChild();            while (curNode != null)            {                switch (curNode.getNodeType())                {                    case Node.ELEMENT_NODE:                        Element curElem = (Element) curNode;                        String ident = curElem.getAttribute("ident");                        ItemRequirement req = _itemRequirements.get(ident);                        if (req == null)                        {                            _LOGGER.warning("YANBuffer - buffs.xml: Item requirement with ident " + ident + " does not exists!");                        }                        else                        {                            items.put(ident, req);                        }                        break;                }                                curNode = curNode.getNextSibling();            }            return Collections.unmodifiableMap(items);        }                private String _getClientSkillIconSource(int skillId)        {            String format = "";            if (skillId < 100)            {                format = "00" + skillId;            }            else if ((skillId > 99) && (skillId < 1000))            {                format = "0" + skillId;            }            else if (skillId == 1517)            {                format = "1499";            }            else if (skillId == 1518)            {                format = "1502";            }            else            {                if ((skillId > 4698) && (skillId < 4701))                {                    format = "1331";                }                else if ((skillId > 4701) && (skillId < 4704))                {                    format = "1332";                }                else                {                    format = Integer.toString(skillId);                }            }                        return "icon.skill" + format;        }                public BuffType getType()        {            return type;        }    }        public final class BuffCategory    {        protected final String ident;        protected final Map<String, Buff> buffs;        /** HTMLTemplatePlaceholder */        protected final HTMLTemplatePlaceholder placeholder;                protected BuffCategory(String ident, String name, Element elem)        {            this.ident = ident;            this.buffs = _parseBuffs(elem);                        this.placeholder = new HTMLTemplatePlaceholder("category", null);            this.placeholder.addChild("ident", ident).addChild("name", name);            if (!this.buffs.isEmpty())            {                HTMLTemplatePlaceholder buffsPlaceholder = this.placeholder.addChild("buffs", null).getChild("buffs");                for (Entry<String, Buff> buff : this.buffs.entrySet())                {                    buffsPlaceholder.addAliasChild(String.valueOf(buffsPlaceholder.getChildsSize()), buff.getValue().placeholder);                }            }        }                private Map<String, Buff> _parseBuffs(Element elem)        {            Map<String, Buff> buffs = new LinkedHashMap<>();            Node curNode = elem.getFirstChild();            while (curNode != null)            {                switch (curNode.getNodeType())                {                    case Node.ELEMENT_NODE:                        Element curElem = (Element) curNode;                        String ident = curElem.getAttribute("ident");                        Buff buff = _buffs.get(ident);                        if (buff == null)                        {                            _LOGGER.warning("YANBuffer - buff_categories.xml: Buff with ident " + ident + " does not exists!");                        }                        else                        {                            buffs.put(ident, buff);                        }                        break;                }                                curNode = curNode.getNextSibling();            }            return Collections.unmodifiableMap(buffs);        }                public Buff getBuff(String buffIdent)        {            return buffs.get(buffIdent);        }    }        public abstract class Buffer    {        /** Can heal a player */        protected final boolean canHeal;        /** Can cancel a player */        protected final boolean canCancel;        /** buff categories */        protected final Map<String, BuffCategory> buffCats;        /** preset bufflists */        protected final Map<String, BuffCategory> presetBufflists;        /** HTMLTemplatePlaceholder */        protected final HTMLTemplatePlaceholder placeholder;                protected Buffer(String xmlFile, String bypassPrefix, String bufferName, Element elem)        {            this.canHeal = Boolean.parseBoolean(elem.getAttribute("can_heal"));            this.canCancel = Boolean.parseBoolean(elem.getAttribute("can_cancel"));            this.buffCats = _parseBuffCats(xmlFile, elem, false);            this.presetBufflists = _parseBuffCats(xmlFile, elem, true);                        this.placeholder = new HTMLTemplatePlaceholder("buffer", null);            this.placeholder.addChild("bypass_prefix", "bypass -h " + bypassPrefix).addChild("name", bufferName).addChild("max_unique_lists", String.valueOf(_maxUniqueLists)).addChild("unique_max_buffs", String.valueOf(_uniqueMaxBuffs)).addChild("unique_max_songs_dances", String.valueOf(_uniqueMaxSongsDances));            if (this.canHeal)            {                this.placeholder.addChild("can_heal", null);            }            if (this.canCancel)            {                this.placeholder.addChild("can_cancel", null);            }            if (!this.buffCats.isEmpty())            {                HTMLTemplatePlaceholder buffCatsPlaceholder = this.placeholder.addChild("categories", null).getChild("categories");                for (Entry<String, BuffCategory> buffCat : this.buffCats.entrySet())                {                    buffCatsPlaceholder.addAliasChild(String.valueOf(buffCatsPlaceholder.getChildsSize()), buffCat.getValue().placeholder);                }            }            if (!this.presetBufflists.isEmpty())            {                HTMLTemplatePlaceholder presetBufflistsPlaceholder = this.placeholder.addChild("presets", null).getChild("presets");                for (Entry<String, BuffCategory> presetBufflist : this.presetBufflists.entrySet())                {                    presetBufflistsPlaceholder.addAliasChild(String.valueOf(presetBufflistsPlaceholder.getChildsSize()), presetBufflist.getValue().placeholder);                }            }        }                private Map<String, BuffCategory> _parseBuffCats(String xmlFile, Element elem, boolean preset)        {            Map<String, BuffCategory> buffCats = new LinkedHashMap<>();            Node curNode = elem.getFirstChild();            while (curNode != null)            {                switch (curNode.getNodeType())                {                    case Node.ELEMENT_NODE:                        Element curElem = (Element) curNode;                        String ident = curElem.getAttribute("ident");                        boolean isPreset = Boolean.parseBoolean(curElem.getAttribute("is_preset"));                        if (preset != isPreset)                        {                            break;                        }                        BuffCategory buffCat = _buffCats.get(ident);                        if (buffCat == null)                        {                            _LOGGER.warning("YANBuffer - " + xmlFile + ": Buff category with ident " + ident + " does not exists!");                        }                        else                        {                            buffCats.put(ident, buffCat);                        }                        break;                }                                curNode = curNode.getNextSibling();            }            return Collections.unmodifiableMap(buffCats);        }                public BuffCategory getBuffCat(String buffCatIdent)        {            return buffCats.get(buffCatIdent);        }                public BuffCategory getPresetBufflist(String presetBufflistIdent)        {            return presetBufflists.get(presetBufflistIdent);        }                public Map<String, BuffCategory> getBuffCats()        {            return buffCats;        }    }        public final class BufferNpc extends Buffer    {        /** npc id */        protected final L2NpcTemplate npc;                protected BufferNpc(L2NpcTemplate npc, Element elem)        {            super("buffer_npcs.xml", YANBufferNpcBypassHandler.BYPASS, npc.getName(), elem);            this.npc = npc;        }    }        public final class VoicedBuffer extends Buffer    {        public final boolean enabled;        public final int requiredItem;                protected VoicedBuffer(Element elem)        {            super("voiced_buffer.xml", "voice ." + YANBufferVoicedCommandHandler.VOICED_COMMAND, "Voiced Command Buffer", elem);            this.enabled = Boolean.parseBoolean(elem.getAttribute("enabled"));            if (elem.hasAttribute("required_item"))            {                this.requiredItem = Integer.parseInt(elem.getAttribute("required_item"));            }            else            {                this.requiredItem = 0;            }        }    }        protected static final Logger _LOGGER = Logger.getLogger(YANBufferData.class.getName());    private static YANBufferData _INSTANCE = null;        public synchronized static void initInstance() throws Exception    {        _INSTANCE = new YANBufferData();    }        public synchronized static YANBufferData getInstance()    {        return _INSTANCE;    }        private final HtmlType _htmlType;    private final long _healCooldown;    protected final int _maxUniqueLists;    protected final int _uniqueMaxBuffs;    protected final int _uniqueMaxSongsDances;    protected final Map<String, ItemRequirement> _itemRequirements = new HashMap<>();    protected final Map<String, Buff> _buffs = new HashMap<>();    protected final Map<String, BuffCategory> _buffCats = new HashMap<>();    private final Map<Integer, BufferNpc> _bufferNpcs = new HashMap<>();    private final VoicedBuffer _voicedBuffer;    protected final ConcurrentHashMap<Integer, Map<Integer, UniqueBufflist>> _uniqueBufflists = new ConcurrentHashMap<>();        private YANBufferData() throws Exception    {        Path xmlPath = Paths.get(Config.DATAPACK_ROOT.getAbsolutePath(), "data", "scripts", YANBuffer.SCRIPT_SUBFOLDER.toString(), "data", "xml");        Path xsdPath = Paths.get(xmlPath.toString(), "xsd");                Element elem = XMLUtils.CreateDocument(xmlPath.resolve("yanbuffer.xml"), xsdPath.resolve("yanbuffer.xsd")).getDocumentElement();        _htmlType = HtmlType.valueOf(elem.getAttribute("dialog_type"));        _healCooldown = Integer.parseInt(elem.getAttribute("heal_cooldown")) * 1000;        _maxUniqueLists = Integer.parseInt(elem.getAttribute("max_unique_lists"));        _uniqueMaxBuffs = Integer.parseInt(elem.getAttribute("unique_max_buffs"));        _uniqueMaxSongsDances = Integer.parseInt(elem.getAttribute("unique_max_songs_dances"));                elem = XMLUtils.CreateDocument(xmlPath.resolve("item_requirements.xml"), xsdPath.resolve("item_requirements.xsd")).getDocumentElement();        _parseItemRequirements(elem);                elem = XMLUtils.CreateDocument(xmlPath.resolve("buffs.xml"), xsdPath.resolve("buffs.xsd")).getDocumentElement();        _parseBuffs(elem);                elem = XMLUtils.CreateDocument(xmlPath.resolve("buff_categories.xml"), xsdPath.resolve("buff_categories.xsd")).getDocumentElement();        _parseBuffCats(elem, _buffCats);                elem = XMLUtils.CreateDocument(xmlPath.resolve("buffer_npcs.xml"), xsdPath.resolve("buffer_npcs.xsd")).getDocumentElement();        _parseBufferNpcs(elem);                elem = XMLUtils.CreateDocument(xmlPath.resolve("voiced_buffer.xml"), xsdPath.resolve("voiced_buffer.xsd")).getDocumentElement();        _voicedBuffer = new VoicedBuffer(elem);                _loadUniqueBufflists();    }        private void _parseItemRequirements(Element elem)    {        Node curNode = elem.getFirstChild();        while (curNode != null)        {            switch (curNode.getNodeType())            {                case Node.ELEMENT_NODE:                    Element curElem = (Element) curNode;                    String ident = curElem.getAttribute("ident");                    int itemId = Integer.parseInt(curElem.getAttribute("id"));                    long itemAmount = Long.parseLong(curElem.getAttribute("amount"));                    L2Item item = ItemTable.getInstance().getTemplate(itemId);                    if (item == null)                    {                        _LOGGER.warning("YANBuffer - item_requirements.xml: Item with id " + itemId + " does not exists!");                    }                    else                    {                        _itemRequirements.put(ident, new ItemRequirement(item, itemAmount));                    }                    break;            }                        curNode = curNode.getNextSibling();        }    }        private void _parseBuffs(Element elem)    {        Node curNode = elem.getFirstChild();        while (curNode != null)        {            switch (curNode.getNodeType())            {                case Node.ELEMENT_NODE:                    Element curElem = (Element) curNode;                    String ident = curElem.getAttribute("ident");                    int skillId = Integer.parseInt(curElem.getAttribute("skill_id"));                    int skillLevel = Integer.parseInt(curElem.getAttribute("skill_level"));                    Skill skill = SkillData.getInstance().getSkill(skillId, skillLevel);                    BuffType buffType = BuffType.valueOf(curElem.getAttribute("type"));                    if (skill == null)                    {                        _LOGGER.warning("YANBuffer - buffs.xml: Skill with id " + skillId + " and level " + skillLevel + " does not exists!");                    }                    else                    {                        _buffs.put(ident, new Buff(ident, skill, buffType, curElem));                    }                    break;            }                        curNode = curNode.getNextSibling();        }    }        private void _parseBuffCats(Element elem, Map<String, BuffCategory> buffCats)    {        Node curNode = elem.getFirstChild();        while (curNode != null)        {            switch (curNode.getNodeType())            {                case Node.ELEMENT_NODE:                    Element curElem = (Element) curNode;                    String ident = curElem.getAttribute("ident");                    buffCats.put(ident, new BuffCategory(ident, curElem.getAttribute("name"), curElem));                    break;            }                        curNode = curNode.getNextSibling();        }    }        private void _parseBufferNpcs(Element elem)    {        Node curNode = elem.getFirstChild();        while (curNode != null)        {            switch (curNode.getNodeType())            {                case Node.ELEMENT_NODE:                    Element curElem = (Element) curNode;                    int npcId = Integer.parseInt(curElem.getAttribute("id"));                    L2NpcTemplate npc = NpcData.getInstance().getTemplate(npcId);                    if (npc == null)                    {                        _LOGGER.warning("YANBuffer - buffer_npcs.xml: Npc with id " + npcId + " does not exists!");                    }                    else                    {                        _bufferNpcs.put(npc.getNpcId(), new BufferNpc(npc, curElem));                    }                    break;            }                        curNode = curNode.getNextSibling();        }    }        private void _loadUniqueBufflists() throws Exception    {        try (Connection con = L2DatabaseFactory.getInstance().getConnection();)        {            try (Statement stmt = con.createStatement();                ResultSet rset = stmt.executeQuery("SELECT ulist_id,ulist_char_id,ulist_name FROM yanb_ulists ORDER BY ulist_char_id ASC");)            {                while (rset.next())                {                    int charId = rset.getInt("ulist_char_id");                    int ulistId = rset.getInt("ulist_id");                    String ulistName = rset.getString("ulist_name");                                        Map<Integer, UniqueBufflist> ulists = _getPlayersULists(charId);                    ulists.put(ulistId, new UniqueBufflist(ulistId, ulistName));                }            }                        for (Entry<Integer, Map<Integer, UniqueBufflist>> ulists : _uniqueBufflists.entrySet())            {                for (Entry<Integer, UniqueBufflist> ulist : ulists.getValue().entrySet())                {                    try (PreparedStatement stmt = con.prepareStatement("SELECT ulist_buff_ident FROM yanb_ulist_buffs WHERE ulist_id=?");)                    {                        stmt.setInt(1, ulist.getKey());                        try (ResultSet rs = stmt.executeQuery();)                        {                            while (rs.next())                            {                                String buffIdent = rs.getString("ulist_buff_ident");                                Buff buff = getBuff(buffIdent);                                if (buff == null)                                {                                    _LOGGER.warning("YANBuffer - Data: Buff with ident does not exists!");                                }                                else                                {                                    ulist.getValue().add(buff);                                }                            }                        }                    }                }            }        }        catch (SQLException sqle)        {            throw new SQLException(sqle);        }    }        private Map<Integer, UniqueBufflist> _getPlayersULists(int playerObjectId)    {        Map<Integer, UniqueBufflist> ulists = _uniqueBufflists.get(playerObjectId);        if (ulists == null)        {            ulists = new LinkedHashMap<>();            _uniqueBufflists.put(playerObjectId, ulists);        }                return ulists;    }        private UniqueBufflist _getPlayersUList(int playerObjectId, String ulistName)    {        Map<Integer, UniqueBufflist> ulists = _getPlayersULists(playerObjectId);        for (Entry<Integer, UniqueBufflist> entry : ulists.entrySet())        {            if (entry.getValue().ulistName.equals(ulistName))            {                return entry.getValue();            }        }        return null;    }        public boolean createUniqueBufflist(int playerObjectId, String ulistName)    {        // prevent duplicate entry        if (_getPlayersUList(playerObjectId, ulistName) != null)        {            return false;        }                try (Connection con = L2DatabaseFactory.getInstance().getConnection();            PreparedStatement stmt = con.prepareStatement("INSERT INTO yanb_ulists (ulist_char_id,ulist_name) VALUES(?,?)", Statement.RETURN_GENERATED_KEYS);)        {            stmt.setInt(1, playerObjectId);            stmt.setString(2, ulistName);            stmt.executeUpdate();            ResultSet rs = stmt.getGeneratedKeys();            rs.next();            int newId = rs.getInt(1);            _getPlayersULists(playerObjectId).put(newId, new UniqueBufflist(newId, ulistName));            return true;        }        catch (SQLException sqle)        {            _LOGGER.log(Level.WARNING, "Failed to insert unique bufflist!", sqle);            return false;        }    }        public void deleteUniqueBufflist(int playerObjectId, String ulistName)    {        UniqueBufflist ulist = _getPlayersUList(playerObjectId, ulistName);        if (ulist == null)        {            return;        }                try (Connection con = L2DatabaseFactory.getInstance().getConnection();            PreparedStatement stmt = con.prepareStatement("DELETE FROM yanb_ulists WHERE ulist_char_id=? AND ulist_id=?");)        {            stmt.setInt(1, playerObjectId);            stmt.setInt(2, ulist.ulistId);            stmt.executeUpdate();            _getPlayersULists(playerObjectId).remove(ulist.ulistId);        }        catch (SQLException sqle)        {            _LOGGER.log(Level.WARNING, "Failed to delete unique bufflist!", sqle);        }    }        public boolean addToUniqueBufflist(int playerObjectId, String ulistName, Buff buff)    {        UniqueBufflist ulist = _getPlayersUList(playerObjectId, ulistName);        // prevent duplicate entry with ulist.contains(buff)        if ((ulist == null) || ulist.contains(buff) || ((buff.getType() == BuffType.BUFF) && (ulist.numBuffs >= _uniqueMaxBuffs)) || ((buff.getType() == BuffType.SONG_DANCE) && (ulist.numSongsDances >= _uniqueMaxSongsDances)))        {            return false;        }                try (Connection con = L2DatabaseFactory.getInstance().getConnection();            PreparedStatement stmt = con.prepareStatement("INSERT INTO yanb_ulist_buffs VALUES(?,?)");)        {            stmt.setInt(1, ulist.ulistId);            stmt.setString(2, buff.ident);            stmt.executeUpdate();            ulist.add(buff);        }        catch (SQLException sqle)        {            _LOGGER.log(Level.WARNING, "Failed to insert buff into unique bufflist!", sqle);            return false;        }                return true;    }        public void removeFromUniqueBufflist(int playerObjectId, String ulistName, Buff buff)    {        UniqueBufflist ulist = _getPlayersUList(playerObjectId, ulistName);        if ((ulist == null) || !ulist.contains(buff))        {            return;        }                try (Connection con = L2DatabaseFactory.getInstance().getConnection();            PreparedStatement stmt = con.prepareStatement("DELETE FROM yanb_ulist_buffs WHERE ulist_id=? AND ulist_buff_ident=?");)        {            stmt.setInt(1, ulist.ulistId);            stmt.setString(2, buff.ident);            stmt.executeUpdate();            ulist.remove(buff);        }        catch (SQLException sqle)        {            _LOGGER.log(Level.WARNING, "Failed to remove buff from unique bufflist!", sqle);        }    }        public HtmlType getHtmlType()    {        return _htmlType;    }        public long getHealCooldown()    {        return _healCooldown;    }        public int getMaxUniqueLists()    {        return _maxUniqueLists;    }        public int getUniqueMaxBuffs()    {        return _uniqueMaxBuffs;    }        public int getUniqueMaxSongsBuffs()    {        return _uniqueMaxSongsDances;    }        public Buff getBuff(String buffIdent)    {        return _buffs.get(buffIdent);    }        public BuffCategory getBuffCat(String buffCatIdent)    {        return _buffCats.get(buffCatIdent);    }        public Map<Integer, BufferNpc> getBufferNpcs()    {        return _bufferNpcs;    }        public BufferNpc getBufferNpc(int npcId)    {        return _bufferNpcs.get(npcId);    }        public VoicedBuffer getVoicedBuffer()    {        return _voicedBuffer;    }        public boolean canHaveMoreBufflists(L2PcInstance player)    {        return _getPlayersULists(player.getObjectId()).size() < _maxUniqueLists;    }        public boolean hasUniqueBufflist(int playerObjectId, String ulistName)    {        return _getPlayersUList(playerObjectId, ulistName) != null;    }        public List<Buff> getUniqueBufflist(int playerObjectId, String ulistName)    {        UniqueBufflist ulist = _getPlayersUList(playerObjectId, ulistName);        if (ulist == null)        {            return null;        }        return Collections.unmodifiableList(ulist);    }        public HTMLTemplatePlaceholder getPlayersUListPlaceholder(int playerObjectId, String ulistName)    {        UniqueBufflist ulist = _getPlayersUList(playerObjectId, ulistName);        if (ulist == null)        {            return null;        }        return ulist.placeholder;    }        public HTMLTemplatePlaceholder getPlayersUListsPlaceholder(int playerObjectId)    {        Map<Integer, UniqueBufflist> ulists = _getPlayersULists(playerObjectId);        if (ulists.isEmpty())        {            return null;        }                HTMLTemplatePlaceholder placeholder = new HTMLTemplatePlaceholder("uniques", null);        for (Entry<Integer, UniqueBufflist> entry : ulists.entrySet())        {            placeholder.addAliasChild(String.valueOf(placeholder.getChildsSize()), entry.getValue().placeholder);        }        return placeholder;    }}
the0ffspring
Posts: 12
Joined: Wed Nov 26, 2014 12:25 am

Re: YANBuffer - Import problem?

Post by the0ffspring »

YANBufferNpcBypassHandler.java

Code: Select all

/* * Copyright (C) 2004-2013 L2J DataPack *  * This file is part of L2J DataPack. *  * L2J DataPack 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 DataPack 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 YANModPack.YANBuffer; import com.l2jserver.gameserver.handler.IBypassHandler;import com.l2jserver.gameserver.model.L2Object;import com.l2jserver.gameserver.model.actor.L2Character;import com.l2jserver.gameserver.model.actor.L2Npc;import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; /** * @author FBIagent */public class YANBufferNpcBypassHandler implements IBypassHandler{    private static final class SingletonHolder    {        protected static final YANBufferNpcBypassHandler INSTANCE = new YANBufferNpcBypassHandler();    }        public static final String BYPASS = "YANBufferNpc";    private static final String[] _BYPASS_LIST = new String[]    {        BYPASS    };        static YANBufferNpcBypassHandler getInstance()    {        return SingletonHolder.INSTANCE;    }        YANBufferNpcBypassHandler()    {    }        @Override    public boolean useBypass(String command, L2PcInstance activeChar, L2Character target)    {        if (!activeChar.validateBypass(command))        {            return false;        }                L2Object playerTarget = activeChar.getTarget();        if ((playerTarget == null) || !playerTarget.isNpc())        {            return false;        }                YANBuffer.getInstance().executeCommand(activeChar, (L2Npc) playerTarget, command.substring(BYPASS.length()).trim());        return true;    }        @Override    public String[] getBypassList()    {        return _BYPASS_LIST;    }} 
the0ffspring
Posts: 12
Joined: Wed Nov 26, 2014 12:25 am

Re: YANBuffer - Import problem?

Post by the0ffspring »

ItemRequirement.java

Code: Select all

/* * 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/>. */package YANModPack.util; import com.l2jserver.gameserver.model.items.L2Item; import YANModPack.util.htmltmpls.HTMLTemplatePlaceholder; /** * @author FBIagent */public final class ItemRequirement{    /** Item id */    public final L2Item item;    /** Item amount */    public final long amount;    /** HTMLTemplatePlaceholder */    public final HTMLTemplatePlaceholder placeholder;        public ItemRequirement(final L2Item item, final long amount)    {        this.item = item;        this.amount = amount;        this.placeholder = new HTMLTemplatePlaceholder("item_requirement", null);        this.placeholder.addChild("id", String.valueOf(item.getItemId())).addChild("icon", item.getIcon()).addChild("name", item.getName()).addChild("amount", String.valueOf(amount));    }} 
Post Reply