MapleItemInformationProvider issue
I set up a local v83 server with MoopleDEV to learn a bit of coding.
I figured I'd start with creating a few useful commands.
So I was trying to create the following command:
!getplayerinventory <tab> <name>
So !getplayerinventory etc Swag would list all items in the etc tab of Swag.
I got it to work, but it displays the ID and not the name of the item, but I cannot get it to work.
I tried to post the code in code and php tags but it does not keep the structure so here is a picture instead.
https://i.gyazo.com/71273faab463eaea...9ffe011d70.png
It is the last commented line that crashes it, the first free writes out properly.
Re: MapleItemInformationProvider issue
When you print an object in java, by default, it invokes the toString() method.
Your toString() method for the item object likely just prints out the itemID; what you have commented out is drawing the item's name and other information from your cache. I don't see why you want to print out the mii object itself, maybe try to uncomment one 'message' method call at a time.
Re: MapleItemInformationProvider issue
That is what I am doing.
MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();
player.message(item.getItemId() + ""); //prints properly
player.message(item.getQuantity() + ""); //prints properly
player.message(mii + ""); //prints out properly
player.message(mii.getName(item.getItemId())); //crash
Re: MapleItemInformationProvider issue
Quote:
Originally Posted by
cljnilsson
That is what I am doing.
MapleItemInformationProvider mii = MapleItemInformationProvider.getInstance();
player.message(item.getItemId() + ""); //prints properly
player.message(item.getQuantity() + ""); //prints properly
player.message(mii + ""); //prints out properly
player.message(mii.getName(item.getItemId())); //crash
mii.getName(item.getItemId()) could be returning null, as the item's name may not be in the cache. Look at the getName method for more information.
I'd try this
PHP Code:
String name = mii.getName(item.getItemId());
if(name == null) player.message("no name in the cache");
else player.message(name);
Re: MapleItemInformationProvider issue
I get the "No name in the cache" for all the items in the inventory.
What does this mean? and how can I fix it.
It is just normal items, items dropped from green snails specifically.
From what I can see the item should be added automatically to the namecache but apparently doesn't.
Re: MapleItemInformationProvider issue
Study the MapleItemInformationProvider class, figure out how it works.
Perhaps the names are never cached at all.
Re: MapleItemInformationProvider issue
Quote:
Originally Posted by
Umbreon
Study the MapleItemInformationProvider class, figure out how it works.
Perhaps the names are never cached at all.
Right.
I was gonna test to see if it works with some sort of debug message but realized I do not know where this debug message appear. In the console window where the server is running?
Re: MapleItemInformationProvider issue
I've done some digging and it seems like getStringData in MapleItemInformationProvider is the function returning null.
PHP Code:
if (cat.equalsIgnoreCase("null")) {
System.out.println("IT REUTNRS NULL! (2)" + itemId);
System.out.println(theData.getChildByPath(String.valueOf(itemId)) + "");
System.out.println(etcStringData + "");
return theData.getChildByPath(String.valueOf(itemId));
}
Output
PHP Code:
IT REUTNRS NULL! (2)4161001
null
provider.wz.XMLDomMapleData@2cc5c898
However, it seems to work fine for use/equips, it is only the etc items that return null.
Re: MapleItemInformationProvider issue
Quote:
Originally Posted by
cljnilsson
However, it seems to work fine for use/equips, it is only the etc items that return null.
Try comparing #getStringData with #getAllItems (and constructor). Perhaps you'll find out why only ETC items are not loaded properly.
Re: MapleItemInformationProvider issue
Looks all fair to me.
PHP Code:
//constructor
cashStringData = stringData.getData("Cash.img");
consumeStringData = stringData.getData("Consume.img");
eqpStringData = stringData.getData("Eqp.img");
etcStringData = stringData.getData("Etc.img");
insStringData = stringData.getData("Ins.img");
petStringData = stringData.getData("Pet.img");
PHP Code:
//getAllItems()
List<Pair<Integer, String>> itemPairs = new ArrayList<>();
MapleData itemsData;
itemsData = stringData.getData("Cash.img");
for (MapleData itemFolder : itemsData.getChildren()) {
itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
}
itemsData = stringData.getData("Consume.img");
for (MapleData itemFolder : itemsData.getChildren()) {
itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
}
itemsData = stringData.getData("Eqp.img").getChildByPath("Eqp");
for (MapleData eqpType : itemsData.getChildren()) {
for (MapleData itemFolder : eqpType.getChildren()) {
itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
}
}
itemsData = stringData.getData("Etc.img").getChildByPath("Etc");
for (MapleData itemFolder : itemsData.getChildren()) {
itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
}
itemsData = stringData.getData("Ins.img");
for (MapleData itemFolder : itemsData.getChildren()) {
itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
}
itemsData = stringData.getData("Pet.img");
for (MapleData itemFolder : itemsData.getChildren()) {
itemPairs.add(new Pair<>(Integer.parseInt(itemFolder.getName()), MapleDataTool.getString("name", itemFolder, "NO-NAME")));
}
return itemPairs;
Re: MapleItemInformationProvider issue
@cljnilsson
and compared with #getStringData ? (pay attention to 'path')
Re: MapleItemInformationProvider issue
getStringData returns
stringData.getData("Etc.img").getChildByPath(String.valueOf(itemId))
getAllItems
stringData.getData("Etc.img").getChildByPath("Etc").getChildren()
So if I use that and then loop through the list and look for the id to get the name?
Re: MapleItemInformationProvider issue
no, I mean
Eqp.img/Eqp/Weapon/ItemID
*see getStringData, cat = "Eqp/Weapon" -> now you can get items directly
Consume.img/ItemID *you can get items directly
Ins.img/ItemID *you can get items directly
Etc.img/Etc/ItemID
*you're missing cat = ???
Re: MapleItemInformationProvider issue
The cat is for equips only since the eqp.img got sub categories.
Etc does not have this.
I edited the return to this:
PHP Code:
MapleData md = theData.getChildByPath(String.valueOf(itemId));
if(theData == etcStringData) {
List<MapleData> l = theData.getChildByPath("Etc").getChildren();
for(MapleData item: l) {
if(Integer.parseInt(item.getName()) == itemId) {
md = item;
break;
}
}
}
return md;
Which works though I know that using such an iteration is not ideal.
Re: MapleItemInformationProvider issue
Quote:
Originally Posted by
cljnilsson
The cat is for equips only since the eqp.img got sub categories.
Etc.img has "Etc" directory... so it should be [cat = "Etc"]