diff --git a/pom.xml b/pom.xml
index dfd7c0b..e95b5c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -146,7 +146,7 @@
me.anjoismysign
blis
- 1.0.1
+ 1.0.2
de.oliver
diff --git a/src/main/java/us/mytheria/bloblib/entities/currency/Currency.java b/src/main/java/us/mytheria/bloblib/entities/currency/Currency.java
index 518c1cc..5c8c3a2 100644
--- a/src/main/java/us/mytheria/bloblib/entities/currency/Currency.java
+++ b/src/main/java/us/mytheria/bloblib/entities/currency/Currency.java
@@ -229,10 +229,8 @@ public String getDisplayName() {
* @return the formatted String
*/
public String display(double amount) {
- return display.replace("%balance%", decimalFormat.format(amount)).replace(
- "%wattsBalance%", Formatter.WATTS((float) amount)).replace(
- "%bytesBalance%", Formatter.BYTES((float) amount)).replace(
- "%gramsBalance%", Formatter.GRAMS((float) amount));
+ String balance = display.replace("%balance%", decimalFormat.format(amount));
+ return Formatter.getInstance().formatAll(balance, amount);
}
/**
diff --git a/src/main/java/us/mytheria/bloblib/itemstack/ItemStackBuilder.java b/src/main/java/us/mytheria/bloblib/itemstack/ItemStackBuilder.java
index 5433576..74f3d64 100644
--- a/src/main/java/us/mytheria/bloblib/itemstack/ItemStackBuilder.java
+++ b/src/main/java/us/mytheria/bloblib/itemstack/ItemStackBuilder.java
@@ -7,10 +7,12 @@
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.enchantments.Enchantment;
+import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
+import org.jetbrains.annotations.Nullable;
import us.mytheria.bloblib.utilities.TextColor;
import java.util.*;
@@ -23,7 +25,7 @@ public final class ItemStackBuilder {
private static final ItemFlag[] ALL_CONSTANTS = ItemFlag.values();
public static ItemStackBuilder build(ItemStack itemStack) {
- return new ItemStackBuilder(itemStack.clone()).hideAll();
+ return new ItemStackBuilder(new ItemStack(itemStack));
}
public static ItemStackBuilder build(Material material) {
@@ -31,7 +33,7 @@ public static ItemStackBuilder build(Material material) {
}
public static ItemStackBuilder build(Material material, int amount) {
- return build(new ItemStack(material, amount));
+ return new ItemStackBuilder(new ItemStack(material, amount));
}
public static ItemStackBuilder build(String material) {
@@ -249,11 +251,15 @@ public ItemStackBuilder color(Color color) {
});
}
- public ItemStackBuilder attribute(Attribute attribute, double amount, AttributeModifier.Operation operation) {
+ public ItemStackBuilder attribute(
+ Attribute attribute,
+ double amount,
+ AttributeModifier.Operation operation,
+ @Nullable EquipmentSlot equipmentSlot) {
return itemMeta(itemMeta -> {
try {
UUID uuid = UUID.randomUUID();
- AttributeModifier modifier = new AttributeModifier(uuid, uuid.toString(), amount, operation);
+ AttributeModifier modifier = new AttributeModifier(uuid, uuid.toString(), amount, operation, equipmentSlot);
itemMeta.addAttributeModifier(attribute, modifier);
} catch (Exception exception) {
Bukkit.getLogger().log(Level.SEVERE, exception, () -> "Failed to add attribute modifier");
diff --git a/src/main/java/us/mytheria/bloblib/itemstack/ItemStackReader.java b/src/main/java/us/mytheria/bloblib/itemstack/ItemStackReader.java
index ecf094f..dfaf17a 100644
--- a/src/main/java/us/mytheria/bloblib/itemstack/ItemStackReader.java
+++ b/src/main/java/us/mytheria/bloblib/itemstack/ItemStackReader.java
@@ -8,6 +8,7 @@
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -102,9 +103,19 @@ public static ItemStackBuilder READ_OR_FAIL_FAST(ConfigurationSection section) {
double amount = attributeSection.getDouble("Amount");
if (!attributeSection.isString("Operation"))
throw new ConfigurationFieldException("Attribute '" + key + "' is missing 'Operation' field");
+ EquipmentSlot equipmentSlot;
+ String readEquipmentSlot = attributeSection.getString("EquipmentSlot");
+ if (readEquipmentSlot != null) {
+ try {
+ equipmentSlot = EquipmentSlot.valueOf(readEquipmentSlot);
+ } catch (IllegalArgumentException exception) {
+ throw new ConfigurationFieldException("EquipmentSlot '" + readEquipmentSlot + "' is not valid");
+ }
+ } else
+ equipmentSlot = null;
AttributeModifier.Operation operation = AttributeModifier.Operation.valueOf(attributeSection.getString("Operation"));
- uber.talk(uber.thanks().attribute(attribute, amount, operation));
- } catch (IllegalArgumentException e) {
+ uber.talk(uber.thanks().attribute(attribute, amount, operation, equipmentSlot));
+ } catch (IllegalArgumentException exception) {
throw new ConfigurationFieldException("Attribute '" + key + "' has an invalid Operation");
}
});
diff --git a/src/main/java/us/mytheria/bloblib/utilities/Formatter.java b/src/main/java/us/mytheria/bloblib/utilities/Formatter.java
index e52b1fb..bf1e8fb 100644
--- a/src/main/java/us/mytheria/bloblib/utilities/Formatter.java
+++ b/src/main/java/us/mytheria/bloblib/utilities/Formatter.java
@@ -1,10 +1,32 @@
package us.mytheria.bloblib.utilities;
+import org.jetbrains.annotations.NotNull;
+
import java.text.DecimalFormat;
public class Formatter {
+ private static Formatter instance;
+
+ private Formatter() {
+ }
+
+ public static Formatter getInstance() {
+ if (instance == null)
+ instance = new Formatter();
+ return instance;
+ }
+
+ public String formatAll(
+ @NotNull String input,
+ double amount) {
+ return input.replace(
+ "%wattsBalance%", watts((float) amount)).replace(
+ "%bytesBalance%", bytes((float) amount)).replace(
+ "%gramsBalance%", grams((float) amount)).replace(
+ "%litersBalance%", liters((float) amount));
+ }
- public static String WATTS(float value) {
+ private String watts(float value) {
String[] arr = {"", "k", "M", "G", "T", "P", "E", "Z", "Y"};
int index = 0;
while ((value / 1000) >= 1) {
@@ -15,7 +37,7 @@ public static String WATTS(float value) {
return String.format("%s%s", decimalFormat.format(value), arr[index]) + "W";
}
- public static String BYTES(float value) {
+ private String bytes(float value) {
String[] arr = {"", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"};
int index = 0;
while ((value / 1024) >= 1) {
@@ -26,8 +48,19 @@ public static String BYTES(float value) {
return String.format("%s%s", decimalFormat.format(value), arr[index]) + "B";
}
- public static String GRAMS(float value) {
- String[] arr = {"g", "kg", "t", "kt", "mt", "gt", "tt", "pt", "et", "zt"};
+ private String grams(float value) {
+ String[] arr = {"g", "kg", "t", "kt", "Mt", "Gt", "Tt", "Pt", "Et", "Zt"};
+ int index = 0;
+ while ((value / 1000) >= 1) {
+ value = value / 1000;
+ index++;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat("#.##");
+ return String.format("%s%s", decimalFormat.format(value), arr[index]);
+ }
+
+ private String liters(float value) {
+ String[] arr = {"L", "kL", "ML", "GL", "TL", "PL", "EL", "ZL", "YL"};
int index = 0;
while ((value / 1000) >= 1) {
value = value / 1000;