mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Fixed Unit Tests for Climbing Pick
This commit is contained in:
parent
9e92f64222
commit
89a5db2593
@ -149,8 +149,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
if (!event.isCancelled()) {
|
||||
Slimefun.runSync(() -> users.remove(p.getUniqueId()), 3L);
|
||||
p.setVelocity(event.getVelocity());
|
||||
p.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
|
||||
swing(p, hand, item);
|
||||
swing(p, block, hand, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,27 +158,32 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
}
|
||||
}
|
||||
|
||||
private void swing(Player p, EquipmentSlot hand, ItemStack item) {
|
||||
private void swing(Player p, Block b, EquipmentSlot hand, ItemStack item) {
|
||||
if (p.getGameMode() != GameMode.CREATIVE) {
|
||||
if (isDualWieldingEnabled()) {
|
||||
if (ThreadLocalRandom.current().nextBoolean()) {
|
||||
damageItem(p, p.getInventory().getItemInMainHand());
|
||||
playSwingAnimation(p, EquipmentSlot.HAND);
|
||||
playAnimation(p, b, EquipmentSlot.HAND);
|
||||
}
|
||||
else {
|
||||
damageItem(p, p.getInventory().getItemInOffHand());
|
||||
playSwingAnimation(p, EquipmentSlot.OFF_HAND);
|
||||
playAnimation(p, b, EquipmentSlot.OFF_HAND);
|
||||
}
|
||||
}
|
||||
else {
|
||||
damageItem(p, item);
|
||||
playSwingAnimation(p, hand);
|
||||
playAnimation(p, b, hand);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void playSwingAnimation(Player p, EquipmentSlot hand) {
|
||||
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||
private void playAnimation(Player p, Block b, EquipmentSlot hand) {
|
||||
MinecraftVersion version = SlimefunPlugin.getMinecraftVersion();
|
||||
|
||||
if (version != MinecraftVersion.UNIT_TEST) {
|
||||
p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
|
||||
|
||||
if (version.isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
|
||||
if (hand == EquipmentSlot.HAND) {
|
||||
p.swingMainHand();
|
||||
}
|
||||
@ -188,6 +192,7 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable() {
|
||||
|
@ -2,11 +2,12 @@ package io.github.thebusybiscuit.slimefun4.testing.tests.items.implementations.t
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.BlockFace;
|
||||
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.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
@ -22,7 +23,7 @@ import io.github.thebusybiscuit.slimefun4.testing.interfaces.SlimefunItemTest;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class TestClimbingPick implements SlimefunItemTest<ClimbingPick> {
|
||||
class TestClimbingPick implements SlimefunItemTest<ClimbingPick> {
|
||||
|
||||
private static ServerMock server;
|
||||
private static SlimefunPlugin plugin;
|
||||
@ -42,28 +43,40 @@ public class TestClimbingPick implements SlimefunItemTest<ClimbingPick> {
|
||||
@Override
|
||||
public ClimbingPick registerSlimefunItem(SlimefunPlugin plugin, String id) {
|
||||
SlimefunItemStack item = new SlimefunItemStack(id, Material.IRON_PICKAXE, "&5Test Pick");
|
||||
ClimbingPick pick = new ClimbingPick(TestUtilities.getCategory(plugin, "climbing_pick"), item, RecipeType.NULL, new ItemStack[9]);
|
||||
|
||||
ClimbingPick pick = new ClimbingPick(TestUtilities.getCategory(plugin, "climbing_pick"), item, RecipeType.NULL, new ItemStack[9]) {
|
||||
|
||||
@Override
|
||||
public boolean isDualWieldingEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
pick.register(plugin);
|
||||
return pick;
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@DisplayName("Test Climbing Pick on various Block Faces")
|
||||
@EnumSource(value = BlockFace.class)
|
||||
public void testItemUse(BlockFace face) {
|
||||
void testItemUse(BlockFace face) {
|
||||
server.getPluginManager().clearEvents();
|
||||
PlayerMock player = server.addPlayer();
|
||||
ClimbingPick pick = registerSlimefunItem(plugin, "TEST_CLIMBING_PICK_" + face.name());
|
||||
Location blockLocation = new Location(player.getLocation().getWorld(), player.getLocation().getBlockX() + 1, player.getLocation().getBlockY(), player.getLocation().getBlockZ());
|
||||
|
||||
boolean shouldCancel = face == BlockFace.DOWN || face == BlockFace.UP;
|
||||
boolean shouldFireEvent = face != BlockFace.DOWN && face != BlockFace.UP;
|
||||
|
||||
BlockMock block1 = new BlockMock(Material.STONE, blockLocation);
|
||||
BlockMock block1 = new BlockMock(Material.ICE, blockLocation);
|
||||
simulateRightClickBlock(player, pick, block1, face);
|
||||
server.getPluginManager().assertEventFired(ClimbingPickLaunchEvent.class);
|
||||
if (!shouldCancel) player.assertSoundHeard(Sound.ENTITY_ENDERMAN_TELEPORT);
|
||||
|
||||
BlockMock block2 = new BlockMock(Material.DIRT, blockLocation);
|
||||
simulateRightClickBlock(player, pick, block2, face);
|
||||
if (shouldFireEvent) {
|
||||
server.getPluginManager().assertEventFired(ClimbingPickLaunchEvent.class);
|
||||
if (!shouldCancel) player.assertSoundHeard(Sound.ENTITY_ENDERMAN_TELEPORT);
|
||||
Assertions.assertTrue(player.getVelocity().length() > 0);
|
||||
}
|
||||
else {
|
||||
Assertions.assertEquals(0, player.getVelocity().length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user