44 lines
1.2 KiB
Java
44 lines
1.2 KiB
Java
package fr.molzonas.painfulloss.provider;
|
|
|
|
import com.earth2me.essentials.Worth;
|
|
import com.earth2me.essentials.IEssentials;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.Optional;
|
|
|
|
public class EssentialsPriceProvider implements PriceProvider {
|
|
private final IEssentials plugin;
|
|
private final Worth worth;
|
|
private boolean ready = false;
|
|
public EssentialsPriceProvider(IEssentials plugin) {
|
|
this.plugin = plugin;
|
|
this.worth = plugin.getWorth();
|
|
this.ready = true;
|
|
}
|
|
|
|
@Override
|
|
public String getName() {
|
|
return "Essentials";
|
|
}
|
|
|
|
@Override
|
|
public Optional<Double> getPrice(ItemStack stack) {
|
|
if (stack == null || stack.getAmount() <= 0) return Optional.empty();
|
|
|
|
try {
|
|
BigDecimal price = worth.getPrice(plugin, stack);
|
|
if (price == null) return Optional.empty();
|
|
if (price.signum() < 0) return Optional.empty();
|
|
return Optional.of(price.doubleValue());
|
|
} catch (Exception e) {
|
|
return Optional.empty();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isReady() {
|
|
return ready;
|
|
}
|
|
}
|