2019-01-27 16:22:05 +01:00
|
|
|
package com.songoda.epicenchants.menus;
|
|
|
|
|
|
|
|
import com.songoda.epicenchants.EpicEnchants;
|
|
|
|
import com.songoda.epicenchants.objects.Group;
|
2019-02-19 14:23:20 +01:00
|
|
|
import com.songoda.epicenchants.utils.objects.FastInv;
|
|
|
|
import com.songoda.epicenchants.utils.objects.ItemBuilder;
|
2019-01-27 16:22:05 +01:00
|
|
|
import org.bukkit.configuration.file.FileConfiguration;
|
2019-04-03 15:58:13 +02:00
|
|
|
import org.bukkit.event.Listener;
|
2019-01-27 16:22:05 +01:00
|
|
|
|
2021-07-10 23:41:20 +02:00
|
|
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.color;
|
|
|
|
import static com.songoda.epicenchants.utils.single.GeneralUtils.getSlots;
|
2019-01-27 16:22:05 +01:00
|
|
|
|
2019-04-03 15:58:13 +02:00
|
|
|
public class MainInfoMenu extends FastInv implements Listener {
|
2019-01-27 16:22:05 +01:00
|
|
|
|
|
|
|
public MainInfoMenu(EpicEnchants instance, FileConfiguration config) {
|
2019-03-19 14:13:27 +01:00
|
|
|
super(config.getInt("rows") * 9, color(config.getString("title")));
|
2019-01-27 16:22:05 +01:00
|
|
|
config.getConfigurationSection("contents").getKeys(false)
|
|
|
|
.stream()
|
|
|
|
.map(s -> "contents." + s)
|
|
|
|
.map(config::getConfigurationSection)
|
2019-08-07 23:13:07 +02:00
|
|
|
.forEach(section -> addItem(getSlots(section.getString("slot")), new ItemBuilder(section).build(), event -> {
|
2019-08-08 01:47:56 +02:00
|
|
|
if (section.getString("group") == null) return;
|
2019-04-04 14:40:11 +02:00
|
|
|
Group group = instance.getGroupManager().getValue(section.getString("group"))
|
|
|
|
.orElseThrow(() -> new IllegalArgumentException("Invalid group: " + section.getString("group")));
|
|
|
|
instance.getInfoManager().getMenu(group).ifPresent(menu -> menu.open(event.getPlayer()));
|
|
|
|
}));
|
2019-01-27 16:22:05 +01:00
|
|
|
}
|
|
|
|
}
|