1.15.2 Enchantment Table Decreasing Higher Enchantment Level Chances

Discussion in 'Spigot Plugin Development' started by OnwexryS, Jan 20, 2020.

  1. I tried to decrease chances with this code it works but only for offer showings. How can I change the result ? Please help me

    Code (Text):
    p=enchantmentTable.getEnchanter();
            if (enchantmentTable.getOffers() != null){
                if (enchantmentTable.getItem() != null){
                    inputItem= enchantmentTable.getItem();
                }
                newInventory=enchantmentTable;
                offerList= enchantmentTable.getOffers();
                for (int i=0; i<offerList.length ; i++) {
                    if (offerList[i] != null){
                        if (offerList[i].getEnchantmentLevel() >=5){
                            if (luck< development.fiveLevelChance){
                                continue;
                            }else{
                                offerList[i].setEnchantmentLevel(offerList[i].getEnchantmentLevel() -1);

                            }
                        }
                        if (offerList[i].getEnchantmentLevel() ==4){
                            if (luck< development.fourLevelChance){
                                continue;
                            }else{
                                offerList[i].setEnchantmentLevel(offerList[i].getEnchantmentLevel() -1);
                            }
                        }
                        if (offerList[i].getEnchantmentLevel() ==3){
                            if (luck< development.threeLevelChance){
                                continue;
                            }else{
                                offerList[i].setEnchantmentLevel(offerList[i].getEnchantmentLevel() -1);
                            }
                        }
                    }
                }
                newInventory= new PrepareItemEnchantEvent(enchantmentTable.getEnchanter(), enchantmentTable.getView(), enchantmentTable.getEnchantBlock(), enchantmentTable.getItem(), offerList, enchantmentTable.getEnchantmentBonus());
                enchantmentTable=newInventory;
            }
     
  2. What exactly are you trying to achieve?
    Based on this page you can directly modify the offers
     
  3. Offers are just previews. When I change the offer result doesn't change. For example with this code I put my diamond sword to enchament table and I saw Sharpness 2 instead of Sharpness 5. But when I click to the offer end get the Item i see Sharpness 5 sword. I want to change this Sharpness 5 result to Sharpness 2 if offer shows so.
     
  4. So you'll need to detect when the player changes the offers and update the new offers
     
  5. No sir, I need to change the result Item. It does not change when I change the offer
     
  6. upload_2020-1-21_2-17-8.png

    But when I get the offer
     
  7. I think youll need to use EnchantItemEvent to listen to the new enchants level
     
    • Agree Agree x 1
  8. Ok, now I am trying it I was already working on it but thanks to you now I am sure this will work
     
  9. It worked thanks
     
    • Like Like x 1