Search in sources :

Example 41 with CustomItemStack

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

the class TestItemSettings method testAlreadyExistingItemSetting.

@Test
@DisplayName("Test Item Settings double-registration")
void testAlreadyExistingItemSetting() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_SETTINGS_TEST", new CustomItemStack(Material.DIAMOND, "&cTest"));
    ItemSetting<String> setting = new ItemSetting<>(item, "test", "Hello World");
    item.addItemSetting(setting);
    Assertions.assertThrows(IllegalArgumentException.class, () -> item.addItemSetting(setting));
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemSetting(io.github.thebusybiscuit.slimefun4.api.items.ItemSetting) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 42 with CustomItemStack

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

the class TestMaterialTagSetting method testAllowedValue.

@Test
@DisplayName("Test allowed value")
void testAllowedValue() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "MATERIAL_SETTING_TEST_2", new CustomItemStack(Material.DIAMOND, "&cTest"));
    MaterialTagSetting setting = new MaterialTagSetting(item, "test", tag);
    item.addItemSetting(setting);
    item.register(plugin);
    List<String> tagContents = tag.getValues().stream().map(Material::name).collect(Collectors.toList());
    Assertions.assertTrue(new HashSet<>(tagContents).equals(new HashSet<>(setting.getValue())));
    List<String> materials = Arrays.asList(Material.REDSTONE.name(), Material.DIAMOND.name());
    setting.update(materials);
    Assertions.assertIterableEquals(materials, setting.getValue());
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 43 with CustomItemStack

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

the class TestDoubleRangeSetting method testConstructorValidation.

@Test
@DisplayName("Test Constructor validation")
void testConstructorValidation() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "DOUBLE_RANGE_TEST_00", new CustomItemStack(Material.DIAMOND, "&cTest"));
    Assertions.assertThrows(IllegalArgumentException.class, () -> new DoubleRangeSetting(item, "test", min, -1.0, max));
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 44 with CustomItemStack

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

the class TestDoubleRangeSetting method testAllowedValue.

@Test
@DisplayName("Test allowed value")
void testAllowedValue() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "DOUBLE_RANGE_TEST_2", new CustomItemStack(Material.DIAMOND, "&cTest"));
    DoubleRangeSetting setting = new DoubleRangeSetting(item, "test", min, 0.25, max);
    item.addItemSetting(setting);
    item.register(plugin);
    Assertions.assertEquals(0.25, setting.getValue());
    setting.update(0.75);
    Assertions.assertEquals(0.75, setting.getValue());
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 45 with CustomItemStack

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

the class HologramProjector method openEditor.

private static void openEditor(@Nonnull Player p, @Nonnull Block projector) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "machines.HOLOGRAM_PROJECTOR.inventory-title"));
    menu.addItem(0, new CustomItemStack(Material.NAME_TAG, "&7Text &e(Click to edit)", "", "&r" + ChatColors.color(BlockStorage.getLocationInfo(projector.getLocation(), "text"))));
    menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
        pl.closeInventory();
        Slimefun.getLocalization().sendMessage(pl, "machines.HOLOGRAM_PROJECTOR.enter-text", true);
        ChatUtils.awaitInput(pl, message -> {
            ArmorStand hologram = getArmorStand(projector, true);
            hologram.setCustomName(ChatColors.color(message));
            BlockStorage.addBlockInfo(projector, "text", hologram.getCustomName());
            openEditor(pl, projector);
        });
        return false;
    });
    menu.addItem(1, new CustomItemStack(Material.CLOCK, "&7Offset: &e" + NumberUtils.roundDecimalNumber(Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)) + 1.0D), "", "&rLeft Click: &7+0.1", "&rRight Click: &7-0.1"));
    menu.addMenuClickHandler(1, (pl, slot, item, action) -> {
        double offset = NumberUtils.reparseDouble(Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)) + (action.isRightClicked() ? -0.1F : 0.1F));
        ArmorStand hologram = getArmorStand(projector, true);
        Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
        hologram.teleport(l);
        BlockStorage.addBlockInfo(projector, OFFSET_PARAMETER, String.valueOf(offset));
        openEditor(pl, projector);
        return false;
    });
    menu.open(p);
}
Also used : ArmorStand(org.bukkit.entity.ArmorStand) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) Location(org.bukkit.Location)

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