From bdbb4c510bd96c97062e184a5112f566e97dfb46 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 13 May 2021 23:47:10 +0200 Subject: [PATCH] Remove code duplication --- .../fightsystem/event/HellsBells.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index e4b1767..56816c0 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -42,6 +42,21 @@ public class HellsBells { this.dz = dz; this.zLength = zLength; } + + Direction other() { + switch (this) { + case NORTH: + return EAST; + case SOUTH: + return WEST; + case EAST: + return NORTH; + case WEST: + return SOUTH; + default: + return this; + } + } } public HellsBells() { @@ -141,19 +156,20 @@ public class HellsBells { new BukkitRunnable() { @Override public void run() { - for (int z = 0; z < width; z++) { + for (int w = 0; w < width; w++) { if (direction == Direction.NORTH || direction == Direction.WEST) { - world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); } else { - world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); - world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT); + world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT); } } - if (length.decrementAndGet() == 0) { + length.decrementAndGet(); + if (length.decrementAndGet() <= 0) { cancel(); } }