Player.openInventory() only opens CraftInventories

Discussion in 'Plugin Development' started by randomizer1234, Aug 7, 2014.

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

    randomizer1234

    Hello.
    I'm writing a plugin for virtual chests.
    I've implemented the interface Inventory, thinking that CraftBukkit's method openInventory() in CraftHumanEntity would open it without problems, since I'm implementing all the methods of the interface.
    Apparently, this is not the case.
    CraftBukkit actually casts the Inventory to CraftInventory here (without even checking if the Inventory is an instance of CraftInventory! TODO...), which I think it is very wrong! Why would you have an Inventory interface for plugins if then only the Craft implementation is usable in CraftBukkit?
    I've checked the sourcecode of the Glowstone server (another server implementing Bukkit), and apparently it does work as I think it should.
    I will open a ticket in the issue tracker after hearing some opinions in the forum.
     
  2. Offline

    fireblast709

    randomizer1234 oooor you use the Bukkit.createInventory() methods?
     
  3. Offline

    randomizer1234

    And get an instance of CraftInventory which is totally useless to me. I'm talking about a different level of abstraction.
    There is a reason if I bothered to reimplement the whole Inventory interface, and CraftBukkit should work with every class implementing it. Sure, it can check if it is the internal implementation, CraftInventory, for optimization purposes, but it should also provide a fallback for any other class implementing Inventory, and should implement all the standard vanilla Minecraft operations for every Inventory (updating the contents as the user interacts with the view on the client for example).
     
  4. Offline

    Shevchik

    Because client doesn't support custom inventories.
    So you should extend CraftInventory instead of impelementing inventory interface.
     
  5. Offline

    fireblast709

    elaborate please.
     
  6. Offline

    randomizer1234

    The client doesn't matter here. My Inventory is a InventoryType.CHEST, which as far as I know is supported by the client since January 2010.
    And no, I should not extend CraftInventory. I should not extend any CraftBukkit classes. As a matter of fact, I should not even think about CraftBukkit while writing a plugin.

    The method you suggested to me returns an instance of a class implementing Inventory, which in the case of CraftBukkit is CraftInventory. That's a utility method. The fact that the method is there doesn't mean that I shouldn't implement my own Inventory if I need a special behavior. That's the exact point of abstraction, that's why Bukkit developers bother writing both Bukkit and CraftBukkit. Bukkit is a level of abstraction, a "contract". CraftBukkit is what adapts the vanilla Minecraft server to that contract. But both CraftBukkit and the plugins should only care about Bukkit, and implement Bukkit.
    What I'm pointing out here is a problem with CraftBukkit's implementation of a Bukkit interface, a breach of the contract, if you will.
     
  7. Offline

    fireblast709

    randomizer1234 nice description of the structure Bukkit uses. Though, I've had my fair share of it the past year or two. There should be no issues on relying on classes that use CraftBukkit classes, unless you don't run a CB server of course.

    If you need some special behaviour, either work with listeners (Bukkit only) or extend CraftInventory (CraftBukkit depend needed)
     
  8. Offline

    randomizer1234

    If I need some special behavior I implement the right interface. I'm writing a plugin for Bukkit, not a mod for CraftBukkit.
    In this case, my plugin works, I've even tested it on Glowstone and the openInventory() method accepts my Inventory implementation. CraftBukkit doesn't, and needs to be patched. Why should I work around a problem instead of solving it (or asking someone better than me to solve it)?
    I'm going to open a issue on the tracker and see what the developers think about that.
    Then, if they agree with me, I will try to branch CraftBukkit and solve it if the developers are working on something else.
    Thank you for your opinion though.

    Here's the issue on the tracker: https://bukkit.atlassian.net/browse/BUKKIT-5750

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page