Hey Guys, I want to create a config where the user can put the enchantment they want and the level, then it would be added to the item in game, how can I do this? Thanks, Niknea
That's quite an open-ended question. You can't expect us to do all the work for you Basically you need to figure out the steps involved in doing this plugin, and then tackle each one individually (divide and conquer, as it's called). Also I think you need to figure out what exactly you mean by "added to the item in game".
I don't know if this works, but I think this should work. (The args do you have to figure out by your self). public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) { if(alias.equalsignorecase("DiaPickaxeSilkTouch") { ItemStack SilkTouch = new ItemStack(Material.DIAMOND_PICKAXE); SilkTouch.AddEnchantments(Enchantment.SILK_TOUCH, 1); p.getInventory.remove(ITEM BEFORE ENCHANTED); p.getInventory.add(SilkTouch); } } Something like this should work, I am not on my 'Coding PC' So I can't test it by my self, I hope this helped you a little bit. (You can figure out by yourself how you put this in a config, I did this in a command because this is easier for me). Kindley Regards, Ramon Peek (Sorry for my bad English, I'm Dutch.)
Make a string like item: 276 1 enchants:sharpness:1,unbreaking:3 name:&6DatoneItem then split the strings and loop through them looking for a string that contains "enchants:"
Onlineids RamonPeek DxDy Alright so here is what I did, yet the enchantment wont add onto the item, here is the code and config. http://pastie.org/9179729. Any help would be great. Here is my full code. Code:java package me.niknea.supremechests; import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.block.Block;import org.bukkit.block.Chest;import org.bukkit.enchantments.Enchantment;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.block.BlockBreakEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.inventory.meta.ItemMeta; import java.util.ArrayList; /*** Created by Niknea on 5/14/14.*/public class SpawningChest implements Listener{ Main plugin; public SpawningChest(Main plugin){ this.plugin = plugin; } Chest chest; @EventHandler public void onChance(BlockBreakEvent e){ Player p = e.getPlayer(); e.setCancelled(true); // Random random = new Random(); // int dice = random.nextInt(21); // if(dice == 7){ Block block = e.getBlock(); Location blockloc = block.getLocation(); blockloc.getBlock().setType(Material.CHEST); chest = (Chest) blockloc.getBlock().getState(); getItems(); // } } public void getItems(){ if(plugin.getConfig().getString("Item0") != null){ int amount = plugin.getConfig().getInt("Item0Amount"); ItemStack Item0 = new ItemStack(Material.getMaterial(plugin.getConfig().getString("Item0")), amount); // Item0.addUnsafeEnchantment(Enchantment.getById(1), 2); ItemMeta meta = Item0.getItemMeta(); if(plugin.getConfig().getInt("Item0Enchantment1") != 99 && plugin.getConfig().getInt("Item0Enchantment1Level") != 99){ int enchantment1 = plugin.getConfig().getInt("Item0Enchantment1"); int enchantment1Level = plugin.getConfig().getInt("Item0Enchantment1Level"); //Item0.addUnsafeEnchantment(Enchantment.getById(Integer.valueOf(enchantment1)), Integer.valueOf(enchantment1Level)); Item0.addUnsafeEnchantment(Enchantment.getById(1), 2); System.out.println("1"); } if(plugin.getConfig().getString("Item0Name") != null){ String displayName = plugin.getConfig().getString("Item0Name"); meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName)); } if(plugin.getConfig().getString("Item0Lore") != null){ ArrayList<String> Item0Lore = new ArrayList<String>(); Item0Lore.add(plugin.getConfig().getString("Item0Lore")); meta.setLore(Item0Lore); Item0Lore.clear(); } Item0.setItemMeta(meta); chest.getBlockInventory().setItem(0, Item0); } }} The enchantment only gets added if the Item0.setItemMeta(meta); is gone, how can I fix that? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Add the enchantments to the meta instead using ItemMeta.addEnchantment, it takes a boolean to ignore safety checks.
I dont meant to be rude but I'm not going to answer either of those. far too obvious, and if they're not, you could always read the documentation, I gave you the method name.
Niknea I will try to figure it out for you this afternoon. . If I figure it out, I will say it to you.