Coins and Coin Purses

Discussion in 'Plugin Development' started by Cyrael, May 24, 2014.

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

    Cyrael

    I've been looking for a bit now and have had no luck.
    So I'm trying to make a custom economy plugin with actual ingame items.
    I have made a custom Gold Coin (ItemStack with DisplayName set) and a custom Coin Purse (again, an ItemStack with DisplayName set)
    Coin Purses have limited storage (let's say it's 10)
    When I pick up a Gold Coin if there is still room in the Coin Purse I want to augment the amount of coins in the purse (part of the ItemStack's MetaData Lore), and any extra that don't fit can just stay in my inventory.

    I've tried using the PlayerPickupItemEvent, though this event is really PlayerPickingUpItemEvent, meaning that at the time the event fires the item hasn't actually entered my inventory yet. This would be fine, except I can't figure out how to destroy the item if it fits into a coin purse. The result is my purse value get's increased AND i get coins in my inventory.

    Does anyone have any pointers on how to achieve this kind of thing?
     
  2. Offline

    Cyrael

    Really? No one has tried to do this before?
     
  3. Offline

    fireblast709

  4. Offline

    Konkz

    With pickupitemevent you can do a check, and if they have no place in their purse just cancel it. That's how all the plugins done it that cancel it if a condition is not met.
     
  5. Offline

    Cyrael

    True Konkz, however I want to just put the coin "loose" in my inventory if there is no room in any bag.

    That's an interesting idea, however it's telling me that the type of the Gold Coin (org.bukkit.craftbukkit.v1_7_r3.CraftItemStack cannot be cast as Entity. To be clear, I never set it to that type of object, I created an ItemStack and changed the metadata. Any idea how exactly I can cast this? From what I can tell CraftItemStack comes from ItemStack, as I'm able to typecast it as ItemStack.

    EDIT: Wow I'm dumb... event.getItem().remove(); lol thanks.
     
  6. Offline

    zackpollard

    <-
    <-
    <-
    <-
    <-
     
  7. Offline

    Cyrael

    zackpollard ... that's not in any way helpful. I DID look through the Java Doc, but if you don't know what you're looking for you're gonna have a hard time finding anything. Next time you think, "I'm gonna go into a thread and instead of being helpful I think I'll be a dick instead" you should really rethink your life.
     
  8. Huh I dont understand - if you want the item loose in your inventory when your purse is full just either leave the event alone whivh makes you pickup the item normally or do e.setCancelled(true) and then player.setItem(your item(stack), pos in your inventory)

    If you just want to get rid of the item just type e.setCancelled(true) - that cancelles the event that you should be picking up an item
     
  9. Offline

    zackpollard

    I felt no need to repost the page to the javadocs that fireblast709 had already posted.
     
  10. Offline

    Cyrael

    zackpollard yea, at that point you don't need to say anything at all.
     
Thread Status:
Not open for further replies.

Share This Page