Added lightness and darkness elemental stats to default config files

This commit is contained in:
Indyuce 2022-03-06 16:24:57 +01:00
parent 677cdae3ba
commit ab5926206d
3 changed files with 47 additions and 40 deletions

View File

@ -1,12 +1,10 @@
package net.Indyuce.mmoitems.manager;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.Type;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.io.File;
import java.util.Collection;
import java.util.HashMap;
@ -15,48 +13,49 @@ import java.util.Map;
import java.util.logging.Level;
public class LoreFormatManager implements Reloadable {
private final Map<String, List<String>> formats = new HashMap<>();
private final Map<String, List<String>> formats = new HashMap<>();
public void reload() {
formats.clear();
File dir = new File(MMOItems.plugin.getDataFolder() + "/language/lore-formats");
for (File file : dir.listFiles())
try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
Validate.isTrue(config.isList("lore-format"), "Invalid lore-format! (" + file.getName() + ")");
formats.put(file.getName().substring(0, file.getName().length() - 4), config.getStringList("lore-format"));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load layout '" + file.getName() + "': " + exception.getMessage());
}
}
public void reload() {
formats.clear();
File dir = new File(MMOItems.plugin.getDataFolder() + "/language/lore-formats");
for (File file : dir.listFiles())
try {
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
Validate.isTrue(config.isList("lore-format"), "Invalid lore-format! (" + file.getName() + ")");
formats.put(file.getName().substring(0, file.getName().length() - 4), config.getStringList("lore-format"));
} catch (IllegalArgumentException exception) {
MMOItems.plugin.getLogger().log(Level.WARNING, "Could not load layout '" + file.getName() + "': " + exception.getMessage());
}
}
public boolean hasFormat(@Nullable String id) {
if (id == null) { return false; }
return formats.containsKey(id);
}
public boolean hasFormat(@NotNull String id) {
return formats.containsKey(id);
}
public Collection<List<String>> getFormats() {
return formats.values();
}
public Collection<List<String>> getFormats() {
return formats.values();
}
/**
* Find a lore format file by specifying its name
*
* @param prioritizedFormatNames The names of the formats to search.
*
* @return The lore format first found from the ones specified, or the default one.
*/
@NotNull public List<String> getFormat(@NotNull String... prioritizedFormatNames) {
/**
* Find a lore format file by specifying its name
*
* @param prioritizedFormatNames The names of the formats to search.
* @return The lore format first found from the ones specified, or the default one.
*/
@NotNull
public List<String> getFormat(@NotNull String... prioritizedFormatNames) {
/*
* Check each specified lore format in order, the first one
* to succeed will be the winner.
*/
for (String format : prioritizedFormatNames) {
if (hasFormat(format)) { return formats.get(format); }
}
/*
* Check each specified lore format in order, the first one
* to succeed will be the winner.
*/
for (String format : prioritizedFormatNames) {
List<String> found = formats.get(format);
if (found != null)
return found;
}
// No lore format found / specified. Go with default.
return MMOItems.plugin.getLanguage().getDefaultLoreFormat();
}
// No lore format found / specified. Go with default.
return MMOItems.plugin.getLanguage().getDefaultLoreFormat();
}
}

View File

@ -126,6 +126,10 @@ lore-format:
- '#thunder-defense#'
- '#water-damage#'
- '#water-defense#'
- '#darkness-damage#'
- '#darkness-defense#'
- '#lightness-damage#'
- '#lightness-defense#'
# - '{bar}&8&m--------&b&l &nEffects&8 &m---------------'
- '{bar}'
- '#effects#'

View File

@ -141,6 +141,8 @@ earth-damage: '&2 ❖ #% Earth Damage'
wind-damage: '&3 &7❖ #% Wind Damage'
thunder-damage: '&e ❖ #% Thunder Damage'
water-damage: '&3 ❖ #% Water Damage'
darkness-damage: '&8 ❖ #% Darkness Damage'
lightness-damage: '&f ❖ #% Light Damage'
# Elemental Defense
fire-defense: '&c ❖ #% Fire Defense'
@ -149,3 +151,5 @@ earth-defense: '&2 ❖ #% Earth Defense'
wind-defense: '&3 &7❖ #% Wind Defense'
thunder-defense: '&e ❖ #% Thunder Defense'
water-defense: '&3 ❖ #% Water Defense'
darkness-defense: '&8 ❖ #% Darkness Defense'
lightness-defense: '&f ❖ #% Light Defense'