Hello! 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
You can either call Code: itemStack.getEnchantments which returns a Map<Enchantment, Integer>, or the slightly more relevant method would be Code: itemStack.containsEnchantment(Enchantment); 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 Code: itemStack.getType(); And as for the player's xp, Code: player.getExp();
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 www.DeepL.com/Translator (free version) Code: player.setExp(playerxp - differenz); player.setLevel( ??? );
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)
Thanks, now use setTotalExperience, but something is not working here either: Code: player.setTotalExperience(0); With this call, the player's exp remain the same. The new values do not work for the item either: Code: Damageable damageeble = (Damageable) item.getItemMeta(); damageeble.setDamage(0); There is no error message, but the values do not change.