Jump to content
  • 0

IconsTable loads data everytime


Question

Posted (edited)

Hello , ive found on forum this code and added it to my project , i am using it for shift + click and lucky chest feature , so that when you open a chest an htm window appears and tells you what item you obtained , count and adds the icon of the item. 

Problem is that everytime shift + click is requested or opening chest , all 10k icons loads and i get this message on gs log:

IconsTable: Succesfully loaded 9209 icons, in 17.0 Milliseconds.

 

the code im using is this:

 

package net.sf.l2j.gameserver.datatables;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Logger;

import net.sf.l2j.gameserver.GameServer;
import net.sf.l2j.gameserver.xmlfactory.XMLDocumentFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

public class IconsTable
{
    public static final Map<Integer, String> Icons = new HashMap<>();
    private static int count;
    private static long t0;
    private static double t;

    private static final Logger _log = Logger.getLogger(GameServer.class.getName());

    public void reload()
    {
        Icons.clear();
        parseData();
    }

    public static void parseData()
    {
       count=0;
        t0 = System.currentTimeMillis();
        try
        {
            File f = new File("./data/xml/icons.xml");
            Document doc = XMLDocumentFactory.getInstance().loadDocument(f);

            for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
            {
                if ("list".equalsIgnoreCase(n.getNodeName()))
                {
                    for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
                    {
                        if (d.getNodeName().equalsIgnoreCase("icon"))
                        {
                            count++;
                            NamedNodeMap attrs = d.getAttributes();
                            Node att = attrs.getNamedItem("Id");
                            Node att2 = attrs.getNamedItem("value");
                            Icons.put(Integer.valueOf(att.getNodeValue()), String.valueOf(att2.getNodeValue()));
                        }
                    }
                }
            }
            t = System.currentTimeMillis() - t0;
            _log.config("IconsTable: Succesfully loaded "+count+" icons, in "+t+" Milliseconds.");
        }
        catch (Exception e)
        {
            _log.config("IconsTable: Failed loading IconsTable. Possible error: "+e.getMessage());
        }
    }

    public static String getIcon(int id)
    {

        if (Icons.get(id)==null)
        {
            _log.config("IconsTable: Invalid Icon request: "+id+", or it doesn't exist, Ignoring ...");
            return "null";
        }
        return Icons.get(id);
    }

    public static final IconsTable getInstance()
    {
        parseData();
        return SingletonHolder._instance;
    }

    private static class SingletonHolder
    {
        protected static final IconsTable _instance = new IconsTable();
    }
}

 

and when i want to get the icon i use this


IconsTable.getInstance().getIcon(ITEMID)) , what i need to know is that if there isn't any way to store all this 10k icons , and load them only once , not for every request to get icon.. 

 

 

EDIT: PROBLEM SOLVED , HERE IS THE FIX :serious:

   public static String getIcon(int id)
    {

        if (Icons.get(id)==null)
        {
            parseData();
            _log.config("IconsTable: Invalid Icon request: "+id+", or it doesn't exist, Ignoring ...");
            return "null";
        }
        return Icons.get(id);
    }

    public static final IconsTable getInstance()
    {
        return SingletonHolder._instance;
    }

i had to remove parsedata(); from the getInstance() and add it after if(icons.get(id)==null) , hope that this won't slowdown server much

Edited by arm4729

2 answers to this question

Recommended Posts

  • 0
Posted

You were invoking the parse Data method to fill the Map from the xml every time you made the query of the icon for its key, the first thing if it could have reduced the performance of your server.

  • 0
Posted

This is not a fix, you should avoid parsing data with every getInstance() call which you already did and parse data once in a private constructor. Reload method should be called on admin commands/bypasses. Anyway, i'm locking this topic since you feel satisfied with this solution. In case you want to unlock send me a dm.

Guest
This topic is now closed to further replies.


  • Posts

    • Even if I was reselling, as you claim, you got refunded down to the last penny. At least when I work with someone, I try to find a solution. Just because something didn’t work for you doesn’t mean it hasn’t worked for others. I’ve provided different kinds of services successfully, and I’ve even had several of your own clients come to me complaining about the mess you left behind, with unfinished code and ongoing issues.   Let’s be real. I supported you and always spoke positively about you until I realized that you only care about your wallet, not how your customers feel. That was disappointing. I don’t care much anymore, because some people change and some don’t. They stay comfortable being that way.   As for the family topic, I didn’t say anything bad or wrong. That was information I heard from a friend. And no, I won’t ban you. It’s not worth the energy to even open the admin panel. You can keep doing what you’re doing, but don’t claim you’re a good and clean person when you clearly don’t value other people’s time, money, or effort.   When you talk about being mature, your actions show the opposite. For once in your life, admit that you're still acting immature. Hopefully one day you'll understand how life really works and learn to move on. But until then, take responsibility and clean up the mess you've left behind.   TL;DR: I won’t be reading anything else, just grabbing popcorn and enjoying the show.
    • Gay whoever doesn't read it
    • Hey everyone, I’m reaching out for urgent support with my NPC stats—specifically Baium, who on my server seems to have gone full god mode. Apparently, I’m the "crazy dreamer" who believes Baium shouldn’t have over 4 million HP, 30k+ P. Atk, attack speed faster than a dagger, and more M. Atk than seven Antharas combined 😅. My server's developer (VILMIS) refuses to provide proper support, claiming I have no idea about the "real stats" and that I’m imagining things. I’ve tried modifying the values through the admin console, but nothing takes effect. I’m desperate—the server launches on 04/10, and I really want these stats to be closer to official NCSOFT values or at least something balanced and realistic. If anyone with experience can lend a hand or point me in the right direction, please reach out. I’d truly appreciate it 🙏    
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock