mirror of
https://github.com/songoda/EpicEnchants.git
synced 2024-09-27 15:22:45 +02:00
34 lines
1014 B
Java
34 lines
1014 B
Java
package com.craftaro.epicenchants.objects;
|
|
|
|
import com.craftaro.epicenchants.utils.single.GeneralUtils;
|
|
import com.craftaro.epicenchants.utils.single.Placeholders;
|
|
import org.bukkit.entity.LivingEntity;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class LeveledModifier {
|
|
private final String string;
|
|
|
|
private LeveledModifier(String string) {
|
|
this.string = string;
|
|
}
|
|
|
|
public static LeveledModifier of(String string) {
|
|
return new LeveledModifier(string);
|
|
}
|
|
|
|
public double get(int level, double def, Player user, LivingEntity opponent) {
|
|
if (this.string == null || this.string.isEmpty()) {
|
|
return def;
|
|
}
|
|
|
|
if (this.string.equalsIgnoreCase("MAX")) {
|
|
return Integer.MAX_VALUE;
|
|
}
|
|
|
|
String toTest = Placeholders.setPlaceholders(this.string, user, opponent, level);
|
|
|
|
Object value = GeneralUtils.parseJS(toTest, "LeveledModifier", def);
|
|
return value instanceof Double ? (double) value : (int) value;
|
|
}
|
|
}
|