2018-10-05 06:48:44 +02:00
|
|
|
package bentobox.addon.limits;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
2019-11-08 21:35:47 +01:00
|
|
|
import java.util.EnumMap;
|
2019-02-07 08:20:45 +01:00
|
|
|
import java.util.List;
|
2018-10-05 06:48:44 +02:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
|
2019-04-23 00:50:15 +02:00
|
|
|
import bentobox.addon.limits.commands.LimitPanel;
|
|
|
|
|
2018-10-05 06:48:44 +02:00
|
|
|
public class Settings {
|
|
|
|
|
2019-11-08 21:35:47 +01:00
|
|
|
private final Map<EntityType, Integer> limits = new EnumMap<>(EntityType.class);
|
2019-02-09 19:30:02 +01:00
|
|
|
private final List<String> gameModes;
|
2018-10-05 06:48:44 +02:00
|
|
|
|
|
|
|
public Settings(Limits addon) {
|
2019-02-07 08:20:45 +01:00
|
|
|
|
|
|
|
// GameModes
|
2019-02-09 07:35:29 +01:00
|
|
|
gameModes = addon.getConfig().getStringList("gamemodes");
|
2019-02-07 08:20:45 +01:00
|
|
|
|
2018-10-05 06:48:44 +02:00
|
|
|
ConfigurationSection el = addon.getConfig().getConfigurationSection("entitylimits");
|
|
|
|
if (el != null) {
|
|
|
|
for (String key : el.getKeys(false)) {
|
|
|
|
EntityType type = getType(key);
|
|
|
|
if (type != null) {
|
2019-06-23 08:41:30 +02:00
|
|
|
if (!type.equals(EntityType.PAINTING) &&
|
|
|
|
!type.equals(EntityType.ITEM_FRAME) &&
|
|
|
|
(!type.isSpawnable() || (LimitPanel.E2M.containsKey(type) && LimitPanel.E2M.get(type) == null))) {
|
2019-04-23 00:50:15 +02:00
|
|
|
addon.logError("Entity type: " + key + " is not supported - skipping...");
|
|
|
|
} else {
|
|
|
|
limits.put(type, el.getInt(key, 0));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addon.logError("Unknown entity type: " + key + " - skipping...");
|
2018-10-05 06:48:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-23 00:50:15 +02:00
|
|
|
addon.log("Entity limits:");
|
|
|
|
limits.entrySet().stream().map(e -> "Limit " + e.getKey().toString() + " to " + e.getValue()).forEach(addon::log);
|
2018-10-05 06:48:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private EntityType getType(String key) {
|
|
|
|
return Arrays.stream(EntityType.values()).filter(v -> v.name().equalsIgnoreCase(key)).findFirst().orElse(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the limits
|
|
|
|
*/
|
|
|
|
public Map<EntityType, Integer> getLimits() {
|
|
|
|
return limits;
|
|
|
|
}
|
|
|
|
|
2019-02-07 08:20:45 +01:00
|
|
|
/**
|
|
|
|
* @return the gameModes
|
|
|
|
*/
|
|
|
|
public List<String> getGameModes() {
|
|
|
|
return gameModes;
|
|
|
|
}
|
|
|
|
|
2018-10-05 06:48:44 +02:00
|
|
|
}
|