Help with a bug encountered in my plugin LinkedChest

Discussion in 'Bukkit Help' started by Ghomerr, Apr 10, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Ghomerr

    Hi Bukkit community.

    I would like to request some help about a weird problem I have encountered using my plugin LinkedChest.

    You can find its thread here : http://forums.bukkit.org/threads/me...ts-together-from-everywhere-1-2-5-r1-0.64972/

    I will describe a bit the plugin to explain how it works to let you understand my problem.

    My plugin allows to link chests together by creating a master chest and then linking other chests to a master chest. In fact, I keep the reference of the Inventory of the master chest in a map and open this inventory with the player method "openInventory" on demand. When a player right-click on a linked chest whose the location is known, I open the Inventory of the master chest and cancel the event of "PlayerInteraction" on this chest.

    Actually, it seems to work perfectly, but... in sometimes, some actions are not taken into account and I really don't know why.

    How to reproduce this bug? Go to a new area and generate some chunks. Create a chest. Fill it. Add it as a master chest using the plugin command "/lc add <chestname>". Then go to another area, far enough to unload the chunk where the master chest has been created. Then create a second chest and link it with the previous master chest. Add or remove some items. Then use the command "/reload". If you re-open the linked chest, your previous actions would not be taken into account, and some items will be missing (if you've added new items) or the removed items will still be in the chest (if you've taken them). However the items you added before linking it will be there.

    If you use the command "/save-all" after adding a chest, or using a linked chest, it works fine.

    I tried to check if the chunk of the master chest is loaded when I opened its Inventory and it seemed always loaded. I also tried to check the Java references of the Inventories and they are always the same after the /reload command.

    I have no other ideas to try or check to find a solution for this problem.

    The source code of the plugin is available in the latest download package. (here: http://dev.bukkit.org/media/files/585/164/LinkedChest-1.2.zip)

    Thank you in advance !

    I think it's not the right section of the forum... It should be in the section Plugin Development, isn't it ? :/

    Sorry for this mistake.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  2. Offline

    Codisimus

    I am receiving reports on most of my plugins of blocks being "unlinked". In my case, I check if blockA.equals(blockB) if the chunk has been unloaded and reloaded then that will return false even if they have the same location. So you proly store the Block object and later try to call a method on it, and if the Chunk was unloaded then the block object is no longer valid? I haven't looked at your code but If I find a solution I will post it here. I noticed how old this post is so you may have already fixed this yourself.
     
  3. Offline

    Ghomerr

    Thank you for being concerned by my problem. :p

    Actually, this is still unsolved.

    I had made some tests about "references" between to moment, before and after a chunk reload, and I found nothing.

    I don't store the Block object but the Inventory. When I printed the reference of this objet, I saw nothing strange when the reload was done. The reference was changed, but I got the right one just after the reload. So, it should be ok.

    I will really appreciate to have some news if you find something !

    Thank you !
     
  4. Offline

    Codisimus

    To fix mine I just store a string of the Block location instead (world'x'y'z) That wouldn't really work for your situation but if you want, I could look at your code to see if I could be any help.
     
  5. Offline

    Ghomerr

    The source code is available in the download file. Feel free to check it.

    I've thought of something to workaround this problem. But it is not really "clean".

    My idea is to keep a copy of the content of each linked inventory. When a player closes a chest, its inventory check if the number of items (to make it fast) is the same as the copy. If this is not the case, I update my copy. When the plugin is unloaded (or disabled), I store my copy in a file which will be reaload when the plugin is enabled.

    If a player opens a chest where the content has not the same number of items as the copy, the copy will replace the content of the inventory (to avoid my problem).

    I don't see any other solution. I will "code" it soon to test it in a real environment.

    Actually, I think it won't work... Because, when a player opens a chest, its content can be modified by another player currently using this chest, so its content won't work... The "best" solution will be to manage all the concurrency on chests, which will mean to remake all the system :/
     
  6. Offline

    Ghomerr

    Well, I think I've finally found my bug.

    I was keeping in RAM (plugin hashmap) all inventories references. As I check if all chests still exist, and getting the reference to the chest block, each time a player tries to open a "linked" chest, I use directly the inventory from the block instead of the one stored in my hashmap.

    I really don't know why I was doing that though I was accessing the chest each time... I'm pretty sure this was the cause of my bug.
     
Thread Status:
Not open for further replies.

Share This Page