Search in sources :

Example 1 with SlotPos

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

the class ShipColorMenu method init.

@Override
public void init() {
    user = service.get(player);
    int row = 1;
    int col = 1;
    addCloseItem();
    for (ColorType colorType : ColorType.values()) {
        if (colorType.getDyeColor() == null)
            continue;
        Material concrete = colorType.getConcrete();
        if (concrete != null) {
            ItemStack color = new ItemBuilder(concrete).name(StringUtils.camelCase(colorType.name())).build();
            contents.set(new SlotPos(row, col), ClickableItem.of(color, e -> {
                user.setShipColor(colorType.getBukkitColor());
                service.save(user);
                e.getPlayer().closeInventory();
                ClientsideBlocks.update(player);
            }));
            if (++col == 8) {
                col = 1;
                ++row;
            }
        }
    }
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) AeveonProjectUser(gg.projecteden.nexus.models.aeveonproject.AeveonProjectUser) StringUtils(gg.projecteden.nexus.utils.StringUtils) AeveonProjectService(gg.projecteden.nexus.models.aeveonproject.AeveonProjectService) ClientsideBlocks(gg.projecteden.nexus.features.events.aeveonproject.effects.ClientsideBlocks) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) ColorType(gg.projecteden.nexus.utils.ColorType) ItemStack(org.bukkit.inventory.ItemStack) Rows(gg.projecteden.nexus.features.menus.api.annotations.Rows) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) InventoryProvider(gg.projecteden.nexus.features.menus.api.content.InventoryProvider) Material(org.bukkit.Material) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) ColorType(gg.projecteden.nexus.utils.ColorType) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 2 with SlotPos

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

the class SwipeCardTask method init.

@Override
public void init() {
    Runnable reset = () -> {
        player.setItemOnCursor(null);
        init();
    };
    SlotPos cardPos = SlotPos.of(1, 1);
    contents.fill(ClickableItem.empty(new ItemBuilder(Material.BLACK_STAINED_GLASS_PANE).name(" ").build()));
    AtomicReference<LocalDateTime> time = new AtomicReference<>();
    contents.set(cardPos, ClickableItem.of(KEY_CARD.get(), click -> {
        if (!click.isLeftClick() || !KEY_CARD.get().isSimilar(click.getItem()) || !(click.getPlayer().getItemOnCursor().getType() == Material.AIR || click.getPlayer().getItemOnCursor().isSimilar(KEY_CARD.get()))) {
            reset.run();
        } else {
            time.set(LocalDateTime.now());
            ClickableItem item = contents.get(cardPos).orElse(null);
            if (item != null)
                contents.set(cardPos, item.clone(new ItemBuilder(Material.LIGHT_GRAY_STAINED_GLASS_PANE).name(" ").build()));
            click.getPlayer().setItemOnCursor(KEY_CARD.get());
        }
    }));
    SlotPos destination = SlotPos.of(1, 7);
    contents.set(destination, ClickableItem.of(new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE).name(" ").build(), click -> {
        if (time.get() == null || !KEY_CARD.get().isSimilar(click.getPlayer().getItemOnCursor())) {
            reset.run();
            return;
        }
        Duration duration = Duration.between(time.get(), LocalDateTime.now());
        double sec = duration.getSeconds() + (duration.getNano() / 1000000000d);
        if (!(sec >= .9d && sec <= 1.2d)) {
            reset.run();
            String fmt = sec < .9d ? "fast" : "slow";
            contents.set(destination, contents.get(destination).get().clone(new ItemBuilder(Material.RED_STAINED_GLASS_PANE).name("Too " + fmt + ", try again").build()));
            new SoundBuilder(Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO).receiver(player).category(SoundCategory.MASTER).volume(2f).play();
        } else {
            getTask().partCompleted(PlayerManager.get(player));
            close();
        }
    }));
}
Also used : LocalDateTime(java.time.LocalDateTime) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) SoundCategory(org.bukkit.SoundCategory) PlayerManager(gg.projecteden.nexus.features.minigames.managers.PlayerManager) Task(gg.projecteden.nexus.features.minigames.models.mechanics.custom.sabotage.Task) LocalDateTime(java.time.LocalDateTime) Sound(org.bukkit.Sound) AtomicReference(java.util.concurrent.atomic.AtomicReference) Supplier(java.util.function.Supplier) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) SoundBuilder(gg.projecteden.nexus.utils.SoundBuilder) ItemStack(org.bukkit.inventory.ItemStack) Rows(gg.projecteden.nexus.features.menus.api.annotations.Rows) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) Title(gg.projecteden.nexus.features.menus.api.annotations.Title) Duration(java.time.Duration) Material(org.bukkit.Material) SoundBuilder(gg.projecteden.nexus.utils.SoundBuilder) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) ClickableItem(gg.projecteden.nexus.features.menus.api.ClickableItem) AtomicReference(java.util.concurrent.atomic.AtomicReference) Duration(java.time.Duration)

Example 3 with SlotPos

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

the class AdventMenu method loadHeads.

public static void loadHeads() {
    // Specific Heads
    origin.getRelative(0, 0, 2).getDrops().stream().findFirst().ifPresent(skull -> lockedHead = new ItemBuilder(skull));
    origin.getRelative(0, 0, 3).getDrops().stream().findFirst().ifPresent(skull -> missedHead = new ItemBuilder(skull));
    origin.getRelative(0, 0, 4).getDrops().stream().findFirst().ifPresent(skull -> toFindHead = new ItemBuilder(skull));
    // Advent menu
    String[] days = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturaday" };
    for (int z = 0; z <= 4; z++) {
        // 0-4 col
        for (int x = 1; x <= 7; x++) {
            // 1-7 row
            Block block = origin.getRelative(x, 0, z);
            if (!isNullOrAir(block)) {
                ItemStack drop = block.getDrops().stream().findFirst().orElse(null);
                if (!isNullOrAir(drop)) {
                    ItemBuilder skull = new ItemBuilder(drop);
                    int size = adventHeadMap.size();
                    if (size <= 6)
                        skull.name(days[size]);
                    adventHeadMap.put(new SlotPos(z, x), skull);
                }
            }
        }
    }
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) SlotPos(gg.projecteden.nexus.features.menus.api.content.SlotPos) Block(org.bukkit.block.Block) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

SlotPos (gg.projecteden.nexus.features.menus.api.content.SlotPos)3 ItemBuilder (gg.projecteden.nexus.utils.ItemBuilder)3 ItemStack (org.bukkit.inventory.ItemStack)3 ClickableItem (gg.projecteden.nexus.features.menus.api.ClickableItem)2 Rows (gg.projecteden.nexus.features.menus.api.annotations.Rows)2 Title (gg.projecteden.nexus.features.menus.api.annotations.Title)2 Material (org.bukkit.Material)2 ClientsideBlocks (gg.projecteden.nexus.features.events.aeveonproject.effects.ClientsideBlocks)1 InventoryProvider (gg.projecteden.nexus.features.menus.api.content.InventoryProvider)1 PlayerManager (gg.projecteden.nexus.features.minigames.managers.PlayerManager)1 Task (gg.projecteden.nexus.features.minigames.models.mechanics.custom.sabotage.Task)1 AeveonProjectService (gg.projecteden.nexus.models.aeveonproject.AeveonProjectService)1 AeveonProjectUser (gg.projecteden.nexus.models.aeveonproject.AeveonProjectUser)1 ColorType (gg.projecteden.nexus.utils.ColorType)1 SoundBuilder (gg.projecteden.nexus.utils.SoundBuilder)1 StringUtils (gg.projecteden.nexus.utils.StringUtils)1 Duration (java.time.Duration)1 LocalDateTime (java.time.LocalDateTime)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Supplier (java.util.function.Supplier)1