Cannot rename item in DelayedTask

Discussion in 'Plugin Development' started by cadenzatb, Jun 1, 2014.

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

    cadenzatb

    I've no idea why this doesn't work. :confused: I just want to rename item in player after they right-click air with a delay.

    Action.LEFT_CLICK_AIR is working! but RIGHT_CLICK_AIR is not :(
    What should I do? :oops:

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    4. final Player p = e.getPlayer();
    5. final ItemStack is = p.getItemInHand();
    6. final ItemMeta im = is.getItemMeta();
    7.  
    8. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    9.  
    10. @Override
    11. public void run() {
    12. im.setDisplayName("&cYEAH :D");
    13. is.setItemMeta(im);
    14. p.sendMessage("ItemMeta set!");
    15. }
    16. }, 20);
    17. }
    18. }
     
  2. Offline

    mactown21

    I think its public void Runnable. Im not for sure since i dont work with bukkut scheduals
     
  3. mactown21
    It's definitely public void run()

    cadenzatb
    Try updating the player's inventory.
     
  4. Offline

    mactown21

    RAFA_GATO_FOFO ok i wassnt for sure, and

    mactown21
    Add player.updateInventory(); right under where the meta changes
     
  5. Offline

    cadenzatb

    @RAFA_GATO_FOFO
    @mactown21

    I tried it and not thing changes. :'(
    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    4. p.updateInventory();
    5. final Player p = e.getPlayer();
    6. final ItemStack is = p.getItemInHand();
    7. final ItemMeta im = is.getItemMeta();
    8.  
    9. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    10.  
    11. @Override
    12. public void run() {
    13. im.setDisplayName("&cYEAH :D");
    14. is.setItemMeta(im);
    15. p.updateInventory();
    16. p.sendMessage("ItemMeta set!");
    17. }
    18. }, 20);
    19. }
    20. }


    ps. if I hold "BOW" or "SWORD" and right-clice it actually works! (I think both of them work because they have an animation when you right-click it) but all other items are still not working. :(
     
  6. Offline

    fireblast709

    cadenzatb try
    Code:java
    1. @EventHandler(ignoreCancelled=true)
    If I recall correctly RIGHT_CLICK_AIR had some thing with being cancelled by default.
     
  7. Offline

    cadenzatb

    @fireblast709
    Unfortunately, :( it still not works.

    But I figured something out.
    I think I have to use this
    Code:java
    1. e.getPlayer().setItemInHand(is);

    instead of just edit old itemstack and it does work !
    But, I have to deal with few other problem such as if player change item-slot or drop-item.

    Thanks everyone btw :)
     
  8. cadenzatb Also, your code didn't check to make sure a player had an item in their hand... that's a problem.
     
Thread Status:
Not open for further replies.

Share This Page