Storage Drawers

Storage Drawers

151M Downloads

Protection Issue

Sir-Will opened this issue ยท 12 comments

commented

hey,
it would be great if the items don't get delivered to the player if the interaction event get canceled from a other mod. As it is impossible to protect the storage drawers currently.

commented

It seems like that this broke upwards of 1.6.2 somewhere, can this be?
It is telling me that the event was called but I still get the item. While adding stuff to a drawer doesn't work when the event is canceled.

commented

Removing an item prompts the Protection message but you still get the item.
When you try to add something, there is a client server desync. The item appears to be in the drawer, on a other update (Reloging / clicking the drawer / inventory sort), the item reappears in your inventory and disappears on the drawer.

commented

You could simply fire the PlayerInteractEvent yourself in your server-side packet handler.

PlayerInteractEvent event = ForgeEventFactory.onPlayerInteract(player, action, x, y, z, face, world);
if (event.isCancelled()) {
    // don't process
    return;
}
// proceed...

This has the advantage that it works with generic protection handlers.

commented

That crossed my mind, but I was somewhat concerned about firing an event in an unexpected place.

commented

Why would that be an unexpected place? The call stack doesn't really matter so it should work after all.

commented

Any news to this?

commented

This should be fixed in 1.4.0-alpha2.

commented

Never crossed my mind. Can you recommend a test case?

commented

Sorry, I'm not sure what do you mean with test case, can you elaborate?

commented

I'm not familiar with anything canceling interaction events. How would you suggest I reproduce this for testing a fix?

commented

I just wrote a simple mod which cancels the event like this:

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onPlayerInteract(PlayerInteractEvent event) {
        event.setCanceled(true);
        event.entityPlayer.addChatMessage(new ChatComponentText("Click!"));
    }

You maybe can look at jabba to see how he handles it as it is a similiar mod and it is not possible to take the items if the event is canceled.

commented

I've run into a problem with this.

JABBA works correctly on left-click because it's handling the server-side onBlockClicked event, and that gets suppressed by the PlayerInteractEvent.

In my case, I need to have sub-block-resolution click data, which is not included with the standard onBlockClicked event. That means I have to handle the event client-side and dispatch a packet with the extra data, and then handle that server-side. Unfortunately, the PlayerInteractEvent does NOT attempt to intercept the client-side block-left-click event.

If you have other ideas to pursue I'll take a look, but otherwise the best I can think of is providing my own cancelable event that another mod could intercept.