Fixed regex for double validation in config

This commit is contained in:
stjn 2021-11-10 20:03:39 +01:00
parent f76543b494
commit 9236befd7f
2 changed files with 9 additions and 7 deletions

View File

@ -5,10 +5,6 @@ import com.alttd.objects.VillagerType;
import com.alttd.util.Logger; import com.alttd.util.Logger;
import com.google.common.collect.Range; import com.google.common.collect.Range;
import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap; import it.unimi.dsi.fastutil.ints.Int2ObjectAVLTreeMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectSortedMaps;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -125,7 +121,7 @@ public final class Config extends AbstractConfig {
public static Int2ObjectAVLTreeMap<Range<Double>> pointsRangeMap = new Int2ObjectAVLTreeMap<>(); public static Int2ObjectAVLTreeMap<Range<Double>> pointsRangeMap = new Int2ObjectAVLTreeMap<>();
private static void loadPointRange() { private static void loadPointRange() {
pointsRangeMap.clear(); pointsRangeMap.clear();
Pattern pattern = Pattern.compile("[1-9][0-9]{0,2}(.[0-9]{1,2})?-[1-9][0-9]{0,2}(.[0-9]{1,2})?"); Pattern pattern = Pattern.compile("(0|([1-9][0-9]{0,2}))(.[0-9]{1,2})?-(0|([1-9][0-9]{0,2}))(.[0-9]{1,2})?");
ConfigurationSection configurationSection = config.getConfigurationSection("points"); ConfigurationSection configurationSection = config.getConfigurationSection("points");
if (configurationSection == null) { if (configurationSection == null) {
@ -154,7 +150,7 @@ public final class Config extends AbstractConfig {
Matcher matcher = pattern.matcher(range); Matcher matcher = pattern.matcher(range);
if (!matcher.matches()) { if (!matcher.matches()) {
Logger.warning("Invalid point value % for % in config " + Logger.warning("Invalid point value % for % in config " +
"should be double - double (0-2.05)", range, key); "should be double-double (0-2.05)", range, key);
continue; continue;
} }
String[] split = range.split("-"); String[] split = range.split("-");

View File

@ -1,5 +1,6 @@
package com.alttd.config; package com.alttd.config;
import com.alttd.VillagerUI;
import com.alttd.objects.Price; import com.alttd.objects.Price;
import com.alttd.util.Logger; import com.alttd.util.Logger;
import com.alttd.util.Utilities; import com.alttd.util.Utilities;
@ -31,10 +32,15 @@ public class WorthConfig extends AbstractConfig {
private static void loadWorth() { //TODO test after removing points private static void loadWorth() { //TODO test after removing points
prices.clear(); prices.clear();
ConfigurationSection worth = config.getConfigurationSection("worth"); ConfigurationSection worth = config.getConfigurationSection("worth");
if (worth == null) {
Logger.severe("No worth in worth.yml! Stopping VillagerUI.");
VillagerUI.getInstance().getServer().getPluginManager().disablePlugin(VillagerUI.getInstance());
return;
}
Set<String> materials = worth.getKeys(false); Set<String> materials = worth.getKeys(false);
for (String key : materials) { for (String key : materials) {
if (key == null) { if (key == null) {
Logger.warning("Invalid key in worth.yml: %.", key); Logger.severe("Null key in worth.yml?");
continue; continue;
} }
prices.put(Material.getMaterial(key), new Price(Utilities.round(worth.getDouble(key), 2))); prices.put(Material.getMaterial(key), new Price(Utilities.round(worth.getDouble(key), 2)));