Search in sources :

Example 1 with LockedItemGroup

use of io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup in project Slimefun4 by Slimefun.

the class SurvivalSlimefunGuide method showItemGroup.

private void showItemGroup(ChestMenu menu, Player p, PlayerProfile profile, ItemGroup group, int index) {
    if (!(group instanceof LockedItemGroup) || !isSurvivalMode() || ((LockedItemGroup) group).hasUnlocked(p, profile)) {
        menu.addItem(index, group.getItem(p));
        menu.addMenuClickHandler(index, (pl, slot, item, action) -> {
            openItemGroup(profile, group, 1);
            return false;
        });
    } else {
        List<String> lore = new ArrayList<>();
        lore.add("");
        for (String line : Slimefun.getLocalization().getMessages(p, "guide.locked-itemgroup")) {
            lore.add(ChatColor.WHITE + line);
        }
        lore.add("");
        for (ItemGroup parent : ((LockedItemGroup) group).getParents()) {
            lore.add(parent.getItem(p).getItemMeta().getDisplayName());
        }
        menu.addItem(index, new CustomItemStack(Material.BARRIER, "&4" + Slimefun.getLocalization().getMessage(p, "guide.locked") + " &7- &f" + group.getItem(p).getItemMeta().getDisplayName(), lore.toArray(new String[0])));
        menu.addMenuClickHandler(index, ChestMenuUtils.getEmptyClickHandler());
    }
}
Also used : LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) FlexItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup) SubItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup) ArrayList(java.util.ArrayList) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack)

Example 2 with LockedItemGroup

use of io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup in project Slimefun4 by Slimefun.

the class TestItemGroups method testLockedItemGroupsParents.

@Test
@DisplayName("Test LockedItemGroup parental locking")
void testLockedItemGroupsParents() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedItemGroup(new NamespacedKey(plugin, "locked"), new CustomItemStack(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null));
    ItemGroup group = new ItemGroup(new NamespacedKey(plugin, "unlocked"), new CustomItemStack(Material.EMERALD, "&5I am SHERlocked"));
    group.register(plugin);
    ItemGroup unregistered = new ItemGroup(new NamespacedKey(plugin, "unregistered"), new CustomItemStack(Material.EMERALD, "&5I am unregistered"));
    LockedItemGroup locked = new LockedItemGroup(new NamespacedKey(plugin, "locked"), new CustomItemStack(Material.GOLD_NUGGET, "&6Locked Test"), group.getKey(), unregistered.getKey());
    locked.register(plugin);
    Assertions.assertTrue(locked.getParents().contains(group));
    Assertions.assertFalse(locked.getParents().contains(unregistered));
    locked.removeParent(group);
    Assertions.assertFalse(locked.getParents().contains(group));
    Assertions.assertThrows(IllegalArgumentException.class, () -> locked.addParent(locked));
    Assertions.assertThrows(IllegalArgumentException.class, () -> locked.addParent(null));
    locked.addParent(group);
    Assertions.assertTrue(locked.getParents().contains(group));
}
Also used : LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) SeasonalItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.SeasonalItemGroup) FlexItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) NamespacedKey(org.bukkit.NamespacedKey) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with LockedItemGroup

use of io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup in project Slimefun4 by Slimefun.

the class TestItemGroups method testLockedItemGroupsUnlocking.

@Test
@DisplayName("Test an unlocked LockedItemGroup")
void testLockedItemGroupsUnlocking() throws InterruptedException {
    Player player = server.addPlayer();
    PlayerProfile profile = TestUtilities.awaitProfile(player);
    Assertions.assertThrows(IllegalArgumentException.class, () -> new LockedItemGroup(new NamespacedKey(plugin, "locked"), new CustomItemStack(Material.GOLD_NUGGET, "&6Locked Test"), (NamespacedKey) null));
    ItemGroup group = new ItemGroup(new NamespacedKey(plugin, "parent"), new CustomItemStack(Material.EMERALD, "&5I am SHERlocked"));
    group.register(plugin);
    LockedItemGroup locked = new LockedItemGroup(new NamespacedKey(plugin, "locked2"), new CustomItemStack(Material.GOLD_NUGGET, "&6Locked Test"), group.getKey());
    locked.register(plugin);
    // No Items, so it should be unlocked
    Assertions.assertTrue(locked.hasUnlocked(player, profile));
    SlimefunItem item = new SlimefunItem(group, new SlimefunItemStack("LOCKED_ITEMGROUP_TEST", new CustomItemStack(Material.LANTERN, "&6Test Item for locked categories")), RecipeType.NULL, new ItemStack[9]);
    item.register(plugin);
    item.load();
    Slimefun.getRegistry().setResearchingEnabled(true);
    Research research = new Research(new NamespacedKey(plugin, "cant_touch_this"), 432432, "MC Hammer", 90);
    research.addItems(item);
    research.register();
    Assertions.assertFalse(profile.hasUnlocked(research));
    Assertions.assertFalse(locked.hasUnlocked(player, profile));
    profile.setResearched(research, true);
    Assertions.assertTrue(locked.hasUnlocked(player, profile));
}
Also used : LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) Player(org.bukkit.entity.Player) LockedItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup) SeasonalItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.SeasonalItemGroup) FlexItemGroup(io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup) 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) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Research(io.github.thebusybiscuit.slimefun4.api.researches.Research) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with LockedItemGroup

use of io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup in project Slimefun4 by Slimefun.

the class LockedItemGroup method register.

@Override
public void register(@Nonnull SlimefunAddon addon) {
    super.register(addon);
    List<NamespacedKey> namespacedKeys = new ArrayList<>();
    for (NamespacedKey key : keys) {
        if (key != null) {
            namespacedKeys.add(key);
        }
    }
    for (ItemGroup itemGroup : Slimefun.getRegistry().getAllItemGroups()) {
        if (namespacedKeys.remove(itemGroup.getKey())) {
            addParent(itemGroup);
        }
    }
    for (NamespacedKey key : namespacedKeys) {
        Slimefun.logger().log(Level.INFO, "Parent \"{0}\" for LockedItemGroup \"{1}\" was not found, probably just disabled.", new Object[] { key, getKey() });
    }
}
Also used : ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) NamespacedKey(org.bukkit.NamespacedKey) ArrayList(java.util.ArrayList)

Aggregations

ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)4 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)3 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)3 LockedItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup)3 NamespacedKey (org.bukkit.NamespacedKey)3 SeasonalItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.SeasonalItemGroup)2 ArrayList (java.util.ArrayList)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)1 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)1 SubItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup)1 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)1 Research (io.github.thebusybiscuit.slimefun4.api.researches.Research)1 Player (org.bukkit.entity.Player)1