Permissions: Won't let Material.MONSTER_EGG, 1, (byte)50)); work, it works in the crafting recipes.

Discussion in 'Plugin Development' started by 17nhammond, Aug 18, 2013.

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

    17nhammond

    The crafting recipe works like this so I don't get why the permissions won't allow byte?

    The mob Spawner works, but not the creeper egg(obviously becuase there is an error ) :)

    This is the error in eclipse:

    The method MONSTER_EGG(int, byte) is undefined for the type





    Code:java
    1. package me.NateD101.spawnercraft;
    2.  
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.inventory.PrepareItemCraftEvent;
    11. import org.bukkit.inventory.ItemStack;
    12.  
    13. public class CraftingEvent implements Listener {
    14.  
    15.  
    16. @EventHandler(priority = EventPriority.HIGHEST)
    17. public void PICE(PrepareItemCraftEvent event)
    18.  
    19. {
    20. Player p = (Player) event.getView().getPlayer();
    21. ItemStack item = event.getInventory().getResult();
    22.  
    23. if (item.getType()==Material.MOB_SPAWNER)
    24. {
    25. if(!p.hasPermission("spawnercraft.mobspawner") && !p.hasPermission("spawnercraft.*"))
    26. {
    27. p.sendMessage(ChatColor.RED + "You don't have permission to craft this item!");
    28.  
    29. event.getInventory().setResult(null);
    30. }
    31. }
    32.  
    33. else if(item.getType()==Material.MONSTER_EGG, 1, (byte)50));
    34. {
    35. if(!p.hasPermission("spawnercraft.creeperegg") && !p.hasPermission("spawnercraft.*"))
    36. {
    37. p.sendMessage(ChatColor.RED + "You don't have permission to craft this item!");
    38.  
    39. event.getInventory().setResult(null);
    40. }
    41. }

     
  2. Offline

    Tirelessly

    1. else if(item.getType()==Material.MONSTER_EGG, 1, (byte)50));
      Well this line doesn't make sense.. MONSTER_EGG is the type, 1 is the amount, and 50 is the data, so why are you trying to check them all against getType(). You can't just copy and paste the ItemStack constuctor.
     
  3. Offline

    Kuuichi

    You could split up that if statement:

    Code:java
    1. if (item.getType() == Material.MONSTER_EGG && item.getData() == (byte)50)


    Or you could create a new ItemStack:

    Code:java
    1. ItemStack compareItem = new ItemStack(Material.EGG, 1, (byte)50);
    2. if (item.equals(compareItem)) {}
     
  4. Offline

    17nhammond

    Kuuichi
    When I put the first option you gave me it gave this error: Incompatible operand types MaterialData and byte.

    Thanks!
    From,
    NateD101
     
  5. Offline

    Kuuichi

    Code:java
    1. if (item.getType() == Material.MONSTER_EGG && item.getData().getData() == (byte)50)


    Sorry, try that.
     
    17nhammond likes this.
  6. Offline

    17nhammond

    Sweet Thanks, That worked!
    Thanks again!
    From,
    NateD101
     
Thread Status:
Not open for further replies.

Share This Page