Solved getTargetBlock() problem

Discussion in 'Plugin Development' started by schegar, Nov 27, 2013.

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

    schegar

    hi i've got a problem while coding a new plugin,
    i want to change the color of a woolblock by clicking with a stick on it
    it works fine exept that the plugin only recognizes that I'm clicking on the block when I'm clicking on top of it.
    does someone knows how to edit the code so that the listener gets the whole block ?
    here's the described code:
    Code:java
    1. @EventHandler
    2. public void onClick(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (p.getItemInHand().getType() == Material.STICK) {
    5. if(p.getTargetBlock(null, 20).getType() == Material.WOOL) {
    6. p.getTargetBlock(null, 20).setData(Byte.valueOf((byte)3));
    7. }
    8. }
    9. }
     
  2. Offline

    pope_on_dope

    Code:
        public void onClick(PlayerInteractEvent e) {
                Player p = e.getPlayer();
                if (p.getItemInHand().getType() ==  Material.STICK) {
                    if(e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) {
                        if(e.getClickedBlock().getType() == Material.WOOL) {
                            //set the wool color
                        }
                    }
                }
            }
     
    schegar likes this.
  3. Offline

    schegar

Thread Status:
Not open for further replies.

Share This Page