Check Enchantment

Discussion in 'Plugin Development' started by Kojote, Apr 9, 2020.

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



    I'm new to Mincract plugin programming and need a little help.

    I would like to query in a condition if an item in my right hand has the enchantment repair.

    So far I have the condition so far, but how do I query further? Furthermore, I wanted to find out how much XP the player and the item has or what kind of item it is. Do I have to query a whole list of items or is this easier?

    if(player.getInventory().getItemInMainHand(). ){


    Thanks a lot for your help.

    Greatings Kojote
  2. Offline


    You can either call
    which returns a Map<Enchantment, Integer>, or the slightly more relevant method would be
    That way you can simply check if the item has the enchantment that you're after

    Also, what do you mean "query a whole list of items", if you have the itemstack that you're checking, then you can call a range of methods, like getting its type
    And as for the player's xp,
  3. Offline


    Many thanks, that helps me a lot!

    I have one more question. In the script I deduct experience points from the player. With decreasing experience points the number of levels would also decrease. I have now found the methods for experience and levels, but I have problems with both.

    1. how do I break the new level, depending on the experience?

    2. when I want to reset the exp, I get an error in the log:

    IllegalArgumentException: Experiance must have been between 0.0 and 1.0 (34)

    34 would be the current number of exp of the player. But why only between 0 to 1?

    Translated with (free version)

    player.setExp(playerxp - differenz);
    player.setLevel( ??? );
    Last edited: Apr 9, 2020
  4. Offline


    As far as I know (may be wrong) is that player.setExp(float) is the xp bar, and 0 is empty while 1 is completely full.
    player.setLevel(int) is the xp levels (the number)
  5. Offline


    Thanks, now use setTotalExperience, but something is not working here either:

    With this call, the player's exp remain the same.

    The new values do not work for the item either:

    Damageable damageeble = (Damageable) item.getItemMeta();
    There is no error message, but the values do not change.
Thread Status:
Not open for further replies.

Share This Page