Custom Enchantments

Discussion in 'Spigot Plugin Development' started by pas5w0rd, May 7, 2017.

  1. Hello all!

    Does anyone know what would be the easiest way to make Tiered Custom Enchants. Like, lets say there are either 4 or 5 tiers. Tier 1, Tier 2, Tier 3 and Tier 4. Then, they can get a book with random chances on it and either apply it to the item or it will randomly fail.

    How would I make a system where it would apply it to the item in tiers, with different colours.

    Any ideas?
    Thanks.
    :D
     
  2. To apply the enchants, do that with lores, i made my custom enchantment plugin for my faction server, and that's how he work ;)
     
  3. Yeah, the lores- its just making a system where it works is what I'm stuck with.
     
  4. To enchant their items, my players pick a book from their inventory, and then put it on the item they want to enchant by clicking, here is the method to apply the enchantment i use:

    The ItemStack i is the item the player want to enchant, and the String s is the enchantment name with the tier. for exemple: "§6Vampire II"

    public void itemSwitch(ItemStack i, String s) {
    ItemGlow glow = new ItemGlow(999);
    if(i.hasItemMeta()) {
    ItemMeta iM = i.getItemMeta();
    if(iM.hasLore()) {
    List<String> iL = iM.getLore();
    iL.add(s);
    iM.setLore(iL);
    iM.addEnchant(glow, 1, false);
    i.setItemMeta(iM);
    } else {
    List<String> iL = new ArrayList<String>();
    iL.add(s);
    iM.setLore(iL);
    }
    } else {
    ItemMeta iM = i.getItemMeta();
    iM.setDisplayName("§6"+i.getType().toString().toLowerCase());
    List<String> iL = new ArrayList<String>();
    iL.add(s);
    iM.setLore(iL);
    iM.addEnchant(glow, 1, false);
    i.setItemMeta(iM);
    }
    }
     
  5. That looks complex and I take it ItemGlow just makes it glow?
     
  6. Yeah, that's another class, an enchantment i made to make the item glow, because the lore doesn't make it lol, you can remove it if you want
     
  7. So the ItemStack is that the item you want to apply it to and then the string is the enchantment name?
     
  8. Yes it is, the string is the name of the enchantment with his tier, seen in the lore, like "§6Vampire II". In this exemple, the enchantment is Vampire II, then in your EntityDamageEntityEvent, check the damager item's lore, and if he contains "§6Vampire II", then put your effects ;)
     
  9. Okay. So I guess this is in like an InventoryClickEvent to detect when the book is clicked on the item with?
     
  10. You're right! :) that's how i did it. if you got difficulties pm me and i'll give you my inventoryclickevent
     
  11. Okay, thanks!
     
  12. I basically have the same system as you for applying enchants but how did you manage to make it so players can combine enchants? That is something I have been struggling to do.
     
  13. Checking the string of the book and the ones in the item's lore, then put some conditions and do what you want :p
     
  14. also if you want to check like "Diamond Hunter III"
    get the "III"
    you can use JAVA indexOf , google it
     
  15. Why would you use indexOf? It would just return the index of the string...I would use charAt or substring.
     
  16. hmm i means like when "III Diamond Hunter"? Sorry for that XD