Search in sources :

Example 1 with InventoryProvider

use of gg.projecteden.nexus.features.menus.api.content.InventoryProvider in project Nexus by ProjectEdenGG.

the class MechanicsMenu method openCustomSettingsMenu.

@SneakyThrows
public static void openCustomSettingsMenu(Player player, Arena arena) {
    Class<? extends InventoryProvider> provider = null;
    customMenus: for (Class<? extends InventoryProvider> menu : new Reflections(ICustomMechanicMenu.class.getPackageName()).getSubTypesOf(InventoryProvider.class)) {
        for (Class<? extends Mechanic> superclass : arena.getMechanic().getSuperclasses()) {
            if (menu.getAnnotation(CustomMechanicSettings.class) != null) {
                List<Class<? extends Mechanic>> classes = Arrays.asList(menu.getAnnotation(CustomMechanicSettings.class).value());
                if (classes.contains(superclass)) {
                    provider = menu;
                    break customMenus;
                }
            }
        }
    }
    if (provider == null) {
        player.playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, 1, 1);
        return;
    }
    final InventoryProvider menu = provider.getDeclaredConstructor(Arena.class).newInstance(arena);
    arena.write();
    menu.open(player);
}
Also used : Mechanic(gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic) ICustomMechanicMenu(gg.projecteden.nexus.features.minigames.menus.custom.ICustomMechanicMenu) CustomMechanicSettings(gg.projecteden.nexus.features.minigames.menus.annotations.CustomMechanicSettings) List(java.util.List) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Reflections(org.reflections.Reflections) SneakyThrows(lombok.SneakyThrows)

Aggregations

InventoryProvider (gg.projecteden.nexus.features.menus.api.content.InventoryProvider)1 CustomMechanicSettings (gg.projecteden.nexus.features.minigames.menus.annotations.CustomMechanicSettings)1 ICustomMechanicMenu (gg.projecteden.nexus.features.minigames.menus.custom.ICustomMechanicMenu)1 Arena (gg.projecteden.nexus.features.minigames.models.Arena)1 Mechanic (gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic)1 List (java.util.List)1 SneakyThrows (lombok.SneakyThrows)1 Reflections (org.reflections.Reflections)1