Getting s specific coloured wool block

Discussion in 'Plugin Development' started by techkatz, Feb 9, 2015.

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

    techkatz

    I am having some trouble with getting a specific coloured wool block. I would like to make it so when a player steps on the colored wool, it changes their armour, and gives them a sword. For some odd reason I cannot get this to work. There are currently no errors. All help will be appreciated, Thanks.

    Code:
    package com.techkatz.colorwheelpvp.wheel;
    
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    
    public class White implements Listener{                  
    
        @EventHandler
         public void onMove(PlayerMoveEvent e)
         {
           
            Player p = e.getPlayer();
            if(p.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.WOOL){
      
                }
           
                p.getInventory().clear();
           
                ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
                LeatherArmorMeta meta1 = (LeatherArmorMeta) helmet.getItemMeta();
                meta1.setColor(Color.WHITE);
                helmet.setItemMeta(meta1);
                p.getInventory().setHelmet(helmet);
              
                ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
                LeatherArmorMeta meta2 = (LeatherArmorMeta) chestplate.getItemMeta();
                meta2.setColor(Color.WHITE);
                chestplate.setItemMeta(meta2);
                p.getInventory().setChestplate(chestplate);
              
                ItemStack pants = new ItemStack(Material.LEATHER_LEGGINGS);
                LeatherArmorMeta meta3 = (LeatherArmorMeta) pants.getItemMeta();
                meta3.setColor(Color.WHITE);
                pants.setItemMeta(meta3);
                p.getInventory().setLeggings(pants);
                    
                ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
                LeatherArmorMeta meta4 = (LeatherArmorMeta) boots.getItemMeta();
                meta4.setColor(Color.WHITE);
                boots.setItemMeta(meta4);
                p.getInventory().setBoots(boots);
              
                ItemStack[] items = {new ItemStack(Material.WOOD_SWORD, 1)};
                p.getItemInHand().setDurability((short) (p.getItemInHand().getDurability() + 1000000000));
                p.getInventory().addItem(items);
               
                p.getInventory().setBoots(boots);
                p.getInventory().setLeggings(pants);
                p.getInventory().setChestplate(chestplate);
                p.getInventory().setHelmet(helmet);
                p.getInventory().addItem(items);
         }
    }
    I noticed, every time I move, no matter if I am on a wool block or not, my armour changes (sets to white armour). I just though I would add that.
     
    Last edited by a moderator: Feb 9, 2015
  2. Offline

    ReadySetPawn

    block#getData()
     
  3. You have the code after the } you need to make it inside the { and }
     
  4. Offline

    techkatz

    So I added the code inside of the if statement, just not sure on how to use the "block#getData()" in my code
     
  5. Offline

    ProMCKingz

    @techkatz
    something on the basis of this; where b represents your block and the number '14' represents the id of the wool.
    if(b.getData() == (byte) 14){
     
  6. Offline

    techkatz

    I am having sort of a mental block, could you just help me out wuth this http://prntscr.com/63ksqy

    Code:
    import org.bukkit.Color;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.LeatherArmorMeta;
    
    public class Red implements Listener{                  
    
        @EventHandler
         public void onMove(PlayerMoveEvent e)
         {
    
            Player p = e.getPlayer();
            if(p.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.WOOL){
                if(b.getData() == (byte) 14){
       
                 p.getInventory().clear();
                   
                    ItemStack helmet = new ItemStack(Material.LEATHER_HELMET);
                    LeatherArmorMeta meta1 = (LeatherArmorMeta) helmet.getItemMeta();
                    meta1.setColor(Color.RED);
                    helmet.setItemMeta(meta1);
                    p.getInventory().setHelmet(helmet);
                  
                    ItemStack chestplate = new ItemStack(Material.LEATHER_CHESTPLATE);
                    LeatherArmorMeta meta2 = (LeatherArmorMeta) chestplate.getItemMeta();
                    meta2.setColor(Color.RED);
                    chestplate.setItemMeta(meta2);
                    p.getInventory().setChestplate(chestplate);
                  
                    ItemStack pants = new ItemStack(Material.LEATHER_LEGGINGS);
                    LeatherArmorMeta meta3 = (LeatherArmorMeta) pants.getItemMeta();
                    meta3.setColor(Color.RED);
                    pants.setItemMeta(meta3);
                    p.getInventory().setLeggings(pants);
                        
                    ItemStack boots = new ItemStack(Material.LEATHER_BOOTS);
                    LeatherArmorMeta meta4 = (LeatherArmorMeta) boots.getItemMeta();
                    meta4.setColor(Color.RED);
                    boots.setItemMeta(meta4);
                    p.getInventory().setBoots(boots);
                  
                    ItemStack[] sword = {new ItemStack(Material.WOOD_SWORD, 1)};
                    p.getItemInHand().setDurability((short) (p.getItemInHand().getDurability() + 1000000000));
                    p.getInventory().addItem(sword);
      
                }           
          }
        }
    }
     
    Last edited by a moderator: Feb 10, 2015
  7. Offline

    ReadySetPawn

    You never defined the variable "b".
     
  8. Offline

    techkatz

    I am confused on how to do that.
    Please help, and paste code.
     
  9. You did this:
    Code:Java
    1.  
    2. if(p.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.WOOL) {
    3. if(b.getData() == (byte) 14){
    4.  

    On this line:
    if(b.getData() == (byte) 14){
    You never defined b.
    You need to make something like this at the beginning of the event:
    Code:Java
    1.  
    2. Block b = p.getLocation().subtract(0, 1, 0).getBlock();
    3.  

    With this you can replace the two if(...){ queries:
    Code:Java
    1.  
    2. if(b.getType() == Material.WOOL) {
    3. if(b.getData().getData() == (byte) 14) {
    4.  
     
  10. Offline

    techkatz

    Thanks it worked, sorry I took so long to respond :p
    All good!
     
  11. Offline

    xTrollxDudex

    You will definitely need to learn java. It will save you a bunch of brain aches.
     
    FisheyLP likes this.
  12. Offline

    techkatz

    Just starting out thanks, PS: the more "x's" you put in your name, does not determine how cool you are.
     
Thread Status:
Not open for further replies.

Share This Page