Jump to content

[SOLVED] How to cancel an item drop/toss by player, without losing the item?


Evert

Recommended Posts

For a server-side mod, that can make some areas private, so other players can't break or build there.

I want to make that those players also can't drop(Q) items there.

 

I can use 'ItemTossEvent', but if that is canceled, the item disappears completely.

 

I tried 'ItemEvent', but that is called with item events where no players are involved and I can't find a way to determine what player dropped the item, so there is no way of knowing if the event has to be canceled.

 

What I'm looking for is:

- A method to return the lost item when using 'ItemTossEvent'.

or

- A method to determine the player name that dropped an item when using 'ItemEvent'.

or

- Some other way to make this work.

 

Thank you.

Link to comment
Share on other sites

Thank you. That works.

 

It is a bit buggy.

When an item is dropped with Q it gets replaced immediately, but when it is dropped with the right click from the inventory screen, it seems to disappear. It reappears later with an inventory change or after reconnecting.

 

	public void itemEvent(ItemTossEvent event)
{
	if ( event.isCancelable() )
	{
		ItemStack itemStack = event.entityItem.item;
		event.setCanceled(true);
		event.player.inventory.addItemStackToInventory(itemStack);
	}
}

Link to comment
Share on other sites

Thank you. That works.

 

It is a bit buggy.

When an item is dropped with Q it gets replaced immediately, but when it is dropped with the right click from the inventory screen, it seems to disappear. It reappears later with an inventory change or after reconnecting.

 

	public void itemEvent(ItemTossEvent event)
{
	if ( event.isCancelable() )
	{
		ItemStack itemStack = event.entityItem.item;
		event.setCanceled(true);
		event.player.inventory.addItemStackToInventory(itemStack);
	}
}

 

Maybe use:

event.player.inventory.onInventoryChanged();

 

after:

event.player.inventory.addItemStackToInventory(itemStack);

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

  • 2 months later...

Sorry for necrobumping, but does anybody have a solution?

 

Like i wrote before. It works, but when items are dropped from the inventory screen, they seem to disappear for a while, but they're not really lost. They reappear after some other action with the inventory or a reconnect.

It is a bit buggy.

When an item is dropped with Q it gets replaced immediately, but when it is dropped with the right click from the inventory screen, it seems to disappear. It reappears later with an inventory change or after reconnecting.

Using the drop key (default: Q) works fine.

 

	public void itemEvent(ItemTossEvent event)
{
	if ( event.isCancelable() )
	{
		ItemStack itemStack = event.entityItem.item;
		event.setCanceled(true);
		event.player.inventory.addItemStackToInventory(itemStack);
	}
}

 

Since mc 1.4.6, I had to change one line:

ItemStack itemStack = event.entityItem.func_92014_d();

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • " BLACK MAGIC INSTANT DEATH SPELL CASTER IN UGANDA, NETHERLANDS, SPAIN, KENYA, RWANDA POWERFUL WITCHCRAFT REVENGE SPELLS CASTER IN GHANA, BENIN. STRONG LOVE SPELLS CASTER IN MAURITIUS, MALTA. VOODOO DOLL SPELLS IN USA, UK,spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
    • SPELL CASTER, DEATH SPELL, SPELL CASTER REVIEW, WITCHCRAFT, PSYCHIC, MAGIC FORUM,spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
    • BLACK MAGIC INSTANT DEATH SPELL CASTER AND POWERFUL+256751735278 BLACK MAGIC INSTANT DEATH SPELL CASTER AND POWERFUL REVENGE SPELLS THAT WORK FAST IN AUSTRALIA, CANADA, UK GERMANY FRANCE DENMARK. +256751735278 Drmama Bonnei , black magic Revenge spells that work overnight or by accident i? Cast these strongest black magic revenge death spells that work fast overnight to kill ex lover, husband, wife girlfriend Enemies overnight without delay. It doesn’t matter whether he or she is in a far location, I guarantee you to have your results you are looking for immediately. Just make sure before you contact me you are committed and you want what you are looking for (Victim Death) because my Revenge spell work fast overnight after casting the spells. Immediately working black magic death spells that work fast will be cast on the person and result is 48hours,24 Hours . How To Cast A Revenge Spell On Someone, Call/ Whats App  Drmama Bonne Revenge Spells That Work Overnight to kill wicked Step-dad/ Step mom Death Revenge Spell on wicked friends, Voodoo Revenge Spells to kill Enemies Black Magic Spells To Harm Someone, Black magic Revenge spells on ex lover Revenge instant Revenge spells on uncle , powerful instant Revenge spells caster, online instant spell that work fast in USA, UK, Kuwait, Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
    • Voodoo Spells Caster /SANGOMA / Death & Revenge Spells  +256751735278 Drmama Bonnei , black magic Revenge spells that work overnight or by accident i? Cast these strongest black magic revenge death spells that work fast overnight to kill ex lover, husband, wife girlfriend Enemies overnight without delay. It doesn’t matter whether he or she is in a far location, I guarantee you to have your results you are looking for immediately. Just make sure before you contact me you are committed and you want what you are looking for (Victim Death) because my Revenge spell work fast overnight after casting the spells. Immediately working black magic death spells that work fast will be cast on the person and result is 48hours,24 Hours . How To Cast A Revenge Spell On Someone, Call/ Whats App  Drmama Bonne Revenge Spells That Work Overnight to kill wicked Step-dad/ Step mom Death Revenge Spell on wicked friends, Voodoo Revenge Spells to kill Enemies Black Magic Spells To Harm Someone, Black magic Revenge spells on ex lover Revenge instant Revenge spells on uncle , powerful instant Revenge spells caster, online instant spell that work fast in USA, UK, Kuwait, Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Germany, Asian, Europe, Philippines, Canada, South Africa, Italy, Peru, India, Iran, Gambia. Sweden, Australia, Nigeria, Spain, Ghana, California, Greece , Voodoo revenge spell casters spell to make someone sick and die without delay. Drmama Bonne +256751735278
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.