Minecraft Eclipse specific animal spawnegg in inventory?
What should I specify for material, e.g. To get a pig spawnegg?
ItemStack test = new ItemStack (Material?);
One must probably change the meta data, e.g. To a pig
How does it work?
CREEPER_SPAWN_EGG
You must have basic knowledge.
Because with CTRL + space bar you can view suggestions
PIG_SPAWN_EGG to get a pig spawnegg
It says that that's not true
Is it possibly a bit more concrete? What are you doing and what exactly is not? Because of inventory, nothing seems to be in sight in this step.
ItemStack is not standard Java. The reference to Minecraft is probably your secret here, which you will not betray us.
If that belongs to any lib or something, look into the corresponding documentary.
I write the source code
Package de.mineground.pet.commands;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
public class PetGUI implements CommandExecutor, Listener {
@Override
public boolean onCommand (CommandSender sender, Command cmd, String label, String [] args) {
Player p = (player) transmitter;
if (p.hasPermission ("pet.open")) {
if ((sender instanceof Player)) {
if (args.length == 0) {
Inventory inventory = Bukkit.createInventory (null, 9 * 3, "§f§lPet §6§lSelection");
p.sendMessage ("§7You have the pet menu open!");
p.openInventory (inventory);
ItemStack KPP = new ItemStack (Material.BARRIER);
ItemMeta ITEMMETA = KPP.getItemMeta ();
ITEMMETA.setDisplayName ("§f§lOnly for §6§lPremium");
KPP.setItemMeta (ITEMMETA);
ItemStack KPS = new ItemStack (Material.BARRIER);
ItemMeta ITEMMETa = KPS.getItemMeta ();
ITEMMETa.setDisplayName ("§f§lOnly for §d§lSupreme");
KPS.setItemMeta (ITEMMETa);
ItemStack KPM = new ItemStack (Material.BARRIER);
ItemMeta ITEMMEta = KPM.getItemMeta ();
ITEMMEta.setDisplayName ("§f§lOnly for §b§lMinegrounder");
KPM.setItemMeta (ITEMMEta);
ItemStack pig = new ItemStack (material?);
ItemMeta meta = pig.getItemMeta ();
meta.setDisplayName ("§f§lOnly for §6§lPremium");
pig.setItemMeta (meta);
if (p.hasPermission ("pet.menu.player")) {
inventory.setItem (0, KPP);
inventory.setItem (1, KPP);
inventory.setItem (2, KPP);
inventory.setItem (3, KPP);
inventory.setItem (4, KPS);
inventory.setItem (5, KPS);
inventory.setItem (6, KPS);
inventory.setItem (7, KPS);
inventory.setItem (8, KPM);
inventory.setItem (9, KPM);
inventory.setItem (10, KPM);
inventory.setItem (11, KPM);
} else {
if (p.hasPermission ("pet.menu.premium")) {
inventory.setItem (0, KPP);
inventory.setItem (1, KPP);
inventory.setItem (2, KPP);
inventory.setItem (3, KPP);
inventory.setItem (4, KPS);
inventory.setItem (5, KPS);
inventory.setItem (6, KPS);
inventory.setItem (7, KPS);
inventory.setItem (8, KPM);
inventory.setItem (9, KPM);
inventory.setItem (10, KPM);
inventory.setItem (11, KPM);
} else {
if (p.hasPermission ("pet.menu.supreme")) {
inventory.setItem (0, KPP);
inventory.setItem (1, KPP);
inventory.setItem (2, KPP);
inventory.setItem (3, KPP);
inventory.setItem (4, KPS);
inventory.setItem (5, KPS);
inventory.setItem (6, KPS);
inventory.setItem (7, KPS);
inventory.setItem (8, KPM);
inventory.setItem (9, KPM);
inventory.setItem (10, KPM);
inventory.setItem (11, KPM);
} else {
if (p.hasPermission ("pet.menu.minegrounder")) {
inventory.setItem (0, KPP);
inventory.setItem (1, KPP);
inventory.setItem (2, KPP);
inventory.setItem (3, KPP);
inventory.setItem (4, KPS);
inventory.setItem (5, KPS);
inventory.setItem (6, KPS);
inventory.setItem (7, KPS);
inventory.setItem (8, KPM);
inventory.setItem (9, KPM);
inventory.setItem (10, KPM);
inventory.setItem (11, KPM);
}
}
}
}
}
}
{
}
}
return true;
}
@EventHandler
public void onClick (InventoryClickEvent e) {
Player p = (Player) e.getWhoClicked ();
if (e.getInventory (). GetName (). Equals ("§f§lPet §6§lSelection")) {
if (e.getCurrentItem ()! = null && e.getCurrentItem (). GetType ()! = Material.AIR) {
e.setCancelled (true);
if (e.getCurrentItem (). GetType () == Material.BARRIER) {
p.sendMessage ("§fPlease buy another rank!");
}
}
}
}
Ok, the missing keyword is Bukkit. You are about to write a plugin intended for the Bukkit server interface. This is an important piece of information that you should write so that you know what you are working with.
3x even and then not? OO
Use docu! Is not a shame…
Call the documentation for class "ItemStack": https://hub.spigotmc.org/...Stack.html
You look (in your case) at the constructors.
You find out: There's one of them who has a material parameter and seems to be suitable for you. So the way is most likely not wrong.
"What exactly is material…" * Kopfkratz *
You click on "Material" at the entry to see the documentation again.
You will see: It is an enum. So a Konstantensammlung. The constants look very suspiciously like all the items you can have as a stack.
Now you are looking for the constant for the Spawnei out. I would say: PIG_SPAWN_EGG
And that's exactly what you give your questionable constructor
----> blabla = new ItemStack (Material.PIG_SPAWN_EGG)
Finished!
Should work like that.