HellsBells #275
@ -42,59 +42,6 @@ public class HellsBells {
|
||||
|
||||
public static final Random random = new Random();
|
||||
|
||||
private enum Direction {
|
||||
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;
|
||||
|
||||
Direction(int dx, int dy, int dz) {
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
this.dz = dz;
|
||||
}
|
||||
|
||||
public static Direction getRandom() {
|
||||
return Direction.DIRECTIONS[random.nextInt(Direction.DIRECTIONS.length)];
|
||||
}
|
||||
|
||||
Direction other() {
|
||||
switch (this) {
|
||||
case NORTH:
|
||||
return EAST;
|
||||
case SOUTH:
|
||||
return WEST;
|
||||
case EAST:
|
||||
return NORTH;
|
||||
case WEST:
|
||||
return SOUTH;
|
||||
default:
|
||||
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() {
|
||||
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
|
||||
|
||||
private final World world = Bukkit.getWorlds().get(0);
|
||||
private final int xLength = Config.RedPasteRegion.getMaxX() - Config.RedPasteRegion.getMinX();
|
||||
private final int zLength = Config.RedPasteRegion.getMaxZ() - Config.RedPasteRegion.getMinZ();
|
||||
@ -108,13 +55,17 @@ public class HellsBells {
|
||||
"§cUnbekanntes Flugobjekt gesichtet, trifft in ca. einer Minute ein.",
|
||||
"§cFlugobjekt gesichtet. Ankunft in ca. einer Minute.",
|
||||
"§cBomber erschienen, Ankunft ca. eine Minute.");
|
||||
private final List<String> stateSwapMessages = Arrays.asList("§aDie Bomben fallen nun schneller.",
|
||||
"§aMehr Bomber im Anflug.",
|
||||
"§aZusätzliche Bomber gesichtet.",
|
||||
"§aDas Bombardement scheint sich zu erhöhen.");
|
||||
|
||||
public void startCountdown() {
|
||||
if (current == State.PRE) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + (startMessages.get(random.nextInt(startMessages.size()))));
|
||||
current = current.getNext();
|
||||
} else if (current != State.LAST && currentDrops >= current.SWITCH_AFTER) {
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDie Bomben fallen nun schneller.");
|
||||
Bukkit.broadcastMessage(FightSystem.PREFIX + (stateSwapMessages.get(random.nextInt(stateSwapMessages.size()))));
|
||||
currentDrops = 0;
|
||||
}
|
||||
|
||||
@ -132,14 +83,28 @@ public class HellsBells {
|
||||
int zOffset = getLengthStart(direction.getLength(zLength, xLength), direction.getLength(width, length.get()));
|
||||
int yOffset = getHeightStart();
|
||||
|
||||
Point redStart = direction.isNorthOrWest() ? new Point(Config.RedPasteRegion.getMaxX() - xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMaxZ() - zOffset) : new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset);
|
||||
Point blueStart = direction.isNorthOrWest() ? new Point(Config.BluePasteRegion.getMinX() + xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMinZ() + zOffset) : new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
|
||||
Point redStart;
|
||||
Point blueStart;
|
||||
|
||||
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 {
|
||||
redStart = new Point(Config.RedPasteRegion.getMinX() + xOffset, Config.RedExtendRegion.getMaxY() + yOffset, Config.RedPasteRegion.getMinZ() + zOffset);
|
||||
blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
|
||||
}
|
||||
|
||||
Zeanon markierte diese Unterhaltung als gelöst
|
||||
currentDropping = Bukkit.getScheduler().runTaskTimer(FightSystem.getPlugin(), () -> {
|
||||
int factor = direction.isNorthOrWest() ? 1 : -1;
|
||||
for (int w = 0; w < width; w++) {
|
||||
world.spawnEntity(redStart.subtractAndToLocation(world, (direction.dx * length.get() + w * direction.other().dx) * factor, 0, (direction.dz * length.get() + w * direction.other().dz) * factor), EntityType.PRIMED_TNT);
|
||||
world.spawnEntity(blueStart.addAndToLocation(world, (direction.dx * length.get() + w * direction.other().dx) * factor, 0, (direction.dz * length.get() + w * direction.other().dz) * factor), EntityType.PRIMED_TNT);
|
||||
if (direction.isNorthOrWest()) {
|
||||
world.spawnEntity(redStart.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (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);
|
||||
} else {
|
||||
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.addAndToLocation(world, -1 * (direction.dx * length.get() + w * direction.other().dx), 0, -1 * (direction.dz * length.get() + w * direction.other().dz)), EntityType.PRIMED_TNT);
|
||||
}
|
||||
}
|
||||
if (length.addAndGet(-2) <= 0) {
|
||||
currentDropping.cancel();
|
||||
@ -159,6 +124,20 @@ public class HellsBells {
|
||||
return 5 + random.nextInt(15);
|
||||
}
|
||||
|
||||
public HellsBells() {
|
||||
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
|
||||
@Override
|
||||
public void enable() {
|
||||
startCountdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
currentCountdown.disable();
|
||||
}
|
||||
}.register();
|
||||
}
|
||||
|
||||
class HellsBellsCountdown extends Countdown {
|
||||
|
||||
public HellsBellsCountdown(int time) {
|
||||
@ -178,18 +157,6 @@ public class HellsBells {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() {
|
||||
startCountdown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
currentCountdown.disable();
|
||||
}
|
||||
}.register();
|
||||
}
|
||||
|
||||
private static class Point {
|
||||
|
||||
private final int x;
|
||||
@ -205,10 +172,6 @@ public class HellsBells {
|
||||
public Location addAndToLocation(World world, int x, int y, int z) {
|
||||
return new Location(world, this.x + x, this.y + y, this.z + z); //NOSONAR
|
||||
}
|
||||
|
||||
public Location subtractAndToLocation(World world, int x, int y, int z) {
|
||||
return new Location(world, this.x - x, this.y - y, this.z - z); //NOSONAR
|
||||
}
|
||||
}
|
||||
|
||||
private enum State {
|
||||
@ -250,4 +213,53 @@ public class HellsBells {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum Direction {
|
||||
NORTH(0, 0, 1),
|
||||
SOUTH(0, 0, -1),
|
||||
EAST(1, 0, 0),
|
||||
WEST(-1, 0, 0);
|
||||
|
||||
|
||||
int dx;
|
||||
int dy;
|
||||
int dz;
|
||||
|
||||
Direction(int dx, int dy, int dz) {
|
||||
this.dx = dx;
|
||||
this.dy = dy;
|
||||
this.dz = dz;
|
||||
}
|
||||
|
||||
public static Direction getRandom() {
|
||||
return Direction.values()[random.nextInt(Direction.values().length)];
|
||||
}
|
||||
|
||||
Direction other() {
|
||||
switch (this) {
|
||||
case NORTH:
|
||||
return EAST;
|
||||
case SOUTH:
|
||||
return WEST;
|
||||
case EAST:
|
||||
return NORTH;
|
||||
case WEST:
|
||||
return SOUTH;
|
||||
default:
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren
Das StateDependent sollte nur die Sachen (de-)aktivieren, nicht das ganze Behaviour innehaben. Um die Nestung zu verringern: Nimm den ganzen Code bis auf die Enable und Disable und bewege den in die HellsBells-Klasse. (Also die übergeordnete)