use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.
the class SlimefunUtils method canPlayerUseItem.
/**
* This checks whether the {@link Player} is able to use the given {@link ItemStack}.
* It will always return <code>true</code> for non-Slimefun items.
* <p>
* If you already have an instance of {@link SlimefunItem}, please use {@link SlimefunItem#canUse(Player, boolean)}.
*
* @param p
* The {@link Player}
* @param item
* The {@link ItemStack} to check
* @param sendMessage
* Whether to send a message response to the {@link Player}
*
* @return Whether the {@link Player} is able to use that item.
*/
public static boolean canPlayerUseItem(@Nonnull Player p, @Nullable ItemStack item, boolean sendMessage) {
Validate.notNull(p, "The player cannot be null");
SlimefunItem sfItem = SlimefunItem.getByItem(item);
if (sfItem != null) {
return sfItem.canUse(p, sendMessage);
} else {
return true;
}
}
use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.
the class SlimefunUtils method isItemSimilar.
public static boolean isItemSimilar(@Nullable ItemStack item, @Nullable ItemStack sfitem, boolean checkLore, boolean checkAmount) {
if (item == null) {
return sfitem == null;
} else if (sfitem == null) {
return false;
} else if (item.getType() != sfitem.getType()) {
return false;
} else if (checkAmount && item.getAmount() < sfitem.getAmount()) {
return false;
} else if (sfitem instanceof SlimefunItemStack && item instanceof SlimefunItemStack) {
return ((SlimefunItemStack) item).getItemId().equals(((SlimefunItemStack) sfitem).getItemId());
} else if (item.hasItemMeta()) {
Debug.log(TestCase.CARGO_INPUT_TESTING, "SlimefunUtils#isItemSimilar - item.hasItemMeta()");
ItemMeta itemMeta = item.getItemMeta();
if (sfitem instanceof SlimefunItemStack) {
Optional<String> id = Slimefun.getItemDataService().getItemData(itemMeta);
if (id.isPresent()) {
return id.get().equals(((SlimefunItemStack) sfitem).getItemId());
}
ItemMetaSnapshot meta = ((SlimefunItemStack) sfitem).getItemMetaSnapshot();
return equalsItemMeta(itemMeta, meta, checkLore);
} else if (sfitem instanceof ItemStackWrapper && sfitem.hasItemMeta()) {
Debug.log(TestCase.CARGO_INPUT_TESTING, " is wrapper");
/*
* Cargo optimization (PR #3258)
*
* Slimefun items may be ItemStackWrapper's in the context of cargo
* so let's try to do an ID comparison before meta comparison
*/
ItemMeta possibleSfItemMeta = sfitem.getItemMeta();
Debug.log(TestCase.CARGO_INPUT_TESTING, " sfitem is ItemStackWrapper - possible SF Item: {}", sfitem);
// Prioritize SlimefunItem id comparison over ItemMeta comparison
if (Slimefun.getItemDataService().hasEqualItemData(possibleSfItemMeta, itemMeta)) {
Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs matched!");
return true;
} else {
Debug.log(TestCase.CARGO_INPUT_TESTING, " Item IDs don't match, checking meta {} == {} (lore: {})", itemMeta, possibleSfItemMeta, checkLore);
return equalsItemMeta(itemMeta, possibleSfItemMeta, checkLore);
}
} else if (sfitem.hasItemMeta()) {
ItemMeta sfItemMeta = sfitem.getItemMeta();
Debug.log(TestCase.CARGO_INPUT_TESTING, " Comparing meta (vanilla items?) - {} == {} (lore: {})", itemMeta, sfItemMeta, checkLore);
return equalsItemMeta(itemMeta, sfItemMeta, checkLore);
} else {
return false;
}
} else {
return !sfitem.hasItemMeta();
}
}
use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.
the class TestFireworksListener method load.
@BeforeAll
public static void load() {
server = MockBukkit.mock();
Slimefun plugin = MockBukkit.load(Slimefun.class);
new FireworksListener(plugin);
}
use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.
the class TestSmithingTableListener method load.
@BeforeAll
public static void load() {
server = MockBukkit.mock();
Slimefun plugin = MockBukkit.load(Slimefun.class);
listener = new SmithingTableListener(plugin);
slimefunTool = TestUtilities.mockSlimefunItem(plugin, "MOCK_DIAMOND_SWORD", new CustomItemStack(Material.DIAMOND_SWORD, "&6Mock"));
slimefunIngot = TestUtilities.mockSlimefunItem(plugin, "MOCK_NETHERITE_INGOT", new CustomItemStack(Material.NETHERITE_INGOT, "&6Mock"));
vanillaTool = TestUtilities.mockVanillaItem(plugin, Material.DIAMOND_SWORD, true);
vanillaIngot = TestUtilities.mockVanillaItem(plugin, Material.NETHERITE_INGOT, true);
slimefunTool.register(plugin);
slimefunIngot.register(plugin);
vanillaTool.register(plugin);
vanillaIngot.register(plugin);
}
use of io.github.thebusybiscuit.slimefun4.implementation.Slimefun in project Slimefun4 by Slimefun.
the class TestCauldronListener method testCauldronWithSlimefunItem.
@Test
@DisplayName("Test Cauldron working as normal with non-leather slimefun items")
void testCauldronWithSlimefunItem() {
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CAULDRON_TEST_MOCK", new CustomItemStack(Material.GOLDEN_APPLE, "&6Mock"));
item.register(plugin);
PlayerInteractEvent event = mockCauldronEvent(item.getItem());
Assertions.assertEquals(Result.DEFAULT, event.useItemInHand());
}
Aggregations