Added validation to material lists to prevent plugin crashes

This commit is contained in:
Niels Vergucht 2018-12-09 13:42:27 +01:00
parent 38330034f9
commit 9c80f031a2
3 changed files with 13 additions and 8 deletions

View File

@ -77,8 +77,8 @@ public class ConfigManager {
psuedoMaterials = new ArrayList<>();
genbucketGroups = new LinkedHashMap<>();
ignoredMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("IGNORE-MATERIALS"));
psuedoMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("PSUEDO-MATERIALS"));
ignoredMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("IGNORE-MATERIALS"), "IGNORE-MATERIALS");
psuedoMaterials = InventoryHelper.convertMaterialList(epicBuckets.getConfig().getStringList("PSUEDO-MATERIALS"), "PSUEDO-MATERIALS");
supportFactions = epicBuckets.getConfig().getBoolean("FACTIONS-SUPPORT");
supportWorldGuard = epicBuckets.getConfig().getBoolean("WORLDGUARD-SUPPORT");
supportGriefPrevention = epicBuckets.getConfig().getBoolean("GRIEFPREVENTION-SUPPORT");

View File

@ -3,8 +3,6 @@ package com.songoda.epicbuckets.util;
import com.songoda.epicbuckets.EpicBuckets;
import com.songoda.epicbuckets.shop.SubShop;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -14,9 +12,15 @@ import java.util.stream.IntStream;
public class InventoryHelper {
public static List<XMaterial> convertMaterialList(List<String> toConvert) {
public static List<XMaterial> convertMaterialList(List<String> toConvert, String item) {
List<XMaterial> converted = new ArrayList<>();
toConvert.forEach(s -> converted.add(XMaterial.valueOf(s.toUpperCase())));
for (String s : toConvert) {
if (!Validator.isMaterial(s.toUpperCase())) {
EpicBuckets.getInstance().getDebugger().sendConsole("Invalid material " + s.toUpperCase() + " in " + item + ", skipping..");
continue;
}
converted.add(XMaterial.valueOf(s.toUpperCase()));
}
return converted;
}

View File

@ -4,8 +4,9 @@
###############################################
# All file file can be found on
# https://www.spigotmc.org/resources/ezbucket-1-7-1-12-region-support-gui-horizontal-vertical-and-infused-gens-genbucket.50944/
# All default configuration files can be found on
# https://www.spigotmc.org/resources/epicbuckets-the-most-powerful-genbucket-plugin.50944/
# Please use 1.13+ material names, the plugin auto converts them to your server version
FACTIONS-SUPPORT: false # MassiveCore and Factions/FactionsUUID/SavageFactions is needed