SteamWar/FightSystem
Archiviert
13
1

Fix HellsBells direction code

Dieser Commit ist enthalten in:
yoyosource 2021-05-18 20:03:44 +02:00
Ursprung 25190098d6
Commit 9d21214204

Datei anzeigen

@ -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);