Addition of UltimateShop Provider & everything around
Took 1 hour 14 minutes
This commit is contained in:
parent
cd97c12647
commit
f55646cf95
6
pom.xml
6
pom.xml
@ -90,5 +90,11 @@
|
||||
<version>2.21.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.superiormc</groupId>
|
||||
<artifactId>ultimateshop</artifactId>
|
||||
<version>3.10.2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package fr.molzonas.painfulloss;
|
||||
|
||||
import fr.molzonas.painfulloss.commands.PainfulLossCommand;
|
||||
import fr.molzonas.painfulloss.enums.PropertiesEnum;
|
||||
import fr.molzonas.painfulloss.utils.PropertiesEnum;
|
||||
import fr.molzonas.painfulloss.listeners.DeathListener;
|
||||
import fr.molzonas.painfulloss.provider.CountPriceProvider;
|
||||
import fr.molzonas.painfulloss.provider.EssentialsPriceProvider;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package fr.molzonas.painfulloss.commands;
|
||||
|
||||
import fr.molzonas.painfulloss.PainfulLoss;
|
||||
import fr.molzonas.painfulloss.enums.PropertiesEnum;
|
||||
import fr.molzonas.painfulloss.utils.PropertiesEnum;
|
||||
import fr.molzonas.painfulloss.utils.Message;
|
||||
import fr.molzonas.painfulloss.utils.PriceCalculator;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package fr.molzonas.painfulloss.listeners;
|
||||
|
||||
import fr.molzonas.painfulloss.PainfulLoss;
|
||||
import fr.molzonas.painfulloss.enums.PropertiesEnum;
|
||||
import fr.molzonas.painfulloss.utils.PropertiesEnum;
|
||||
import fr.molzonas.painfulloss.utils.Message;
|
||||
import fr.molzonas.painfulloss.utils.PriceCalculator;
|
||||
import org.bukkit.GameRule;
|
||||
@ -31,7 +31,7 @@ public class DeathListener implements Listener {
|
||||
|
||||
if (lostItems.isEmpty()) return;
|
||||
|
||||
double total = PriceCalculator.estimate(lostItems);
|
||||
double total = PriceCalculator.estimate(lostItems, player);
|
||||
|
||||
if (PropertiesEnum.ENCHANT_ENABLED.getBoolean()) total += PriceCalculator.enchantEstimate(lostItems);
|
||||
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
package fr.molzonas.painfulloss.provider;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CountPriceProvider implements PriceProvider{
|
||||
@ -11,10 +14,15 @@ public class CountPriceProvider implements PriceProvider{
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getPrice(ItemStack stack) {
|
||||
public Optional<Double> getPrice(ItemStack stack, @Nullable Player player) {
|
||||
return Optional.of((double) stack.getAmount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getPrices(List<ItemStack> stack, @org.jetbrains.annotations.Nullable Player player) {
|
||||
return Optional.of(stack.stream().mapToDouble(ItemStack::getAmount).sum());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCountBased() {
|
||||
return true;
|
||||
|
||||
@ -2,8 +2,10 @@ package fr.molzonas.painfulloss.provider;
|
||||
|
||||
import com.earth2me.essentials.Worth;
|
||||
import com.earth2me.essentials.IEssentials;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Optional;
|
||||
|
||||
@ -23,7 +25,7 @@ public class EssentialsPriceProvider implements PriceProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getPrice(ItemStack stack) {
|
||||
public Optional<Double> getPrice(ItemStack stack, @Nullable Player player) {
|
||||
if (stack == null || stack.getAmount() <= 0) return Optional.empty();
|
||||
|
||||
try {
|
||||
|
||||
@ -1,12 +1,19 @@
|
||||
package fr.molzonas.painfulloss.provider;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PriceProvider {
|
||||
String getName();
|
||||
Optional<Double> getPrice(ItemStack stack);
|
||||
Optional<Double> getPrice(ItemStack stack, @Nullable Player player);
|
||||
default Optional<Double> getPrices(List<ItemStack> stack, @Nullable Player player) {
|
||||
if (stack.isEmpty()) return Optional.empty();
|
||||
return Optional.of(stack.stream().mapToDouble(x -> this.getPrice(x, player).orElse(0d)).sum());
|
||||
}
|
||||
default boolean isReady() { return true; }
|
||||
default boolean isCountBased() { return false; }
|
||||
}
|
||||
|
||||
@ -0,0 +1,43 @@
|
||||
package fr.molzonas.painfulloss.provider;
|
||||
|
||||
import cn.superiormc.ultimateshop.api.ShopHelper;
|
||||
import cn.superiormc.ultimateshop.objects.items.AbstractSingleThing;
|
||||
import cn.superiormc.ultimateshop.objects.items.GiveResult;
|
||||
import fr.molzonas.painfulloss.utils.PropertiesEnum;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class UltimateShopPriceProvider implements PriceProvider {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "UltimateShop";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Double> getPrice(ItemStack stack, @Nullable Player player) {
|
||||
if (stack == null || stack.getType() == Material.AIR || stack.getAmount() <= 0) return Optional.empty();
|
||||
double total = 0d;
|
||||
GiveResult gr = ShopHelper.getSellPrices(new ItemStack[]{stack}, player, stack.getAmount());
|
||||
if (gr == null) return Optional.empty();
|
||||
Map<AbstractSingleThing, BigDecimal> map = gr.getResultMap();
|
||||
if (map == null || map.isEmpty()) return Optional.empty();
|
||||
for (Map.Entry<AbstractSingleThing, BigDecimal> entry : map.entrySet()) {
|
||||
AbstractSingleThing key = entry.getKey();
|
||||
BigDecimal value = entry.getValue();
|
||||
ConfigurationSection section = key.getSingleSection();
|
||||
String econ = section.getString("economy-plugin", "");
|
||||
if (econ.equalsIgnoreCase(PropertiesEnum.PRICE_PROVIDER.getString())) {
|
||||
total += value.doubleValue();
|
||||
}
|
||||
}
|
||||
return total > 0 ? Optional.of(total) : Optional.empty();
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,6 @@
|
||||
package fr.molzonas.painfulloss.utils;
|
||||
|
||||
import fr.molzonas.painfulloss.PainfulLoss;
|
||||
import fr.molzonas.painfulloss.enums.PropertiesEnum;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -15,23 +14,23 @@ public class PriceCalculator {
|
||||
private PriceCalculator() {}
|
||||
|
||||
public static Double estimate(Player player) {
|
||||
return estimate(player.getInventory().getContents());
|
||||
return estimate(player.getInventory().getContents(), player);
|
||||
}
|
||||
|
||||
public static Double estimate(ItemStack[] items) {
|
||||
public static Double estimate(ItemStack[] items, Player player) {
|
||||
double rs = 0d;
|
||||
for (ItemStack item : items) {
|
||||
rs += estimate(item);
|
||||
rs += estimate(item, player);
|
||||
}
|
||||
return rs;
|
||||
}
|
||||
|
||||
public static Double estimate(List<ItemStack> items) {
|
||||
return items.stream().mapToDouble(PriceCalculator::estimate).sum();
|
||||
public static Double estimate(List<ItemStack> items, Player player) {
|
||||
return items.stream().mapToDouble(x -> estimate(x, player)).sum();
|
||||
}
|
||||
|
||||
public static Double estimate(ItemStack item) {
|
||||
return PainfulLoss.getPriceProvider().getPrice(item).orElse(0d);
|
||||
public static Double estimate(ItemStack item, Player player) {
|
||||
return PainfulLoss.getPriceProvider().getPrice(item, player).orElse(0d);
|
||||
}
|
||||
|
||||
public static Double enchantEstimate(Player player) {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
package fr.molzonas.painfulloss.enums;
|
||||
package fr.molzonas.painfulloss.utils;
|
||||
|
||||
import fr.molzonas.painfulloss.PainfulLoss;
|
||||
import lombok.Getter;
|
||||
@ -12,7 +12,8 @@ public enum PropertiesEnum {
|
||||
DEBUG("debug", "false"),
|
||||
PRICE_PROVIDER("priceProvider"),
|
||||
ENCHANT_ENABLED("estimation.enchant.enabled"),
|
||||
ENCHANT_DEFAULT_PER_LEVEL("estimation.enchant.default_per_level")
|
||||
ENCHANT_DEFAULT_PER_LEVEL("estimation.enchant.default_per_level"),
|
||||
ECONOMY_PROVIDER("economyProvider", "Vault")
|
||||
;
|
||||
|
||||
@Getter private final String path;
|
||||
@ -8,6 +8,9 @@ debug: false
|
||||
# Keep it empty will take the first available in order between UltimateShop, Essentials and Count.
|
||||
priceProvider:
|
||||
|
||||
# Used to do estimations with UltimateShop, can only be Vault... for now.
|
||||
economyProvider: Vault
|
||||
|
||||
estimation:
|
||||
# Is enchants on items used in worth calculation ?
|
||||
enchant:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user