ClickInventoryEvent not firing

I am trying to block certain items from being obtained in certain worlds. Since I only care about items obtained through creative mode I thought to only check ClickInventoryEvent.Creative.

Here the code I am trying to use to accomplish this: http://pastebin.com/Fa77Ze3X

It is in my main class annotaded by @Plugin and all other events are working fine.

I added the loggers to see how much of my code actually worked. Running the plugin on my server, nothing gets logged no matter what and items are obtainable as usual.

Both dev environment and server are running API 5 on builds 2070+, so I think that the event should be implemented in both systems. Also, no errors get displayed in the console, so there doesn’t seem to be an issue in that regard.

Sorry that the event isn’t clear - I need to get around to adding javadocs to it.

ClickInventoryEvent.Creative is only fired for inventory interactions in creative mode - not for items obtained in Creative mode. Because of the way the Vanilla client works, ClickInventoryEvent.Creative is unfortunately the only type of ClickInventoryEvent you will receive for a player in Creative.

@Aaron1011

Is it possible to work out an items spawn cause for being added to the players inventory in the creative menus,
Add custom data to the item to retain that the item was spawned in creative,
and filter the items that were spawned in creative when the world changes?

@floh Even if the above turns out to be possible, you would then have to deal with player duplicating items from the survival world in the creative world, adding custom data to them would then cause them not to stack, so you would also probably want to mark the items with lore that were spawned in creative, so that the player will know which items will be removed.

It’s also really easy to accidentally delete survival items in creative mode.

My personal recommendation would be to rethink how you are handling this, and replace the players entire inventory when they cross worlds, akin to multiverse-inventories, or have a “mod mode” plugin that when players enter creative in the survival world for whatever reason, that their inventories swap out.

If you wanted to take it a step further you could make it so people in creative can’t edit blocks or inventories in the wilderness, and only in designated creative plots / spawn.

Is it possible to work out an items spawn cause for being added to the players inventory in the creative menus,

It might be, but it would be difficult. Internally, the client only sends Creative Inventory Action packets for inventory interactions done in Creative mode. I would need to double-check, but I don’t think this packet is sent when you take an item out of the creative menu - only when you place it into your inventory.

It might still be possible to detect taking items out of the inventory, by tracking ‘pickup’ events (making a slot empty) and ‘place’ events (setting an itemstack into a slot). ‘Normal’ interactions with an inventory while in creative mode should have both of these fired, whereas taking items out of the creative menu should only fire the latter event. There would probably be additional complications, such as handling identical ItemStacks in the inventory, but in principle, it could work.

@ryantheleach I am already currently using seperate inventories for multiple worlds. The only problem is that I am running a pixelmon server and I want to prevent people from boosting up their pokemon in their creative worlds since the pokemon are the same over all worlds and pixelmon is closed source, so I have no way to change that.

To combat this I thought i could add all the items I want banned to a list and then compare the list to players inventories, removing any matches. Would you know of any other events which could be used?

Yeah dunno sorry, I havn’t really messed around with creative mode stuff much.

@Aaron1011 any ideas?

The only real other advice I can really offer, is maybe having a separate server for creative, behind a proxy… but you have likely already ruled that out.

Well I’m already using bungeecord. The problem is that I do want Pixelmon to stay the same, just not be upgraded with items in the creative world. The only way I could see doing that is somehow syncing the pixelmon every time someone logs on to the creative server. Though, then legit lvls gained in creative are lost, which isnt ideal either.

How did people do it on bukkit? These kinds of plugins existed on bukkit. Well not per world ones I think, but that isn’t the main issue here. The server receives the same events since the client isnt different in any way, so I don’t see why this shouldn’t be possible using Sponge events

@Aaron1011 sorry if i’m being slow or blind, but I haven’t been able to find pickup or place events in the item event api?

Not sure if this will help but have you experimented with this?

1 Like

well… Now I feel plain stupid. There seems to be a @TrenTech plugin for everything :stuck_out_tongue:

Looks like i’m using that. Though I will have to look at the source since I am quite curious how you got it to work.

Thank you for your amazing plugins though.

1 Like

Yeah I have no life

1 Like

In any case, your “lack” of one makes mine so much easier.

Looks like this issue can be closed, even though this is more of a workaround to the actual issue addressed since there doesnt seem to be a fitting event, or better said, the documentation is still lacking.

Thanks for your help guys ^^