mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-11-29 16:15:17 +01:00
Minor fixes
This commit is contained in:
parent
02d784489b
commit
88c8998727
@ -29,11 +29,11 @@ public class CommandEcoskip implements CommandExecutor {
|
|||||||
if(meta == null) {
|
if(meta == null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(meta.getPersistentDataContainer().has(EnchantDisplay.keySkip, PersistentDataType.INTEGER)) {
|
if(meta.getPersistentDataContainer().has(EnchantDisplay.KEY_SKIP, PersistentDataType.INTEGER)) {
|
||||||
meta.getPersistentDataContainer().remove(EnchantDisplay.keySkip);
|
meta.getPersistentDataContainer().remove(EnchantDisplay.KEY_SKIP);
|
||||||
player.sendMessage(ConfigManager.getLang().getMessage("skip-removed"));
|
player.sendMessage(ConfigManager.getLang().getMessage("skip-removed"));
|
||||||
} else {
|
} else {
|
||||||
meta.getPersistentDataContainer().set(EnchantDisplay.keySkip, PersistentDataType.INTEGER, 1);
|
meta.getPersistentDataContainer().set(EnchantDisplay.KEY_SKIP, PersistentDataType.INTEGER, 1);
|
||||||
player.sendMessage(ConfigManager.getLang().getMessage("skip-added"));
|
player.sendMessage(ConfigManager.getLang().getMessage("skip-added"));
|
||||||
}
|
}
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
|
@ -33,12 +33,12 @@ public class EnchantDisplay {
|
|||||||
* @deprecated This is no longer used due to a change in the lore storage mechanism
|
* @deprecated This is no longer used due to a change in the lore storage mechanism
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private static final NamespacedKey key = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-len");
|
private static final NamespacedKey KEY = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-len");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The meta key to hide enchantments in lore
|
* The meta key to hide enchantments in lore
|
||||||
*/
|
*/
|
||||||
public static final NamespacedKey keySkip = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-skip");
|
public static final NamespacedKey KEY_SKIP = new NamespacedKey(EcoEnchantsPlugin.getInstance(), "ecoenchantlore-skip");
|
||||||
|
|
||||||
private static final String prefix = "§w";
|
private static final String prefix = "§w";
|
||||||
|
|
||||||
@ -101,15 +101,15 @@ public class EnchantDisplay {
|
|||||||
if(itemLore == null) itemLore = new ArrayList<>();
|
if(itemLore == null) itemLore = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (meta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER)) {
|
if (meta.getPersistentDataContainer().has(KEY, PersistentDataType.INTEGER)) {
|
||||||
int enchantLoreLength = meta.getPersistentDataContainer().get(key, PersistentDataType.INTEGER);
|
int enchantLoreLength = meta.getPersistentDataContainer().get(KEY, PersistentDataType.INTEGER);
|
||||||
if(itemLore.size() >= enchantLoreLength) {
|
if(itemLore.size() >= enchantLoreLength) {
|
||||||
itemLore.subList(0, enchantLoreLength).clear();
|
itemLore.subList(0, enchantLoreLength).clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {}
|
} catch (NullPointerException ignored) {}
|
||||||
|
|
||||||
meta.getPersistentDataContainer().remove(key);
|
meta.getPersistentDataContainer().remove(KEY);
|
||||||
itemLore.removeIf((s) -> s.startsWith(prefix));
|
itemLore.removeIf((s) -> s.startsWith(prefix));
|
||||||
|
|
||||||
if (meta instanceof EnchantmentStorageMeta) {
|
if (meta instanceof EnchantmentStorageMeta) {
|
||||||
@ -147,7 +147,7 @@ public class EnchantDisplay {
|
|||||||
|
|
||||||
if(meta == null) return oldItem;
|
if(meta == null) return oldItem;
|
||||||
|
|
||||||
if(meta.getPersistentDataContainer().has(keySkip, PersistentDataType.INTEGER))
|
if(meta.getPersistentDataContainer().has(KEY_SKIP, PersistentDataType.INTEGER))
|
||||||
return oldItem;
|
return oldItem;
|
||||||
|
|
||||||
if(meta.hasLore())
|
if(meta.hasLore())
|
||||||
|
@ -2,8 +2,30 @@ package com.willfp.ecoenchants.util;
|
|||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class NumberUtils {
|
public class NumberUtils {
|
||||||
|
|
||||||
|
private final static TreeMap<Integer, String> NUMERALS = new TreeMap<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
|
||||||
|
NUMERALS.put(1000, "M");
|
||||||
|
NUMERALS.put(900, "CM");
|
||||||
|
NUMERALS.put(500, "D");
|
||||||
|
NUMERALS.put(400, "CD");
|
||||||
|
NUMERALS.put(100, "C");
|
||||||
|
NUMERALS.put(90, "XC");
|
||||||
|
NUMERALS.put(50, "L");
|
||||||
|
NUMERALS.put(40, "XL");
|
||||||
|
NUMERALS.put(10, "X");
|
||||||
|
NUMERALS.put(9, "IX");
|
||||||
|
NUMERALS.put(5, "V");
|
||||||
|
NUMERALS.put(4, "IV");
|
||||||
|
NUMERALS.put(1, "I");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bias the input value according to a curve
|
* Bias the input value according to a curve
|
||||||
* @param input The input value
|
* @param input The input value
|
||||||
@ -48,39 +70,13 @@ public class NumberUtils {
|
|||||||
* @return The number, converted to a roman numeral
|
* @return The number, converted to a roman numeral
|
||||||
*/
|
*/
|
||||||
public static String toNumeral(int number) {
|
public static String toNumeral(int number) {
|
||||||
|
if (number >= 1 && number <= 4096) {
|
||||||
LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>();
|
int l = NUMERALS.floorKey(number);
|
||||||
roman_numerals.put("M", 1000);
|
if (number == l) {
|
||||||
roman_numerals.put("CM", 900);
|
return NUMERALS.get(number);
|
||||||
roman_numerals.put("D", 500);
|
|
||||||
roman_numerals.put("CD", 400);
|
|
||||||
roman_numerals.put("C", 100);
|
|
||||||
roman_numerals.put("XC", 90);
|
|
||||||
roman_numerals.put("L", 50);
|
|
||||||
roman_numerals.put("XL", 40);
|
|
||||||
roman_numerals.put("X", 10);
|
|
||||||
roman_numerals.put("IX", 9);
|
|
||||||
roman_numerals.put("V", 5);
|
|
||||||
roman_numerals.put("IV", 4);
|
|
||||||
roman_numerals.put("I", 1);
|
|
||||||
StringBuilder res = new StringBuilder();
|
|
||||||
for (Map.Entry<String, Integer> entry : roman_numerals.entrySet()) {
|
|
||||||
int matches = number / entry.getValue();
|
|
||||||
res.append(repeat(entry.getKey(), matches));
|
|
||||||
number = number % entry.getValue();
|
|
||||||
}
|
}
|
||||||
return res.toString();
|
return NUMERALS.get(l) + toNumeral(number - l);
|
||||||
}
|
} else return String.valueOf(number);
|
||||||
|
|
||||||
private static String repeat(String s, int n) {
|
|
||||||
if (s == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < n; i++) {
|
|
||||||
sb.append(s);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user