diff --git a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java index 02b5ccc..353c2b4 100644 --- a/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java +++ b/FightSystem_Main/src/de/steamwar/fightsystem/event/HellsBells.java @@ -30,13 +30,12 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.EntityType; -import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; -import org.bukkit.scheduler.BukkitTask; public class HellsBells { @@ -44,23 +43,21 @@ public class HellsBells { public static final Random random = new Random(); private enum Direction { - NORTH(0, 0, 1, true), - SOUTH(0, 0, -1, true), - EAST(1, 0, 0, false), - WEST(-1, 0, 0, false); + NORTH(0, 0, 1), + SOUTH(0, 0, -1), + EAST(1, 0, 0), + WEST(-1, 0, 0); static final Direction[] DIRECTIONS = values(); int dx; int dy; int dz; - boolean zLength; - Direction(int dx, int dy, int dz, boolean zLength) { + Direction(int dx, int dy, int dz) { this.dx = dx; this.dy = dy; this.dz = dz; - this.zLength = zLength; } public static Direction getRandom() { @@ -81,6 +78,18 @@ public class HellsBells { return this; } } + + public int getLength(int length1, int length2) { + return isNorthOrSouth() ? length1 : length2; + } + + public boolean isNorthOrSouth() { + return this == NORTH || this == SOUTH; + } + + public boolean isNorthOrWest() { + return this == NORTH || this == WEST; + } } public HellsBells() { @@ -117,16 +126,16 @@ public class HellsBells { public void drop() { Direction direction = Direction.getRandom(); - AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10)); + AtomicInteger length = new AtomicInteger(10 + random.nextInt(direction.getLength(zLength, xLength) - 10)); int width = 5 + random.nextInt(5); - int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); - int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); + int xOffset = getWidthStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width)); + int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get())); int yOffset = getHeightStart(); Point redStart; Point blueStart; - if (direction == Direction.NORTH || direction == Direction.WEST) { + if (direction.isNorthOrWest()) { redStart = new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset); blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset); } else { @@ -136,7 +145,7 @@ public class HellsBells { currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { for (int w = 0; w < width; w++) { - if (direction == Direction.NORTH || direction == Direction.WEST) { + if (direction.isNorthOrWest()) { 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() + w * direction.other().dx, 0, direction.dz * length.get() + w * direction.other().dz), EntityType.PRIMED_TNT);