Search in sources :

Example 26 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestPermissionsService method testHasPermissionFalse.

@Test
@DisplayName("Test Players without permissions being denied access")
void testHasPermissionFalse() {
    PermissionsService service = new PermissionsService(plugin);
    Player player = server.addPlayer();
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItemStack(Material.EMERALD, "&bBad omen"));
    service.setPermission(item, "slimefun.tests");
    Assertions.assertFalse(service.hasPermission(player, item));
}
Also used : Player(org.bukkit.entity.Player) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 27 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestPermissionsService method testDefaultPermission.

@ParameterizedTest
@DisplayName("Test if no permission is set by default")
@ValueSource(booleans = { false, true })
void testDefaultPermission(boolean registered) {
    PermissionsService service = new PermissionsService(plugin);
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItemStack(Material.EMERALD, "&bBad omen"));
    if (registered) {
        service.register(Arrays.asList(item), false);
    }
    Optional<String> permission = service.getPermission(item);
    Assertions.assertFalse(permission.isPresent());
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 28 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestPermissionsService method testHasPermissionTrue.

@Test
@DisplayName("Test if the Player will pass the permissions check if no permission was set")
void testHasPermissionTrue() {
    PermissionsService service = new PermissionsService(plugin);
    Player player = server.addPlayer();
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PERMISSIONS_TEST", new CustomItemStack(Material.EMERALD, "&bBad omen"));
    Assertions.assertTrue(service.hasPermission(player, null));
    Assertions.assertTrue(service.hasPermission(player, item));
    service.setPermission(item, "none");
    Assertions.assertTrue(service.hasPermission(player, item));
}
Also used : Player(org.bukkit.entity.Player) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 29 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestGuideHistory method testSlimefunItem.

@Test
@DisplayName("Test adding a SlimefunItem to Guide History")
void testSlimefunItem() throws InterruptedException {
    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    GuideHistory history = profile.getGuideHistory();
    Assertions.assertThrows(IllegalArgumentException.class, () -> history.add((SlimefunItem) null));
    Assertions.assertEquals(0, history.size());
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "HISTORIC_ITEM", new CustomItemStack(Material.DIORITE, "&4I am really running out of ideas for item names"));
    history.add(item);
    Assertions.assertEquals(1, history.size());
}
Also used : Player(org.bukkit.entity.Player) PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) GuideHistory(io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 30 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestGuideHistory method testItemGroup.

@Test
@DisplayName("Test adding an ItemGroup to Guide History")
void testItemGroup() throws InterruptedException {
    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    GuideHistory history = profile.getGuideHistory();
    ItemGroup itemGroup = new ItemGroup(new NamespacedKey(plugin, "itemgroup_guide_history"), new CustomItemStack(Material.BEDROCK, "&4Can't touch this"));
    Assertions.assertThrows(IllegalArgumentException.class, () -> history.add((ItemGroup) null, 1));
    Assertions.assertThrows(IllegalArgumentException.class, () -> history.add(itemGroup, -20));
    Assertions.assertEquals(0, history.size());
    history.add(itemGroup, 1);
    Assertions.assertEquals(1, history.size());
    // This should not add a new entry but rather only update the page
    history.add(itemGroup, 2);
    Assertions.assertEquals(1, history.size());
}
Also used : Player(org.bukkit.entity.Player) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) PlayerProfile(io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile) NamespacedKey(org.bukkit.NamespacedKey) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) GuideHistory(io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)172 Test (org.junit.jupiter.api.Test)100 DisplayName (org.junit.jupiter.api.DisplayName)90 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)83 ItemStack (org.bukkit.inventory.ItemStack)70 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)43 NamespacedKey (org.bukkit.NamespacedKey)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Player (org.bukkit.entity.Player)25 ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)22 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)20 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)18 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)12 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)11 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)10 ArrayList (java.util.ArrayList)10 Nonnull (javax.annotation.Nonnull)10 Material (org.bukkit.Material)10 LockedItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup)9 Location (org.bukkit.Location)9