Adding enchants to the worth, removing EXP (TODO later)
This commit is contained in:
parent
6cd20b565b
commit
a3b0965c47
@ -47,7 +47,7 @@ public final class PainfulLoss extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void langInit() {
|
private void langInit() {
|
||||||
Locale locale = Locale.forLanguageTag(PropertiesEnum.LOCALE.getValue());
|
Locale locale = Locale.forLanguageTag(PropertiesEnum.LOCALE.getString());
|
||||||
Message.init(locale);
|
Message.init(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,7 +88,7 @@ public final class PainfulLoss extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Selection
|
// Selection
|
||||||
String provider = PropertiesEnum.PRICE_PROVIDER.getValue();
|
String provider = PropertiesEnum.PRICE_PROVIDER.getString();
|
||||||
if (provider != null) {
|
if (provider != null) {
|
||||||
switch (provider.toLowerCase()) {
|
switch (provider.toLowerCase()) {
|
||||||
case "ultimateshop": priceProvider = ultimateShopProvider.orElse(countProvider); break;
|
case "ultimateshop": priceProvider = ultimateShopProvider.orElse(countProvider); break;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package fr.molzonas.painfulloss.commands;
|
package fr.molzonas.painfulloss.commands;
|
||||||
|
|
||||||
import fr.molzonas.painfulloss.PainfulLoss;
|
import fr.molzonas.painfulloss.PainfulLoss;
|
||||||
|
import fr.molzonas.painfulloss.enums.PropertiesEnum;
|
||||||
import fr.molzonas.painfulloss.utils.Message;
|
import fr.molzonas.painfulloss.utils.Message;
|
||||||
import fr.molzonas.painfulloss.utils.PriceCalculator;
|
import fr.molzonas.painfulloss.utils.PriceCalculator;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -75,14 +76,16 @@ public class PainfulLossCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
private boolean commandWorth(CommandSender commandSender, String[] args) {
|
private boolean commandWorth(CommandSender commandSender, String[] args) {
|
||||||
if (args.length == 1 && commandSender instanceof Player p && commandSender.hasPermission("painfulloss.worth")) {
|
if (args.length == 1 && commandSender instanceof Player p && commandSender.hasPermission("painfulloss.worth")) {
|
||||||
commandSender.sendMessage(Message.of("command.worth", PriceCalculator.estimate(p)));
|
commandSender.sendMessage(Message.of("command.worth", PriceCalculator.estimate(p)
|
||||||
|
+ (PropertiesEnum.ENCHANT_ENABLED.getBoolean() ? PriceCalculator.enchantEstimate(p) : 0)));
|
||||||
} else if (args.length == 2 && commandSender.hasPermission("painfulloss.worth.other")) {
|
} else if (args.length == 2 && commandSender.hasPermission("painfulloss.worth.other")) {
|
||||||
Player p = PainfulLoss.getInstance().getServer().getPlayer(args[1]);
|
Player p = PainfulLoss.getInstance().getServer().getPlayer(args[1]);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
commandSender.sendMessage(Message.of("command.worth.unknownplayer", args[1]));
|
commandSender.sendMessage(Message.of("command.worth.unknownplayer", args[1]));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
commandSender.sendMessage(Message.of("command.worth.other", PriceCalculator.estimate(p)));
|
commandSender.sendMessage(Message.of("command.worth.other", p.getName(), PriceCalculator.estimate(p)
|
||||||
|
+ (PropertiesEnum.ENCHANT_ENABLED.getBoolean() ? PriceCalculator.enchantEstimate(p) : 0)));
|
||||||
} else {
|
} else {
|
||||||
return commandNotAutorised(commandSender);
|
return commandNotAutorised(commandSender);
|
||||||
}
|
}
|
||||||
@ -97,11 +100,17 @@ public class PainfulLossCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (args.length == 1) {
|
if (args.length == 1) {
|
||||||
completions.add("test");
|
completions.add("test");
|
||||||
completions.add("help");
|
completions.add("help");
|
||||||
|
completions.add("worth");
|
||||||
if (commandSender.hasPermission("painfulloss.admin")) completions.add("reload");
|
if (commandSender.hasPermission("painfulloss.admin")) completions.add("reload");
|
||||||
}
|
}
|
||||||
if (args.length == 2 && "test".equalsIgnoreCase(args[0])) {
|
if (args.length == 2) {
|
||||||
completions.add("fr-FR");
|
if ("test".equalsIgnoreCase(args[0])) {
|
||||||
completions.add("en-US");
|
completions.add("fr-FR");
|
||||||
|
completions.add("en-US");
|
||||||
|
}
|
||||||
|
if ("worth".equalsIgnoreCase(args[0]) && commandSender.hasPermission("painfulloss.worth.other")) {
|
||||||
|
completions = PainfulLoss.getInstance().getServer().getOnlinePlayers().stream().map(Player::getName).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return completions;
|
return completions;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,16 @@ package fr.molzonas.painfulloss.enums;
|
|||||||
import fr.molzonas.painfulloss.PainfulLoss;
|
import fr.molzonas.painfulloss.PainfulLoss;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public enum PropertiesEnum {
|
public enum PropertiesEnum {
|
||||||
LOCALE("locale", PainfulLoss.DEFAULT_LOCALE_TAG),
|
LOCALE("locale", PainfulLoss.DEFAULT_LOCALE_TAG),
|
||||||
DEBUG("debug", "false"),
|
DEBUG("debug", "false"),
|
||||||
PRICE_PROVIDER("priceProvider")
|
PRICE_PROVIDER("priceProvider"),
|
||||||
|
ENCHANT_ENABLED("estimation.enchant.enabled"),
|
||||||
|
ENCHANT_DEFAULT_PER_LEVEL("estimation.enchant.default_per_level")
|
||||||
;
|
;
|
||||||
|
|
||||||
@Getter private final String path;
|
@Getter private final String path;
|
||||||
@ -21,8 +27,25 @@ public enum PropertiesEnum {
|
|||||||
this.fallback = fallback;
|
this.fallback = fallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getValue() {
|
public String getString() {
|
||||||
String value = PainfulLoss.getInstance().getConfig().getString(this.getPath());
|
String value = PainfulLoss.getInstance().getConfig().getString(this.getPath());
|
||||||
return value == null ? fallback : value;
|
return value == null ? fallback : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean getBoolean() {
|
||||||
|
return PainfulLoss.getInstance().getConfig().getBoolean(this.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getDouble() {
|
||||||
|
return PainfulLoss.getInstance().getConfig().getDouble(this.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Double> getEnchantConfigTable() {
|
||||||
|
Map<String, Double> enchantConfig = new HashMap<>();
|
||||||
|
Set<String> keys = PainfulLoss.getInstance().getConfig().getConfigurationSection("estimation.enchant.table").getKeys(false);
|
||||||
|
for (String key : keys) {
|
||||||
|
enchantConfig.put(key, PainfulLoss.getInstance().getConfig().getDouble("estimation.enchant.table." + key, 0d));
|
||||||
|
}
|
||||||
|
return enchantConfig;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package fr.molzonas.painfulloss.listeners;
|
package fr.molzonas.painfulloss.listeners;
|
||||||
|
|
||||||
import fr.molzonas.painfulloss.PainfulLoss;
|
import fr.molzonas.painfulloss.PainfulLoss;
|
||||||
|
import fr.molzonas.painfulloss.enums.PropertiesEnum;
|
||||||
import fr.molzonas.painfulloss.utils.Message;
|
import fr.molzonas.painfulloss.utils.Message;
|
||||||
import fr.molzonas.painfulloss.utils.PriceCalculator;
|
import fr.molzonas.painfulloss.utils.PriceCalculator;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
@ -32,10 +33,12 @@ public class DeathListener implements Listener {
|
|||||||
|
|
||||||
double total = PriceCalculator.estimate(lostItems);
|
double total = PriceCalculator.estimate(lostItems);
|
||||||
|
|
||||||
|
if (PropertiesEnum.ENCHANT_ENABLED.getBoolean()) total += PriceCalculator.enchantEstimate(lostItems);
|
||||||
|
|
||||||
if (PainfulLoss.getPriceProvider().isCountBased()) {
|
if (PainfulLoss.getPriceProvider().isCountBased()) {
|
||||||
player.sendMessage(Message.of("death.summary.count", player.getName(), total));
|
player.sendMessage(Message.of("death.summary.count", player.getName(), total));
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(Message.of("death.summary.value", player.getName(), numberFormat(total)));
|
PainfulLoss.getInstance().getServer().broadcastMessage(Message.of("death.summary.value", player.getName(), numberFormat(total)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,9 +10,11 @@ import java.util.Optional;
|
|||||||
public class EssentialsPriceProvider implements PriceProvider {
|
public class EssentialsPriceProvider implements PriceProvider {
|
||||||
private final IEssentials plugin;
|
private final IEssentials plugin;
|
||||||
private final Worth worth;
|
private final Worth worth;
|
||||||
|
private boolean ready = false;
|
||||||
public EssentialsPriceProvider(IEssentials plugin) {
|
public EssentialsPriceProvider(IEssentials plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.worth = plugin.getWorth();
|
this.worth = plugin.getWorth();
|
||||||
|
this.ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -33,4 +35,9 @@ public class EssentialsPriceProvider implements PriceProvider {
|
|||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReady() {
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,15 @@
|
|||||||
package fr.molzonas.painfulloss.utils;
|
package fr.molzonas.painfulloss.utils;
|
||||||
|
|
||||||
import fr.molzonas.painfulloss.PainfulLoss;
|
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;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class PriceCalculator {
|
public class PriceCalculator {
|
||||||
private PriceCalculator() {}
|
private PriceCalculator() {}
|
||||||
@ -28,4 +33,35 @@ public class PriceCalculator {
|
|||||||
public static Double estimate(ItemStack item) {
|
public static Double estimate(ItemStack item) {
|
||||||
return PainfulLoss.getPriceProvider().getPrice(item).orElse(0d);
|
return PainfulLoss.getPriceProvider().getPrice(item).orElse(0d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Double enchantEstimate(Player player) {
|
||||||
|
return enchantEstimate(player.getInventory().getContents());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double enchantEstimate(ItemStack[] items) {
|
||||||
|
double rs = 0d;
|
||||||
|
for (ItemStack item : items) {
|
||||||
|
rs += enchantEstimate(item);
|
||||||
|
}
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double enchantEstimate(List<ItemStack> items) {
|
||||||
|
return items.stream().mapToDouble(PriceCalculator::enchantEstimate).sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Double enchantEstimate(ItemStack item) {
|
||||||
|
if (item == null
|
||||||
|
|| item.getType() == Material.AIR
|
||||||
|
|| item.getEnchantments().isEmpty()) return 0d;
|
||||||
|
double total = 0d;
|
||||||
|
double defaultRate = PropertiesEnum.ENCHANT_DEFAULT_PER_LEVEL.getDouble();
|
||||||
|
Map<String, Double> tableEnchant = PropertiesEnum.getEnchantConfigTable();
|
||||||
|
Map<Enchantment, Integer> enchants = item.getEnchantments();
|
||||||
|
for (Map.Entry<Enchantment, Integer> e : enchants.entrySet()) {
|
||||||
|
String enchantKey = e.getKey().getKey().getKey().toUpperCase(Locale.ROOT);
|
||||||
|
total += tableEnchant.getOrDefault(enchantKey, defaultRate) * e.getValue();
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,17 +8,13 @@ debug: false
|
|||||||
# Keep it empty will take the first available in order between UltimateShop, Essentials and Count.
|
# Keep it empty will take the first available in order between UltimateShop, Essentials and Count.
|
||||||
priceProvider:
|
priceProvider:
|
||||||
|
|
||||||
# How estimations works,
|
|
||||||
estimation:
|
estimation:
|
||||||
xp:
|
# Is enchants on items used in worth calculation ?
|
||||||
enabled: true
|
|
||||||
price_per_point: 0.5
|
|
||||||
show_in_message: true
|
|
||||||
show_in_message_with_level: true
|
|
||||||
|
|
||||||
enchant:
|
enchant:
|
||||||
enabled: true
|
enabled: true
|
||||||
default_per_level: 0
|
default_per_level: 0 # If not in the table below, the base price per level for enchants
|
||||||
|
# Evaluate every enchant worth in money per level
|
||||||
|
# Use https://minecraft.fandom.com/wiki/Enchanting for IDs (identifier, but in all cap)
|
||||||
table:
|
table:
|
||||||
SHARPNESS: 100
|
SHARPNESS: 100
|
||||||
EFFICIENCY: 100
|
EFFICIENCY: 100
|
||||||
|
|||||||
@ -1,8 +1,13 @@
|
|||||||
death.summary.value=&c{0} lost the equivalent of &e{1}$&c.
|
# On death
|
||||||
death.summary.count=&c{0} lost &e{1}&c item(s).
|
death.summary.count=&c{0} lost &e{1}&c item(s).
|
||||||
death.topitem=&7Most valuable: &6{0} &7(&e{1}&7)
|
death.summary.value=&c{0} lost the equivalent of &e{1}$&c.
|
||||||
|
death.topitem=&cMost valuable: &6{0} &c(&6{1}$&c)
|
||||||
|
|
||||||
|
# On command
|
||||||
command.worth=&6Your full inventory is worth {0}$.
|
command.worth=&6Your full inventory is worth {0}$.
|
||||||
command.worth.other=&6{0} full inventory is worth {1}$.
|
command.worth.other=&6{0} full inventory is worth {1}$.
|
||||||
command.worth.unknownplayer=&cThe requested player ({0}) has not been found.
|
command.worth.unknownplayer=&cThe requested player ({0}) has not been found.
|
||||||
|
|
||||||
|
# Plugin core & misc
|
||||||
plugin.reload=&aPainfulLoss has successfully reloaded.
|
plugin.reload=&aPainfulLoss has successfully reloaded.
|
||||||
plugin.unknown=&4Unknown command. Please use &c/painfullost help &4to get some help.
|
plugin.unknown=&4Unknown command. Please use &c/painfullost help &4to get some help.
|
||||||
@ -1,8 +1,13 @@
|
|||||||
death.summary.value=&c{0} a perdu l'équivalent de &e{1}$&c.
|
# On death
|
||||||
death.summary.count=&c{0} a perdu &e{1}&c item(s).
|
death.summary.count=&c{0} a perdu &e{1}&c item(s).
|
||||||
|
death.summary.value=&c{0} a perdu l'équivalent de &e{1}$&c.
|
||||||
death.topitem=&7Objet le plus cher : &6{0} &7(&e{1}&7)
|
death.topitem=&7Objet le plus cher : &6{0} &7(&e{1}&7)
|
||||||
|
|
||||||
|
# On command
|
||||||
command.worth=&6Votre inventaire complet vaut {0}$.
|
command.worth=&6Votre inventaire complet vaut {0}$.
|
||||||
command.worth.other=&6L''inventaire complet de {0} vaut {1}$.
|
command.worth.other=&6L''inventaire complet de {0} vaut {1}$.
|
||||||
command.worth.unknownplayer=&cLe joueur demandé ({0}) n''a pas été trouvé.
|
command.worth.unknownplayer=&cLe joueur demandé ({0}) n''a pas été trouvé.
|
||||||
|
|
||||||
|
# Plugin core & misc
|
||||||
plugin.reload=&aPainfulLoss a été rechargé avec succès.
|
plugin.reload=&aPainfulLoss a été rechargé avec succès.
|
||||||
plugin.unknown=&4Commande inconnue. Merci d'utiliser &c/painfulloss help &4pour obtenir de l'aide.
|
plugin.unknown=&4Commande inconnue. Merci d'utiliser &c/painfulloss help &4pour obtenir de l'aide.
|
||||||
Loading…
x
Reference in New Issue
Block a user