PrepareCraftEvent isRepair always false

Discussion in 'Plugin Development' started by Skylong_, Mar 28, 2021.

  1. Offline

    Skylong_

    I am new in bukkit plugins development so this is probably a dumb question but i don know why this code always set my variable as false. So i hope that somebody here may help me to understand.
    Code:
        private boolean repairFlag;
    
        @EventHandler
        public void isRepair(PrepareItemCraftEvent event) {
            if(event.isRepair()) {
                repairFlag = true;
            }else {
                repairFlag = false;
            }
            Bukkit.broadcastMessage("repairFlag set to "+repairFlag);
        }
     
  2. Offline

    KarimAKL

    @Skylong_ PrepareItemCraftEvent#isRepair() is returning false, so it goes to your else statement and sets the field to false.

    Btw, instead of this:
    Code:Java
    1. if (event.isRepair()) {
    2. repairFlag = true;
    3. } else {
    4. repairFlag = false;
    5. }

    You can do this:
    Code:Java
    1. repairFlag = event.isRepair();
     
    Skylong_ likes this.
  3. Offline

    Skylong_

    Ok but when i made something like this (even after to use your code implements, btw thank you).

    upload_2021-3-28_18-30-50.png

    The return still holds as false. What i actually want to is know why.

    But thank you for your help anyway! ;)
     

Share This Page