Refactor PlayerShops to use Dialogs.
This commit is contained in:
@@ -65,4 +65,37 @@ public class EconomyUtils {
|
||||
return bd.doubleValue();
|
||||
}
|
||||
|
||||
public static Double parseValue(String input) {
|
||||
Double value = null;
|
||||
if (input == null || input.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
value = Double.parseDouble(input);
|
||||
} catch (NumberFormatException ex) {
|
||||
Double multiplier = multiplierValue(input.substring(input.length() - 1));
|
||||
if (multiplier == null) {
|
||||
multiplier = 1.0;
|
||||
}
|
||||
try {
|
||||
value = Double.parseDouble(input.substring(0, input.length() - 1));
|
||||
} catch (NumberFormatException ignored) {}
|
||||
if (value != null) {
|
||||
value = value * multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static Double multiplierValue(String input) {
|
||||
Double value = null;
|
||||
switch(input.toLowerCase()) {
|
||||
case "k" -> value = 1000.0;
|
||||
case "m" -> value = 1000000.0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,20 +2,17 @@ package com.alttd.playershops.utils;
|
||||
|
||||
import com.alttd.playershops.shop.PlayerShop;
|
||||
import com.alttd.playershops.shop.ShopTransaction;
|
||||
import com.alttd.playershops.utils.sprite.MaterialSprites;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.ShulkerBox;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.*;
|
||||
import org.bukkit.map.MapView;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -168,7 +165,7 @@ public class ShopUtil {
|
||||
Component component;
|
||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
if (item == null || item.getType().equals(Material.AIR))
|
||||
return miniMessage.deserialize("NONE");
|
||||
return miniMessage.deserialize("No item");
|
||||
boolean dname = item.hasItemMeta() && item.getItemMeta().hasDisplayName();
|
||||
if (dname) {
|
||||
component = item.getItemMeta().displayName();
|
||||
@@ -205,4 +202,18 @@ public class ShopUtil {
|
||||
public static double round(double price) {
|
||||
return (double) Math.round(price * 100) / 100;
|
||||
}
|
||||
|
||||
public static Component spriteComponent(ItemStack itemStack) {
|
||||
Component component = Component.empty();
|
||||
if (itemStack == null || itemStack.getType() == Material.AIR) return component;
|
||||
|
||||
component = MaterialSprites.get(itemStack.getType()).append(Component.space()).append(
|
||||
itemStack.displayName().hoverEvent(itemStack.asHoverEvent()));
|
||||
|
||||
return component;
|
||||
}
|
||||
|
||||
public static Component spriteComponent(Material material) {
|
||||
return MaterialSprites.get(material).append(Component.space()).append(Component.text(material.key().value()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user