Search in sources :

Example 1 with SlimefunGuideImplementation

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation in project Slimefun4 by Slimefun.

the class TestGuideOpening method prepare.

@ParametersAreNonnullByDefault
@Nonnull
private PlayerProfile prepare(SlimefunGuideImplementation guide, Consumer<GuideHistory> consumer) throws InterruptedException {
    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    GuideHistory history = profile.getGuideHistory();
    consumer.accept(history);
    history.openLastEntry(guide);
    return profile;
}
Also used : Player(org.bukkit.entity.Player) PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) Nonnull(javax.annotation.Nonnull) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 2 with SlimefunGuideImplementation

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation in project Slimefun4 by Slimefun.

the class TestGuideOpening method testOpenMainMenu.

@Test
@DisplayName("Test if the Slimefun Guide Main Menu can be opened from the History")
void testOpenMainMenu() throws InterruptedException {
    SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class);
    PlayerProfile profile = prepare(guide, history -> {
    });
    Mockito.verify(guide).openMainMenu(profile, 1);
}
Also used : PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with SlimefunGuideImplementation

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation in project Slimefun4 by Slimefun.

the class TestGuideOpening method testOpenSearch.

@Test
@DisplayName("Test if the Slimefun Search can be opened from the History")
void testOpenSearch() throws InterruptedException {
    String query = "electric";
    SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class);
    PlayerProfile profile = prepare(guide, history -> history.add(query));
    Mockito.verify(guide).openSearch(profile, query, false);
}
Also used : PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with SlimefunGuideImplementation

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation in project Slimefun4 by Slimefun.

the class TestGuideOpening method testOpenItemStack.

@Test
@DisplayName("Test if an ItemStack can be viewed from the History")
void testOpenItemStack() throws InterruptedException {
    ItemStack item = new ItemStack(Material.REDSTONE_BLOCK);
    SlimefunGuideImplementation guide = Mockito.mock(SlimefunGuideImplementation.class);
    PlayerProfile profile = prepare(guide, history -> history.add(item, 1));
    Mockito.verify(guide).displayItem(profile, item, 1, false);
}
Also used : PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with SlimefunGuideImplementation

use of io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation in project Slimefun4 by Slimefun.

the class Research method unlockFromGuide.

/**
 * Handle what to do when a {@link Player} clicks on an un-researched item in
 * a {@link SlimefunGuideImplementation}.
 *
 * @param guide
 *            The {@link SlimefunGuideImplementation} used.
 * @param player
 *            The {@link Player} who clicked on the item.
 * @param profile
 *            The {@link PlayerProfile} of that {@link Player}.
 * @param sfItem
 *            The {@link SlimefunItem} on which the {@link Player} clicked.
 * @param itemGroup
 *            The {@link ItemGroup} where the {@link Player} was.
 * @param page
 *            The page number of where the {@link Player} was in the {@link ItemGroup};
 */
@ParametersAreNonnullByDefault
public void unlockFromGuide(SlimefunGuideImplementation guide, Player player, PlayerProfile profile, SlimefunItem sfItem, ItemGroup itemGroup, int page) {
    if (!Slimefun.getRegistry().getCurrentlyResearchingPlayers().contains(player.getUniqueId())) {
        if (profile.hasUnlocked(this)) {
            guide.openItemGroup(profile, itemGroup, page);
        } else {
            PlayerPreResearchEvent event = new PlayerPreResearchEvent(player, this, sfItem);
            Bukkit.getPluginManager().callEvent(event);
            if (!event.isCancelled()) {
                if (this.canUnlock(player)) {
                    guide.unlockItem(player, sfItem, pl -> guide.openItemGroup(profile, itemGroup, page));
                } else {
                    Slimefun.getLocalization().sendMessage(player, "messages.not-enough-xp", true);
                }
            }
        }
    }
}
Also used : PlayerPreResearchEvent(io.github.thebusybiscuit.slimefun4.api.events.PlayerPreResearchEvent) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Aggregations

PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)9 DisplayName (org.junit.jupiter.api.DisplayName)7 Test (org.junit.jupiter.api.Test)7 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)4 Player (org.bukkit.entity.Player)3 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)2 SlimefunGuideImplementation (io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideImplementation)2 Nonnull (javax.annotation.Nonnull)2 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)2 NamespacedKey (org.bukkit.NamespacedKey)2 PlayerPreResearchEvent (io.github.thebusybiscuit.slimefun4.api.events.PlayerPreResearchEvent)1 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)1 Research (io.github.thebusybiscuit.slimefun4.api.researches.Research)1 ItemStack (org.bukkit.inventory.ItemStack)1