SteamWar/FightSystem
Archiviert
13
1

HellsBells #275

Manuell gemergt
Lixfel hat 19 Commits von Hells_bells nach master 2021-06-25 07:17:45 +02:00 zusammengeführt
Nur Änderungen aus Commit 9d21214204 werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -30,13 +30,12 @@ import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import org.bukkit.scheduler.BukkitTask;
public class HellsBells { public class HellsBells {
@ -44,23 +43,21 @@ public class HellsBells {
public static final Random random = new Random(); public static final Random random = new Random();
private enum Direction { private enum Direction {
NORTH(0, 0, 1, true), NORTH(0, 0, 1),
SOUTH(0, 0, -1, true), SOUTH(0, 0, -1),
EAST(1, 0, 0, false), EAST(1, 0, 0),
WEST(-1, 0, 0, false); WEST(-1, 0, 0);
static final Direction[] DIRECTIONS = values(); static final Direction[] DIRECTIONS = values();
int dx; int dx;
int dy; int dy;
int dz; int dz;
boolean zLength;
Direction(int dx, int dy, int dz, boolean zLength) { Direction(int dx, int dy, int dz) {
this.dx = dx; this.dx = dx;
this.dy = dy; this.dy = dy;
this.dz = dz; this.dz = dz;
this.zLength = zLength;
} }
public static Direction getRandom() { public static Direction getRandom() {
@ -81,6 +78,18 @@ public class HellsBells {
return this; 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() { public HellsBells() {
@ -117,16 +126,16 @@ public class HellsBells {
public void drop() { public void drop() {
Direction direction = Direction.getRandom(); 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 width = 5 + random.nextInt(5);
int xOffset = getWidthStart(direction.zLength ? xLength : zLength, direction.zLength ? length.get() : width); int xOffset = getWidthStart(direction.getLength(xLength, zLength), direction.getLength(length.get(), width));
int zOffset = getLengthStart(direction.zLength ? zLength : xLength, direction.zLength ? width : length.get()); int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get()));
int yOffset = getHeightStart(); int yOffset = getHeightStart();
Point redStart; Point redStart;
Point blueStart; 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); 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); blueStart = new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset);
} else { } else {
@ -136,7 +145,7 @@ public class HellsBells {
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> { currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
for (int w = 0; w < width; w++) { 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(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); 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);