mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
Fixes #2423
This commit is contained in:
parent
8440143f41
commit
42f849d891
@ -90,6 +90,7 @@
|
||||
* Fixed #2454
|
||||
* Fixed #2457
|
||||
* Fixed #2411
|
||||
* Fixed #2423
|
||||
|
||||
## Release Candidate 16 (07 Sep 2020)
|
||||
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16
|
||||
|
@ -30,7 +30,7 @@ public class CauldronListener implements SlimefunCraftingListener {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onAnvil(PlayerInteractEvent e) {
|
||||
public void onCauldronUse(PlayerInteractEvent e) {
|
||||
if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
|
||||
Block block = e.getClickedBlock();
|
||||
|
||||
|
@ -0,0 +1,106 @@
|
||||
package io.github.thebusybiscuit.slimefun4.testing.tests.listeners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||
import be.seeseemelk.mockbukkit.ServerMock;
|
||||
import be.seeseemelk.mockbukkit.block.BlockMock;
|
||||
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.listeners.crafting.CauldronListener;
|
||||
import io.github.thebusybiscuit.slimefun4.testing.TestUtilities;
|
||||
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
|
||||
|
||||
class TestCauldronListener {
|
||||
|
||||
private static SlimefunPlugin plugin;
|
||||
private static CauldronListener listener;
|
||||
private static ServerMock server;
|
||||
|
||||
@BeforeAll
|
||||
public static void load() {
|
||||
server = MockBukkit.mock();
|
||||
plugin = MockBukkit.load(SlimefunPlugin.class);
|
||||
listener = new CauldronListener(plugin);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void unload() {
|
||||
MockBukkit.unmock();
|
||||
}
|
||||
|
||||
private PlayerInteractEvent mockCauldronEvent(ItemStack item) {
|
||||
Player player = server.addPlayer();
|
||||
Block block = new BlockMock(Material.CAULDRON);
|
||||
PlayerInteractEvent event = new PlayerInteractEvent(player, Action.RIGHT_CLICK_BLOCK, item, block, BlockFace.UP, EquipmentSlot.HAND);
|
||||
|
||||
listener.onCauldronUse(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Cauldron handling null")
|
||||
void testCauldronWithNull() {
|
||||
PlayerInteractEvent event = mockCauldronEvent(null);
|
||||
Assertions.assertEquals(Result.DEFAULT, event.useItemInHand());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Cauldron working as normal with unrelated items")
|
||||
void testCauldronWithNormalItem() {
|
||||
PlayerInteractEvent event = mockCauldronEvent(new ItemStack(Material.GOLD_BLOCK));
|
||||
Assertions.assertEquals(Result.DEFAULT, event.useItemInHand());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Cauldron working as normal with normal leather armor")
|
||||
void testCauldronWithNormalLeatherArmor() {
|
||||
PlayerInteractEvent event = mockCauldronEvent(new ItemStack(Material.LEATHER_BOOTS));
|
||||
Assertions.assertEquals(Result.DEFAULT, event.useItemInHand());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Cauldron working as normal with non-leather slimefun items")
|
||||
void testCauldronWithSlimefunItem() {
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CAULDRON_TEST_MOCK", new CustomItem(Material.GOLDEN_APPLE, "&6Mock"));
|
||||
item.register(plugin);
|
||||
|
||||
PlayerInteractEvent event = mockCauldronEvent(item.getItem());
|
||||
Assertions.assertEquals(Result.DEFAULT, event.useItemInHand());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Cauldron being cancelled with slimefun leather armor")
|
||||
void testCauldronWithSlimefunLeatherArmor() {
|
||||
SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "CAULDRON_TEST_MOCK_LEATHER", new CustomItem(Material.LEATHER_BOOTS, "&6Mock"));
|
||||
item.register(plugin);
|
||||
|
||||
PlayerInteractEvent event = mockCauldronEvent(item.getItem());
|
||||
Assertions.assertEquals(Result.DENY, event.useItemInHand());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Test Cauldron working as normal with vanilla slimefun leather armor")
|
||||
void testCauldronWithVanillaLeatherArmor() {
|
||||
VanillaItem item = TestUtilities.mockVanillaItem(plugin, Material.LEATHER_CHESTPLATE, true);
|
||||
item.register(plugin);
|
||||
|
||||
PlayerInteractEvent event = mockCauldronEvent(item.getItem());
|
||||
Assertions.assertEquals(Result.DEFAULT, event.useItemInHand());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user