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());
}
}
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));
}
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));
}
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() });
}
}
Aggregations