HellsBells #275
@ -7,20 +7,43 @@ import de.steamwar.fightsystem.countdown.SWSound;
|
|||||||
import de.steamwar.fightsystem.states.FightState;
|
import de.steamwar.fightsystem.states.FightState;
|
||||||
import de.steamwar.fightsystem.states.StateDependent;
|
import de.steamwar.fightsystem.states.StateDependent;
|
||||||
import de.steamwar.fightsystem.winconditions.Winconditions;
|
import de.steamwar.fightsystem.winconditions.Winconditions;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import org.bukkit.Bukkit;
|
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.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
|
||||||
public class HellsBells {
|
public class HellsBells {
|
||||||
|
|
||||||
public static final Random random = new Random();
|
public static final Random random = new Random();
|
||||||
|
|
||||||
|
private enum Direction {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
|
|||||||
|
NORTH(0, 0, 1, true),
|
||||||
|
SOUTH(0, 0, -1, true),
|
||||||
|
EAST(1, 0, 0, false),
|
||||||
|
WEST(-1, 0, 0, false);
|
||||||
|
|
||||||
|
static final List<Direction> DIRECTIONS = Arrays.asList(values());
|
||||||
|
|
||||||
|
int dx;
|
||||||
|
int dy;
|
||||||
|
int dz;
|
||||||
|
boolean zLength;
|
||||||
|
|
||||||
|
Direction(int dx, int dy, int dz, boolean zLength) {
|
||||||
|
this.dx = dx;
|
||||||
|
this.dy = dy;
|
||||||
|
this.dz = dz;
|
||||||
|
this.zLength = zLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
Lixfel
hat
Subklassen bitte nach dem Inhalt der Hauptklasse. Subklassen bitte nach dem Inhalt der Hauptklasse.
|
|||||||
|
|
||||||
public HellsBells() {
|
public HellsBells() {
|
||||||
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
|
new StateDependent(Winconditions.HELLS_BELLS, FightState.Running) {
|
||||||
|
|
||||||
@ -93,26 +116,18 @@ public class HellsBells {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drop() {
|
public void drop() {
|
||||||
if (random.nextBoolean()) {
|
Direction direction = Direction.DIRECTIONS.get(random.nextInt(Direction.DIRECTIONS.size()));
|
||||||
sideRun(random.nextBoolean());
|
|
||||||
} else {
|
|
||||||
frontRun(random.nextBoolean());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
AtomicInteger length = new AtomicInteger(10 + random.nextInt((direction.zLength ? zLength : xLength) - 10));
|
||||||
private void sideRun(boolean invert) {
|
|
||||||
int length = 10 + random.nextInt(zLength - 10);
|
|
||||||
int width = 5 + random.nextInt(5);
|
int width = 5 + random.nextInt(5);
|
||||||
int xOffset = getWidthStart(xLength, width);
|
int xOffset = getWidthStart(direction.zLength ? xLength : zLength, width);
|
||||||
int zOffset = getLengthStart(zLength, length);
|
int zOffset = getLengthStart(direction.zLength ? zLength : xLength, length.get());
|
||||||
int yOffset = getHeightStart();
|
int yOffset = getHeightStart();
|
||||||
|
|
||||||
|
|
||||||
Point redStart;
|
Point redStart;
|
||||||
Point blueStart;
|
Point blueStart;
|
||||||
|
|
||||||
if (invert) {
|
if (direction == Direction.NORTH || direction == Direction.WEST) {
|
||||||
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);
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Gibt es nicht random.nextInt(MIN, MAX)? (kA) Gibt es nicht random.nextInt(MIN, MAX)? (kA)
YoyoNow
hat
Nein leider bietet die normale Random implementation dies nicht an. Nein leider bietet die normale Random implementation dies nicht an.
|
|||||||
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 {
|
||||||
@ -120,79 +135,24 @@ public class HellsBells {
|
|||||||
blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
|
blueStart = new Point(Config.BluePasteRegion.getMaxX() - xOffset, Config.BlueExtendRegion.getMaxY() + yOffset, Config.BluePasteRegion.getMaxZ() - zOffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
dropSideBombs(redStart, blueStart, width, new int[]{length}, invert);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dropSideBombs(Point redStart, Point blueStart, int width, int[] x, boolean invert) {
|
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Diesen if-Block kann man denke ich vereinfachen, wenn man stattdessen in den Assignments mit dem conditional-Operator arbeitet ?:. Diesen if-Block kann man denke ich vereinfachen, wenn man stattdessen in den Assignments mit dem conditional-Operator arbeitet ?:.
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (int z = 0; z < width; z++) {
|
for (int z = 0; z < width; z++) {
|
||||||
Lixfel
hat
Kann glaube noch private static sein. Kann glaube noch private static sein.
|
|||||||
if (invert) {
|
if (direction == Direction.NORTH || direction == Direction.WEST) {
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Könnte man statt diesen Ifs nicht einfach eine Methode in der Direction machen, die dann den passenden Wert zurückgibt? Könnte man statt diesen Ifs nicht einfach eine Methode in der Direction machen, die dann den passenden Wert zurückgibt?
|
|||||||
world.spawnEntity(redStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT);
|
world.spawnEntity(redStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT);
|
||||||
|
|
||||||
world.spawnEntity(blueStart.addAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT);
|
world.spawnEntity(blueStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT);
|
||||||
} else {
|
} else {
|
||||||
world.spawnEntity(redStart.addAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT);
|
world.spawnEntity(redStart.addAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT);
|
||||||
|
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Auch hier müsste das zu einer Methode in Direction umwandelbar sein. Auch hier müsste das zu einer Methode in Direction umwandelbar sein.
Lixfel
hat
Stat dem If-Block mit Subtract and add: Alle Werte mit Stat dem If-Block mit Subtract and add: Alle Werte mit `int factor = direction.isNorthOrWest() ? 1 : -1;` multiplizieren.
|
|||||||
world.spawnEntity(blueStart.subtractAndToLocation(world, x[0], 0, z), EntityType.PRIMED_TNT);
|
world.spawnEntity(blueStart.subtractAndToLocation(world, direction.dx * length.get(), 0, direction.dz * length.get()), EntityType.PRIMED_TNT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x[0] < 2) {
|
if (length.decrementAndGet() == 0) {
|
||||||
this.cancel();
|
cancel();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x[0] -= 2;
|
|
||||||
}
|
|
||||||
}.runTaskTimer(FightSystem.getPlugin(), 0, 4L);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void frontRun(boolean invert) {
|
|
||||||
int length = 10 + random.nextInt(xLength - 10);
|
|
||||||
int width = 5 + random.nextInt(5);
|
|
||||||
int xOffset = getWidthStart(zLength, length);
|
|
||||||
int zOffset = getLengthStart(xLength, width);
|
|
||||||
int yOffset = getHeightStart();
|
|
||||||
|
|
||||||
Point redStart;
|
|
||||||
Point blueStart;
|
|
||||||
|
|
||||||
if (invert) {
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
dropFrontBombs(redStart, blueStart, width, new int[]{length}, invert);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dropFrontBombs(Point redStart, Point blueStart, int width, int[] z, boolean invert) {
|
|
||||||
new BukkitRunnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (int x = 0; x < width; x++) {
|
|
||||||
if (invert) {
|
|
||||||
world.spawnEntity(redStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT);
|
|
||||||
|
|
||||||
world.spawnEntity(blueStart.addAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT);
|
|
||||||
} else {
|
|
||||||
world.spawnEntity(redStart.addAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT);
|
|
||||||
|
|
||||||
world.spawnEntity(blueStart.subtractAndToLocation(world, x, 0, z[0]), EntityType.PRIMED_TNT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (z[0] < 2) {
|
|
||||||
this.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
z[0] -= 2;
|
|
||||||
}
|
}
|
||||||
YoyoNow markierte diese Unterhaltung als gelöst
Veraltet
Lixfel
hat
Üblicherweise verwenden wir eher Bukkit...getScheduler().runTaskTimer(Plugin, lambda-Methode, Zeit(en)) Üblicherweise verwenden wir eher Bukkit...getScheduler().runTaskTimer(Plugin, lambda-Methode, Zeit(en))
|
|||||||
}.runTaskTimer(FightSystem.getPlugin(), 0, 4L);
|
}.runTaskTimer(FightSystem.getPlugin(), 0, 4L);
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren
Du kannst dafür nicht BlockFace verwenden?
In der 1.8 gibt es BlockFace mit dem toVector intern noch nicht.