Get enchantment by ingame display?

Discussion in 'Plugin Development' started by callum2904, Jul 2, 2015.

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

    callum2904

    I am making a basic plugin for my own use to create custom items with a list of commands, one command that is causing me an issue is adding an enchantment to an item. I have the code to do so but my issue is most of the time the enchantment is returning null when trying to find it by string.

    When I use Enchatment.values to see all of the enchantment names it displays
    [​IMG]
    however in game the enchantment on an item does not look like this so when i try to use the command argument "sharpness" it does not find the enchantment that when ingame displays as "sharpness".

    Is there a way to use the ingame enchantment names such as sharpness and such or do i have to learn these to use off the top of my head?
     
  2. Offline

    567legodude

    @callum2904 All I can give is this.
    Code:
    final static Enchantment PROTECTION = Enchantment.PROTECTION_ENVIRONMENTAL;
        final static Enchantment FIRE_PROTECTION = Enchantment.PROTECTION_FIRE;
        final static Enchantment FEATHER_FALLING = Enchantment.PROTECTION_FALL;
        final static Enchantment BLAST_PROTECTION = Enchantment.PROTECTION_EXPLOSIONS;
        final static Enchantment PROJECTILE_PROTECTION = Enchantment.PROTECTION_PROJECTILE;
        final static Enchantment RESPIRATION = Enchantment.OXYGEN;
        final static Enchantment AQUA_AFFINITY = Enchantment.WATER_WORKER;
        final static Enchantment SHARPNESS = Enchantment.DAMAGE_ALL;
        final static Enchantment SMITE = Enchantment.DAMAGE_UNDEAD;
        final static Enchantment BANE = Enchantment.DAMAGE_ARTHROPODS;
        final static Enchantment KNOCKBACK = Enchantment.KNOCKBACK;
        final static Enchantment FIRE_ASPECT = Enchantment.FIRE_ASPECT;
        final static Enchantment LOOTING = Enchantment.LOOT_BONUS_MOBS;
        final static Enchantment EFFICIENCY = Enchantment.DIG_SPEED;
        final static Enchantment SILK_TOUCH = Enchantment.SILK_TOUCH;
        final static Enchantment UNBREAKING = Enchantment.DURABILITY;
        final static Enchantment FORTUNE = Enchantment.LOOT_BONUS_BLOCKS;
        final static Enchantment POWER = Enchantment.ARROW_DAMAGE;
        final static Enchantment PUNCH = Enchantment.ARROW_KNOCKBACK;
        final static Enchantment FLAME = Enchantment.ARROW_FIRE;
        final static Enchantment INFINITY = Enchantment.ARROW_INFINITE;
        final static Enchantment THORNS = Enchantment.THORNS;
    This just defines enchantments using the normal names.
    Then whenever you need sharpness enchantment you just call SHARPNESS instead of Enchantment.DAMAGE_ALL.
     
    dlange likes this.
  3. Offline

    dlange

    But also he might want to get used to the enchants, as it will make life a lot harder if you have to find that code and put it in every time.
     
  4. Offline

    Konato_K

    @callum2904 Just a question, do you want to use these to insert in your code? Or to use in a command-like thing (/enchant sharpness 2)?
     
Thread Status:
Not open for further replies.

Share This Page