How would you make this sort of command: /xeongive <name> <item> [amount] **<item> would be a custom itemstack. I have a start to it already: if(label.equalsIgnoreCase("xeongive")){ if(player.hasPermission("xeon.give")){ if (args.length == 0){ player.sendMessage("A full list of items can be found here:"); } } else if (args.length == 1){ //PlayerName } else if (args.length == 2){ //Item } else if (args.legnth == 3){ //Amount } } Thanks -Misteroid
The first thing which you would need to do would be to setup an ArrayList of Itemstacks. This ArrayList will be used later to retrieve the itemstacks. The second thing which you need to do is to add a custom Itemstack to the ArrayList so that you can loop through it later When you want to get the names of it, you can use a for loop to get the name of it. You can use the following code to retrieve the names. (so you can print it to the user). Code: for(ItemStack item : <ItemStackArray>) { player.sendMessage(item.getItemMeta().getDisplayName()); }
I hope nobody is going to just spoon feed you code, you wont learn anything. You will need to get the custom player first, by checking if the player is online/real. Then check if the <Item> is a real item, with Material.getMaterial(String name); Last of all, check if the int that they give you is an Integer. In the long run you will thank me
Update: @nverdier Command.getName() doesn't work for me. The player detecting doesn't work Code: if (label.equalsIgnoreCase("xeongive")) { Player player = (Player)sender; List<ItemStack> itemStack = new ArrayList<ItemStack>(); ItemStack item = new ItemStack(Material.CHEST, 1); ItemMeta meta = item.getItemMeta(); meta.setDisplayName("§9Mystical Crate"); List<String> lore = new ArrayList<String>(); lore.add("§bA mysterious box from our store!"); lore.add("§7Hold Shift + Right Click to open this!"); meta.setLore(lore); item.setItemMeta(meta); if (player.hasPermission("xeon.give")) { if (args.length == 0) { player.sendMessage("A full list of items can be found here:"); } } else if (args.length == 1) { if (player.getServer().getPlayer(args[0]) != null){ Player targetPlayer = player.getServer().getPlayer(args[0]); targetPlayer.sendMessage("test"); } else { player.sendMessage("Invalid player"); } }else if (args.length == 2) { // Item } else if (args.length == 3) { // Amount } } return false; } thats all I have done so far
@Misteroid You can't just use Command.getName(), you have to replace 'Command' with the instance of the command. Which is one of the arguments in the onCommand method.