1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Some additional cleanup

This commit is contained in:
TheBusyBiscuit 2021-09-03 14:01:55 +02:00
parent 9451e256e5
commit 6951251394
28 changed files with 147 additions and 148 deletions

View File

@ -72,6 +72,7 @@ This RC brings a lot of breaking changes to the API. For more info on why we did
* Fixed #3225
* Fixed #3206
* Fixed androids not respecting Worldborders
* Fixed Ender Lumps showing an incorrect recipe in the guide
## Release Candidate 26 (20 Jul 2021)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#26

View File

@ -27,7 +27,8 @@ import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuide;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
/**
* Represents a category, which structure multiple {@link SlimefunItem} in the {@link SlimefunGuide}.
* Represents an item group, which structure
* multiple {@link SlimefunItem} in the {@link SlimefunGuide}.
*
* @author TheBusyBiscuit
*
@ -74,8 +75,8 @@ public class ItemGroup implements Keyed {
*/
@ParametersAreNonnullByDefault
public ItemGroup(NamespacedKey key, ItemStack item, int tier) {
Validate.notNull(key, "A Category's NamespacedKey must not be null!");
Validate.notNull(item, "A Category's ItemStack must not be null!");
Validate.notNull(key, "An item group's NamespacedKey must not be null!");
Validate.notNull(item, "An item group's ItemStack must not be null!");
this.item = item;
this.key = key;
@ -95,9 +96,10 @@ public class ItemGroup implements Keyed {
}
/**
* Registers this category.
* Registers this {@link ItemGroup}.
* <p>
* By default, a category is automatically registered when a {@link SlimefunItem} was added to it.
* By default, an {@link ItemGroup} is automatically registered when
* a {@link SlimefunItem} was added to it.
*
* @param addon
* The {@link SlimefunAddon} that wants to register this {@link ItemGroup}
@ -106,7 +108,7 @@ public class ItemGroup implements Keyed {
Validate.notNull(addon, "The Addon cannot be null");
if (isRegistered()) {
throw new UnsupportedOperationException("This Category has already been registered!");
throw new UnsupportedOperationException("This ItemGroup has already been registered!");
}
this.addon = addon;
@ -135,7 +137,7 @@ public class ItemGroup implements Keyed {
public void setTier(int tier) {
this.tier = tier;
// Refresh Category order if already registered.
// Refresh ItemGroup order if already registered.
if (isRegistered()) {
sortCategoriesByTier();
}
@ -167,7 +169,7 @@ public class ItemGroup implements Keyed {
* the {@link SlimefunItem} that should be added to this {@link ItemGroup}
*/
public void add(@Nonnull SlimefunItem item) {
Validate.notNull(item, "Cannot add null Items to a Category!");
Validate.notNull(item, "Cannot add null Items to an ItemGroup!");
if (items.contains(item)) {
// Ignore duplicate entries
@ -184,7 +186,7 @@ public class ItemGroup implements Keyed {
* the {@link SlimefunItem} that should be removed from this {@link ItemGroup}
*/
public void remove(@Nonnull SlimefunItem item) {
Validate.notNull(item, "Cannot remove null from a Category!");
Validate.notNull(item, "Cannot remove null from an ItemGroup!");
items.remove(item);
}
@ -250,7 +252,7 @@ public class ItemGroup implements Keyed {
/**
* Returns all instances of {@link SlimefunItem} bound to this {@link ItemGroup}.
*
* @return the list of SlimefunItems bound to this category
* @return the list of SlimefunItems bound to this {@link ItemGroup}
*/
@Nonnull
public List<SlimefunItem> getItems() {

View File

@ -21,7 +21,7 @@ import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
/**
* Represents a {@link ItemGroup} that cannot be opened until the parent category/categories
* Represents a {@link ItemGroup} that cannot be opened until the parent group(s)
* are fully unlocked.
* <p>
* See {@link ItemGroup} for the complete documentation.
@ -38,15 +38,15 @@ public class LockedItemGroup extends ItemGroup {
private final Set<ItemGroup> parents = new HashSet<>();
/**
* The basic constructor for a LockedCategory.
* The basic constructor for a LockedItemGroup.
* Like {@link ItemGroup}, the default tier is automatically set to 3.
*
* @param key
* A unique identifier for this category
* A unique identifier for this group
* @param item
* The display item for this category
* The display item for this group
* @param parents
* The parent categories for this category
* The parent categories for this group
*
*/
@ParametersAreNonnullByDefault
@ -55,22 +55,22 @@ public class LockedItemGroup extends ItemGroup {
}
/**
* The constructor for a LockedCategory.
* The constructor for a LockedItemGroup.
*
* @param key
* A unique identifier for this category
* A unique identifier for this group
* @param item
* The display item for this category
* The display item for this group
* @param tier
* The tier of this category
* The tier of this group
* @param parents
* The parent categories for this category
* The parent categories for this group
*
*/
@ParametersAreNonnullByDefault
public LockedItemGroup(NamespacedKey key, ItemStack item, int tier, NamespacedKey... parents) {
super(key, item, tier);
Validate.noNullElements(parents, "A LockedCategory must not have any 'null' parents!");
Validate.noNullElements(parents, "A LockedItemGroup must not have any 'null' parents!");
this.keys = parents;
}
@ -94,51 +94,50 @@ public class LockedItemGroup extends ItemGroup {
}
for (NamespacedKey key : namespacedKeys) {
Slimefun.logger().log(Level.INFO, "Parent \"{0}\" for Category \"{1}\" was not found, probably just disabled.", new Object[] { key, getKey() });
Slimefun.logger().log(Level.INFO, "Parent \"{0}\" for LockedItemGroup \"{1}\" was not found, probably just disabled.", new Object[] { key, getKey() });
}
}
/**
* Gets the list of parent categories for this {@link LockedItemGroup}.
* Gets the list of parent item groups for this {@link LockedItemGroup}.
*
* @return the list of parent categories
* @return the list of parent item groups
*
* @see #addParent(ItemGroup)
* @see #removeParent(ItemGroup)
*/
@Nonnull
public Set<ItemGroup> getParents() {
public @Nonnull Set<ItemGroup> getParents() {
return parents;
}
/**
* Adds a parent {@link ItemGroup} to this {@link LockedItemGroup}.
*
* @param category
* @param group
* The {@link ItemGroup} to add as a parent
*
* @see #getParents()
* @see #removeParent(ItemGroup)
*/
public void addParent(ItemGroup category) {
if (category == this || category == null) {
throw new IllegalArgumentException("Category '" + item.getItemMeta().getDisplayName() + "' cannot be a parent of itself or have a 'null' parent.");
public void addParent(ItemGroup group) {
if (group == this || group == null) {
throw new IllegalArgumentException("ItemGroup '" + item.getItemMeta().getDisplayName() + "' cannot be a parent of itself or have a 'null' parent.");
}
parents.add(category);
parents.add(group);
}
/**
* Removes a {@link ItemGroup} from the parents of this {@link LockedItemGroup}.
*
* @param category
* @param group
* The {@link ItemGroup} to remove from the parents of this {@link LockedItemGroup}
*
* @see #getParents()
* @see #addParent(ItemGroup)
*/
public void removeParent(@Nonnull ItemGroup category) {
parents.remove(category);
public void removeParent(@Nonnull ItemGroup group) {
parents.remove(group);
}
/**
@ -155,8 +154,8 @@ public class LockedItemGroup extends ItemGroup {
Validate.notNull(p, "The player cannot be null!");
Validate.notNull(profile, "The Profile cannot be null!");
for (ItemGroup category : parents) {
for (SlimefunItem item : category.getItems()) {
for (ItemGroup parent : parents) {
for (SlimefunItem item : parent.getItems()) {
// Check if the Player has researched every item (if the item is enabled)
if (!item.isDisabledIn(p.getWorld()) && item.hasResearch() && !profile.hasUnlocked(item.getResearch())) {
return false;

View File

@ -41,25 +41,25 @@ public class NestedItemGroup extends FlexItemGroup {
/**
* This will add the given {@link SubItemGroup} to this {@link NestedItemGroup}.
*
* @param category
* @param group
* The {@link SubItemGroup} to add.
*/
public void addSubGroup(@Nonnull SubItemGroup category) {
Validate.notNull(category, "The sub item group cannot be null!");
public void addSubGroup(@Nonnull SubItemGroup group) {
Validate.notNull(group, "The sub item group cannot be null!");
subGroups.add(category);
subGroups.add(group);
}
/**
* This will remove the given {@link SubItemGroup} from this {@link NestedItemGroup} (if present).
*
* @param category
* @param group
* The {@link SubItemGroup} to remove.
*/
public void removeSubGroup(@Nonnull SubItemGroup category) {
Validate.notNull(category, "The sub item group cannot be null!");
public void removeSubGroup(@Nonnull SubItemGroup group) {
Validate.notNull(group, "The sub item group cannot be null!");
subGroups.remove(category);
subGroups.remove(group);
}
@Override

View File

@ -32,11 +32,11 @@ public class SeasonalItemGroup extends ItemGroup {
* @param key
* The {@link NamespacedKey} that is used to identify this {@link ItemGroup}
* @param month
* The month when the category should be displayed (from 1 = January ; to 12 = December)
* The month when the {@link ItemGroup} should be displayed (from 1 = January ; to 12 = December)
* @param tier
* The tier of this category
* The tier of this {@link ItemGroup}
* @param item
* The display item for this category
* The display item for this {@link ItemGroup}
*/
@ParametersAreNonnullByDefault
public SeasonalItemGroup(NamespacedKey key, Month month, int tier, ItemStack item) {
@ -51,8 +51,7 @@ public class SeasonalItemGroup extends ItemGroup {
*
* @return the {@link Month} in which this {@link SeasonalItemGroup} appears
*/
@Nonnull
public Month getMonth() {
public @Nonnull Month getMonth() {
return month;
}

View File

@ -22,7 +22,7 @@ import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
*/
public class SubItemGroup extends ItemGroup {
private final NestedItemGroup multiCategory;
private final NestedItemGroup parentItemGroup;
@ParametersAreNonnullByDefault
public SubItemGroup(NamespacedKey key, NestedItemGroup parent, ItemStack item) {
@ -33,9 +33,9 @@ public class SubItemGroup extends ItemGroup {
public SubItemGroup(NamespacedKey key, NestedItemGroup parent, ItemStack item, int tier) {
super(key, item, tier);
Validate.notNull(parent, "The parent category cannot be null");
Validate.notNull(parent, "The parent group cannot be null");
multiCategory = parent;
parentItemGroup = parent;
parent.addSubGroup(this);
}
@ -48,17 +48,16 @@ public class SubItemGroup extends ItemGroup {
return true;
}
@Nonnull
public final NestedItemGroup getParent() {
return multiCategory;
public final @Nonnull NestedItemGroup getParent() {
return parentItemGroup;
}
@Override
public final void register(@Nonnull SlimefunAddon addon) {
super.register(addon);
if (!multiCategory.isRegistered()) {
multiCategory.register(addon);
if (!parentItemGroup.isRegistered()) {
parentItemGroup.register(addon);
}
}

View File

@ -76,7 +76,7 @@ public class Research implements Keyed {
}
@Override
public NamespacedKey getKey() {
public @Nonnull NamespacedKey getKey() {
return key;
}
@ -114,8 +114,7 @@ public class Research implements Keyed {
*
* @return The localized Name of this {@link Research}.
*/
@Nonnull
public String getName(@Nonnull Player p) {
public @Nonnull String getName(@Nonnull Player p) {
String localized = Slimefun.getLocalization().getResearchName(p, key);
return localized != null ? localized : name;
}

View File

@ -2,4 +2,4 @@
* This package holds everything connected to the {@link io.github.thebusybiscuit.slimefun4.core.researching.Research}
* class.
*/
package io.github.thebusybiscuit.slimefun4.core.researching;
package io.github.thebusybiscuit.slimefun4.api.researches;

View File

@ -66,7 +66,7 @@ import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.MenuClickHan
*/
public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
private static final int CATEGORY_SIZE = 36;
private static final int MAX_ITEM_GROUPS = 36;
private static final Sound sound = Sound.ITEM_BOOK_PAGE_TURN;
private final int[] recipeSlots = { 3, 4, 5, 12, 13, 14, 21, 22, 23 };
@ -128,9 +128,9 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
SlimefunAddon addon = group.getAddon();
if (addon != null) {
addon.getLogger().log(Level.SEVERE, x, () -> "Could not display Category: " + group);
addon.getLogger().log(Level.SEVERE, x, () -> "Could not display item group: " + group);
} else {
Slimefun.logger().log(Level.SEVERE, x, () -> "Could not display Category: " + group);
Slimefun.logger().log(Level.SEVERE, x, () -> "Could not display item group: " + group);
}
}
}
@ -153,23 +153,23 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
}
ChestMenu menu = create(p);
List<ItemGroup> categories = getVisibleItemGroups(p, profile);
List<ItemGroup> itemGroups = getVisibleItemGroups(p, profile);
int index = 9;
createHeader(p, profile, menu);
int target = (CATEGORY_SIZE * (page - 1)) - 1;
int target = (MAX_ITEM_GROUPS * (page - 1)) - 1;
while (target < (categories.size() - 1) && index < CATEGORY_SIZE + 9) {
while (target < (itemGroups.size() - 1) && index < MAX_ITEM_GROUPS + 9) {
target++;
ItemGroup category = categories.get(target);
showItemGroup(menu, p, profile, category, index);
ItemGroup group = itemGroups.get(target);
showItemGroup(menu, p, profile, group, index);
index++;
}
int pages = target == categories.size() - 1 ? page : (categories.size() - 1) / CATEGORY_SIZE + 1;
int pages = target == itemGroups.size() - 1 ? page : (itemGroups.size() - 1) / MAX_ITEM_GROUPS + 1;
menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page, pages));
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
@ -245,7 +245,7 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
addBackButton(menu, 1, p, profile);
int pages = (category.getItems().size() - 1) / CATEGORY_SIZE + 1;
int pages = (category.getItems().size() - 1) / MAX_ITEM_GROUPS + 1;
menu.addItem(46, ChestMenuUtils.getPreviousButton(p, page, pages));
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
@ -270,9 +270,9 @@ public class SurvivalSlimefunGuide implements SlimefunGuideImplementation {
});
int index = 9;
int categoryIndex = CATEGORY_SIZE * (page - 1);
int categoryIndex = MAX_ITEM_GROUPS * (page - 1);
for (int i = 0; i < CATEGORY_SIZE; i++) {
for (int i = 0; i < MAX_ITEM_GROUPS; i++) {
int target = categoryIndex + i;
if (target >= category.getItems().size()) {

View File

@ -40,7 +40,7 @@ class TestChargeCommand {
@Test
@DisplayName("Test if /sf charge charges the item the player is holding")
void testCommand() {
ItemGroup category = TestUtilities.getCategory(plugin, "rechargeable");
ItemGroup category = TestUtilities.getItemGroup(plugin, "rechargeable");
SlimefunItemStack RECHARGEABLE_ITEM = new SlimefunItemStack("SF_CHARGE_TEST_ITEM", Material.REDSTONE_BLOCK, "Rechargeable Item", "This isn't real", LoreBuilder.powerCharged(0, 100));
new RechargeableMock(category, RECHARGEABLE_ITEM, RecipeType.NULL, new ItemStack[9]).register(plugin);

View File

@ -41,7 +41,7 @@ class TestDamageableItem {
}
public static MockDamageable getDummyItem(String id, boolean damageable, @Nullable Enchantment enchantment, @Nullable Integer enchantmentLevel) {
ItemGroup category = TestUtilities.getCategory(plugin, "damageable_item_test");
ItemGroup category = TestUtilities.getItemGroup(plugin, "damageable_item_test");
SlimefunItemStack stack = new SlimefunItemStack("DAMAGEABLE_PICKAXE_" + id, Material.DIAMOND_PICKAXE, "&4This pickaxe can break", "&6It appears, it breaks, but most importantly, it tests.");
if (enchantment != null && enchantmentLevel != null) {
ItemMeta im = stack.getItemMeta();

View File

@ -37,7 +37,7 @@ class TestRadioactiveItem {
@EnumSource(value = Radioactivity.class)
@DisplayName("Test radioactive items being radioactive")
void testWikiPages(Radioactivity radioactivity) {
ItemGroup category = TestUtilities.getCategory(plugin, "radioactivity_test");
ItemGroup category = TestUtilities.getItemGroup(plugin, "radioactivity_test");
SlimefunItemStack stack = new SlimefunItemStack("RADIOACTIVE_" + radioactivity.name(), Material.EMERALD, "&4Radioactive!!!", "Imagine dragons");
RadioactiveItem item = new RadioactiveItem(category, radioactivity, stack, RecipeType.NULL, new ItemStack[9]);

View File

@ -203,7 +203,7 @@ class TestAutoCrafter {
@Nonnull
private AbstractAutoCrafter getVanillaAutoCrafter() {
SlimefunItemStack item = new SlimefunItemStack("MOCK_AUTO_CRAFTER", Material.CRAFTING_TABLE, "Mock Auto Crafter");
return new VanillaAutoCrafter(TestUtilities.getCategory(plugin, "auto_crafter"), item, RecipeType.NULL, new ItemStack[9]);
return new VanillaAutoCrafter(TestUtilities.getItemGroup(plugin, "auto_crafter"), item, RecipeType.NULL, new ItemStack[9]);
}
}

View File

@ -37,7 +37,7 @@ class TestEnderBackpack implements SlimefunItemTest<EnderBackpack> {
@Override
public EnderBackpack registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.ENDER_CHEST, "&5Test Ender Backpack");
EnderBackpack backpack = new EnderBackpack(TestUtilities.getCategory(plugin, "ender_backpack"), item, RecipeType.NULL, new ItemStack[9]);
EnderBackpack backpack = new EnderBackpack(TestUtilities.getItemGroup(plugin, "ender_backpack"), item, RecipeType.NULL, new ItemStack[9]);
backpack.register(plugin);
return backpack;
}

View File

@ -39,7 +39,7 @@ class TestDietCookie implements SlimefunItemTest<DietCookie> {
@Override
public DietCookie registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.COOKIE, "&5Test Cookie");
DietCookie cookie = new DietCookie(TestUtilities.getCategory(plugin, "diet_cookie"), item, RecipeType.NULL, new ItemStack[9]);
DietCookie cookie = new DietCookie(TestUtilities.getItemGroup(plugin, "diet_cookie"), item, RecipeType.NULL, new ItemStack[9]);
cookie.register(plugin);
return cookie;
}

View File

@ -37,7 +37,7 @@ class TestMeatJerky implements SlimefunItemTest<MeatJerky> {
@Override
public MeatJerky registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.COOKED_BEEF, "&5Test Jerky");
MeatJerky meat = new MeatJerky(TestUtilities.getCategory(plugin, "test_jerky"), item, RecipeType.NULL, new ItemStack[9]);
MeatJerky meat = new MeatJerky(TestUtilities.getItemGroup(plugin, "test_jerky"), item, RecipeType.NULL, new ItemStack[9]);
meat.register(plugin);
return meat;
}

View File

@ -38,7 +38,7 @@ class TestMonsterJerky implements SlimefunItemTest<MonsterJerky> {
@Override
public MonsterJerky registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.ROTTEN_FLESH, "&5Test Monster Jerky");
MonsterJerky jerky = new MonsterJerky(TestUtilities.getCategory(plugin, "monster_jerky"), item, RecipeType.NULL, new ItemStack[9]);
MonsterJerky jerky = new MonsterJerky(TestUtilities.getItemGroup(plugin, "monster_jerky"), item, RecipeType.NULL, new ItemStack[9]);
jerky.register(plugin);
return jerky;
}

View File

@ -55,7 +55,7 @@ class TestClimbingPick implements SlimefunItemTest<ClimbingPick> {
@Override
public ClimbingPick registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.IRON_PICKAXE, "&5Test Pick", id);
ClimbingPick pick = new ClimbingPick(TestUtilities.getCategory(plugin, "climbing_pick"), item, RecipeType.NULL, new ItemStack[9]) {
ClimbingPick pick = new ClimbingPick(TestUtilities.getItemGroup(plugin, "climbing_pick"), item, RecipeType.NULL, new ItemStack[9]) {
@Override
public boolean isDualWieldingEnabled() {

View File

@ -38,7 +38,7 @@ class TestPortableDustbin implements SlimefunItemTest<PortableDustbin> {
@Override
public PortableDustbin registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.BUCKET, "&4Test Dustbin");
PortableDustbin dustbin = new PortableDustbin(TestUtilities.getCategory(plugin, "dustbin"), item, RecipeType.NULL, new ItemStack[9]);
PortableDustbin dustbin = new PortableDustbin(TestUtilities.getItemGroup(plugin, "dustbin"), item, RecipeType.NULL, new ItemStack[9]);
dustbin.register(plugin);
return dustbin;
}

View File

@ -46,7 +46,7 @@ class TestTapeMeasure implements SlimefunItemTest<TapeMeasure> {
@Override
public TapeMeasure registerSlimefunItem(Slimefun plugin, String id) {
SlimefunItemStack item = new SlimefunItemStack(id, Material.PLAYER_HEAD, "&5Test Pick", id);
TapeMeasure tapeMeasure = new TapeMeasure(TestUtilities.getCategory(plugin, "tape_measure"), item, RecipeType.NULL, new ItemStack[9]);
TapeMeasure tapeMeasure = new TapeMeasure(TestUtilities.getItemGroup(plugin, "tape_measure"), item, RecipeType.NULL, new ItemStack[9]);
tapeMeasure.register(plugin);
return tapeMeasure;
}

View File

@ -49,7 +49,7 @@ class TestBeeListener {
PlayerProfile profile = TestUtilities.awaitProfile(player);
if (hasArmor) {
ItemGroup category = TestUtilities.getCategory(plugin, "bee_suit_test");
ItemGroup category = TestUtilities.getItemGroup(plugin, "bee_suit_test");
SlimefunItemStack chestplate = new SlimefunItemStack("MOCK_BEE_SUIT", Material.LEATHER_CHESTPLATE, "&cBee Suit Prototype");
MockBeeProtectionSuit armor = new MockBeeProtectionSuit(category, chestplate);
armor.register(plugin);

View File

@ -67,7 +67,7 @@ class TestCargoNodeListener {
Block b = l.getBlock();
Block against = b.getRelative(BlockFace.DOWN);
ItemGroup category = TestUtilities.getCategory(plugin, "cargo_test");
ItemGroup category = TestUtilities.getItemGroup(plugin, "cargo_test");
SlimefunItemStack item = new SlimefunItemStack("MOCK_CARGO_NODE", new CustomItemStack(Material.PLAYER_HEAD, "&4Cargo node!"));
CargoInputNode node = new CargoInputNode(category, item, RecipeType.NULL, new ItemStack[9], null);
node.register(plugin);
@ -86,7 +86,7 @@ class TestCargoNodeListener {
Block b = l.getBlock();
b.setType(Material.GRASS);
ItemGroup category = TestUtilities.getCategory(plugin, "cargo_test");
ItemGroup category = TestUtilities.getItemGroup(plugin, "cargo_test");
SlimefunItemStack item = new SlimefunItemStack("MOCK_CARGO_NODE_2", new CustomItemStack(Material.PLAYER_HEAD, "&4Cargo node!"));
CargoInputNode node = new CargoInputNode(category, item, RecipeType.NULL, new ItemStack[9], null);
node.register(plugin);

View File

@ -61,7 +61,7 @@ class TestSoulboundListener {
PlayerMock player = server.addPlayer();
SlimefunItemStack item = new SlimefunItemStack("SOULBOUND_ITEM_" + (enabled ? "ENABLED" : "DISABLED"), Material.DIAMOND_SWORD, "&5Soulbound Sword");
SoulboundItem soulboundItem = new SoulboundItem(TestUtilities.getCategory(plugin, "soulbound"), item, RecipeType.NULL, new ItemStack[9]);
SoulboundItem soulboundItem = new SoulboundItem(TestUtilities.getItemGroup(plugin, "soulbound"), item, RecipeType.NULL, new ItemStack[9]);
soulboundItem.register(plugin);
if (!enabled) {

View File

@ -86,7 +86,7 @@ class TestVillagerTradingListener {
@Test
void testTradingWithSyntheticEmerald() {
ItemGroup category = TestUtilities.getCategory(plugin, "shiny_emeralds");
ItemGroup category = TestUtilities.getItemGroup(plugin, "shiny_emeralds");
SlimefunItemStack stack = new SlimefunItemStack("FAKE_EMERALD", Material.EMERALD, "&aTrade me");
SyntheticEmerald item = new SyntheticEmerald(category, stack, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[9]);
item.register(plugin);

View File

@ -30,7 +30,7 @@ import io.github.thebusybiscuit.slimefun4.test.TestUtilities;
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
class TestCategories {
class TestItemGroups {
private static ServerMock server;
private static Slimefun plugin;
@ -47,8 +47,8 @@ class TestCategories {
}
@Test
@DisplayName("Test the Getters for Category")
void testCategoryGetters() {
@DisplayName("Test the Getters for ItemGroup")
void testItemGroupGetters() {
ItemGroup category = new ItemGroup(new NamespacedKey(plugin, "getter_test"), new CustomItemStack(Material.DIAMOND_AXE, "&6Testing"));
Assertions.assertEquals(3, category.getTier());
@ -62,10 +62,10 @@ class TestCategories {
}
@Test
@DisplayName("Test adding an item to a Category")
@DisplayName("Test adding an item to a ItemGroup")
void testAddItem() {
ItemGroup category = new ItemGroup(new NamespacedKey(plugin, "items_test"), new CustomItemStack(Material.DIAMOND_AXE, "&6Testing"));
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_ITEMS_TEST_ITEM", new CustomItemStack(Material.BAMBOO, "&6Test Bamboo"));
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_GROUPS_TEST_ITEM", new CustomItemStack(Material.BAMBOO, "&6Test Bamboo"));
item.setItemGroup(category);
item.register(plugin);
item.load();
@ -81,96 +81,96 @@ class TestCategories {
}
@Test
@DisplayName("Test hidden Categories")
@DisplayName("Test hidden Item Groups")
void testHidden() {
ItemGroup category = new ItemGroup(new NamespacedKey(plugin, "hiddenCategory"), new ItemStack(Material.BEACON));
ItemGroup group = new ItemGroup(new NamespacedKey(plugin, "hiddenItemGroup"), new ItemStack(Material.BEACON));
Player player = server.addPlayer();
// Empty Categories are also hidden
Assertions.assertTrue(category.isHidden(player));
// Empty Item Groups are also hidden
Assertions.assertTrue(group.isHidden(player));
SlimefunItem disabledItem = TestUtilities.mockSlimefunItem(plugin, "DISABLED_CATEGORY_ITEM", new CustomItemStack(Material.BEETROOT, "&4Disabled"));
Slimefun.getItemCfg().setValue("DISABLED_CATEGORY_ITEM.enabled", false);
disabledItem.setItemGroup(category);
SlimefunItem disabledItem = TestUtilities.mockSlimefunItem(plugin, "DISABLED_ITEM_GROUP_ITEM", new CustomItemStack(Material.BEETROOT, "&4Disabled"));
Slimefun.getItemCfg().setValue("DISABLED_ITEM_GROUP_ITEM.enabled", false);
disabledItem.setItemGroup(group);
disabledItem.register(plugin);
disabledItem.load();
// A disabled Item should also make the Category hide
Assertions.assertTrue(category.isHidden(player));
// A disabled Item should also make the ItemGroup hide
Assertions.assertTrue(group.isHidden(player));
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_HIDDEN_TEST", new CustomItemStack(Material.BAMBOO, "&6Test Bamboo"));
item.setItemGroup(category);
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_GROUP_HIDDEN_TEST", new CustomItemStack(Material.BAMBOO, "&6Test Bamboo"));
item.setItemGroup(group);
item.setHidden(true);
item.register(plugin);
item.load();
// A hidden Item should also make the Category hide
Assertions.assertTrue(category.isHidden(player));
// A hidden Item should also make the ItemGroup hide
Assertions.assertTrue(group.isHidden(player));
item.setHidden(false);
Assertions.assertFalse(category.isHidden(player));
Assertions.assertFalse(group.isHidden(player));
}
@Test
@DisplayName("Test Category#contains")
@DisplayName("Test ItemGroup#contains")
void testContains() {
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CATEGORY_TEST_ITEM_2", new CustomItemStack(Material.BOW, "&6Test Bow"));
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "ITEM_GROUP_TEST_ITEM_2", new CustomItemStack(Material.BOW, "&6Test Bow"));
item.register(plugin);
item.load();
ItemGroup category = item.getItemGroup();
ItemGroup group = item.getItemGroup();
Assertions.assertTrue(category.contains(item));
Assertions.assertFalse(category.contains(null));
Assertions.assertTrue(group.contains(item));
Assertions.assertFalse(group.contains(null));
// Unregistered Item
Assertions.assertFalse(category.contains(TestUtilities.mockSlimefunItem(plugin, "NULL", new ItemStack(Material.BEDROCK))));
Assertions.assertFalse(group.contains(TestUtilities.mockSlimefunItem(plugin, "NULL", new ItemStack(Material.BEDROCK))));
}
@Test
@DisplayName("Test LockedCategory parental locking")
void testLockedCategoriesParents() {
@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 category = new ItemGroup(new NamespacedKey(plugin, "unlocked"), new CustomItemStack(Material.EMERALD, "&5I am SHERlocked"));
category.register(plugin);
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"), category.getKey(), unregistered.getKey());
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(category));
Assertions.assertTrue(locked.getParents().contains(group));
Assertions.assertFalse(locked.getParents().contains(unregistered));
locked.removeParent(category);
Assertions.assertFalse(locked.getParents().contains(category));
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(category);
Assertions.assertTrue(locked.getParents().contains(category));
locked.addParent(group);
Assertions.assertTrue(locked.getParents().contains(group));
}
@Test
@DisplayName("Test an unlocked LockedCategory")
void testLockedCategoriesUnlocking() throws InterruptedException {
@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 category = new ItemGroup(new NamespacedKey(plugin, "parent"), new CustomItemStack(Material.EMERALD, "&5I am SHERlocked"));
category.register(plugin);
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"), category.getKey());
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(category, new SlimefunItemStack("LOCKED_CATEGORY_TEST", new CustomItemStack(Material.LANTERN, "&6Test Item for locked categories")), RecipeType.NULL, new ItemStack[9]);
SlimefunItem item = new SlimefunItem(group, new SlimefunItemStack("LOCKED_CATEGORY_TEST", new CustomItemStack(Material.LANTERN, "&6Test Item for locked categories")), RecipeType.NULL, new ItemStack[9]);
item.register(plugin);
item.load();
@ -188,30 +188,30 @@ class TestCategories {
}
@Test
@DisplayName("Test a seasonal Category")
void testSeasonalCategories() {
@DisplayName("Test a seasonal ItemGroup")
void ItemGroups() {
// Category with current Month
Month month = LocalDate.now().getMonth();
SeasonalItemGroup category = new SeasonalItemGroup(new NamespacedKey(plugin, "seasonal"), month, 1, new CustomItemStack(Material.NETHER_STAR, "&cSeasonal Test"));
SeasonalItemGroup group = new SeasonalItemGroup(new NamespacedKey(plugin, "seasonal"), month, 1, new CustomItemStack(Material.NETHER_STAR, "&cSeasonal Test"));
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "SEASONAL_ITEM", new CustomItemStack(Material.NETHER_STAR, "&dSeasonal Test Star"));
item.setItemGroup(category);
item.setItemGroup(group);
item.register(plugin);
item.load();
Player player = server.addPlayer();
Assertions.assertEquals(month, category.getMonth());
Assertions.assertFalse(category.isHidden(player));
Assertions.assertEquals(month, group.getMonth());
Assertions.assertFalse(group.isHidden(player));
// Category with future Month
SeasonalItemGroup category2 = new SeasonalItemGroup(category.getKey(), month.plus(6), 1, new CustomItemStack(Material.MILK_BUCKET, "&dSeasonal Test"));
SeasonalItemGroup category2 = new SeasonalItemGroup(group.getKey(), month.plus(6), 1, new CustomItemStack(Material.MILK_BUCKET, "&dSeasonal Test"));
Assertions.assertTrue(category2.isHidden(player));
}
@Test
@DisplayName("Test the FlexCategory")
@DisplayName("Test the FlexItemGroup")
void testFlexCategory() {
FlexItemGroup category = new FlexItemGroup(new NamespacedKey(plugin, "flex"), new CustomItemStack(Material.REDSTONE, "&4Weird flex but ok")) {
FlexItemGroup group = new FlexItemGroup(new NamespacedKey(plugin, "flex"), new CustomItemStack(Material.REDSTONE, "&4Weird flex but ok")) {
@Override
public void open(Player p, PlayerProfile profile, SlimefunGuideMode layout) {
@ -225,11 +225,11 @@ class TestCategories {
};
Player player = server.addPlayer();
Assertions.assertFalse(category.isHidden(player));
Assertions.assertFalse(group.isHidden(player));
Assertions.assertThrows(UnsupportedOperationException.class, () -> category.add(null));
Assertions.assertThrows(UnsupportedOperationException.class, () -> category.contains(null));
Assertions.assertThrows(UnsupportedOperationException.class, () -> category.remove(null));
Assertions.assertThrows(UnsupportedOperationException.class, () -> category.getItems());
Assertions.assertThrows(UnsupportedOperationException.class, () -> group.add(null));
Assertions.assertThrows(UnsupportedOperationException.class, () -> group.contains(null));
Assertions.assertThrows(UnsupportedOperationException.class, () -> group.remove(null));
Assertions.assertThrows(UnsupportedOperationException.class, () -> group.getItems());
}
}

View File

@ -121,7 +121,7 @@ class TestRechargeableItems {
}
private RechargeableMock mock(String id, float capacity) {
ItemGroup category = TestUtilities.getCategory(plugin, "rechargeable");
ItemGroup category = TestUtilities.getItemGroup(plugin, "rechargeable");
return new RechargeableMock(category, new SlimefunItemStack(id, new CustomItemStack(Material.REDSTONE_LAMP, "&3" + id)), capacity);
}

View File

@ -59,7 +59,7 @@ class TestArmorTask {
PotionEffect[] effects = { new PotionEffect(PotionEffectType.SPEED, 50, 3), new PotionEffect(PotionEffectType.SATURATION, 128, 12) };
SlimefunItemStack helmet = new SlimefunItemStack("HELMET_FLEX", Material.IRON_HELMET, "&bSuper cool Helmet");
SlimefunArmorPiece armor = new SlimefunArmorPiece(TestUtilities.getCategory(plugin, "armor_test"), helmet, RecipeType.NULL, new ItemStack[9], effects);
SlimefunArmorPiece armor = new SlimefunArmorPiece(TestUtilities.getItemGroup(plugin, "armor_test"), helmet, RecipeType.NULL, new ItemStack[9], effects);
armor.register(plugin);
player.getInventory().setHelmet(helmet.clone());
@ -80,7 +80,7 @@ class TestArmorTask {
// Setting the time to noon, to exclude the Solar Helmet check
player.getWorld().setTime(16000);
ItemGroup category = TestUtilities.getCategory(plugin, "hazmat_suit_test");
ItemGroup category = TestUtilities.getItemGroup(plugin, "hazmat_suit_test");
SlimefunItemStack item = new SlimefunItemStack("MOCK_URANIUM_" + String.valueOf(hazmat).toUpperCase(Locale.ROOT) + "_" + String.valueOf(radioactiveFire).toUpperCase(Locale.ROOT), Material.EMERALD, "&aHi, I am deadly");
new RadioactiveItem(category, Radioactivity.VERY_DEADLY, item, RecipeType.NULL, new ItemStack[9]).register(plugin);

View File

@ -43,7 +43,7 @@ public final class TestUtilities {
}
@ParametersAreNonnullByDefault
public static @Nonnull ItemGroup getCategory(Plugin plugin, String name) {
public static @Nonnull ItemGroup getItemGroup(Plugin plugin, String name) {
return new ItemGroup(new NamespacedKey(plugin, name), new CustomItemStack(Material.NETHER_STAR, "&4Test Category"));
}