From ab8d9c13f5e6044cc73134c2b92dcd12abd8bfa4 Mon Sep 17 00:00:00 2001 From: Joseph Hale Date: Sat, 14 Aug 2021 17:26:48 -0700 Subject: [PATCH] Refactor Utilities Package The `util` package's main class `Utilities` was starting to get large due to the many different types of methods contained within it. This commit splits those methods into more classes with names that are more semantically meaningful. --- .../jhale1805/powerarrow/ExplosiveArrow.java | 4 +- .../jhale1805/powerarrow/ForestFireArrow.java | 7 +- .../github/jhale1805/powerarrow/NetArrow.java | 7 +- .../jhale1805/powerarrow/SwapArrow.java | 4 +- .../io/github/jhale1805/util/BlockTools.java | 74 ++++++++++++ .../io/github/jhale1805/util/EventTools.java | 27 +++++ .../io/github/jhale1805/util/Incrementor.java | 60 ++++++++++ .../github/jhale1805/util/LocationTools.java | 23 ++++ .../github/jhale1805/util/ParticleTools.java | 28 +++++ .../io/github/jhale1805/util/Utilities.java | 106 ------------------ .../powerarrow/ExplosiveArrowTest.java | 10 +- .../powerarrow/ForestFireArrowTest.java | 18 +-- .../jhale1805/powerarrow/NetArrowTest.java | 18 +-- .../jhale1805/powerarrow/SwapArrowTest.java | 10 +- 14 files changed, 252 insertions(+), 144 deletions(-) create mode 100644 src/main/java/io/github/jhale1805/util/BlockTools.java create mode 100644 src/main/java/io/github/jhale1805/util/EventTools.java create mode 100644 src/main/java/io/github/jhale1805/util/Incrementor.java create mode 100644 src/main/java/io/github/jhale1805/util/LocationTools.java create mode 100644 src/main/java/io/github/jhale1805/util/ParticleTools.java delete mode 100644 src/main/java/io/github/jhale1805/util/Utilities.java diff --git a/src/main/java/io/github/jhale1805/powerarrow/ExplosiveArrow.java b/src/main/java/io/github/jhale1805/powerarrow/ExplosiveArrow.java index 80f0b8c..79bab51 100644 --- a/src/main/java/io/github/jhale1805/powerarrow/ExplosiveArrow.java +++ b/src/main/java/io/github/jhale1805/powerarrow/ExplosiveArrow.java @@ -6,7 +6,7 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapelessRecipe; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.EventTools; public class ExplosiveArrow extends PowerArrow { @@ -45,7 +45,7 @@ public class ExplosiveArrow extends PowerArrow { if (!(event.getEntity().getFireTicks() > 0)) return; - Location impactLocation = Utilities.getImpactLocation(event); + Location impactLocation = EventTools.getImpactLocation(event); if (impactLocation != null) { event.getEntity().getWorld().createExplosion( impactLocation, // Cause the explosion where the arrow hit. diff --git a/src/main/java/io/github/jhale1805/powerarrow/ForestFireArrow.java b/src/main/java/io/github/jhale1805/powerarrow/ForestFireArrow.java index b879219..8e2c366 100644 --- a/src/main/java/io/github/jhale1805/powerarrow/ForestFireArrow.java +++ b/src/main/java/io/github/jhale1805/powerarrow/ForestFireArrow.java @@ -7,7 +7,8 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.BlockTools; +import io.github.jhale1805.util.EventTools; public class ForestFireArrow extends PowerArrow { @@ -49,9 +50,9 @@ public class ForestFireArrow extends PowerArrow { @Override protected void onThisProjectileHit(ProjectileHitEvent event) { - Location impactLocation = Utilities.getImpactLocation(event); + Location impactLocation = EventTools.getImpactLocation(event); if (impactLocation != null) { - Utilities.replaceAirWith(Material.FIRE, impactLocation, 1); + BlockTools.replaceAirWith(Material.FIRE, impactLocation, 1); } } diff --git a/src/main/java/io/github/jhale1805/powerarrow/NetArrow.java b/src/main/java/io/github/jhale1805/powerarrow/NetArrow.java index 95dff3c..56c308d 100644 --- a/src/main/java/io/github/jhale1805/powerarrow/NetArrow.java +++ b/src/main/java/io/github/jhale1805/powerarrow/NetArrow.java @@ -7,7 +7,8 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapedRecipe; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.BlockTools; +import io.github.jhale1805.util.EventTools; public class NetArrow extends PowerArrow { @@ -48,9 +49,9 @@ public class NetArrow extends PowerArrow { @Override protected void onThisProjectileHit(ProjectileHitEvent event) { - Location impactLocation = Utilities.getImpactLocation(event); + Location impactLocation = EventTools.getImpactLocation(event); if (impactLocation != null) { - Utilities.replaceAirWith(Material.COBWEB, impactLocation, 0.5); + BlockTools.replaceAirWith(Material.COBWEB, impactLocation, 0.5); } } diff --git a/src/main/java/io/github/jhale1805/powerarrow/SwapArrow.java b/src/main/java/io/github/jhale1805/powerarrow/SwapArrow.java index 407a6cc..1d16dad 100644 --- a/src/main/java/io/github/jhale1805/powerarrow/SwapArrow.java +++ b/src/main/java/io/github/jhale1805/powerarrow/SwapArrow.java @@ -9,7 +9,7 @@ import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.Recipe; import org.bukkit.inventory.ShapelessRecipe; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.LocationTools; public class SwapArrow extends PowerArrow { @@ -56,7 +56,7 @@ public class SwapArrow extends PowerArrow { if (hitEntity != null && hitEntity instanceof LivingEntity && shooter != null) { - Utilities.swapEntityLocations(shooter, hitEntity); + LocationTools.swapEntities(shooter, hitEntity); shooter.damage(TELEPORT_DAMAGE); ((LivingEntity) hitEntity).damage(TELEPORT_DAMAGE); } diff --git a/src/main/java/io/github/jhale1805/util/BlockTools.java b/src/main/java/io/github/jhale1805/util/BlockTools.java new file mode 100644 index 0000000..6d535b6 --- /dev/null +++ b/src/main/java/io/github/jhale1805/util/BlockTools.java @@ -0,0 +1,74 @@ +package io.github.jhale1805.util; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; + +public class BlockTools { + + public static void replaceAll( + Material originalMaterial, + Material newMaterial, + Location loc1, + Location loc2) { + + // Validate parameters + if (newMaterial == null) throw new IllegalArgumentException("You must specify a newMaterial!"); + if (loc1 == null || loc2 == null) throw new IllegalArgumentException("You must specify a complete bounding box!"); + if (!loc1.getWorld().equals(loc2.getWorld())) throw new IllegalArgumentException("loc1 and loc2 must be in the same world!"); + + // Replace the blocks + for (Integer x : new Incrementor(loc1.getBlockX(), loc2.getBlockX())) { + for (Integer y : new Incrementor(loc1.getBlockY(), loc2.getBlockY())) { + for (Integer z : new Incrementor(loc1.getBlockZ(), loc2.getBlockZ())) { + Location toCheck = new Location(loc1.getWorld(), x, y, z); + Block toReplace = loc1.getWorld().getBlockAt(toCheck); + if (originalMaterial == null || toReplace.getType() == originalMaterial) { + toReplace.setType(newMaterial); + } + } + } + } + } + + /** + * Replaces all Air blocks within the specified (cubic) radius of the + * given centerPoint with the specified Material. + * + * @param material The material with which to replace the air. + * @param centerPoint The centerpoint of the scan for air to replace + * @param radius The radius around the centerpoint in which to look for air + * blocks to replace. Recommended max is 3 (this isn't WorldEdit!) + * Expected to be positive, but absolute valued in case you try to + * be tricky :D + */ + public static void replaceAirWith(Material material, Location centerPoint, double radius) { + // Validate parameters + if (material == null) { + throw new IllegalArgumentException("You must specify a Material!"); + } + if (centerPoint == null) { + throw new IllegalArgumentException("You must specify a centerPoint!"); + } + radius = Math.abs(radius); + + // Replace the blocks + for (double dx = -radius; dx <= radius; dx++) { + for (double dy = -radius; dy <= radius ; dy++) { + for (double dz = -radius; dz <= radius; dz++) { + Location toCheck = new Location( + centerPoint.getWorld(), + centerPoint.getX() + dx, + centerPoint.getY() + dy, + centerPoint.getZ() + dz + ); + Block toReplace = centerPoint.getWorld().getBlockAt(toCheck); + if (toReplace.getType() == Material.AIR) { + toReplace.setType(material); + } + } + } + } + } + +} diff --git a/src/main/java/io/github/jhale1805/util/EventTools.java b/src/main/java/io/github/jhale1805/util/EventTools.java new file mode 100644 index 0000000..c8a68aa --- /dev/null +++ b/src/main/java/io/github/jhale1805/util/EventTools.java @@ -0,0 +1,27 @@ +package io.github.jhale1805.util; + +import org.bukkit.Location; +import org.bukkit.event.entity.ProjectileHitEvent; + +public class EventTools { + + /** + * Returns the Location where the projectile hit. + * + * Abstracts out the complexity of determining whether the projectile hit + * a block or an Entity. + * + * @param event The event from which you want the impact location. + * @return The Location where the projectile hit. + */ + public static Location getImpactLocation(ProjectileHitEvent event) { + Location loc = null; + if (event.getHitBlock() != null) { + loc = event.getHitBlock().getRelative(event.getHitBlockFace()).getLocation(); + } else if (event.getHitEntity() != null) { + loc = event.getHitEntity().getLocation(); + } + return loc; + } + +} diff --git a/src/main/java/io/github/jhale1805/util/Incrementor.java b/src/main/java/io/github/jhale1805/util/Incrementor.java new file mode 100644 index 0000000..cd88ef8 --- /dev/null +++ b/src/main/java/io/github/jhale1805/util/Incrementor.java @@ -0,0 +1,60 @@ +package io.github.jhale1805.util; + +import java.util.Iterator; + +/** + * A utility class that can iterate between any two integers. + */ +public class Incrementor implements Iterable { + + private Integer start; + private Integer end; + + private class NumberIterator implements Iterator { + + private Integer start; + private Integer current; + private Integer end; + + public NumberIterator(Integer start, Integer end) { + this.start = start; + this.current = start; + this.end = end; + } + + @Override + public boolean hasNext() { + if (start < end) return current - end > 1; + else if (start > end) return end - current > 1; + else return false; + } + + @Override + public Integer next() { + int out = current; + + if (current < end) current++; + else if (current > end) current--; + else; // Nothing to increment towards. + + return out; + } + + } + + /** + * Standard constructor + * @param start The initial value of the iteration sequence. + * @param end The ending value of the iteration sequence. + */ + public Incrementor(Integer start, Integer end) { + this.start = start; + this.end = end; + } + + @Override + public Iterator iterator() { + return new NumberIterator(start, end); + } + +} diff --git a/src/main/java/io/github/jhale1805/util/LocationTools.java b/src/main/java/io/github/jhale1805/util/LocationTools.java new file mode 100644 index 0000000..4a588a0 --- /dev/null +++ b/src/main/java/io/github/jhale1805/util/LocationTools.java @@ -0,0 +1,23 @@ +package io.github.jhale1805.util; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; + +public class LocationTools { + + /** + * Swaps the location of the two given entities. + * + * @param e1 The entity to teleport to the position of e2. + * @param e2 The entity to teleport to the position of e1. + */ + public static void swapEntities(Entity e1, Entity e2) { + if (e1 != null || e2 != null) { + Location loc1 = e1.getLocation(); + Location loc2 = e2.getLocation(); + e1.teleport(loc2); + e2.teleport(loc1); + } + } + +} diff --git a/src/main/java/io/github/jhale1805/util/ParticleTools.java b/src/main/java/io/github/jhale1805/util/ParticleTools.java new file mode 100644 index 0000000..a365322 --- /dev/null +++ b/src/main/java/io/github/jhale1805/util/ParticleTools.java @@ -0,0 +1,28 @@ +package io.github.jhale1805.util; + +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + +public class ParticleTools { + + /** + * Draws particles of the given type along the line specified by + * `from` to `to`. + * + * @param particle The particle to draw + * @param from The start point of the line of particles + * @param to The end point of the line of particles + */ + public static void drawParticles(Particle particle, Location from, Location to){ + if (!from.getWorld().equals(to.getWorld())) return; + + Vector direction = to.toVector().subtract(from.toVector()).normalize().multiply(0.4); + Location particleLocation = from.clone(); + while(particleLocation.distanceSquared(to) > 1){ + particleLocation = particleLocation.add(direction); + particleLocation.getWorld().spawnParticle(particle, particleLocation, 1); + } + } + +} diff --git a/src/main/java/io/github/jhale1805/util/Utilities.java b/src/main/java/io/github/jhale1805/util/Utilities.java deleted file mode 100644 index cfebfd6..0000000 --- a/src/main/java/io/github/jhale1805/util/Utilities.java +++ /dev/null @@ -1,106 +0,0 @@ -package io.github.jhale1805.util; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Particle; -import org.bukkit.block.Block; -import org.bukkit.entity.Entity; -import org.bukkit.event.entity.ProjectileHitEvent; -import org.bukkit.util.Vector; - -public class Utilities { - - /** - * Draws particles of the given type along the line specified by - * `from` to `to`. - * - * @param particle The particle to draw - * @param from The start point of the line of particles - * @param to The end point of the line of particles - */ - public static void drawParticles(Particle particle, Location from, Location to){ - if (!from.getWorld().equals(to.getWorld())) return; - - Vector direction = to.toVector().subtract(from.toVector()).normalize().multiply(0.4); - Location particleLocation = from.clone(); - while(particleLocation.distanceSquared(to) > 1){ - particleLocation = particleLocation.add(direction); - particleLocation.getWorld().spawnParticle(particle, particleLocation, 1); - } - } - - /** - * Returns the Location where the projectile hit. - * - * Abstracts out the complexity of determining whether the projectile hit - * a block or an Entity. - * - * @param event The event from which you want the impact location. - * @return The Location where the projectile hit. - */ - public static Location getImpactLocation(ProjectileHitEvent event) { - Location loc = null; - if (event.getHitBlock() != null) { - loc = event.getHitBlock().getRelative(event.getHitBlockFace()).getLocation(); - } else if (event.getHitEntity() != null) { - loc = event.getHitEntity().getLocation(); - } - return loc; - } - - /** - * Replaces all Air blocks within the specified (cubic) radius of the - * given centerPoint with the specified Material. - * - * @param material The material with which to replace the air. - * @param centerPoint The centerpoint of the scan for air to replace - * @param radius The radius around the centerpoint in which to look for air - * blocks to replace. Recommended max is 3 (this isn't WorldEdit!) - * Expected to be positive, but absolute valued in case you try to - * be tricky :D - */ - public static void replaceAirWith(Material material, Location centerPoint, double radius) { - // Validate parameters - if (material == null) { - throw new IllegalArgumentException("You must specify a Material!"); - } - if (centerPoint == null) { - throw new IllegalArgumentException("You must specify a centerPoint!"); - } - radius = Math.abs(radius); - - // Replace the blocks - for (double dx = -radius; dx <= radius; dx++) { - for (double dy = -radius; dy <= radius ; dy++) { - for (double dz = -radius; dz <= radius; dz++) { - Location toCheck = new Location( - centerPoint.getWorld(), - centerPoint.getX() + dx, - centerPoint.getY() + dy, - centerPoint.getZ() + dz - ); - Block toReplace = centerPoint.getWorld().getBlockAt(toCheck); - if (toReplace.getType() == Material.AIR) { - toReplace.setType(material); - } - } - } - } - } - - /** - * Swaps the location of the two given entities. - * - * @param e1 The entity to teleport to the position of e2. - * @param e2 The entity to teleport to the position of e1. - */ - public static void swapEntityLocations(Entity e1, Entity e2) { - if (e1 != null || e2 != null) { - Location loc1 = e1.getLocation(); - Location loc2 = e2.getLocation(); - e1.teleport(loc2); - e2.teleport(loc1); - } - } - -} diff --git a/src/test/java/io/github/jhale1805/powerarrow/ExplosiveArrowTest.java b/src/test/java/io/github/jhale1805/powerarrow/ExplosiveArrowTest.java index 262f26a..22d4e8b 100644 --- a/src/test/java/io/github/jhale1805/powerarrow/ExplosiveArrowTest.java +++ b/src/test/java/io/github/jhale1805/powerarrow/ExplosiveArrowTest.java @@ -4,7 +4,7 @@ package io.github.jhale1805.powerarrow; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.jhale1805.PowerProjectilePlugin; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.EventTools; import org.junit.*; @@ -58,8 +58,8 @@ public class ExplosiveArrowTest { ProjectileHitEvent mockEvent = mock(ProjectileHitEvent.class, RETURNS_DEEP_STUBS); when(mockEvent.getEntity().getFireTicks()).thenReturn(10); // Execute test - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { - mockUtils.when(() -> Utilities.getImpactLocation(any(ProjectileHitEvent.class))) + try (MockedStatic mockUtils = mockStatic(EventTools.class)) { + mockUtils.when(() -> EventTools.getImpactLocation(any(ProjectileHitEvent.class))) .thenReturn(null); new ExplosiveArrow().onThisProjectileHit(mockEvent); // Verify that none of the createExplostion methods were called: https://stackoverflow.com/a/46038313/14765128 @@ -75,8 +75,8 @@ public class ExplosiveArrowTest { Location mockLocation = mock(Location.class); when(mockEvent.getEntity().getFireTicks()).thenReturn(10); // Execute test - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { - mockUtils.when(() -> Utilities.getImpactLocation(any(ProjectileHitEvent.class))) + try (MockedStatic mockUtils = mockStatic(EventTools.class)) { + mockUtils.when(() -> EventTools.getImpactLocation(any(ProjectileHitEvent.class))) .thenReturn(mockLocation); new ExplosiveArrow().onThisProjectileHit(mockEvent); // Verify results diff --git a/src/test/java/io/github/jhale1805/powerarrow/ForestFireArrowTest.java b/src/test/java/io/github/jhale1805/powerarrow/ForestFireArrowTest.java index 61f643a..5adee79 100644 --- a/src/test/java/io/github/jhale1805/powerarrow/ForestFireArrowTest.java +++ b/src/test/java/io/github/jhale1805/powerarrow/ForestFireArrowTest.java @@ -4,7 +4,8 @@ package io.github.jhale1805.powerarrow; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.jhale1805.PowerProjectilePlugin; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.BlockTools; +import io.github.jhale1805.util.EventTools; import org.junit.*; @@ -45,14 +46,14 @@ public class ForestFireArrowTest { public void test_onThisProjectileHit_hitLocation() { // Setup mocks ProjectileHitEvent mockEvent = mock(ProjectileHitEvent.class, RETURNS_DEEP_STUBS); + Location mockHitLocation = mock(Location.class); when(mockEvent.getHitBlock()).thenReturn(null); + when(mockEvent.getHitEntity().getLocation()).thenReturn(mockHitLocation); // Execute test - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { - mockUtils.when(() -> Utilities.getImpactLocation(any(ProjectileHitEvent.class))) - .thenReturn(mock(Location.class)); + try (MockedStatic mockBlockTools = mockStatic(BlockTools.class)) { new ForestFireArrow().onThisProjectileHit(mockEvent); // Verify results - mockUtils.verify(() -> Utilities.replaceAirWith( + mockBlockTools.verify(() -> BlockTools.replaceAirWith( eq(Material.FIRE), any(Location.class), anyDouble())); } } @@ -62,13 +63,12 @@ public class ForestFireArrowTest { // Setup mocks ProjectileHitEvent mockEvent = mock(ProjectileHitEvent.class, RETURNS_DEEP_STUBS); when(mockEvent.getHitBlock()).thenReturn(null); + when(mockEvent.getHitEntity()).thenReturn(null); // Execute test - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { - mockUtils.when(() -> Utilities.getImpactLocation(any(ProjectileHitEvent.class))) - .thenReturn(null); + try (MockedStatic mockBlockTools = mockStatic(BlockTools.class)) { new ForestFireArrow().onThisProjectileHit(mockEvent); // Verify results - mockUtils.verify(() -> Utilities.replaceAirWith( + mockBlockTools.verify(() -> BlockTools.replaceAirWith( any(Material.class), any(Location.class), anyDouble()), never()); } diff --git a/src/test/java/io/github/jhale1805/powerarrow/NetArrowTest.java b/src/test/java/io/github/jhale1805/powerarrow/NetArrowTest.java index 49af0cc..e30f732 100644 --- a/src/test/java/io/github/jhale1805/powerarrow/NetArrowTest.java +++ b/src/test/java/io/github/jhale1805/powerarrow/NetArrowTest.java @@ -4,7 +4,8 @@ package io.github.jhale1805.powerarrow; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.jhale1805.PowerProjectilePlugin; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.BlockTools; +import io.github.jhale1805.util.EventTools; import org.junit.*; import org.mockito.MockedStatic; @@ -45,14 +46,14 @@ public class NetArrowTest { public void test_onThisProjectileHit_hitLocation() { // Setup mocks ProjectileHitEvent mockEvent = mock(ProjectileHitEvent.class, RETURNS_DEEP_STUBS); + Location mockHitLocation = mock(Location.class); when(mockEvent.getHitBlock()).thenReturn(null); + when(mockEvent.getHitEntity().getLocation()).thenReturn(mockHitLocation); // Execute test - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { - mockUtils.when(() -> Utilities.getImpactLocation(any(ProjectileHitEvent.class))) - .thenReturn(mock(Location.class)); + try (MockedStatic mockUtils = mockStatic(BlockTools.class)) { new NetArrow().onThisProjectileHit(mockEvent); // Verify results - mockUtils.verify(() -> Utilities.replaceAirWith( + mockUtils.verify(() -> BlockTools.replaceAirWith( eq(Material.COBWEB), any(Location.class), anyDouble())); } } @@ -62,13 +63,12 @@ public class NetArrowTest { // Setup mocks ProjectileHitEvent mockEvent = mock(ProjectileHitEvent.class, RETURNS_DEEP_STUBS); when(mockEvent.getHitBlock()).thenReturn(null); + when(mockEvent.getHitEntity()).thenReturn(null); // Execute test - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { - mockUtils.when(() -> Utilities.getImpactLocation(any(ProjectileHitEvent.class))) - .thenReturn(null); + try (MockedStatic mockUtils = mockStatic(BlockTools.class)) { new NetArrow().onThisProjectileHit(mockEvent); // Verify results - mockUtils.verify(() -> Utilities.replaceAirWith( + mockUtils.verify(() -> BlockTools.replaceAirWith( any(Material.class), any(Location.class), anyDouble()), never()); } diff --git a/src/test/java/io/github/jhale1805/powerarrow/SwapArrowTest.java b/src/test/java/io/github/jhale1805/powerarrow/SwapArrowTest.java index 7e80a04..2d981f4 100644 --- a/src/test/java/io/github/jhale1805/powerarrow/SwapArrowTest.java +++ b/src/test/java/io/github/jhale1805/powerarrow/SwapArrowTest.java @@ -3,7 +3,7 @@ package io.github.jhale1805.powerarrow; import be.seeseemelk.mockbukkit.MockBukkit; import be.seeseemelk.mockbukkit.ServerMock; import io.github.jhale1805.PowerProjectilePlugin; -import io.github.jhale1805.util.Utilities; +import io.github.jhale1805.util.LocationTools; import org.junit.*; import org.mockito.MockedStatic; @@ -49,11 +49,11 @@ public class SwapArrowTest { LivingEntity mockHitEntity = mock(LivingEntity.class); when(mockEvent.getEntity().getShooter()).thenReturn(mockPlayer); when(mockEvent.getHitEntity()).thenReturn(mockHitEntity); - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { + try (MockedStatic mockUtils = mockStatic(LocationTools.class)) { // Execute test new SwapArrow().onThisProjectileHit(mockEvent); // Verify results - mockUtils.verify(() -> Utilities.swapEntityLocations(mockPlayer, mockHitEntity)); + mockUtils.verify(() -> LocationTools.swapEntities(mockPlayer, mockHitEntity)); } verify(mockPlayer).damage(anyDouble()); verify(mockHitEntity).damage(anyDouble()); @@ -67,12 +67,12 @@ public class SwapArrowTest { Entity mockHitEntity = mock(Entity.class); when(mockEvent.getHitEntity()).thenReturn(mockHitEntity); when(mockEvent.getEntity().getShooter()).thenReturn(mockPlayer); - try (MockedStatic mockUtils = mockStatic(Utilities.class)) { + try (MockedStatic mockUtils = mockStatic(LocationTools.class)) { // Execute test new SwapArrow().onThisProjectileHit(mockEvent); // Verify results mockUtils.verify(() -> - Utilities.swapEntityLocations( + LocationTools.swapEntities( any(Entity.class), any(Entity.class) ), never()); -- 2.51.2