InventoryMoveItemEvent Cancel Glitchy

Discussion in 'Plugin Development' started by NaruSenpai, Nov 9, 2015.

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


    I'm trying to prevent players from moving items in shop GUIs, I'm using
        public void onInvMove(InventoryMoveItemEvent e)
            Inventory dest = (Inventory) e.getDestination();
            if (dest.toString() == "Market")
    But it only cancels the event a portion of the time, does anyone have anything more efficient?
  2. Offline


    Yeah, that is the ping between the client and the server (it doesn't matters if it is local or not) Basically not the canceling takes time. The player must send his action to the server, then the server to the plugin, then it gets back the reaction, and it must send this to the player. This can't be done immedialitely (except if you have a quantum computer and a net, that would make Nasas look like a babys toy)
  3. Offline


    @NaruSenpai You can get around this by listening to the inventory click event and cancelling it if they click on an item that you don't want them to take.
  4. Offline


    I think it would be glitchy too
  5. Offline


    @mcdorli & @CoolDude53
    I was afraid someone would say something like that. Thanks for explaining. I'll try listening to inventory click and see if the results are any better.
  6. Offline


    You don't have to check for items specifically, just check if the Inventory they're operating in is equal to your Shop GUI inventory, if so: cancel the event. It's not buggy.
  7. Offline


    I do p.updateInventory();
  8. Offline


    A few things:
    1. InventoryMoveItemEvent is for things like hoppers (& droppers?) (See:, I'd suggest using InventoryClickEvent
    2. Lets say that this did work: You are toString()'ing an Inventory and (attempting, see below) to test if a string "Market" matches a string that would look something like this: [email protected] (You'd probably want to try Inventory#getName)
    3. You are comparing strings with '==' which tests for reference equality, you should be using .equals() or .equalsIgnoreCase() to compare the contents of the string

    Quite frankly, I am surprised that it:
    Latency to the server is rather negligible unless you have a terrible connection to the server. Localhost latency would usually be 0 - 1 milliseconds, which is virtually nothing. As for time it takes for cancelling the event, again it is negligible
    Last edited: Nov 9, 2015
  9. Offline


    Don't forget that minecraft only does checks every 20 ticks (hopefully), so there is 5 milliseconds max, vefore it even starts to react.
  10. Offline


    One tick is 50 milliseconds (1 second is 1000 milliseconds)
  11. Offline


    Yeah, 1 zero was left of accidentally. If you can tell the difference between 60 fps and 20 fps, then you will always notice the little glitchyness.
Thread Status:
Not open for further replies.

Share This Page