All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.inventory.transaction.action.TakeLevelAction Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.inventory.transaction.action;

import cn.nukkit.Player;
import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.item.Item;
import lombok.ToString;

@PowerNukkitOnly
@ToString(callSuper = true)
public class TakeLevelAction extends InventoryAction {
    
    private final int levels;

    @PowerNukkitOnly
    public TakeLevelAction(int levels) {
        super(Item.get(0), Item.get(0));
        this.levels = levels;
    }

    @PowerNukkitOnly
    public int getLevels() {
        return levels;
    }
    
    @Override
    public boolean isValid(Player source) {
        return source.isCreative() || source.getExperienceLevel() >= levels;
    }
    
    @Override
    public boolean execute(Player source) {
        if (source.isCreative()) {
            return true;
        }
        int playerLevels = source.getExperienceLevel();
        if (playerLevels < levels) {
            return false;
        }
        source.setExperience(source.getExperience(), playerLevels - levels, false);
        return true;
    }
    
    @Override
    public void onExecuteSuccess(Player source) {
    
    }
    
    @Override
    public void onExecuteFail(Player source) {
    
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy