CraftItemEvent

Discussion in 'Plugin Development' started by TehVoyager, Jan 24, 2014.

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

    TehVoyager

    I can't get the display name of the crafted item.
    Code:java
    1. @EventHandler
    2. public void onCraft(CraftItemEvent e){
    3. ItemStack i = e.getInventory().getResult();
    4. ItemMeta im = i.getItemMeta();
    5. Material imat = i.getType();
    6. if(imat == Material.WOOD_HOE || imat == Material.STONE_HOE || imat == Material.GOLD_HOE || imat == Material.DIAMOND_HOE){
    7. if(im.getDisplayName().equalsIgnoreCase("Pistol")){
    8.  
    9. }else{
    10. e.getInventory().setResult(new ItemStack(Material.IRON_HOE));
    11. }
    12. }
    13. }

    It throws an error if the hoes name is not pistol and doesnt make it iron.
     
  2. Offline

    calebbfmv

    Your checking the Returned Item, not the Item Placed...
     
  3. Offline

    TehVoyager

    calebbfmv
    Pretty Sure Im Checking the right item(the one that was crafted) getCurrentItem Doesn't work.
     
  4. Offline

    calebbfmv

    TehVoyager
    Well then, do some debugging and try catches and != null checvks
     
  5. TehVoyager
    Maybe try this:

    Code:java
    1. if (!(im.getDisplayName().equalsIgnoreCase("Pistol")){
    2. e.getInventory().setResult(new ItemStack(Material.IRON_HOE));
    3. }else{
    4. //stuff
    5. }
     
  6. Offline

    TehVoyager

    The Gaming Grunts Throws An Error :/ This Works Some How:
    Code:java
    1. if(imat == Material.WOOD_HOE || imat == Material.STONE_HOE || imat == Material.GOLD_HOE || imat == Material.DIAMOND_HOE){
    2. try{
    3. if(im.getDisplayName().equalsIgnoreCase("Pistol")){
    4.  
    5. }else{
    6. e.getInventory().setResult(new ItemStack(Material.IRON_HOE));
    7. }
    8. }catch(Exception ex){
    9. e.getInventory().setResult(new ItemStack(Material.IRON_HOE));
    10. }
    11. }


    It's Not Exactly Pretty but what ever....
     
Thread Status:
Not open for further replies.

Share This Page