Solved Give items threw signs?

Discussion in 'Plugin Development' started by BSteurful, Apr 16, 2014.

Thread Status:
Not open for further replies.
  1. Hello people! I am working on a sign / chest shop thingie-ma-doo-thing but it is not really working.

    This is what I have:

    Code:
    @EventHandler
    public void onBuyOrSell(PlayerInteractEvent event) {
     
    Action action = event.getAction();
    Player player = event.getPlayer();
    Block block = event.getClickedBlock();
     
    if (action == Action.LEFT_CLICK_BLOCK) {
    // TODO
    }
     
    if (action == Action.RIGHT_CLICK_BLOCK) {
    if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
     
    BlockState state = block.getState();
    Sign sign = (Sign) state;
    String line1 = sign.getLine(1);
     
    try {
    player.getInventory().addItem(new ItemStack(Material.getMaterial(line1)));
    } catch (Exception e) {
    player.sendMessage("oeps");
    }
    }
    }
    }
    
     
  2. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    BSteurful moved to the appropriate subforum from the feedback forum.
     
  3. What do you mean with that? Sorry, my English is not that good...
     
  4. Offline

    mbaxter ʇıʞʞnq ɐ sɐɥ ı

    You posted this to the Feedback forum. I have moved it to the Plugin Development forum.
     
  5. Oke, thanks.
     
  6. Offline

    Floofy

    It works fine for me.

    Note a few things:

    Code:java
    1. @EventHandler
    2. public void onBuyOrSell(PlayerInteractEvent event) {
    3.  
    4. Action action = event.getAction();
    5. Player player = event.getPlayer();
    6. Block block = event.getClickedBlock();
    7.  
    8. if (action == Action.LEFT_CLICK_BLOCK) {
    9. // TODO
    10. }
    11. //You should use an if/else if statement rather than two ifs.
    12. else if (action == Action.RIGHT_CLICK_BLOCK) {
    13. if (block.getType() == Material.WALL_SIGN || block.getType() == Material.SIGN_POST) {
    14.  
    15. BlockState state = block.getState();
    16. Sign sign = (Sign) state;
    17.  
    18. //This selects the SECOND line, just making sure you know. If you want it to select the first, use 0, not 1.
    19. String line1 = sign.getLine(1);
    20.  
    21. try {
    22. player.getInventory().addItem(new ItemStack(Material.getMaterial(line1)));
    23. //You need to refresh their inventory using this method.
    24. player.updateInventory();
    25. } catch (Exception e) {
    26. player.sendMessage("oeps");
    27. }
    28. }
    29. }
    30. }


    If this doesn't help, what exactly isn't working?
     
  7. Okay I didn't refresh the inventory. Thank! It works now!
     
Thread Status:
Not open for further replies.

Share This Page