Please help with my code.

Discussion in 'Plugin Development' started by TeddyDev, Oct 27, 2014.

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

    TeddyDev

    So im in the making of a plugin and the aim is to have a changing lore.
    If the code see's a diamond sword in somebodys inventory it will set a specified lore.
    and if they add enchantments it will add a lore. also if the enchatment is upgraded it will upgrade the lore. BUT.. im having trouble adding more enchantments!

    Can some please tell me how i could add more enchantments to this code
    Code:java
    1. @Override
    2. public void onEnable() {
    3. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    4. @SuppressWarnings("deprecation")
    5. public void run() {
    6. for(Player all : Bukkit.getOnlinePlayers()) {
    7. for(ItemStack i : all.getInventory().getContents()) {
    8. if(i != null) {
    9. if(i.getType() == Material.DIAMOND_SWORD) {
    10. ItemMeta m = i.getItemMeta();
    11.  
    12. m.setLore(getLore(i));
    13. i.setItemMeta(m);
    14. }
    15. }
    16. }
    17. }
    18. }
    19. }, 5, 5);
    20. }
    21.  
    22. public List<String> getLore(ItemStack item) {
    23. List<String> lore = new ArrayList<String>();
    24.  
    25. lore.add(" ");
    26. lore.add(info);
    27.  
    28. if(item.getEnchantments().containsKey(Enchantment.DAMAGE_ALL)) {
    29. if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 1) {
    30. lore.add(sharpness1);
    31.  
    32. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 2) {
    33. lore.add(sharpness2);
    34.  
    35. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 3) {
    36. lore.add(sharpness3);
    37.  
    38. } else if(item.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 4) {
    39. lore.add(sharpness4);
    40.  
    41. } else {
    42. lore.add(sharpness5);
    43. }
    44. }
    45. return lore;
    46. }
    47. }
     
  2. Offline

    97WaterPolo

    TeddyDev
    If you want the enchant to be in the lore, you could do something like

    for (Player p : all players)
    for (ItemStack is : p.getInventory().getContents)
    if is contains Enchantment.YOUR_ENCHANT
    set the lore to null
    set the lore to your enchant and then get the level of the enchant.

    Hope this is what you meant! :D
     
  3. Offline

    Orange Tabby

Thread Status:
Not open for further replies.

Share This Page