mirror of
https://github.com/GeorgH93/Minepacks.git
synced 2024-12-04 14:03:24 +01:00
Improve item config loader
This commit is contained in:
parent
e4823ff592
commit
8a8c1be3ae
@ -31,6 +31,7 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BackpacksConfig extends Configuration
|
||||
{
|
||||
@ -40,7 +41,7 @@ public class BackpacksConfig extends Configuration
|
||||
public BackpacksConfig(final @NotNull JavaPlugin plugin)
|
||||
{
|
||||
super(plugin, CONFIG_VERSION, CONFIG_VERSION, "backpacks.yml");
|
||||
loadItemConfigs();
|
||||
loadItemConfigs("Items");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -60,9 +61,9 @@ protected void doUpgrade(@NotNull YamlFileManager oldConfig)
|
||||
doUpgrade(oldConfig, new HashMap<>(), getYamlE().getKeysFiltered("Items\\..*"));
|
||||
}
|
||||
|
||||
private void loadItemConfigs()
|
||||
private void loadItemConfigs(final @NotNull String parentKey)
|
||||
{
|
||||
getYamlE().getKeysFiltered("Items\\.[^.]*\\.Material").forEach(materialKey -> {
|
||||
getYamlE().getKeysFiltered(parentKey + "\\.[^.]*\\.Material").forEach(materialKey -> {
|
||||
final String key = materialKey.substring(0, materialKey.length() - ".Material".length());
|
||||
try
|
||||
{
|
||||
@ -79,7 +80,7 @@ private void loadItemConfigs()
|
||||
final String material = getYamlE().getString(key + ".Material");
|
||||
final int model = getYamlE().getInt(key + ".Model");
|
||||
final int amount = getYamlE().getInt(key + ".Amount", 1);
|
||||
itemConfigs.put(key, new ItemConfig(key.substring("Items.".length()), material, amount, displayName, loreFinal, model, getConfigE().getString(key + ".HeadValue", null)));
|
||||
itemConfigs.put(key, new ItemConfig(key.substring(parentKey.length() + 1), material, amount, displayName, loreFinal, model, getConfigE().getString(key + ".HeadValue", null)));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@ -92,4 +93,9 @@ private void loadItemConfigs()
|
||||
{
|
||||
return itemConfigs.get(name);
|
||||
}
|
||||
|
||||
public @NotNull List<ItemConfig> getBackpackItems()
|
||||
{
|
||||
return itemConfigs.entrySet().stream().filter(entry -> entry.getKey().startsWith("Items.")).map(Map.Entry::getValue).collect(Collectors.toList());
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@
|
||||
@Getter
|
||||
public final class ItemConfig
|
||||
{
|
||||
private final @Nullable String name;
|
||||
private final @NotNull String name;
|
||||
private final @NotNull Material material;
|
||||
private final @NotNull String displayName;
|
||||
private final @Nullable List<String> lore;
|
||||
@ -41,7 +41,7 @@ public final class ItemConfig
|
||||
private final @Nullable String value;
|
||||
private final @NotNull IItemProducer producer;
|
||||
|
||||
public ItemConfig(final @Nullable String name, final @NotNull String material, final int amount, final @NotNull String displayName, final @Nullable List<String> lore, int model, final @Nullable String value) throws IllegalArgumentException
|
||||
public ItemConfig(final @NotNull String name, final @NotNull String material, final int amount, final @NotNull String displayName, final @Nullable List<String> lore, int model, final @Nullable String value) throws IllegalArgumentException
|
||||
{
|
||||
assert model < 0;
|
||||
this.name = name;
|
||||
|
Loading…
Reference in New Issue
Block a user