Solved Egg type problem

Discussion in 'Plugin Development' started by Matroxko, Jul 17, 2017.

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

    Matroxko

    I'm recently creating pet plugin with inventory menu.
    How can i get type of egg like sheep, chicken, cow ...?
    My code:
    Code:java
    1.  
    2. public void onInvnetoryClick(InventoryClickEvent e) {
    3.  
    4. Player player = (Player) e.getWhoClicked();
    5. Material item = e.getCurrentItem().getType();
    6.  
    7. if(e.getInventory().getName().equals(GUI.PetMenu.getName())) {
    8.  
    9. e.setCancelled(true);
    10.  
    11. if(item == Material.MONSTER_EGG) {
    12.  
    13. Pets.spawnSheep(player.getUniqueId());ň
    14.  
    15. } else if (item == Material.BARRIER) {
    16.  
    17. player.closeInventory();
    18. }
    19. }
    20. }
    21.  

    Thx ! :)
     
  2. Offline

    Machine Maker

    @Matroxko
    Get the ItemMeta from the spawn egg ItemStack and cast it to SpawnEggMeta. You can then use getSpawnedType() on the SpawnEggMeta.
     
    Matroxko likes this.
  3. Offline

    Matroxko

    but how should I get SpawnEggMeta from ItemMeta. IDK how to cast ItemStack with SpawnEggMeta. Can u show me it with code Please ! Thx :)
     
  4. Offline

    Machine Maker

    @Matroxko
    Casting objects is a important concept to understand. Try looking up some of examples online next time.

    Code:
    SpawnEggMeta meta = (SpawnEggMeta) item.getItemMeta();
     
Thread Status:
Not open for further replies.

Share This Page