Swapping block in hand for another on command

Discussion in 'Plugin Development' started by Ps300300, Jul 15, 2014.

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

    Ps300300

    Hello, i need some help to check that the player has eg a "White wool block" in their hand and then when the use a command eg "/dye blue" it changes it to a blue wool block (removes other, gives blue). I would like to do this for every wool block and clay block and glass panes and blocks.
    Thanks

    Nothing?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    caderape

    check the item in hand when they perform the command, with gettype(), and if it's white wool, set the item in hand by a new itemstack (Material, amount, data)
     
  3. First, check if they have that kind of block in their hand.
    Code:java
    1. // This is just for the example, you can change the material
    2. if(player.getItemInHand().getType() == Material.WOOL) {
    3. ItemStack item = player.getItemInHand();
    4. item.setDurability(DyeColor.valueOf(args[0]).getData());
    5. /* Ignore the deprecation, as there's no other method,
    6. * else then opening the enum and seeing the value of every color and then comparing,
    7. * so doing it like that is better.
    8. */
    9. }
     
  4. Offline

    Ps300300


    So do I have to change the dyecolor value for each colour
     
  5. Ps300300 Not exactly, you change the durability value with another value which you got from the DyeColor enum.
     
Thread Status:
Not open for further replies.

Share This Page