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

com.sucy.skill.dynamic.condition.FoodCondition Maven / Gradle / Ivy

Go to download

A Minecraft Bukkit plugin aiming to provide an easy code API and skill editor for all server owners to create unique and fully custom classes and skills.

There is a newer version: 1.3.1-R1
Show newest version
package com.sucy.skill.dynamic.condition;

import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;

public class FoodCondition extends ConditionComponent {
    private static final String TYPE = "type";
    private static final String MIN  = "min-value";
    private static final String MAX  = "max-value";

    @Override
    boolean test(final LivingEntity caster, final int level, final LivingEntity target) {
        if (!(target instanceof Player)) {
            return false;
        }

        final String type = settings.getString(TYPE).toLowerCase();
        final double min  = parseValues(caster, MIN, level, 0);
        final double max  = parseValues(caster, MAX, level, 999);

        double value;
        switch (type) {
            case "difference percent":
                value = (((Player) target).getFoodLevel() - ((Player) caster).getFoodLevel()) * 100
                        / ((Player) caster).getFoodLevel();
                break;
            case "difference":
                value = ((Player) target).getFoodLevel() - ((Player) caster).getFoodLevel();
                break;
            case "percent":
                value = ((Player) target).getFoodLevel() * 100 / 20;
                break;
            default:
                value = ((Player) target).getFoodLevel();
        }
        return value >= min && value <= max;
    }

    @Override
    public String getKey() {
        return "food";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy